Skip to:
Content

BuddyPress.org

Ticket #8470: 8470.2.patch

File 8470.2.patch, 7.9 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/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}