示例#1
0
 /**
  * Are we looking at Gallery or Media Directories?
  *
  */
 public function is_directory()
 {
     // Bail if not looking at the registration or activation page
     if (!mpp_is_gallery_directory()) {
         return;
     }
     bp_set_theme_compat_active(true);
     buddypress()->theme_compat->use_with_current_theme = true;
     // Not a directory
     bp_update_is_directory(true, 'mediapress');
     // Setup actions
     add_filter('bp_get_buddypress_template', array($this, 'template_hierarchy'));
     add_action('bp_template_include_reset_dummy_post_data', array($this, 'dummy_post'));
     add_filter('bp_replace_the_content', array($this, 'directory_content'));
 }
/**
 * Load a specific template file with fallback support.
 *
 * Example:
 *   bp_core_load_template( 'members/index' );
 * Loads:
 *   wp-content/themes/[activated_theme]/members/index.php
 *
 * @param array $templates Array of templates to attempt to load.
 */
function bp_core_load_template($templates)
{
    global $wp_query;
    // Reset the post.
    bp_theme_compat_reset_post(array('ID' => 0, 'is_404' => true, 'post_status' => 'publish'));
    // Set theme compat to false since the reset post function automatically sets
    // theme compat to true.
    bp_set_theme_compat_active(false);
    // Fetch each template and add the php suffix.
    $filtered_templates = array();
    foreach ((array) $templates as $template) {
        $filtered_templates[] = $template . '.php';
    }
    // Only perform template lookup for bp-default themes.
    if (!bp_use_theme_compat_with_current_theme()) {
        $template = locate_template((array) $filtered_templates, false);
        // Theme compat doesn't require a template lookup.
    } else {
        $template = '';
    }
    /**
     * Filters the template locations.
     *
     * Allows plugins to alter where the template files are located.
     *
     * @since 1.1.0
     *
     * @param string $template           Located template path.
     * @param array  $filtered_templates Array of templates to attempt to load.
     */
    $located_template = apply_filters('bp_located_template', $template, $filtered_templates);
    if (!empty($located_template)) {
        // Template was located, lets set this as a valid page and not a 404.
        status_header(200);
        $wp_query->is_page = true;
        $wp_query->is_singular = true;
        $wp_query->is_404 = false;
        /**
         * Fires before the loading of a located template file.
         *
         * @since 1.6.0
         *
         * @param string $located_template Template found to be loaded.
         */
        do_action('bp_core_pre_load_template', $located_template);
        /**
         * Filters the selected template right before loading.
         *
         * @since 1.1.0
         *
         * @param string $located_template Template found to be loaded.
         */
        load_template(apply_filters('bp_load_template', $located_template));
        /**
         * Fires after the loading of a located template file.
         *
         * @since 1.6.0
         *
         * @param string $located_template Template found that was loaded.
         */
        do_action('bp_core_post_load_template', $located_template);
        // Kill any other output after this.
        exit;
        // No template found, so setup theme compatibility.
        // @todo Some other 404 handling if theme compat doesn't kick in.
    } else {
        // We know where we are, so reset important $wp_query bits here early.
        // The rest will be done by bp_theme_compat_reset_post() later.
        if (is_buddypress()) {
            status_header(200);
            $wp_query->is_page = true;
            $wp_query->is_singular = true;
            $wp_query->is_404 = false;
        }
        /**
         * Fires if there are no found templates to load and theme compat is needed.
         *
         * @since 1.7.0
         */
        do_action('bp_setup_theme_compat');
    }
}
示例#3
0
 /**
  * Hook into the template_include filter to load custom template files
  *
  * @param string $template Template file path of the default template
  * @return string File path of the template file to be loaded
  */
 function template_include($template)
 {
     // if it is not our route, return the default template early
     if (!$this->is_template()) {
         return $template;
     }
     // otherwise, apply a filter to the template,
     // pass the template  and slug to the function hooking here
     // so it can load a custom template
     $template_load = new RTMediaTemplate();
     global $new_rt_template;
     $new_rt_template = $template_load->set_template($template);
     $new_rt_template = apply_filters("rtmedia_" . $this->slug . "_include", $new_rt_template);
     global $rt_ajax_request;
     $rt_ajax_request = false;
     // check if it is an ajax request
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         $rt_ajax_request = true;
     }
     if ($rt_ajax_request) {
         return $new_rt_template;
     }
     if (function_exists('bp_set_theme_compat_active')) {
         bp_set_theme_compat_active(apply_filters('rtmedia_main_template_set_theme_compat', true));
     }
     add_filter('the_content', array(&$this, 'rt_replace_the_content'));
     $this->rt_theme_compat_reset_post();
     return apply_filters('rtmedia_main_template_include', $template, $new_rt_template);
 }
