[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> options-privacy.php (source)

   1  <?php
   2  /**
   3   * Privacy Settings Screen.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once  __DIR__ . '/admin.php';
  11  
  12  if ( ! current_user_can( 'manage_privacy_options' ) ) {
  13      wp_die( __( 'Sorry, you are not allowed to manage privacy options on this site.' ) );
  14  }
  15  
  16  if ( isset( $_GET['tab'] ) && 'policyguide' === $_GET['tab'] ) {
  17      require_once  __DIR__ . '/privacy-policy-guide.php';
  18      return;
  19  }
  20  
  21  // Used in the HTML title tag.
  22  $title = __( 'Privacy' );
  23  
  24  add_filter(
  25      'admin_body_class',
  26      static function ( $body_class ) {
  27          $body_class .= ' privacy-settings ';
  28  
  29          return $body_class;
  30      }
  31  );
  32  
  33  $action = $_POST['action'] ?? '';
  34  
  35  get_current_screen()->add_help_tab(
  36      array(
  37          'id'      => 'overview',
  38          'title'   => __( 'Overview' ),
  39          'content' =>
  40                  '<p>' . __( 'The Privacy screen lets you either build a new privacy-policy page or choose one you already have to show.' ) . '</p>' .
  41                  '<p>' . __( 'This screen includes suggestions to help you write your own privacy policy. However, it is your responsibility to use these resources correctly, to provide the information required by your privacy policy, and to keep this information current and accurate.' ) . '</p>',
  42      )
  43  );
  44  
  45  get_current_screen()->set_help_sidebar(
  46      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  47      '<p>' . __( '<a href="https://wordpress.org/documentation/article/settings-privacy-screen/">Documentation on Privacy Settings</a>' ) . '</p>'
  48  );
  49  
  50  if ( ! empty( $action ) ) {
  51      check_admin_referer( $action );
  52  
  53      if ( 'set-privacy-page' === $action ) {
  54          $previous_privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
  55          $privacy_policy_page_id          = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0;
  56          update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id );
  57  
  58          $privacy_page_message_type = 'success';
  59  
  60          if ( $privacy_policy_page_id ) {
  61              $privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' );
  62  
  63              /*
  64               * Don't always link to the menu customizer:
  65               *
  66               * - Unpublished pages can't be selected by default.
  67               * - `WP_Customize_Nav_Menus::__construct()` checks the user's capabilities.
  68               * - Themes might not "officially" support menus.
  69               */
  70              if (
  71                  'publish' === get_post_status( $privacy_policy_page_id )
  72                  && current_user_can( 'edit_theme_options' )
  73                  && current_theme_supports( 'menus' )
  74              ) {
  75                  $privacy_page_updated_message = sprintf(
  76                      /* translators: %s: URL to Customizer -> Menus. */
  77                      __( 'Privacy Policy page setting updated successfully. Remember to <a href="%s">update your menus</a>!' ),
  78                      esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) )
  79                  );
  80              }
  81          } elseif ( $previous_privacy_policy_page_id ) {
  82              // A previously set Privacy Policy page was cleared.
  83              $privacy_page_updated_message = __( 'Privacy Policy page removed.' );
  84          } else {
  85              // No Privacy Policy page was set before, and none is set now.
  86              $privacy_page_updated_message = __( 'No Privacy Policy page is currently set.' );
  87              $privacy_page_message_type    = 'info';
  88          }
  89  
  90          add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, $privacy_page_message_type );
  91      } elseif ( 'create-privacy-page' === $action ) {
  92  
  93          if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
  94              require_once  ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
  95          }
  96  
  97          $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content();
  98          $privacy_policy_page_id      = wp_insert_post(
  99              array(
 100                  'post_title'   => __( 'Privacy Policy' ),
 101                  'post_status'  => 'draft',
 102                  'post_type'    => 'page',
 103                  'post_content' => $privacy_policy_page_content,
 104              ),
 105              true
 106          );
 107  
 108          if ( is_wp_error( $privacy_policy_page_id ) ) {
 109              add_settings_error(
 110                  'page_for_privacy_policy',
 111                  'page_for_privacy_policy',
 112                  __( 'Unable to create a Privacy Policy page.' ),
 113                  'error'
 114              );
 115          } else {
 116              update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id );
 117  
 118              wp_redirect( admin_url( 'post.php?post=' . $privacy_policy_page_id . '&action=edit' ) );
 119              exit;
 120          }
 121      }
 122  }
 123  
 124  // If a Privacy Policy page ID is available, make sure the page actually exists. If not, display an error.
 125  $privacy_policy_page_exists = false;
 126  $privacy_policy_page_id     = (int) get_option( 'wp_page_for_privacy_policy' );
 127  
 128  if ( ! empty( $privacy_policy_page_id ) ) {
 129  
 130      $privacy_policy_page = get_post( $privacy_policy_page_id );
 131  
 132      if ( ! $privacy_policy_page instanceof WP_Post ) {
 133          add_settings_error(
 134              'page_for_privacy_policy',
 135              'page_for_privacy_policy',
 136              __( 'The currently selected Privacy Policy page does not exist. Please create or select a new page.' ),
 137              'error'
 138          );
 139      } else {
 140          if ( 'trash' === $privacy_policy_page->post_status ) {
 141              add_settings_error(
 142                  'page_for_privacy_policy',
 143                  'page_for_privacy_policy',
 144                  sprintf(
 145                      /* translators: %s: URL to Pages Trash. */
 146                      __( 'The currently selected Privacy Policy page is in the Trash. Please create or select a new Privacy Policy page or <a href="%s">restore the current page</a>.' ),
 147                      'edit.php?post_status=trash&post_type=page'
 148                  ),
 149                  'error'
 150              );
 151          } else {
 152              $privacy_policy_page_exists = true;
 153          }
 154      }
 155  }
 156  
 157  $parent_file = 'options-general.php';
 158  
 159  wp_enqueue_script( 'privacy-tools' );
 160  
 161  require_once  ABSPATH . 'wp-admin/admin-header.php';
 162  
 163  ?>
 164  <div class="privacy-settings-header">
 165      <div class="privacy-settings-title-section">
 166          <h1>
 167              <?php _e( 'Privacy' ); ?>
 168          </h1>
 169      </div>
 170  
 171      <nav class="privacy-settings-tabs-wrapper hide-if-no-js" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
 172          <a href="<?php echo esc_url( admin_url( 'options-privacy.php' ) ); ?>" class="privacy-settings-tab active" aria-current="true">
 173              <?php
 174              /* translators: Tab heading for Site Health Status page. */
 175              _ex( 'Settings', 'Privacy Settings' );
 176              ?>
 177          </a>
 178  
 179          <a href="<?php echo esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) ); ?>" class="privacy-settings-tab">
 180              <?php
 181              /* translators: Tab heading for Site Health Status page. */
 182              _ex( 'Policy Guide', 'Privacy Settings' );
 183              ?>
 184          </a>
 185      </nav>
 186  </div>
 187  
 188  <hr class="wp-header-end">
 189  
 190  <?php
 191  wp_admin_notice(
 192      __( 'The Privacy Settings require JavaScript.' ),
 193      array(
 194          'type'               => 'error',
 195          'additional_classes' => array( 'hide-if-js' ),
 196      )
 197  );
 198  ?>
 199  
 200  <div class="privacy-settings-body hide-if-no-js">
 201      <h2><?php _e( 'Privacy Settings' ); ?></h2>
 202      <p>
 203          <?php _e( 'As a website owner, you may need to follow national or international privacy laws. For example, you may need to create and display a privacy policy.' ); ?>
 204          <?php _e( 'If you already have a Privacy Policy page, please select it below. If not, please create one.' ); ?>
 205      </p>
 206      <p>
 207          <?php _e( 'The new page will include help and suggestions for your privacy policy.' ); ?>
 208          <?php _e( 'However, it is your responsibility to use those resources correctly, to provide the information that your privacy policy requires, and to keep that information current and accurate.' ); ?>
 209      </p>
 210      <p>
 211          <?php _e( 'After your Privacy Policy page is set, you should edit it.' ); ?>
 212          <?php _e( 'You should also review your privacy policy from time to time, especially after installing or updating any themes or plugins. There may be changes or new suggested information for you to consider adding to your policy.' ); ?>
 213      </p>
 214      <p>
 215          <?php
 216          if ( $privacy_policy_page_exists ) {
 217              $edit_href = add_query_arg(
 218                  array(
 219                      'post'   => $privacy_policy_page_id,
 220                      'action' => 'edit',
 221                  ),
 222                  admin_url( 'post.php' )
 223              );
 224              $view_href = get_permalink( $privacy_policy_page_id );
 225              ?>
 226                  <strong>
 227                  <?php
 228                  if ( 'publish' === get_post_status( $privacy_policy_page_id ) ) {
 229                      printf(
 230                          /* translators: 1: URL to edit Privacy Policy page, 2: URL to view Privacy Policy page. */
 231                          __( '<a href="%1$s">Edit</a> or <a href="%2$s">view</a> your Privacy Policy page content.' ),
 232                          esc_url( $edit_href ),
 233                          esc_url( $view_href )
 234                      );
 235                  } else {
 236                      printf(
 237                          /* translators: 1: URL to edit Privacy Policy page, 2: URL to preview Privacy Policy page. */
 238                          __( '<a href="%1$s">Edit</a> or <a href="%2$s">preview</a> your Privacy Policy page content.' ),
 239                          esc_url( $edit_href ),
 240                          esc_url( $view_href )
 241                      );
 242                  }
 243                  ?>
 244                  </strong>
 245              <?php
 246          }
 247          printf(
 248              /* translators: 1: Privacy Policy guide URL, 2: Additional link attributes, 3: Accessibility text. */
 249              __( 'Need help putting together your new Privacy Policy page? <a href="%1$s" %2$s>Check out the privacy policy guide%3$s</a> for recommendations on what content to include, along with policies suggested by your plugins and theme.' ),
 250              esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) ),
 251              '',
 252              ''
 253          );
 254          ?>
 255      </p>
 256      <hr>
 257      <?php
 258      $has_pages = (bool) get_posts(
 259          array(
 260              'post_type'      => 'page',
 261              'posts_per_page' => 1,
 262              'post_status'    => array(
 263                  'publish',
 264                  'draft',
 265              ),
 266          )
 267      );
 268      ?>
 269      <table class="form-table tools-privacy-policy-page" role="presentation">
 270          <tr>
 271              <th scope="row">
 272                  <label for="create-page">
 273                  <?php
 274                  if ( $has_pages ) {
 275                      _e( 'Create a new Privacy Policy page' );
 276                  } else {
 277                      _e( 'There are no pages.' );
 278                  }
 279                  ?>
 280                  </label>
 281              </th>
 282              <td>
 283                  <form class="wp-create-privacy-page" method="post">
 284                      <input type="hidden" name="action" value="create-privacy-page" />
 285                      <?php
 286                      wp_nonce_field( 'create-privacy-page' );
 287                      submit_button( __( 'Create' ), 'secondary', 'submit', false, array( 'id' => 'create-page' ) );
 288                      ?>
 289                  </form>
 290              </td>
 291          </tr>
 292          <?php if ( $has_pages ) : ?>
 293          <tr>
 294              <th scope="row">
 295                  <label for="page_for_privacy_policy">
 296                      <?php
 297                      if ( $privacy_policy_page_exists ) {
 298                          _e( 'Change your Privacy Policy page' );
 299                      } else {
 300                          _e( 'Select a Privacy Policy page' );
 301                      }
 302                      ?>
 303                  </label>
 304              </th>
 305              <td>
 306                  <form method="post">
 307                      <input type="hidden" name="action" value="set-privacy-page" />
 308                      <?php
 309                      wp_dropdown_pages(
 310                          array(
 311                              'name'              => 'page_for_privacy_policy',
 312                              'show_option_none'  => __( '&mdash; Select &mdash;' ),
 313                              'option_none_value' => '0',
 314                              'selected'          => $privacy_policy_page_id,
 315                              'post_status'       => array( 'draft', 'publish' ),
 316                          )
 317                      );
 318  
 319                      wp_nonce_field( 'set-privacy-page' );
 320  
 321                      submit_button( __( 'Use This Page' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) );
 322                      ?>
 323                  </form>
 324              </td>
 325          </tr>
 326          <?php endif; ?>
 327      </table>
 328  </div>
 329  <?php
 330  
 331  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Wed Aug 12 08:20:21 2026 Cross-referenced by PHPXref