function sfc_share_button_automatic($content) { global $post; $post_types = apply_filters('sfc_share_post_types', get_post_types(array('public' => true))); if (!in_array($post->post_type, $post_types)) { return $content; } // exclude bbPress post types if (function_exists('bbp_is_custom_post_type') && bbp_is_custom_post_type()) { return $content; } $options = get_option('sfc_options'); $button = get_sfc_share_button(); switch ($options['share_position']) { case "before": $content = $button . $content; break; case "after": $content = $content . $button; break; case "both": $content = $button . $content . $button; break; case "manual": default: break; } return $content; }
/** * Only clean post caches for main bbPress posts. * * Check that the post being updated is a bbPress post type, saves the * post ID to be used later, and adds an action to 'clean_post_cache' that * prevents child post caches from being cleared. * * @since bbPress (r4011) * * @param int $post_id The post ID being updated * @return If invalid post data */ public function pre_post_update($post_id = 0) { // Bail if post ID is not a bbPress post type if (empty($post_id) || !bbp_is_custom_post_type($post_id)) { return; } // Store the $post_id $this->updating_post = $post_id; // Skip related post cache invalidation. This prevents invalidating the // caches of the child posts when there is no reason to do so. add_action('clean_post_cache', array($this, 'skip_related_posts')); }
function sfc_base_meta() { global $post; $options = get_option('sfc_options'); // exclude bbPress post types if (function_exists('bbp_is_custom_post_type') && bbp_is_custom_post_type()) { return; } $excerpt = ''; if (is_singular()) { global $wp_the_query; if ($id = $wp_the_query->get_queried_object_id()) { $post = get_post($id); } // get the content from the main post on the page $content = sfc_base_make_excerpt($post); $images = sfc_base_find_images($post); $video = sfc_base_find_video($post); $title = get_the_title(); $permalink = get_permalink(); echo "<meta property='og:type' content='article' />\n"; echo "<meta property='og:title' content='" . esc_attr($title) . "' />\n"; echo "<meta property='og:url' content='" . esc_url($permalink) . "' />\n"; echo "<meta property='og:description' content='" . esc_attr($content) . "' />\n"; if (!empty($images)) { foreach ($images as $image) { echo "<meta property='og:image' content='{$image}' />\n"; } } if (!empty($video)) { foreach ($video as $type => $value) { echo "<meta property='og:video{$type}' href='{$value}' />\n"; } } } else { if (is_home()) { echo "<meta property='og:type' content='blog' />\n"; echo "<meta property='og:title' content='" . get_bloginfo("name") . "' />\n"; echo "<meta property='og:url' content='" . esc_url(get_bloginfo("url")) . "' />\n"; } } // stuff on all pages echo "<meta property='og:site_name' content='" . get_bloginfo("name") . "' />\n"; echo "<meta property='fb:app_id' content='" . esc_attr($options["appid"]) . "' />\n"; }
/** * Filter sample permalinks so that certain languages display properly. * * @since bbPress (r3336) * * @param string $post_link Custom post type permalink * @param object $_post Post data object * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. * @param bool $sample Optional, defaults to false. Is it a sample permalink. * * @uses is_admin() To make sure we're on an admin page * @uses bbp_is_custom_post_type() To get the forum post type * * @return string The custom post type permalink */ function bbp_filter_sample_permalink($post_link, $_post, $leavename = false, $sample = false) { // Bail if not on an admin page and not getting a sample permalink if (!empty($sample) && is_admin() && bbp_is_custom_post_type()) { return urldecode($post_link); } // Return post link return $post_link; }
function sfc_base_meta() { $post = ''; $fbmeta = array(); $options = get_option('sfc_options'); // exclude bbPress post types if (function_exists('bbp_is_custom_post_type') && bbp_is_custom_post_type()) { return; } $excerpt = ''; if (is_singular()) { global $wp_the_query; if ($id = $wp_the_query->get_queried_object_id()) { $post = get_post($id); } // get the content from the main post on the page $content = sfc_base_make_excerpt($post); $title = get_the_title($post->ID); $title = strip_tags($title); $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); $title = htmlspecialchars_decode($title); $permalink = get_permalink(); $fbmeta['og:type'] = 'article'; $fbmeta['og:title'] = esc_attr($title); $fbmeta['og:url'] = esc_url($permalink); $fbmeta['og:description'] = esc_attr($content); } else { // non singular pages need images and descriptions too if (!empty($options['default_image'])) { $fbmeta['og:image'][] = $options['default_image']; } if (!empty($options['default_description'])) { $fbmeta['og:description'] = esc_attr($options['default_description']); } } if (is_home()) { $fbmeta['og:type'] = 'blog'; $fbmeta['og:title'] = get_bloginfo("name"); $fbmeta['og:url'] = esc_url(get_bloginfo("url")); } // stuff on all pages $fbmeta['og:site_name'] = get_bloginfo("name"); if (!empty($options["appid"])) { $fbmeta['fb:app_id'] = esc_attr($options["appid"]); } $fbmeta['og:locale'] = sfc_get_locale(); $fbmeta = apply_filters('sfc_base_meta', $fbmeta, $post); foreach ($fbmeta as $prop => $content) { if (is_array($content)) { foreach ($content as $item) { echo "<meta property='{$prop}' content='{$item}' />\n"; if ($prop == 'og:image') { echo "<link rel='image_src' href='{$item}' />\n"; } } } else { echo "<meta property='{$prop}' content='{$content}' />\n"; if ($prop == 'og:image') { echo "<link rel='image_src' href='{$content}' />\n"; } } } }
/** * Reset main query vars and filter 'the_content' to output a bbPress * template part as needed. * * @since bbPress (r3032) * @param string $template * @uses bbp_is_single_user() To check if page is single user * @uses bbp_get_single_user_template() To get user template * @uses bbp_is_single_user_edit() To check if page is single user edit * @uses bbp_get_single_user_edit_template() To get user edit template * @uses bbp_is_single_view() To check if page is single view * @uses bbp_get_single_view_template() To get view template * @uses bbp_is_forum_edit() To check if page is forum edit * @uses bbp_get_forum_edit_template() To get forum edit template * @uses bbp_is_topic_merge() To check if page is topic merge * @uses bbp_get_topic_merge_template() To get topic merge template * @uses bbp_is_topic_split() To check if page is topic split * @uses bbp_get_topic_split_template() To get topic split template * @uses bbp_is_topic_edit() To check if page is topic edit * @uses bbp_get_topic_edit_template() To get topic edit template * @uses bbp_is_reply_edit() To check if page is reply edit * @uses bbp_get_reply_edit_template() To get reply edit template * @uses bbp_set_theme_compat_template() To set the global theme compat template */ function bbp_template_include_theme_compat($template = '') { // Bail if the template already matches a bbPress template. This includes // archive-* and single-* WordPress post_type matches (allowing // themes to use the expected format) as well as all bbPress-specific // template files for users, topics, forums, etc... if (!empty(bbpress()->theme_compat->bbpress_template)) { return $template; } /** Users *************************************************************/ if (bbp_is_single_user() || bbp_is_single_user_edit()) { // Reset post bbp_theme_compat_reset_post(array('post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'comment_status' => 'closed')); /** Forums ************************************************************/ // Single forum edit } elseif (bbp_is_forum_edit()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_forum_id()), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); // Forum archive } elseif (bbp_is_forum_archive()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_forum_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); /** Topics ************************************************************/ // Topic archive } elseif (bbp_is_topic_archive()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single topic } elseif (bbp_is_topic_edit() || bbp_is_topic_split() || bbp_is_topic_merge()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_topic_id()), 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed')); /** Replies ***********************************************************/ // Reply archive } elseif (is_post_type_archive(bbp_get_reply_post_type())) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); // Single reply } elseif (bbp_is_reply_edit()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_reply_id()), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed')); /** Views *************************************************************/ } elseif (bbp_is_single_view()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Topic Tags ********************************************************/ } elseif (bbp_is_topic_tag_edit()) { // Stash the current term in a new var set_query_var('bbp_topic_tag', get_query_var('term')); // Reset the post with our new title bbp_theme_compat_reset_post(array('post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'))); } elseif (bbp_is_topic_tag()) { // Stash the current term in a new var set_query_var('bbp_topic_tag', get_query_var('term')); // Reset the post with our new title bbp_theme_compat_reset_post(array('post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'))); /** Single Forums/Topics/Replies **************************************/ } elseif (bbp_is_custom_post_type()) { bbp_set_theme_compat_active(); } /** * If we are relying on bbPress'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 bbp_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 the 'bbp_get_bbpress_template' to override the array of * possible templates, or 'bbp_bbpress_template' to override the result. */ if (bbp_is_theme_compat_active()) { // Remove all filters from the_content bbp_remove_all_filters('the_content'); // Add a filter on the_content late, which we will later remove add_filter('the_content', 'bbp_replace_the_content'); // Find the appropriate template file $template = bbp_get_theme_compat_templates(); } return apply_filters('bbp_template_include_theme_compat', $template); }