Skip to:
Content

BuddyPress.org


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

Move bp-blogs classes to their own files.

See #6870.

File:
1 edited

Legend:

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

    r10417 r10517  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
     12
     13require dirname( __FILE__ ) . '/classes/class-bp-blogs-theme-compat.php';
    1214
    1315/**
     
    7173/** Theme Compatibility *******************************************************/
    7274
    73 /**
    74  * The main theme compat class for BuddyPress Blogs.
    75  *
    76  * This class sets up the necessary theme compatibility actions to safely output
    77  * group template parts to the_title and the_content areas of a theme.
    78  *
    79  * @since 1.7.0
    80  */
    81 class BP_Blogs_Theme_Compat {
    82 
    83     /**
    84      * Set up theme compatibility for the Blogs component.
    85      *
    86      * @since 1.7.0
    87      */
    88     public function __construct() {
    89         add_action( 'bp_setup_theme_compat', array( $this, 'is_blogs' ) );
    90     }
    91 
    92     /**
    93      * Are we looking at something that needs Blogs theme compatibility?
    94      *
    95      * @since 1.7.0
    96      */
    97     public function is_blogs() {
    98 
    99         // Bail if not looking at a group.
    100         if ( ! bp_is_blogs_component() )
    101             return;
    102 
    103         // Bail if looking at a users sites.
    104         if ( bp_is_user() )
    105             return;
    106 
    107         // Blog Directory.
    108         if ( is_multisite() && ! bp_current_action() ) {
    109             bp_update_is_directory( true, 'blogs' );
    110 
    111             /**
    112              * Fires if in the blog directory and BuddyPress needs Blog theme compatibility,
    113              * before the actions and filters are added.
    114              *
    115              * @since 1.5.0
    116              */
    117             do_action( 'bp_blogs_screen_index' );
    118 
    119             add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    120             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    121             add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    122 
    123         // Create blog.
    124         } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) {
    125             add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
    126             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
    127             add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );
    128         }
    129     }
    130 
    131     /** Directory *************************************************************/
    132 
    133     /**
    134      * Add template hierarchy to theme compat for the blog directory page.
    135      *
    136      * This is to mirror how WordPress has
    137      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    138      *
    139      * @since 1.8.0
    140      *
    141      * @param string $templates The templates from bp_get_theme_compat_templates().
    142      * @return array $templates Array of custom templates to look for.
    143      */
    144     public function directory_template_hierarchy( $templates ) {
    145 
    146         /**
    147          * Filters the custom templates used for theme compat with the blog directory page.
    148          *
    149          * @since 1.8.0
    150          *
    151          * @param array $value Array of template paths to add to template list to look for.
    152          */
    153         $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
    154             'blogs/index-directory.php'
    155         ) );
    156 
    157         // Merge new templates with existing stack
    158         // @see bp_get_theme_compat_templates().
    159         $templates = array_merge( (array) $new_templates, $templates );
    160 
    161         return $templates;
    162     }
    163 
    164     /**
    165      * Update the global $post with directory data.
    166      *
    167      * @since 1.7.0
    168      */
    169     public function directory_dummy_post() {
    170 
    171         bp_theme_compat_reset_post( array(
    172             'ID'             => 0,
    173             'post_title'     => __( 'Sites', 'buddypress' ),
    174             'post_author'    => 0,
    175             'post_date'      => 0,
    176             'post_content'   => '',
    177             'post_type'      => 'page',
    178             'post_status'    => 'publish',
    179             'is_page'        => true,
    180             'comment_status' => 'closed'
    181         ) );
    182     }
    183 
    184     /**
    185      * Filter the_content with the groups index template part.
    186      *
    187      * @since 1.7.0
    188      */
    189     public function directory_content() {
    190         return bp_buffer_template_part( 'blogs/index', null, false );
    191     }
    192 
    193     /** Create ****************************************************************/
    194 
    195     /**
    196      * Add custom template hierarchy to theme compat for the blog create page.
    197      *
    198      * This is to mirror how WordPress has
    199      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    200      *
    201      * @since 1.8.0
    202      *
    203      * @param string $templates The templates from bp_get_theme_compat_templates().
    204      * @return array $templates Array of custom templates to look for.
    205      */
    206     public function create_template_hierarchy( $templates ) {
    207 
    208         /**
    209          * Filters the custom templates used for theme compat with the blog create page.
    210          *
    211          * @since 1.8.0
    212          *
    213          * @param array $value Array of template paths to add to template list to look for.
    214          */
    215         $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
    216             'blogs/index-create.php'
    217         ) );
    218 
    219         // Merge new templates with existing stack
    220         // @see bp_get_theme_compat_templates().
    221         $templates = array_merge( (array) $new_templates, $templates );
    222 
    223         return $templates;
    224     }
    225 
    226     /**
    227      * Update the global $post with create screen data.
    228      *
    229      * @since 1.7.0
    230      */
    231     public function create_dummy_post() {
    232 
    233         // Title based on ability to create blogs.
    234         if ( is_user_logged_in() && bp_blog_signup_enabled() ) {
    235             $title = __( 'Create a Site', 'buddypress' );
    236         } else {
    237             $title = __( 'Sites', 'buddypress' );
    238         }
    239 
    240         bp_theme_compat_reset_post( array(
    241             'ID'             => 0,
    242             'post_title'     => $title,
    243             'post_author'    => 0,
    244             'post_date'      => 0,
    245             'post_content'   => '',
    246             'post_type'      => 'page',
    247             'post_status'    => 'publish',
    248             'is_page'        => true,
    249             'comment_status' => 'closed'
    250         ) );
    251     }
    252 
    253     /**
    254      * Filter the_content with the create screen template part.
    255      *
    256      * @since 1.7.0
    257      */
    258     public function create_content() {
    259         return bp_buffer_template_part( 'blogs/create', null, false );
    260     }
    261 }
    26275new BP_Blogs_Theme_Compat();
Note: See TracChangeset for help on using the changeset viewer.