/**
 * Conditionally replace 'the_content'.
 *
 * Replaces the_content() if the post_type being displayed is one that would
 * normally be handled by BuddyPress, but proper single page templates do not
 * exist in the currently active theme.
 *
 * @since BuddyPress (1.7.0)
 *
 * @param string $content Original post content.
 * @return string $content Post content, potentially modified.
 */
function bp_replace_the_content($content = '')
{
    // Bail if not the main loop where theme compat is happening
    if (!bp_do_theme_compat()) {
        return $content;
    }
    // Set theme compat to false early, to avoid recursion from nested calls to
    // the_content() that execute before theme compat has unhooked itself.
    bp_set_theme_compat_active(false);
    // Do we have new content to replace the old content?
    $new_content = apply_filters('bp_replace_the_content', $content);
    // Juggle the content around and try to prevent unsightly comments
    if (!empty($new_content) && $new_content !== $content) {
        // Set the content to be the new content
        $content = $new_content;
        // Clean up after ourselves
        unset($new_content);
        // Reset the $post global
        wp_reset_postdata();
    }
    // Return possibly hi-jacked content
    return $content;
}
/**
 * Conditionally replace 'the_content'.
 *
 * Replaces the_content() if the post_type being displayed is one that would
 * normally be handled by BuddyPress, but proper single page templates do not
 * exist in the currently active theme.
 *
 * @since 1.7.0
 *
 * @param string $content Original post content.
 * @return string $content Post content, potentially modified.
 */
function bp_replace_the_content($content = '')
{
    // Bail if not the main loop where theme compat is happening.
    if (!bp_do_theme_compat()) {
        return $content;
    }
    // Set theme compat to false early, to avoid recursion from nested calls to
    // the_content() that execute before theme compat has unhooked itself.
    bp_set_theme_compat_active(false);
    /**
     * Filters the content to replace in the post.
     *
     * @since 1.7.0
     *
     * @param string $content Original post content.
     */
    $new_content = apply_filters('bp_replace_the_content', $content);
    // Juggle the content around and try to prevent unsightly comments.
    if (!empty($new_content) && $new_content !== $content) {
        // Set the content to be the new content.
        $content = $new_content;
        // Clean up after ourselves.
        unset($new_content);
        // Reset the $post global.
        wp_reset_postdata();
    }
    // Return possibly hi-jacked content.
    return $content;
}
示例#6
0
/**
 * Load a specific template file with fallback support.
 *
 * Example:
 *   bp_core_load_template( 'members/index' );
 * Loads:
 *   wp-content/themes/[activated_theme]/members/index.php
 *
 * @param array $templates Array of templates to attempt to load.
 * @return bool|null Returns false on failure.
 */
