options-privacy.php (9314B)
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 dirname( __FILE__ ) . '/privacy-policy-guide.php'; 18 return; 19 } 20 21 add_filter( 22 'admin_body_class', 23 function( $body_class ) { 24 $body_class .= ' privacy-settings '; 25 26 return $body_class; 27 } 28 ); 29 30 $action = isset( $_POST['action'] ) ? $_POST['action'] : ''; 31 32 if ( ! empty( $action ) ) { 33 check_admin_referer( $action ); 34 35 if ( 'set-privacy-page' === $action ) { 36 $privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0; 37 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); 38 39 $privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' ); 40 41 if ( $privacy_policy_page_id ) { 42 /* 43 * Don't always link to the menu customizer: 44 * 45 * - Unpublished pages can't be selected by default. 46 * - `WP_Customize_Nav_Menus::__construct()` checks the user's capabilities. 47 * - Themes might not "officially" support menus. 48 */ 49 if ( 50 'publish' === get_post_status( $privacy_policy_page_id ) 51 && current_user_can( 'edit_theme_options' ) 52 && current_theme_supports( 'menus' ) 53 ) { 54 $privacy_page_updated_message = sprintf( 55 /* translators: %s: URL to Customizer -> Menus. */ 56 __( 'Privacy Policy page setting updated successfully. Remember to <a href="%s">update your menus</a>!' ), 57 esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) ) 58 ); 59 } 60 } 61 62 add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' ); 63 } elseif ( 'create-privacy-page' === $action ) { 64 65 if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { 66 require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php'; 67 } 68 69 $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content(); 70 $privacy_policy_page_id = wp_insert_post( 71 array( 72 'post_title' => __( 'Privacy Policy' ), 73 'post_status' => 'draft', 74 'post_type' => 'page', 75 'post_content' => $privacy_policy_page_content, 76 ), 77 true 78 ); 79 80 if ( is_wp_error( $privacy_policy_page_id ) ) { 81 add_settings_error( 82 'page_for_privacy_policy', 83 'page_for_privacy_policy', 84 __( 'Unable to create a Privacy Policy page.' ), 85 'error' 86 ); 87 } else { 88 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); 89 90 wp_redirect( admin_url( 'post.php?post=' . $privacy_policy_page_id . '&action=edit' ) ); 91 exit; 92 } 93 } 94 } 95 96 // If a Privacy Policy page ID is available, make sure the page actually exists. If not, display an error. 97 $privacy_policy_page_exists = false; 98 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 99 100 if ( ! empty( $privacy_policy_page_id ) ) { 101 102 $privacy_policy_page = get_post( $privacy_policy_page_id ); 103 104 if ( ! $privacy_policy_page instanceof WP_Post ) { 105 add_settings_error( 106 'page_for_privacy_policy', 107 'page_for_privacy_policy', 108 __( 'The currently selected Privacy Policy page does not exist. Please create or select a new page.' ), 109 'error' 110 ); 111 } else { 112 if ( 'trash' === $privacy_policy_page->post_status ) { 113 add_settings_error( 114 'page_for_privacy_policy', 115 'page_for_privacy_policy', 116 sprintf( 117 /* translators: %s: URL to Pages Trash. */ 118 __( '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>.' ), 119 'edit.php?post_status=trash&post_type=page' 120 ), 121 'error' 122 ); 123 } else { 124 $privacy_policy_page_exists = true; 125 } 126 } 127 } 128 129 $parent_file = 'options-general.php'; 130 131 wp_enqueue_script( 'privacy-tools' ); 132 133 require_once ABSPATH . 'wp-admin/admin-header.php'; 134 135 ?> 136 <div class="privacy-settings-header"> 137 <div class="privacy-settings-title-section"> 138 <h1> 139 <?php _e( 'Privacy' ); ?> 140 </h1> 141 </div> 142 143 <nav class="privacy-settings-tabs-wrapper hide-if-no-js" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>"> 144 <a href="<?php echo esc_url( admin_url( 'options-privacy.php' ) ); ?>" class="privacy-settings-tab active" aria-current="true"> 145 <?php 146 /* translators: Tab heading for Site Health Status page. */ 147 _ex( 'Settings', 'Privacy Settings' ); 148 ?> 149 </a> 150 151 <a href="<?php echo esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) ); ?>" class="privacy-settings-tab"> 152 <?php 153 /* translators: Tab heading for Site Health Status page. */ 154 _ex( 'Policy Guide', 'Privacy Settings' ); 155 ?> 156 </a> 157 </nav> 158 </div> 159 160 <hr class="wp-header-end"> 161 162 <div class="notice notice-error hide-if-js"> 163 <p><?php _e( 'The Privacy Settings require JavaScript.' ); ?></p> 164 </div> 165 166 <div class="privacy-settings-body hide-if-no-js"> 167 <h2><?php _e( 'Privacy Settings' ); ?></h2> 168 <p> 169 <?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.' ); ?> 170 <?php _e( 'If you already have a Privacy Policy page, please select it below. If not, please create one.' ); ?> 171 </p> 172 <p> 173 <?php _e( 'The new page will include help and suggestions for your Privacy Policy.' ); ?> 174 <?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.' ); ?> 175 </p> 176 <p> 177 <?php _e( 'After your Privacy Policy page is set, we suggest that you edit it.' ); ?> 178 <?php _e( 'We would also suggest reviewing 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.' ); ?> 179 </p> 180 <p> 181 <?php 182 if ( $privacy_policy_page_exists ) { 183 $edit_href = add_query_arg( 184 array( 185 'post' => $privacy_policy_page_id, 186 'action' => 'edit', 187 ), 188 admin_url( 'post.php' ) 189 ); 190 $view_href = get_permalink( $privacy_policy_page_id ); 191 ?> 192 <strong> 193 <?php 194 if ( 'publish' === get_post_status( $privacy_policy_page_id ) ) { 195 printf( 196 /* translators: 1: URL to edit Privacy Policy page, 2: URL to view Privacy Policy page. */ 197 __( '<a href="%1$s">Edit</a> or <a href="%2$s">view</a> your Privacy Policy page content.' ), 198 esc_url( $edit_href ), 199 esc_url( $view_href ) 200 ); 201 } else { 202 printf( 203 /* translators: 1: URL to edit Privacy Policy page, 2: URL to preview Privacy Policy page. */ 204 __( '<a href="%1$s">Edit</a> or <a href="%2$s">preview</a> your Privacy Policy page content.' ), 205 esc_url( $edit_href ), 206 esc_url( $view_href ) 207 ); 208 } 209 ?> 210 </strong> 211 <?php 212 } 213 printf( 214 /* translators: 1: Privacy Policy guide URL, 2: Additional link attributes, 3: Accessibility text. */ 215 __( 'Need help putting together your new Privacy Policy page? <a href="%1$s" %2$s>Check out our Privacy Policy guide%3$s</a> for recommendations on what content to include, along with policies suggested by your plugins and theme.' ), 216 esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) ), 217 '', 218 '' 219 ); 220 ?> 221 </p> 222 <hr> 223 <?php 224 $has_pages = (bool) get_posts( 225 array( 226 'post_type' => 'page', 227 'posts_per_page' => 1, 228 'post_status' => array( 229 'publish', 230 'draft', 231 ), 232 ) 233 ); 234 ?> 235 <table class="form-table tools-privacy-policy-page" role="presentation"> 236 <tr> 237 <th scope="row"> 238 <label for="create-page"> 239 <?php 240 if ( $has_pages ) { 241 _e( 'Create a new Privacy Policy Page' ); 242 } else { 243 _e( 'There are no pages.' ); 244 } 245 ?> 246 </label> 247 </th> 248 <td> 249 <form class="wp-create-privacy-page" method="post" action=""> 250 <input type="hidden" name="action" value="create-privacy-page" /> 251 <?php 252 wp_nonce_field( 'create-privacy-page' ); 253 submit_button( __( 'Create' ), 'secondary', 'submit', false, array( 'id' => 'create-page' ) ); 254 ?> 255 </form> 256 </td> 257 </tr> 258 <?php if ( $has_pages ) : ?> 259 <tr> 260 <th scope="row"> 261 <label for="page_for_privacy_policy"> 262 <?php 263 if ( $privacy_policy_page_exists ) { 264 _e( 'Change your Privacy Policy page' ); 265 } else { 266 _e( 'Select a Privacy Policy page' ); 267 } 268 ?> 269 </label> 270 </th> 271 <td> 272 <form method="post" action=""> 273 <input type="hidden" name="action" value="set-privacy-page" /> 274 <?php 275 wp_dropdown_pages( 276 array( 277 'name' => 'page_for_privacy_policy', 278 'show_option_none' => __( '— Select —' ), 279 'option_none_value' => '0', 280 'selected' => $privacy_policy_page_id, 281 'post_status' => array( 'draft', 'publish' ), 282 ) 283 ); 284 285 wp_nonce_field( 'set-privacy-page' ); 286 287 submit_button( __( 'Use This Page' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) ); 288 ?> 289 </form> 290 </td> 291 </tr> 292 <?php endif; ?> 293 </table> 294 </div> 295 <?php 296 297 require_once ABSPATH . 'wp-admin/admin-footer.php';