Skip to:
Content

BuddyPress.org

Ticket #8470: 8470.patch

File 8470.patch, 13.4 KB (added by imath, 5 years ago)
  • src/bp-activity/classes/class-bp-activity-component.php

    diff --git src/bp-activity/classes/class-bp-activity-component.php src/bp-activity/classes/class-bp-activity-component.php
    index d44879fd3..93f441351 100644
    class BP_Activity_Component extends BP_Component { 
    502502                        )
    503503                );
    504504        }
     505
     506        /**
     507         * Add the Activity directory state.
     508         *
     509         * @since 8.0.0
     510         *
     511         * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
     512         * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
     513         * @return array          See BP_Component::admin_directory_states() for description.
     514         */
     515        public function admin_directory_states( $states = array(), $post = null ) {
     516                $bp = buddypress();
     517
     518                if ( isset( $bp->pages->activity->id ) && (int) $bp->pages->activity->id === (int) $post->ID ) {
     519                        $states['page_for_activity_directory'] = _x( 'BP Activity Page', 'page label', 'buddypress' );
     520                }
     521
     522                return parent::admin_directory_states( $states, $post );
     523        }
    505524}
  • src/bp-blogs/classes/class-bp-blogs-component.php

    diff --git src/bp-blogs/classes/class-bp-blogs-component.php src/bp-blogs/classes/class-bp-blogs-component.php
    index 9ad5e6d1f..749c91ef0 100644
    class BP_Blogs_Component extends BP_Component { 
    379379
    380380                parent::rest_api_init( $controllers );
    381381        }
     382
     383        /**
     384         * Add the Sites directory states.
     385         *
     386         * @since 8.0.0
     387         *
     388         * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
     389         * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
     390         * @return array          See BP_Component::admin_directory_states() for description.
     391         */
     392        public function admin_directory_states( $states = array(), $post = null ) {
     393                $bp = buddypress();
     394
     395                if ( isset( $bp->pages->blogs->id ) && (int) $bp->pages->blogs->id === (int) $post->ID ) {
     396                        $states['page_for_sites_directory'] = _x( 'BP Sites Page', 'page label', 'buddypress' );
     397                }
     398
     399                return parent::admin_directory_states( $states, $post );
     400        }
    382401}
  • src/bp-core/admin/bp-core-admin-actions.php

    diff --git src/bp-core/admin/bp-core-admin-actions.php src/bp-core/admin/bp-core-admin-actions.php
    index 68e5d30b0..3c7fae966 100644
    add_action( 'bp_admin_init', 'bp_do_activation_redirect', 1 ); 
    5959// Add a new separator.
    6060add_action( 'bp_admin_menu', 'bp_admin_separator' );
    6161
     62// Add a filter to include BP Components directory pages display states.
     63add_filter( 'display_post_states', 'bp_admin_display_directory_states', 10, 2 );
     64
    6265/**
    6366 * When a new site is created in a multisite installation, run the activation
    6467 * routine on that site.
    function bp_register_admin_settings() { 
    234237         */
    235238        do_action( 'bp_register_admin_settings' );
    236239}
     240
     241/**
     242 * Dedicated filter to inform about BP components directory page states.
     243 *
     244 * @since 8.0.0
     245 *
     246 * @param string[] $post_states An array of post display states.
     247 * @param WP_Post  $post        The current post object.
     248 */
     249function bp_admin_display_directory_states( $post_states = array(), $post = null ) {
     250        /**
     251         * Filter here to add BP Directory pages.
     252         *
     253         * Used internaly by BP_Component->admin_directory_states(). Please use the dynamic
     254         * filter in BP_Component->admin_directory_states() to edit the directory state
     255         * according to the component's ID.
     256         *
     257         * @since 8.0.0
     258         *
     259         * @param array    $value An empty array.
     260         * @param WP_Post  $post  The current post object.
     261         */
     262        $directory_page_states = apply_filters( 'bp_admin_display_directory_states', array(), $post );
     263
     264        if ( $directory_page_states ) {
     265                $post_states = array_merge( $post_states, $directory_page_states );
     266        }
     267
     268        return $post_states;
     269}
  • src/bp-core/admin/bp-core-admin-slugs.php

    diff --git src/bp-core/admin/bp-core-admin-slugs.php src/bp-core/admin/bp-core-admin-slugs.php
    index 52ef6e36c..432b6f409 100644
    function bp_core_admin_slugs_options() { 
    117117        // Set up an array of components (along with component names) that have directory pages.
    118118        $directory_pages = bp_core_admin_get_directory_pages();
    119119
    120         if ( !empty( $directory_pages ) ) : ?>
     120        if ( ! empty( $directory_pages ) ) : ?>
    121121
    122                 <h3><?php _e( 'Directories', 'buddypress' ); ?></h3>
     122                <h3><?php esc_html_e( 'Directories', 'buddypress' ); ?></h3>
    123123
    124                 <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
     124                <p><?php esc_html_e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
    125125
    126126                <table class="form-table">
    127127                        <tbody>
    function bp_core_admin_slugs_options() { 
    141141                                                                'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
    142142                                                                'echo'             => false,
    143143                                                                'show_option_none' => __( '- None -', 'buddypress' ),
    144                                                                 'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
     144                                                                'selected'         => ! empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
    145145                                                        ) ); ?>
    146146
    147147                                                        <?php if ( ! empty( $existing_pages[ $name ] ) && get_post( $existing_pages[ $name ] ) ) : ?>
    148148
    149149                                                                <a href="<?php echo esc_url( get_permalink( $existing_pages[$name] ) ); ?>" class="button-secondary" target="_bp">
    150                                                                         <?php _e( 'View', 'buddypress' ); ?> <span class="dashicons dashicons-external" aria-hidden="true"></span>
     150                                                                        <?php esc_html_e( 'View', 'buddypress' ); ?> <span class="dashicons dashicons-external" aria-hidden="true"></span>
    151151                                                                        <span class="screen-reader-text"><?php esc_html_e( '(opens in a new tab)', 'buddypress' ); ?></span>
    152152                                                                </a>
    153153
    function bp_core_admin_slugs_options() { 
    185185
    186186        if ( !empty( $static_pages ) ) : ?>
    187187
    188                 <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
     188                <h3><?php esc_html_e( 'Registration', 'buddypress' ); ?></h3>
    189189
    190190                <?php if ( bp_get_signup_allowed() || bp_get_members_invitations_allowed() ) : ?>
    191                         <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
     191                        <p>
     192                                <?php esc_html_e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?>
     193                                <?php esc_html_e( 'These pages will only be reachable by users who are not logged in.', 'buddypress' ); ?>
     194                        </p>
    192195                <?php else : ?>
    193196                        <?php if ( is_multisite() ) : ?>
    194197                                <p>
    195198                                        <?php
    196                                         /* translators: %s: the link to the Network settings page */
    197                                         printf( __( 'Registration is currently disabled.  Before associating a page is allowed, please enable registration by selecting either the "User accounts may be registered" or "Both sites and user accounts can be registered" option on <a href="%s">this page</a>.', 'buddypress' ), network_admin_url( 'settings.php' ) );
     199                                        printf(
     200                                                /* translators: %s: the link to the Network settings page */
     201                                                esc_html_x( 'Registration is currently disabled.  Before associating a page is allowed, please enable registration by selecting either the "User accounts may be registered" or "Both sites and user accounts can be registered" option on %s.', 'Disabled registration message for multisite config', 'buddypress' ),
     202                                                sprintf(
     203                                                        '<a href="%1$s">%2$s</a>',
     204                                                        esc_url( network_admin_url( 'settings.php' ) ),
     205                                                        esc_html_x( 'this page', 'Link text for the Multisite’s network settings page', 'buddypress' )
     206                                                )
     207                                        );
    198208                                        ?>
    199209                                </p>
    200210                        <?php else : ?>
    201211                                <p>
    202212                                        <?php
    203                                         /* translators: %s: the link to the Site settings page */
    204                                         printf( __( 'Registration is currently disabled.  Before associating a page is allowed, please enable registration by clicking on the "Anyone can register" checkbox on <a href="%s">this page</a>.', 'buddypress' ), admin_url( 'options-general.php' ) );
     213                                        printf(
     214                                                /* translators: %s: the link to the Site general options page */
     215                                                esc_html_x( 'Registration is currently disabled.  Before associating a page is allowed, please enable registration by clicking on the "Anyone can register" checkbox on %s.', 'Disabled registration message for regular site config', 'buddypress' ),
     216                                                sprintf(
     217                                                        '<a href="%1$s">%2$s</a>',
     218                                                        esc_url( admin_url( 'options-general.php' ) ),
     219                                                        esc_html_x( 'this page', 'Link text for the Site’s general options page', 'buddypress' )
     220                                                )
     221                                        );
    205222                                        ?>
    206223                                </p>
    207224                        <?php endif; ?>
    function bp_core_admin_slugs_options() { 
    228245                                                                'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
    229246                                                        ) ) ?>
    230247
    231                                                         <?php if ( ! empty( $existing_pages[ $name ] ) && get_post( $existing_pages[ $name ] ) ) : ?>
    232 
    233                                                                 <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
    234 
    235                                                         <?php endif; ?>
    236 
    237248                                                        <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
    238249
    239250                                                </td>
    function bp_core_admin_slugs_options() { 
    266277function bp_core_admin_slugs_setup_handler() {
    267278
    268279        if ( isset( $_POST['bp-admin-pages-submit'] ) ) {
    269                 if ( !check_admin_referer( 'bp-admin-pages-setup' ) )
     280                if ( ! check_admin_referer( 'bp-admin-pages-setup' ) ) {
    270281                        return false;
     282                }
    271283
    272284                // Then, update the directory pages.
    273285                if ( isset( $_POST['bp_pages'] ) ) {
  • src/bp-core/classes/class-bp-component.php

    diff --git src/bp-core/classes/class-bp-component.php src/bp-core/classes/class-bp-component.php
    index ee3dfde6d..7349a6722 100644
    class BP_Component { 
    471471                        add_action( 'bp_blocks_init', array( $this, 'blocks_init' ), 10 );
    472472                }
    473473
     474                // Set directory page states.
     475                add_filter( 'bp_admin_display_directory_states', array( $this, 'admin_directory_states' ), 10, 2 );
     476
    474477                /**
    475478                 * Fires at the end of the setup_actions method inside BP_Component.
    476479                 *
    class BP_Component { 
    946949                 */
    947950                do_action( 'bp_' . $this->id . '_blocks_init' );
    948951        }
     952
     953        /**
     954         * Add component's directory states.
     955         *
     956         * @since 8.0.0
     957         *
     958         * @param string[] $states An array of post display states.
     959         * @param WP_Post  $post   The current post object.
     960         * @return array           The component's directory states.
     961         */
     962        public function admin_directory_states( $states = array(), $post = null ) {
     963                if ( $this->has_directory ) {
     964                        /**
     965                         * Filter here to edit the component's directory states.
     966                         *
     967                         * This is a dynamic hook that is based on the component string ID.
     968                         *
     969                         * @since 8.0.0
     970                         *
     971                         * @param string[] $states An array of post display states.
     972                         */
     973                        return apply_filters( 'bp_' . $this->id . '_admin_directory_states', $states );
     974                }
     975
     976                return $states;
     977        }
    949978}
    950979endif; // BP_Component.
  • src/bp-groups/classes/class-bp-groups-component.php

    diff --git src/bp-groups/classes/class-bp-groups-component.php src/bp-groups/classes/class-bp-groups-component.php
    index d15a7cb58..ea852d93d 100644
    class BP_Groups_Component extends BP_Component { 
    10641064                        )
    10651065                );
    10661066        }
     1067
     1068        /**
     1069         * Add the Groups directory states.
     1070         *
     1071         * @since 8.0.0
     1072         *
     1073         * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
     1074         * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
     1075         * @return array          See BP_Component::admin_directory_states() for description.
     1076         */
     1077        public function admin_directory_states( $states = array(), $post = null ) {
     1078                $bp = buddypress();
     1079
     1080                if ( isset( $bp->pages->groups->id ) && (int) $bp->pages->groups->id === (int) $post->ID ) {
     1081                        $states['page_for_groups_directory'] = _x( 'BP Groups Page', 'page label', 'buddypress' );
     1082                }
     1083
     1084                return parent::admin_directory_states( $states, $post );
     1085        }
    10671086}
  • src/bp-members/classes/class-bp-members-component.php

    diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php
    index 8effd0cf0..7ce8b3752 100644
    class BP_Members_Component extends BP_Component { 
    835835                        )
    836836                );
    837837        }
     838
     839        /**
     840         * Add the Members directory states.
     841         *
     842         * @since 8.0.0
     843         *
     844         * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
     845         * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
     846         * @return array          See BP_Component::admin_directory_states() for description.
     847         */
     848        public function admin_directory_states( $states = array(), $post = null ) {
     849                $bp = buddypress();
     850
     851                if ( isset( $bp->pages->members->id ) && (int) $bp->pages->members->id === (int) $post->ID ) {
     852                        $states['page_for_members_directory'] = _x( 'BP Members Page', 'page label', 'buddypress' );
     853                }
     854
     855                if ( bp_get_signup_allowed() || bp_get_members_invitations_allowed() ) {
     856                        if ( isset( $bp->pages->register->id ) && (int) $bp->pages->register->id === (int) $post->ID ) {
     857                                $states['page_for_bp_registration'] = _x( 'BP Registration Page', 'page label', 'buddypress' );
     858                        }
     859
     860                        if ( isset( $bp->pages->activate->id ) && (int) $bp->pages->activate->id === (int) $post->ID ) {
     861                                $states['page_for_bp_activation'] = _x( 'BP Activation Page', 'page label', 'buddypress' );
     862                        }
     863                }
     864
     865                return parent::admin_directory_states( $states, $post );
     866        }
    838867}