function bp_core_load_template($templates)
{
    global $wp_query;
    // check if BP page belongs to, or is a child of, a BP directory page
    $page_id = false;
    foreach ((array) buddypress()->pages as $page) {
        if ($page->name == buddypress()->unfiltered_uri[buddypress()->unfiltered_uri_offset]) {
            $page_id = $page->id;
            break;
        }
    }
    // Set up reset post args
    $reset_post_args = array('is_404' => true, 'post_status' => 'publish');
    // BP page exists - fill in the $wp_query->post object
    //
    // bp_theme_compat_reset_post() looks at the $wp_query->post object to fill in
    // the post globals
    if (!empty($page_id)) {
        $wp_query->post = get_post($page_id);
        $reset_post_args['ID'] = $page_id;
    } else {
        $reset_post_args['ID'] = 0;
    }
    // Reset the post
    bp_theme_compat_reset_post($reset_post_args);
    // Set theme compat to false since the reset post function automatically sets
    // theme compat to true
    bp_set_theme_compat_active(false);
    // Fetch each template and add the php suffix
    $filtered_templates = array();
    foreach ((array) $templates as $template) {
        $filtered_templates[] = $template . '.php';
    }
    // Only perform template lookup for bp-default themes
    if (!bp_use_theme_compat_with_current_theme()) {
        $template = locate_template((array) $filtered_templates, false);
        // Theme compat doesn't require a template lookup
    } else {
        $template = '';
    }
    // Filter the template locations so that plugins can alter where they are located
    $located_template = apply_filters('bp_located_template', $template, $filtered_templates);
    if (!empty($located_template)) {
        // Template was located, lets set this as a valid page and not a 404.
        status_header(200);
        $wp_query->is_page = true;
        $wp_query->is_singular = true;
        $wp_query->is_404 = false;
        do_action('bp_core_pre_load_template', $located_template);
        load_template(apply_filters('bp_load_template', $located_template));
        do_action('bp_core_post_load_template', $located_template);
        // Kill any other output after this.
        exit;
        // No template found, so setup theme compatability
        // @todo Some other 404 handling if theme compat doesn't kick in
    } else {
        // We know where we are, so reset important $wp_query bits here early.
        // The rest will be done by bp_theme_compat_reset_post() later.
        if (is_buddypress()) {
            status_header(200);
            $wp_query->is_page = true;
            $wp_query->is_singular = true;
            $wp_query->is_404 = false;
        }
        do_action('bp_setup_theme_compat');
    }
}
示例#7
0
 /**
  * We're not setting a dummy post for our post type, but we do need to
  * activate theme compat
  *
  * @todo This seems very wrong. Figure it out
  *
  * @since 1.3
  */
 public function single_dummy_post()
 {
     bp_set_theme_compat_active();
 }
/**
 * Load a specific template file with fallback support.
 *
 * Example:
 *   bp_core_load_template( 'members/index' );
 * Loads:
 *   wp-content/themes/[activated_theme]/members/index.php
 *
 * @param array $templates Array of templates to attempt to load.
 * @return bool|null Returns false on failure.
 */
function bp_core_load_template( $templates ) {
	global $wp_query;

	// Reset the post
	bp_theme_compat_reset_post( array(
		'ID'          => 0,
		'is_404'      => true,
		'post_status' => 'publish',
	) );

	// Set theme compat to false since the reset post function automatically sets
	// theme compat to true
	bp_set_theme_compat_active( false );

	// Fetch each template and add the php suffix
	$filtered_templates = array();
	foreach ( (array) $templates as $template ) {
		$filtered_templates[] = $template . '.php';
	}

	// Only perform template lookup for bp-default themes
	if ( ! bp_use_theme_compat_with_current_theme() ) {
		$template = locate_template( (array) $filtered_templates, false );

	// Theme compat doesn't require a template lookup
	} else {
		$template = '';
	}

	// Filter the template locations so that plugins can alter where they are located
	$located_template = apply_filters( 'bp_located_template', $template, $filtered_templates );
	if ( !empty( $located_template ) ) {
		// Template was located, lets set this as a valid page and not a 404.
		status_header( 200 );
		$wp_query->is_page     = true;
		$wp_query->is_singular = true;
		$wp_query->is_404      = false;

		do_action( 'bp_core_pre_load_template', $located_template );

		load_template( apply_filters( 'bp_load_template', $located_template ) );

		do_action( 'bp_core_post_load_template', $located_template );

		// Kill any other output after this.
		exit();

	// No template found, so setup theme compatibility
	// @todo Some other 404 handling if theme compat doesn't kick in
	} else {

		// We know where we are, so reset important $wp_query bits here early.
		// The rest will be done by bp_theme_compat_reset_post() later.
		if ( is_buddypress() ) {
			status_header( 200 );
			$wp_query->is_page     = true;
			$wp_query->is_singular = true;
			$wp_query->is_404      = false;
		}

		do_action( 'bp_setup_theme_compat' );
	}
}