Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 05:15:55 AM (10 years ago)
Author:
boonebgorges
Message:

Move bp-members classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-screens.php

    r10487 r10521  
    1212// Exit if accessed directly.
    1313defined( 'ABSPATH' ) || exit;
     14
     15require dirname( __FILE__ ) . '/classes/class-bp-members-theme-compat.php';
     16require dirname( __FILE__ ) . '/classes/class-bp-registration-theme-compat.php';
    1417
    1518/**
     
    382385/** Theme Compatibility *******************************************************/
    383386
    384 /**
    385  * The main theme compat class for BuddyPress Members.
    386  *
    387  * This class sets up the necessary theme compatibility actions to safely output
    388  * member template parts to the_title and the_content areas of a theme.
    389  *
    390  * @since 1.7.0
    391  */
    392 class BP_Members_Theme_Compat {
    393 
    394         /**
    395          * Set up the members component theme compatibility.
    396          *
    397          * @since 1.7.0
    398          */
    399         public function __construct() {
    400                 add_action( 'bp_setup_theme_compat', array( $this, 'is_members' ) );
    401         }
    402 
    403         /**
    404          * Are we looking at something that needs members theme compatibility?
    405          *
    406          * @since 1.7.0
    407          */
    408         public function is_members() {
    409 
    410                 // Bail if not looking at the members component or a user's page.
    411                 if ( ! bp_is_members_component() && ! bp_is_user() ) {
    412                         return;
    413                 }
    414 
    415                 // Members Directory.
    416                 if ( ! bp_current_action() && ! bp_current_item() ) {
    417                         bp_update_is_directory( true, 'members' );
    418 
    419                         /**
    420                          * Fires if looking at Members directory when needing theme compat.
    421                          *
    422                          * @since 1.5.0
    423                          */
    424                         do_action( 'bp_members_screen_index' );
    425 
    426                         add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    427                         add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    428                         add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    429 
    430                 // User page.
    431                 } elseif ( bp_is_user() ) {
    432 
    433                         // If we're on a single activity permalink page, we shouldn't use the members
    434                         // template, so stop here!
    435                         if ( bp_is_active( 'activity' ) && bp_is_single_activity() ) {
    436                                 return;
    437                         }
    438 
    439                         /**
    440                          * Fires if looking at Members user page when needing theme compat.
    441                          *
    442                          * @since 1.5.0
    443                          */
    444                         do_action( 'bp_members_screen_display_profile' );
    445 
    446                         add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
    447                         add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post'    ) );
    448                         add_filter( 'bp_replace_the_content',                    array( $this, 'single_dummy_content' ) );
    449 
    450                 }
    451         }
    452 
    453         /** Directory *************************************************************/
    454 
    455         /**
    456          * Add template hierarchy to theme compat for the members directory page.
    457          *
    458          * This is to mirror how WordPress has
    459          * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    460          *
    461          * @since 1.8.0
    462          *
    463          * @param array $templates The templates from bp_get_theme_compat_templates().
    464          * @return array $templates Array of custom templates to look for.
    465          */
    466         public function directory_template_hierarchy( $templates = array() ) {
    467 
    468                 // Set up the template hierarchy.
    469                 $new_templates = array();
    470                 if ( '' !== bp_get_current_member_type() ) {
    471                         $new_templates[] = 'members/index-directory-type-' . sanitize_file_name( bp_get_current_member_type() ) . '.php';
    472                 }
    473                 $new_templates[] = 'members/index-directory.php';
    474 
    475                 /**
    476                  * Filters the template hierarchy for theme compat and members directory page.
    477                  *
    478                  * @since 1.8.0
    479                  *
    480                  * @param array $value Array of template paths to add to hierarchy.
    481                  */
    482                 $new_templates = apply_filters( 'bp_template_hierarchy_members_directory', $new_templates );
    483 
    484                 // Merge new templates with existing stack
    485                 // @see bp_get_theme_compat_templates().
    486                 $templates = array_merge( (array) $new_templates, $templates );
    487 
    488                 return $templates;
    489         }
    490 
    491         /**
    492          * Update the global $post with directory data.
    493          *
    494          * @since 1.7.0
    495          */
    496         public function directory_dummy_post() {
    497                 bp_theme_compat_reset_post( array(
    498                         'ID'             => 0,
    499                         'post_title'     => bp_get_directory_title( 'members' ),
    500                         'post_author'    => 0,
    501                         'post_date'      => 0,
    502                         'post_content'   => '',
    503                         'post_type'      => 'page',
    504                         'post_status'    => 'publish',
    505                         'is_page'        => true,
    506                         'comment_status' => 'closed'
    507                 ) );
    508         }
    509 
    510         /**
    511          * Filter the_content with the members index template part.
    512          *
    513          * @since 1.7.0
    514          */
    515         public function directory_content() {
    516                 return bp_buffer_template_part( 'members/index', null, false );
    517         }
    518 
    519         /** Single ****************************************************************/
    520 
    521         /**
    522          * Add custom template hierarchy to theme compat for member pages.
    523          *
    524          * This is to mirror how WordPress has
    525          * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    526          *
    527          * @since 1.8.0
    528          *
    529          * @param string $templates The templates from
    530          *                          bp_get_theme_compat_templates().
    531          * @return array $templates Array of custom templates to look for.
    532          */
    533         public function single_template_hierarchy( $templates ) {
    534                 // Setup some variables we're going to reference in our custom templates.
    535                 $user_nicename = buddypress()->displayed_user->userdata->user_nicename;
    536 
    537                 /**
    538                  * Filters the template hierarchy for theme compat and member pages.
    539                  *
    540                  * @since 1.8.0
    541                  *
    542                  * @param array $value Array of template paths to add to hierarchy.
    543                  */
    544                 $new_templates = apply_filters( 'bp_template_hierarchy_members_single_item', array(
    545                         'members/single/index-id-'        . sanitize_file_name( bp_displayed_user_id() ) . '.php',
    546                         'members/single/index-nicename-'  . sanitize_file_name( $user_nicename )         . '.php',
    547                         'members/single/index-action-'    . sanitize_file_name( bp_current_action() )    . '.php',
    548                         'members/single/index-component-' . sanitize_file_name( bp_current_component() ) . '.php',
    549                         'members/single/index.php'
    550                 ) );
    551 
    552                 // Merge new templates with existing stack
    553                 // @see bp_get_theme_compat_templates().
    554                 $templates = array_merge( (array) $new_templates, $templates );
    555 
    556                 return $templates;
    557         }
    558 
    559         /**
    560          * Update the global $post with the displayed user's data.
    561          *
    562          * @since 1.7.0
    563          */
    564         public function single_dummy_post() {
    565                 bp_theme_compat_reset_post( array(
    566                         'ID'             => 0,
    567                         'post_title'     => bp_get_displayed_user_fullname(),
    568                         'post_author'    => 0,
    569                         'post_date'      => 0,
    570                         'post_content'   => '',
    571                         'post_type'      => 'page',
    572                         'post_status'    => 'publish',
    573                         'is_page'        => true,
    574                         'comment_status' => 'closed'
    575                 ) );
    576         }
    577 
    578         /**
    579          * Filter the_content with the members' single home template part.
    580          *
    581          * @since 1.7.0
    582          */
    583         public function single_dummy_content() {
    584                 return bp_buffer_template_part( 'members/single/home', null, false );
    585         }
    586 }
    587387new BP_Members_Theme_Compat();
    588 
    589 /**
    590  * The main theme compat class for BuddyPress Registration.
    591  *
    592  * This class sets up the necessary theme compatibility actions to safely output
    593  * registration template parts to the_title and the_content areas of a theme.
    594  *
    595  * @since 1.7.0
    596  */
    597 class BP_Registration_Theme_Compat {
    598 
    599         /**
    600          * Setup the groups component theme compatibility.
    601          *
    602          * @since 1.7.0
    603          */
    604         public function __construct() {
    605                 add_action( 'bp_setup_theme_compat', array( $this, 'is_registration' ) );
    606         }
    607 
    608         /**
    609          * Are we looking at either the registration or activation pages?
    610          *
    611          * @since 1.7.0
    612          */
    613         public function is_registration() {
    614 
    615                 // Bail if not looking at the registration or activation page.
    616                 if ( ! bp_is_register_page() && ! bp_is_activation_page() ) {
    617                         return;
    618                 }
    619 
    620                 // Not a directory.
    621                 bp_update_is_directory( false, 'register' );
    622 
    623                 // Setup actions.
    624                 add_filter( 'bp_get_buddypress_template',                array( $this, 'template_hierarchy' ) );
    625                 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'dummy_post'    ) );
    626                 add_filter( 'bp_replace_the_content',                    array( $this, 'dummy_content' ) );
    627         }
    628 
    629         /** Template ***********************************************************/
    630 
    631         /**
    632          * Add template hierarchy to theme compat for registration/activation pages.
    633          *
    634          * This is to mirror how WordPress has
    635          * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    636          *
    637          * @since 1.8.0
    638          *
    639          * @param string $templates The templates from bp_get_theme_compat_templates().
    640          * @return array $templates Array of custom templates to look for.
    641          */
    642         public function template_hierarchy( $templates ) {
    643                 $component = sanitize_file_name( bp_current_component() );
    644 
    645                 /**
    646                  * Filters the template hierarchy for theme compat and registration/activation pages.
    647                  *
    648                  * This filter is a variable filter that depends on the current component
    649                  * being used.
    650                  *
    651                  * @since 1.8.0
    652                  *
    653                  * @param array $value Array of template paths to add to hierarchy.
    654                  */
    655                 $new_templates = apply_filters( "bp_template_hierarchy_{$component}", array(
    656                         "members/index-{$component}.php"
    657                 ) );
    658 
    659                 // Merge new templates with existing stack
    660                 // @see bp_get_theme_compat_templates().
    661                 $templates = array_merge( (array) $new_templates, $templates );
    662 
    663                 return $templates;
    664         }
    665 
    666         /**
    667          * Update the global $post with dummy data.
    668          *
    669          * @since 1.7.0
    670          */
    671         public function dummy_post() {
    672                 // Registration page.
    673                 if ( bp_is_register_page() ) {
    674                         $title = __( 'Create an Account', 'buddypress' );
    675 
    676                         if ( 'completed-confirmation' == bp_get_current_signup_step() ) {
    677                                 $title = __( 'Check Your Email To Activate Your Account!', 'buddypress' );
    678                         }
    679 
    680                 // Activation page.
    681                 } else {
    682                         $title = __( 'Activate Your Account', 'buddypress' );
    683 
    684                         if ( bp_account_was_activated() ) {
    685                                 $title = __( 'Account Activated', 'buddypress' );
    686                         }
    687                 }
    688 
    689                 bp_theme_compat_reset_post( array(
    690                         'ID'             => 0,
    691                         'post_title'     => $title,
    692                         'post_author'    => 0,
    693                         'post_date'      => 0,
    694                         'post_content'   => '',
    695                         'post_type'      => 'page',
    696                         'post_status'    => 'publish',
    697                         'is_page'        => true,
    698                         'comment_status' => 'closed'
    699                 ) );
    700         }
    701 
    702         /**
    703          * Filter the_content with either the register or activate templates.
    704          *
    705          * @since 1.7.0
    706          */
    707         public function dummy_content() {
    708                 if ( bp_is_register_page() ) {
    709                         return bp_buffer_template_part( 'members/register', null, false );
    710                 } else {
    711                         return bp_buffer_template_part( 'members/activate', null, false );
    712                 }
    713         }
    714 }
    715388new BP_Registration_Theme_Compat();
Note: See TracChangeset for help on using the changeset viewer.