Make WordPress Core

Ticket #46829: 46829.2.diff

File 46829.2.diff, 2.9 KB (added by audrasjb, 4 years ago)

Coding standards + add condition if check if the privacy policy page exists

  • src/wp-includes/class-wp-customize-nav-menus.php

    diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php
    index 3348aab..49edb15 100644
    a b final class WP_Customize_Nav_Menus { 
    139139         */
    140140        public function load_available_items_query( $type = 'post_type', $object = 'page', $page = 0 ) {
    141141                $items = array();
     142                $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    142143
    143144                if ( 'post_type' === $type ) {
    144145                        $post_type = get_post_type_object( $object );
    final class WP_Customize_Nav_Menus { 
    156157                                        'object'     => '',
    157158                                        'url'        => home_url(),
    158159                                );
     160
     161                                // Add "Privacy Policy" link. Treat as a page, but switch to custom on add.
     162                                if ( ! empty( $privacy_policy_page_id ) ) {
     163                                        $items[] = array(
     164                                                'id'         => 'privacy-policy',
     165                                                'title'      => _x( 'Privacy Policy', 'nav menu privacy policy page label' ),
     166                                                'type'       => 'custom',
     167                                                'type_label' => _x( 'Privacy Policy', 'nav menu privacy policy page label' ),
     168                                                'object'     => '',
     169                                                'url'        => get_permalink( $privacy_policy_page_id ),
     170                                        );
     171                                }
    159172                        } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) {
    160173                                // Add a post type archive link.
    161174                                $items[] = array(
    final class WP_Customize_Nav_Menus { 
    188201                                                'orderby'     => 'date',
    189202                                                'order'       => 'DESC',
    190203                                                'post_type'   => $object,
     204                                                'exclude'     => array( $privacy_policy_page_id ),
    191205                                        )
    192206                                )
    193207                        );
    final class WP_Customize_Nav_Menus { 
    305319        public function search_available_items_query( $args = array() ) {
    306320                $items = array();
    307321
     322                $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    308323                $post_type_objects = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
    309324                $query             = array(
    310325                        'post_type'              => array_keys( $post_type_objects ),
    final class WP_Customize_Nav_Menus { 
    313328                        'update_post_meta_cache' => false,
    314329                        'post_status'            => 'publish',
    315330                        'posts_per_page'         => 20,
     331                        'post__not_in'           => array( $privacy_policy_page_id ),
    316332                );
    317333
    318334                $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
    final class WP_Customize_Nav_Menus { 
    402418                                        'url'        => home_url(),
    403419                                );
    404420                        }
     421
     422                        $title   = _x( 'Privacy Policy', 'nav menu privacy policy page label' );
     423                        $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] );
     424                        if ( $matches ) {
     425                                $items[] = array(
     426                                        'id'         => 'privacy-policy',
     427                                        'title'      => $title,
     428                                        'type'       => 'custom',
     429                                        'type_label' => $title,
     430                                        'object'     => '',
     431                                        'url'        => get_permalink( $privacy_policy_page_id ),
     432                                );
     433                        }
    405434                }
    406435
    407436                /**