/** * Check if this is an embedded product - to make sure we don't mess up regular posts. * * @since 2.4.11 * @return bool */ public static function is_embedded_product() { if (function_exists('is_embed') && is_embed() && is_product()) { return true; } return false; }
/** * Remove the title from the Status Update oembed. * * @param string $title Post title. * @param int $id Post ID. * * @return string */ public function remove_embed_title($title, $id) { $post = get_post($id); if (is_embed() && 'sp_status_update' === $post->post_type) { return ''; } return $title; }
/** * Add our own method is_embed to check by WordPress Version and function is_embed * to prevent fatal errors in WordPress 4.3 and earlier * * @version 4.2.1 */ public static function is_embed() { global $wp_version; if (version_compare($wp_version, '4.4', '<') || !function_exists('is_embed')) { return false; } return is_embed(); }
/** * Load a template. * * Handles template usage so that we can use our own templates instead of the themes. * * Templates are in the 'templates' folder. woocommerce looks for theme. * overrides in /theme/woocommerce/ by default. * * For beginners, it also looks for a woocommerce.php template first. If the user adds. * this to the theme (containing a woocommerce() inside) this will be used for all. * woocommerce templates. * * @param mixed $template * @return string */ public static function template_loader($template) { if (is_embed()) { return $template; } if ($default_file = self::get_template_loader_default_file()) { /** * Filter hook to choose which files to find before WooCommerce does it's own logic. * * @since 2.7.0 * @var array */ $search_files = self::get_template_loader_files($default_file); $template = locate_template($search_files); if (!$template || WC_TEMPLATE_DEBUG_MODE) { $template = WC()->plugin_path() . '/templates/' . $default_file; } } return $template; }
/** * Load a template. * * Handles template usage so that we can use our own templates instead of the themes. * * Templates are in the 'templates' folder. woocommerce looks for theme. * overrides in /theme/woocommerce/ by default. * * For beginners, it also looks for a woocommerce.php template first. If the user adds. * this to the theme (containing a woocommerce() inside) this will be used for all. * woocommerce templates. * * @param mixed $template * @return string */ public static function template_loader($template) { $find = array('woocommerce.php'); $file = ''; if (is_embed()) { return $template; } if (is_single() && get_post_type() == 'product') { $file = 'single-product.php'; $find[] = $file; $find[] = WC()->template_path() . $file; } elseif (is_product_taxonomy()) { $term = get_queried_object(); if (is_tax('product_cat') || is_tax('product_tag')) { $file = 'taxonomy-' . $term->taxonomy . '.php'; } else { $file = 'archive-product.php'; } $find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php'; $find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php'; $find[] = 'taxonomy-' . $term->taxonomy . '.php'; $find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php'; $find[] = $file; $find[] = WC()->template_path() . $file; } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) { $file = 'archive-product.php'; $find[] = $file; $find[] = WC()->template_path() . $file; } if ($file) { $template = locate_template(array_unique($find)); if (!$template || WC_TEMPLATE_DEBUG_MODE) { $template = WC()->plugin_path() . '/templates/' . $file; } } return $template; }
function is_admin_bar_showing() { global $show_admin_bar, $pagenow; // For all these types of requests, we never want an admin bar. if (defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST')) { return false; } if (is_embed()) { return false; } // Integrated into the admin. if (is_admin()) { return true; } if (!isset($show_admin_bar)) { if (!is_user_logged_in() || 'wp-login.php' == $pagenow) { $show_admin_bar = false; } else { $show_admin_bar = _get_admin_bar_pref(); } } $show_admin_bar = apply_filters('show_admin_bar', $show_admin_bar); return $show_admin_bar; }
// Process feeds and trackbacks even if not using themes. if (is_robots()) { /** * Fired when the template loader determines a robots.txt request. * * @since 2.1.0 */ do_action('do_robots'); return; } elseif (is_feed()) { do_feed(); return; } elseif (is_trackback()) { include ABSPATH . 'wp-trackback.php'; return; } elseif (is_embed()) { $template = ABSPATH . WPINC . '/embed-template.php'; /** * Filter the template used for embedded posts. * * @since 4.4.0 * * @param string $template Path to the template file. */ $template = apply_filters('embed_template', $template); include $template; return; } if (defined('WP_USE_THEMES') && WP_USE_THEMES) { $template = false; if (is_404() && ($template = get_404_template())) {
/** * Determine whether the admin bar should be showing. * * @since 3.1.0 * * @global bool $show_admin_bar * @global string $pagenow * * @return bool Whether the admin bar should be showing. */ function is_admin_bar_showing() { global $show_admin_bar, $pagenow; // For all these types of requests, we never want an admin bar. if (defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST')) { return false; } if (is_embed()) { return false; } // Integrated into the admin. if (is_admin()) { return true; } if (!isset($show_admin_bar)) { if (!is_user_logged_in() || 'wp-login.php' == $pagenow) { $show_admin_bar = false; } else { $show_admin_bar = _get_admin_bar_pref(); } } /** * Filters whether to show the admin bar. * * Returning false to this hook is the recommended way to hide the admin bar. * The user's display preference is used for logged in users. * * @since 3.1.0 * * @param bool $show_admin_bar Whether the admin bar should be shown. Default false. */ $show_admin_bar = apply_filters('show_admin_bar', $show_admin_bar); return $show_admin_bar; }
/** * Disable the admin bar in the embed template. */ function wp_oembed_disable_admin_bar() { if (is_embed()) { add_filter('show_admin_bar', '__return_false', 9999); } }
function test_is_embed_404() { $this->go_to(home_url('/?p=12345&embed=true')); $this->assertTrue(is_embed()); }
/** * Test is_embed. */ function test_is_embed() { $this->assertFalse(is_embed()); $post_id = $this->factory->post->create(); $this->go_to(get_post_embed_url($post_id)); $this->assertTrue(is_embed()); $file = DIR_TESTDATA . '/images/canola.jpg'; $attachment_id = $this->factory->attachment->create_object($file, $post_id, array('post_mime_type' => 'image/jpeg')); $this->go_to(get_post_embed_url($attachment_id)); $this->assertTrue(is_embed()); $this->go_to(home_url('/?p=123&embed=true')); $this->assertTrue(is_embed()); }
/** * Filters the string in the "more" link displayed after a trimmed excerpt. * * @since 4.4.0 * * @param string $more_string The string shown within the more link. * @return string The modified excerpt. */ function wp_embed_excerpt_more($more_string) { if (!is_embed()) { return $more_string; } return sprintf(_x('… %s', 'read more link'), sprintf('<a class="wp-embed-more" href="%s" target="_top">%s</a>', get_the_permalink(), __('Read more'))); }
* Fired when the template loader determines a robots.txt request. * * @since 2.1.0 */ do_action('do_robots'); return; } elseif (is_feed()) { do_feed(); return; } elseif (is_trackback()) { include ABSPATH . 'wp-trackback.php'; return; } if (defined('WP_USE_THEMES') && WP_USE_THEMES) { $template = false; if (is_embed() && ($template = get_embed_template())) { } elseif (is_404() && ($template = get_404_template())) { } elseif (is_search() && ($template = get_search_template())) { } elseif (is_front_page() && ($template = get_front_page_template())) { } elseif (is_home() && ($template = get_home_template())) { } elseif (is_post_type_archive() && ($template = get_post_type_archive_template())) { } elseif (is_tax() && ($template = get_taxonomy_template())) { } elseif (is_attachment() && ($template = get_attachment_template())) { remove_filter('the_content', 'prepend_attachment'); } elseif (is_single() && ($template = get_single_template())) { } elseif (is_page() && ($template = get_page_template())) { } elseif (is_singular() && ($template = get_singular_template())) { } elseif (is_category() && ($template = get_category_template())) { } elseif (is_tag() && ($template = get_tag_template())) { } elseif (is_author() && ($template = get_author_template())) { } elseif (is_date() && ($template = get_date_template())) {
/** * Create content. * * @param string $content Post content. * @param string $post \WP_Query. * * @return string */ public function doing_show_in($content = '', $post = null) { $options = Options::get('all'); $show_in = $options['post_types']; $raw = apply_filters(VA_SOCIALBUZZ_PREFIX . 'raw_the_content', $content); $content = apply_filters(VA_SOCIALBUZZ_PREFIX . 'create_the_content', $content, $raw); $conditions = !(is_embed() || is_feed() || is_front_page() || is_home()) && is_singular() && in_the_loop() && isset($show_in) && in_array(get_post_type(), $show_in); $conditions = apply_filters(VA_SOCIALBUZZ_PREFIX . 'show_in_conditions', $conditions, $post->ID); if ($conditions) { // Recommend you don't use this short code registering your own post data. $content .= do_shortcode('[socialbuzz box="select"]'); } return $content; }
/** * Redirect old slugs to the correct permalink. * * Attempts to find the current slug from the past slugs. * * @since 2.1.0 * * @global WP_Query $wp_query Global WP_Query instance. * @global wpdb $wpdb WordPress database abstraction object. * @global WP_Rewrite $wp_rewrite WordPress rewrite component. */ function wp_old_slug_redirect() { global $wp_query, $wp_rewrite; if (get_queried_object()) { return; } if ('' !== $wp_query->query_vars['name']) { global $wpdb; // Guess the current post_type based on the query vars. if (get_query_var('post_type')) { $post_type = get_query_var('post_type'); } elseif (get_query_var('attachment')) { $post_type = 'attachment'; } elseif (!empty($wp_query->query_vars['pagename'])) { $post_type = 'page'; } else { $post_type = 'post'; } if (is_array($post_type)) { if (count($post_type) > 1) { return; } $post_type = reset($post_type); } // Do not attempt redirect for hierarchical post types if (is_post_type_hierarchical($post_type)) { return; } $query = $wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta}, {$wpdb->posts} WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']); // if year, monthnum, or day have been specified, make our query more precise // just in case there are multiple identical _wp_old_slug values if ('' != $wp_query->query_vars['year']) { $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); } if ('' != $wp_query->query_vars['monthnum']) { $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); } if ('' != $wp_query->query_vars['day']) { $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); } $id = (int) $wpdb->get_var($query); if (!$id) { return; } $link = get_permalink($id); if (is_feed()) { $link = user_trailingslashit(trailingslashit($link) . 'feed'); } elseif (isset($GLOBALS['wp_query']->query_vars['paged']) && $GLOBALS['wp_query']->query_vars['paged'] > 1) { $link = user_trailingslashit(trailingslashit($link) . 'page/' . $GLOBALS['wp_query']->query_vars['paged']); } elseif (is_embed()) { $link = user_trailingslashit(trailingslashit($link) . 'embed'); } elseif (is_404()) { // Add rewrite endpoints if necessary. foreach ($wp_rewrite->endpoints as $endpoint) { if ($endpoint[2] && false !== get_query_var($endpoint[2], false)) { $link = user_trailingslashit(trailingslashit($link) . $endpoint[1]); } } } /** * Filter the old slug redirect URL. * * @since 4.4.0 * * @param string $link The redirect URL. */ $link = apply_filters('old_slug_redirect_url', $link); if (!$link) { return; } wp_redirect($link, 301); // Permanent redirect exit; } }
/** * Load a specific template file with fallback support. * * Example: * bp_core_load_template( 'members/index' ); * Loads: * wp-content/themes/[activated_theme]/members/index.php * * @since 1.0.0 * * @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 current page is an embed, wipe out bp-default template. * * Wiping out the bp-default template allows WordPress to use their special * embed template, which is what we want. */ if (function_exists('is_embed') && is_embed()) { $located_template = ''; } 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'); } }
/** * Filters the string in the 'more' link displayed after a trimmed excerpt. * * Replaces '[...]' (appended to automatically generated excerpts) with an * ellipsis and a "Continue reading" link in the embed template. * * @since 4.4.0 * * @param string $more_string Default 'more' string. * @return string 'Continue reading' link prepended with an ellipsis. */ function wp_embed_excerpt_more($more_string) { if (!is_embed()) { return $more_string; } $link = sprintf('<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>', esc_url(get_permalink()), sprintf(__('Continue reading %s'), '<span class="screen-reader-text">' . get_the_title() . '</span>')); return ' … ' . $link; }
/** * Reset main query vars and filter 'the_content' to output a BuddyPress template part as needed. * * @since 1.7.0 * * @param string $template Template name. * @return string $template Template name. */ function bp_template_include_theme_compat($template = '') { // If embed template, bail. if (true === function_exists('is_embed') && is_embed()) { return $template; } // If the current theme doesn't need theme compat, bail at this point. if (!bp_use_theme_compat_with_current_theme()) { return $template; } /** * Fires when resetting main query vars and filtering 'the_content' to output BuddyPress template parts. * * Use this action to execute code that will communicate to BuddyPress's * theme compatibility layer whether or not we're replacing the_content() * with some other template part. * * @since 1.7.0 */ do_action('bp_template_include_reset_dummy_post_data'); // Bail if the template already matches a BuddyPress template. if (!empty(buddypress()->theme_compat->found_template)) { return $template; } /** * If we are relying on BuddyPress's built in theme compatibility to load * the proper content, we need to intercept the_content, replace the * output, and display ours instead. * * To do this, we first remove all filters from 'the_content' and hook * our own function into it, which runs a series of checks to determine * the context, and then uses the built in shortcodes to output the * correct results from inside an output buffer. * * Uses bp_get_theme_compat_templates() to provide fall-backs that * should be coded without superfluous mark-up and logic (prev/next * navigation, comments, date/time, etc...) * * Hook into 'bp_get_buddypress_template' to override the array of * possible templates, or 'bp_buddypress_template' to override the result. */ if (bp_is_theme_compat_active()) { $template = bp_get_theme_compat_templates(); add_filter('the_content', 'bp_replace_the_content'); // Add BuddyPress's head action to wp_head. if (!has_action('wp_head', 'bp_head')) { add_action('wp_head', 'bp_head'); } } /** * Filters the template name to include. * * @since 1.7.0 * * @param string $template Template name. */ return apply_filters('bp_template_include_theme_compat', $template); }