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