Index: wp-admin/options-privacy.php =================================================================== --- wp-admin/options-privacy.php (revision 47259) +++ wp-admin/options-privacy.php (working copy) @@ -13,25 +13,34 @@ wp_die( __( 'Sorry, you are not allowed to manage privacy on this site.' ) ); } -$action = isset( $_POST['action'] ) ? $_POST['action'] : ''; +$title = __( 'Privacy Settings' ); +$parent_file = 'options-general.php'; +$action = isset( $_POST['action'] ) ? $_POST['action'] : ''; +$option_page = isset( $_POST['option_page'] ) ? $_POST['option_page'] : ''; + +global $wpdb; + if ( ! empty( $action ) ) { - check_admin_referer( $action ); + check_admin_referer( $option_page . '-options' ); - if ( 'set-privacy-page' === $action ) { - $privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0; + $update_page = ( isset( $_POST['page_for_privacy_policy'] ) && ( $_POST['page_for_privacy_policy'] != get_option( 'wp_page_for_privacy_policy' ) ) ); + $create_page = isset( $_POST['create_privacy_page'] ); + + if ( $update_page ) { + $privacy_policy_page_id = (int) $_POST['page_for_privacy_policy']; update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); $privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' ); if ( $privacy_policy_page_id ) { - /* - * Don't always link to the menu customizer: - * - * - Unpublished pages can't be selected by default. - * - `WP_Customize_Nav_Menus::__construct()` checks the user's capabilities. - * - Themes might not "officially" support menus. - */ + /* + * Don't always link to the menu customizer: + * + * - Unpublished pages can't be selected by default. + * - `WP_Customize_Nav_Menus::__construct()` checks the user's capabilities. + * - Themes might not "officially" support menus. + */ if ( 'publish' === get_post_status( $privacy_policy_page_id ) && current_user_can( 'edit_theme_options' ) @@ -43,19 +52,22 @@ esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) ) ); } - } + } + if ( !$create_page ) add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' ); + } - add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' ); - } elseif ( 'create-privacy-page' === $action ) { + if ( $create_page ) { if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php'; } + $has_pages_with_default_title = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status IN ( 'publish', 'draft' ) AND post_title = %s;", 'page', __( 'Privacy Policy' ) ) ); + $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content(); $privacy_policy_page_id = wp_insert_post( array( - 'post_title' => __( 'Privacy Policy' ), + 'post_title' => ( $has_pages_with_default_title ) ? sprintf( __( 'Privacy Policy (%1$d)' ), $has_pages_with_default_title + 1 ) : __( 'Privacy Policy' ), 'post_status' => 'draft', 'post_type' => 'page', 'post_content' => $privacy_policy_page_content, @@ -70,19 +82,20 @@ __( 'Unable to create a Privacy Policy page.' ), 'error' ); + $privacy_policy_page_id = false; } else { update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); - - wp_redirect( admin_url( 'post.php?post=' . $privacy_policy_page_id . '&action=edit' ) ); - exit; + add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', __( 'Privacy Policy page created successfully.' ), 'success' ); } } } // If a Privacy Policy page ID is available, make sure the page actually exists. If not, display an error. -$privacy_policy_page_exists = false; -$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); +$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); + +$tools_privacy_edit = ''; + if ( ! empty( $privacy_policy_page_id ) ) { $privacy_policy_page = get_post( $privacy_policy_page_id ); @@ -94,8 +107,7 @@ __( 'The currently selected Privacy Policy page does not exist. Please create or select a new page.' ), 'error' ); - } else { - if ( 'trash' === $privacy_policy_page->post_status ) { + } elseif ( 'trash' === $privacy_policy_page->post_status ) { add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', @@ -106,36 +118,8 @@ ), 'error' ); - } else { - $privacy_policy_page_exists = true; - } - } -} + } else { /* $privacy_policy_page_exists = true; */ -$title = __( 'Privacy Settings' ); -$parent_file = 'options-general.php'; - -require_once ABSPATH . 'wp-admin/admin-header.php'; - -?> -
- - -
-- - -
-- - -
- $privacy_policy_page_id, @@ -145,110 +129,124 @@ ); $view_href = get_permalink( $privacy_policy_page_id ); - ?> -- Edit or view your Privacy Policy page content.' ), + + if ( $create_page ) { + $privacy_page_create_message = sprintf( + /* translators: 1: URL to edit Privacy Policy page, 2: URL to preview Privacy Policy page, 3: URL to Customizer -> Menus */ + __( 'You can already edit or preview your Privacy Policy page content. Remember to update your menus!' ), esc_url( $edit_href ), + esc_url( $view_href ), + esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) ) + ); + add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_create_message, 'success' ); + + } else { + $tools_privacy_edit = ( 'publish' === get_post_status( $privacy_policy_page_id ) ) + ? sprintf( + /* translators: 1: URL to edit Privacy Policy page, 2: URL to view Privacy Policy page. */ + __( 'You can already edit or view your Privacy Policy page content.' ), + esc_url( $edit_href ), esc_url( $view_href ) - ); - } else { - printf( - /* translators: 1: URL to edit Privacy Policy page, 2: URL to preview Privacy Policy page. */ - __( 'Edit or preview your Privacy Policy page content.' ), - esc_url( $edit_href ), - esc_url( $view_href ) - ); - } - ?> -
- edit or preview your Privacy Policy page content.' ), + esc_url( $edit_href ), + esc_url( $view_href ) + ); + } } - ?> -- Check out our guide%3$s for recommendations on what content to include, along with policies suggested by your plugins and theme.' ), - esc_url( admin_url( 'privacy-policy-guide.php' ) ), - '', - '' - ); - ?> -
+} -- - | -
- 'page',
- 'posts_per_page' => 1,
- 'post_status' => array(
- 'publish',
- 'draft',
- ),
- )
- );
- if ( $has_pages ) :
- ?>
-
-
+get_current_screen()->set_help_sidebar(
+ ' ' . __( 'For more information:' ) . ' ' . + /* translators: 1: Privacy Policy guide URL */ + '' . sprintf( __( 'Privacy Policy guide' ), esc_url( admin_url( 'privacy-policy-guide.php' ) ) ) . ' ' . + '' . __( 'Documentation on Privacy Settings' ) . ' ' . + '' . __( 'Support' ) . ' ' +); - - |
-
---|