function jetpack_og_tags() { /** * Allow Jetpack to output Open Graph Meta Tags. * * @module sharedaddy, publicize * * @since 2.0.0 * @deprecated 2.0.3 Duplicative filter. Use `jetpack_enable_open_graph`. * * @param bool true Should Jetpack's Open Graph Meta Tags be enabled. Default to true. */ if (false === apply_filters('jetpack_enable_opengraph', true)) { _deprecated_function('jetpack_enable_opengraph', '2.0.3', 'jetpack_enable_open_graph'); return; } // Disable the widont filter on WP.com to avoid stray  s $disable_widont = remove_filter('the_title', 'widont'); $og_output = "\n<!-- Jetpack Open Graph Tags -->\n"; $tags = array(); /** * Filter the minimum width of the images used in Jetpack Open Graph Meta Tags. * * @module sharedaddy, publicize * * @since 2.0.0 * * @param int 200 Minimum image width used in Jetpack Open Graph Meta Tags. */ $image_width = absint(apply_filters('jetpack_open_graph_image_width', 200)); /** * Filter the minimum height of the images used in Jetpack Open Graph Meta Tags. * * @module sharedaddy, publicize * * @since 2.0.0 * * @param int 200 Minimum image height used in Jetpack Open Graph Meta Tags. */ $image_height = absint(apply_filters('jetpack_open_graph_image_height', 200)); $description_length = 197; if (is_home() || is_front_page()) { $site_type = get_option('open_graph_protocol_site_type'); $tags['og:type'] = !empty($site_type) ? $site_type : 'website'; $tags['og:title'] = get_bloginfo('name'); $tags['og:description'] = get_bloginfo('description'); $front_page_id = get_option('page_for_posts'); if ($front_page_id && is_home()) { $tags['og:url'] = get_permalink($front_page_id); } else { $tags['og:url'] = home_url('/'); } // Associate a blog's root path with one or more Facebook accounts $facebook_admins = get_option('facebook_admins'); if (!empty($facebook_admins)) { $tags['fb:admins'] = $facebook_admins; } } else { if (is_author()) { $tags['og:type'] = 'profile'; $author = get_queried_object(); $tags['og:title'] = $author->display_name; if (!empty($author->user_url)) { $tags['og:url'] = $author->user_url; } else { $tags['og:url'] = get_author_posts_url($author->ID); } $tags['og:description'] = $author->description; $tags['profile:first_name'] = get_the_author_meta('first_name', $author->ID); $tags['profile:last_name'] = get_the_author_meta('last_name', $author->ID); } else { if (is_singular()) { global $post; $data = $post; // so that we don't accidentally explode the global $tags['og:type'] = 'article'; if (empty($data->post_title)) { $tags['og:title'] = ' '; } else { /** This filter is documented in core/src/wp-includes/post-template.php */ $tags['og:title'] = wp_kses(apply_filters('the_title', $data->post_title, $data->ID), array()); } $tags['og:url'] = get_permalink($data->ID); if (!post_password_required()) { if (!empty($data->post_excerpt)) { $tags['og:description'] = preg_replace('@https?://[\\S]+@', '', strip_shortcodes(wp_kses($data->post_excerpt, array()))); } else { $exploded_content_on_more_tag = explode('<!--more-->', $data->post_content); $tags['og:description'] = wp_trim_words(preg_replace('@https?://[\\S]+@', '', strip_shortcodes(wp_kses($exploded_content_on_more_tag[0], array())))); } } if (empty($tags['og:description'])) { /** * Filter the fallback `og:description` used when no excerpt information is provided. * * @module sharedaddy, publicize * * @since 3.9.0 * * @param string $var Fallback og:description. Default is translated `Visit the post for more'. * @param object $data Post object for the current post. */ $tags['og:description'] = apply_filters('jetpack_open_graph_fallback_description', __('Visit the post for more.', 'jetpack'), $data); } else { // Intentionally not using a filter to prevent pollution. @see https://github.com/Automattic/jetpack/pull/2899#issuecomment-151957382 $tags['og:description'] = wp_kses(trim(convert_chars(wptexturize($tags['og:description']))), array()); } $tags['article:published_time'] = date('c', strtotime($data->post_date_gmt)); $tags['article:modified_time'] = date('c', strtotime($data->post_modified_gmt)); if (post_type_supports(get_post_type($data), 'author') && isset($data->post_author)) { $publicize_facebook_user = get_post_meta($data->ID, '_publicize_facebook_user', true); if (!empty($publicize_facebook_user)) { $tags['article:author'] = esc_url($publicize_facebook_user); } } } } } /** * Allow plugins to inject additional template-specific Open Graph tags. * * @module sharedaddy, publicize * * @since 3.0.0 * * @param array $tags Array of Open Graph Meta tags. * @param array $args Array of image size parameters. */ $tags = apply_filters('jetpack_open_graph_base_tags', $tags, compact('image_width', 'image_height')); // Re-enable widont if we had disabled it if ($disable_widont) { add_filter('the_title', 'widont'); } /** * Do not return any Open Graph Meta tags if we don't have any info about a post. * * @module sharedaddy, publicize * * @since 3.0.0 * * @param bool true Do not return any Open Graph Meta tags if we don't have any info about a post. */ if (empty($tags) && apply_filters('jetpack_open_graph_return_if_empty', true)) { return; } $tags['og:site_name'] = get_bloginfo('name'); // Get image info and build tags if (!post_password_required()) { $image_info = jetpack_og_get_image($image_width, $image_height); $tags['og:image'] = $image_info['src']; if (!empty($image_info['width'])) { $tags['og:image:width'] = $image_info['width']; } if (!empty($image_info['height'])) { $tags['og:image:height'] = $image_info['height']; } } // Facebook whines if you give it an empty title if (empty($tags['og:title'])) { $tags['og:title'] = __('(no title)', 'jetpack'); } // Shorten the description if it's too long if (isset($tags['og:description'])) { $tags['og:description'] = strlen($tags['og:description']) > $description_length ? mb_substr($tags['og:description'], 0, $description_length) . '…' : $tags['og:description']; } // Try to add OG locale tag if the WP->FB data mapping exists if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { require_once JETPACK__GLOTPRESS_LOCALES_PATH; $_locale = get_locale(); // We have to account for w.org vs WP.com locale divergence if (defined('IS_WPCOM') && IS_WPCOM) { $gp_locale = GP_Locales::by_field('slug', $_locale); } else { $gp_locale = GP_Locales::by_field('wp_locale', $_locale); } } if (isset($gp_locale->facebook_locale) && !empty($gp_locale->facebook_locale)) { $tags['og:locale'] = $gp_locale->facebook_locale; } /** * Allow the addition of additional Open Graph Meta tags, or modify the existing tags. * * @module sharedaddy, publicize * * @since 2.0.0 * * @param array $tags Array of Open Graph Meta tags. * @param array $args Array of image size parameters. */ $tags = apply_filters('jetpack_open_graph_tags', $tags, compact('image_width', 'image_height')); // secure_urls need to go right after each og:image to work properly so we will abstract them here $secure = $tags['og:image:secure_url'] = empty($tags['og:image:secure_url']) ? '' : $tags['og:image:secure_url']; unset($tags['og:image:secure_url']); $secure_image_num = 0; foreach ((array) $tags as $tag_property => $tag_content) { // to accommodate multiple images $tag_content = (array) $tag_content; $tag_content = array_unique($tag_content); foreach ($tag_content as $tag_content_single) { if (empty($tag_content_single)) { continue; } // Don't ever output empty tags $og_tag = sprintf('<meta property="%s" content="%s" />', esc_attr($tag_property), esc_attr($tag_content_single)); /** * Filter the HTML Output of each Open Graph Meta tag. * * @module sharedaddy, publicize * * @since 2.0.0 * * @param string $og_tag HTML HTML Output of each Open Graph Meta tag. */ $og_output .= apply_filters('jetpack_open_graph_output', $og_tag); $og_output .= "\n"; if ('og:image' == $tag_property) { if (is_array($secure) && !empty($secure[$secure_image_num])) { $og_tag = sprintf('<meta property="og:image:secure_url" content="%s" />', esc_url($secure[$secure_image_num])); /** This filter is documented in functions.opengraph.php */ $og_output .= apply_filters('jetpack_open_graph_output', $og_tag); $og_output .= "\n"; } else { if (!is_array($secure) && !empty($secure)) { $og_tag = sprintf('<meta property="og:image:secure_url" content="%s" />', esc_url($secure)); /** This filter is documented in functions.opengraph.php */ $og_output .= apply_filters('jetpack_open_graph_output', $og_tag); $og_output .= "\n"; } } $secure_image_num++; } } } echo $og_output; }
/** * This function needs to get loaded after the scripts get added to the page. * */ function likes_master() { $protocol = 'http'; if (is_ssl()) { $protocol = 'https'; } $_locale = get_locale(); // We have to account for WP.org vs WP.com locale divergence if ($this->in_jetpack) { if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { return false; } require_once JETPACK__GLOTPRESS_LOCALES_PATH; $gp_locale = GP_Locales::by_field('wp_locale', $_locale); $_locale = isset($gp_locale->slug) ? $gp_locale->slug : ''; } $likes_locale = '' == $_locale || 'en' == $_locale ? '' : '&lang=' . strtolower($_locale); $src = sprintf('%1$s://widgets.wp.com/likes/master.html?ver=%2$s#ver=%2$s%3$s', $protocol, $this->version, $likes_locale); $likersText = wp_kses(__('<span>%d</span> bloggers like this:', 'jetpack'), array('span' => array())); ?> <iframe src='<?php echo $src; ?> ' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe> <div id='likes-other-gravatars'><div class="likes-text"><?php echo $likersText; ?> </div><ul class="wpl-avatars sd-like-gravatars"></ul></div> <?php }
function guess_locale_from_lang($lang) { if ('en' == $lang || 'en_US' == $lang || !$lang) { return 'en_US'; } if (!class_exists('GP_Locales')) { if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { return false; } require JETPACK__GLOTPRESS_LOCALES_PATH; } if (defined('IS_WPCOM') && IS_WPCOM) { // WP.com: get_locale() returns 'it' $locale = GP_Locales::by_slug($lang); } else { // Jetpack: get_locale() returns 'it_IT'; $locale = GP_Locales::by_field('wp_locale', $lang); } if (!$locale) { return false; } if (empty($locale->facebook_locale)) { if (empty($locale->wp_locale)) { return false; } else { // Facebook SDK is smart enough to fall back to en_US if a // locale isn't supported. Since supported Facebook locales // can fall out of sync, we'll attempt to use the known // wp_locale value and rely on said fallback. return $locale->wp_locale; } } return $locale->facebook_locale; }
function guess_locale_from_lang($lang) { if ('en' == $lang || 'en_US' == $lang || !$lang) { return 'en_US'; } if (!class_exists('GP_Locales')) { if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { return false; } require JETPACK__GLOTPRESS_LOCALES_PATH; } if (defined('IS_WPCOM') && IS_WPCOM) { // WP.com: get_locale() returns 'it' $locale = GP_Locales::by_slug($lang); } else { // Jetpack: get_locale() returns 'it_IT'; $locale = GP_Locales::by_field('facebook_locale', $lang); } if (!$locale || empty($locale->facebook_locale)) { return 'en_US'; // Facebook requires a locale when pulling their SDK. } return $locale->facebook_locale; }
/** * Builds a URL to the Jetpack connection auth page * * @since 3.9.5 * * @param bool $raw If true, URL will not be escaped. * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. * If string, will be a custom redirect. * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. * * @return string Connect URL */ function build_connect_url($raw = false, $redirect = false, $from = false) { if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) { $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register'); if (is_network_admin()) { $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url); } } else { require_once JETPACK__GLOTPRESS_LOCALES_PATH; $role = $this->translate_current_user_to_role(); $signed_role = $this->sign_role($role); $user = wp_get_current_user(); $redirect = $redirect ? esc_url_raw($redirect) : esc_url_raw(menu_page_url('jetpack', false)); $gp_locale = GP_Locales::by_field('wp_locale', get_locale()); if (isset($_REQUEST['is_multisite'])) { $redirect = Jetpack_Network::init()->get_url('network_admin_page'); } $secrets = Jetpack::init()->generate_secrets('authorize'); @(list($secret) = explode(':', $secrets)); $site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false; $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), menu_page_url('jetpack', false)), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => 'calypso', 'secret' => $secret, 'locale' => isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon)); $url = add_query_arg($args, Jetpack::api_url('authorize')); } if ($from) { $url = add_query_arg('from', $from, $url); } if (isset($_GET['calypso_env'])) { $url = add_query_arg('calypso_env', $_GET['calypso_env'], $url); } return $raw ? $url : esc_url($url); }
/** * This function needs to get loaded after the scripts get added to the page. * */ function likes_master() { $protocol = 'http'; if (is_ssl()) { $protocol = 'https'; } if (version_compare($GLOBALS['wp_version'], '3.8-alpha', '>=')) { add_filter('mp6_enabled', '__return_true', 97); } $_locale = get_locale(); // We have to account for WP.org vs WP.com locale divergence if ($this->in_jetpack) { if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { return false; } require_once JETPACK__GLOTPRESS_LOCALES_PATH; $gp_locale = GP_Locales::by_field('wp_locale', $_locale); $_locale = isset($gp_locale->slug) ? $gp_locale->slug : ''; } $likes_locale = '' == $_locale || 'en' == $_locale ? '' : '&lang=' . strtolower($_locale); // @todo: Remove this opt-out filter in the future if (apply_filters('wpl_sharing_2014_1', true)) { $src = sprintf('%1$s://widgets.wp.com/likes/master.html?ver=%2$s#ver=%2$s%3$s&mp6=%4$d', $protocol, $this->version, $likes_locale, apply_filters('mp6_enabled', 0)); } else { $src = sprintf('%1$s://widgets.wp.com/likes/master-legacy.html?ver=%2$s#ver=%2$s%3$s&mp6=%4$d', $protocol, $this->version, $likes_locale, apply_filters('mp6_enabled', 0)); } $likersText = wp_kses(__('<span>%d</span> bloggers like this:', 'jetpack'), array('span' => array())); ?> <iframe src='<?php echo $src; ?> ' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe> <div id='likes-other-gravatars'><div class="likes-text"><?php echo $likersText; ?> </div><ul class="wpl-avatars sd-like-gravatars"></ul></div> <?php }
/** * Builds a URL to the Jetpack connection auth page * * @since 3.9.5 * * @param bool $raw If true, URL will not be escaped. * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. * If string, will be a custom redirect. * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. * * @return string Connect URL */ function build_connect_url($raw = false, $redirect = false, $from = false) { if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) { $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register'); if (is_network_admin()) { $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url); } } else { if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && (include_once JETPACK__GLOTPRESS_LOCALES_PATH)) { $gp_locale = GP_Locales::by_field('wp_locale', get_locale()); } $role = self::translate_current_user_to_role(); $signed_role = self::sign_role($role); $user = wp_get_current_user(); $jetpack_admin_page = esc_url_raw(admin_url('admin.php?page=jetpack')); $redirect = $redirect ? wp_validate_redirect(esc_url_raw($redirect), $jetpack_admin_page) : $jetpack_admin_page; if (isset($_REQUEST['is_multisite'])) { $redirect = Jetpack_Network::init()->get_url('network_admin_page'); } $secrets = Jetpack::init()->generate_secrets('authorize'); @(list($secret) = explode(':', $secrets)); $site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false; /** * Filter the type of authorization. * 'calypso' completes authorization on wordpress.com/jetpack/connect * while 'jetpack' ( or any other value ) completes the authorization at jetpack.wordpress.com. * * @since 4.3.3 * * @param string $auth_type Defaults to 'calypso', can also be 'jetpack'. */ $auth_type = apply_filters('jetpack_auth_type', 'calypso'); $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), esc_url(admin_url('admin.php?page=jetpack'))), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => $auth_type, 'secret' => $secret, 'locale' => isset($gp_locale) && isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon)); $url = add_query_arg($args, Jetpack::api_url('authorize')); } if ($from) { $url = add_query_arg('from', $from, $url); } if (isset($_GET['calypso_env'])) { $url = add_query_arg('calypso_env', sanitize_key($_GET['calypso_env']), $url); } return $raw ? $url : esc_url($url); }
function guess_locale_from_lang($lang) { if ('en' == $lang || 'en_US' == $lang || !$lang) { return 'en_US'; } if (!class_exists('GP_Locales')) { require JETPACK__PLUGIN_DIR . 'locales.php'; } // Jetpack: get_locale() returns 'it_IT'; $locale = GP_Locales::by_field('wp_locale', $lang); if (!$locale || empty($locale->facebook_locale)) { return false; } return $locale->facebook_locale; }
function jetpack_og_tags() { if (false === apply_filters('jetpack_enable_opengraph', true)) { _deprecated_function('jetpack_enable_opengraph', '2.0.3', 'jetpack_enable_open_graph'); return; } // Disable the widont filter on WP.com to avoid stray  s $disable_widont = remove_filter('the_title', 'widont'); $og_output = "\n<!-- Jetpack Open Graph Tags -->\n"; $tags = array(); $image_width = absint(apply_filters('jetpack_open_graph_image_width', 200)); $image_height = absint(apply_filters('jetpack_open_graph_image_height', 200)); $description_length = 197; if (is_home() || is_front_page()) { $site_type = get_option('open_graph_protocol_site_type'); $tags['og:type'] = !empty($site_type) ? $site_type : 'website'; $tags['og:title'] = get_bloginfo('name'); $tags['og:description'] = get_bloginfo('description'); $front_page_id = get_option('page_for_posts'); if ($front_page_id && is_home()) { $tags['og:url'] = get_permalink($front_page_id); } else { $tags['og:url'] = home_url('/'); } // Associate a blog's root path with one or more Facebook accounts $facebook_admins = get_option('facebook_admins'); if (!empty($facebook_admins)) { $tags['fb:admins'] = $facebook_admins; } } else { if (is_author()) { $tags['og:type'] = 'profile'; $author = get_queried_object(); $tags['og:title'] = $author->display_name; if (!empty($author->user_url)) { $tags['og:url'] = $author->user_url; } else { $tags['og:url'] = get_author_posts_url($author->ID); } $tags['og:description'] = $author->description; $tags['profile:first_name'] = get_the_author_meta('first_name', $author->ID); $tags['profile:last_name'] = get_the_author_meta('last_name', $author->ID); } else { if (is_singular()) { global $post; $data = $post; // so that we don't accidentally explode the global $tags['og:type'] = 'article'; $tags['og:title'] = empty($data->post_title) ? ' ' : wp_kses($data->post_title, array()); $tags['og:url'] = get_permalink($data->ID); if (!post_password_required()) { $tags['og:description'] = !empty($data->post_excerpt) ? preg_replace('@https?://[\\S]+@', '', strip_shortcodes(wp_kses($data->post_excerpt, array()))) : wp_trim_words(preg_replace('@https?://[\\S]+@', '', strip_shortcodes(wp_kses($data->post_content, array())))); } if (empty($tags['og:description'])) { $tags['og:description'] = __('Visit the post for more.', 'jetpack'); } $tags['article:published_time'] = date('c', strtotime($data->post_date_gmt)); $tags['article:modified_time'] = date('c', strtotime($data->post_modified_gmt)); if (post_type_supports(get_post_type($data), 'author') && isset($data->post_author)) { $publicize_facebook_user = get_post_meta($data->ID, '_publicize_facebook_user', true); if (!empty($publicize_facebook_user)) { $tags['article:author'] = esc_url($publicize_facebook_user); } else { $tags['article:author'] = get_author_posts_url($data->post_author); } } } } } // Allow plugins to inject additional template-specific open graph tags $tags = apply_filters('jetpack_open_graph_base_tags', $tags, compact('image_width', 'image_height')); // Re-enable widont if we had disabled it if ($disable_widont) { add_filter('the_title', 'widont'); } if (empty($tags) && apply_filters('jetpack_open_graph_return_if_empty', true)) { return; } $tags['og:site_name'] = get_bloginfo('name'); if (!post_password_required()) { $tags['og:image'] = jetpack_og_get_image($image_width, $image_height); } // Facebook whines if you give it an empty title if (empty($tags['og:title'])) { $tags['og:title'] = __('(no title)', 'jetpack'); } // Shorten the description if it's too long if (isset($tags['og:description'])) { $tags['og:description'] = strlen($tags['og:description']) > $description_length ? mb_substr($tags['og:description'], 0, $description_length) . '...' : $tags['og:description']; } // Try to add OG locale tag if the WP->FB data mapping exists if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { require_once JETPACK__GLOTPRESS_LOCALES_PATH; $_locale = get_locale(); // We have to account for WP.org vs WP.com locale divergence if (defined('IS_WPCOM') && IS_WPCOM) { $gp_locale = GP_Locales::by_field('slug', $_locale); } else { $gp_locale = GP_Locales::by_field('wp_locale', $_locale); } } if (isset($gp_locale->facebook_locale) && !empty($gp_locale->facebook_locale)) { $tags['og:locale'] = $gp_locale->facebook_locale; } // Add any additional tags here, or modify what we've come up with $tags = apply_filters('jetpack_open_graph_tags', $tags, compact('image_width', 'image_height')); // secure_urls need to go right after each og:image to work properly so we will abstract them here $secure = $tags['og:image:secure_url'] = empty($tags['og:image:secure_url']) ? '' : $tags['og:image:secure_url']; unset($tags['og:image:secure_url']); $secure_image_num = 0; foreach ((array) $tags as $tag_property => $tag_content) { // to accommodate multiple images $tag_content = (array) $tag_content; $tag_content = array_unique($tag_content); foreach ($tag_content as $tag_content_single) { if (empty($tag_content_single)) { continue; } // Don't ever output empty tags $og_tag = sprintf('<meta property="%s" content="%s" />', esc_attr($tag_property), esc_attr($tag_content_single)); $og_output .= apply_filters('jetpack_open_graph_output', $og_tag); $og_output .= "\n"; if ('og:image' == $tag_property) { if (is_array($secure) && !empty($secure[$secure_image_num])) { $og_tag = sprintf('<meta property="og:image:secure_url" content="%s" />', esc_url($secure[$secure_image_num])); $og_output .= apply_filters('jetpack_open_graph_output', $og_tag); $og_output .= "\n"; } else { if (!is_array($secure) && !empty($secure)) { $og_tag = sprintf('<meta property="og:image:secure_url" content="%s" />', esc_url($secure)); $og_output .= apply_filters('jetpack_open_graph_output', $og_tag); $og_output .= "\n"; } } $secure_image_num++; } } } echo $og_output; }
function admin_bar_menu() { global $wp_admin_bar, $current_blog; if (!is_object($wp_admin_bar)) { return; } $wpcom_locale = get_locale(); if (!class_exists('GP_Locales')) { if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) { require JETPACK__GLOTPRESS_LOCALES_PATH; } } if (class_exists('GP_Locales')) { $wpcom_locale_object = GP_Locales::by_field('wp_locale', get_locale()); if ($wpcom_locale_object instanceof GP_Locale) { $wpcom_locale = $wpcom_locale_object->slug; } } $classes = 'wpnt-loading wpn-read'; $wp_admin_bar->add_menu(array('id' => 'notes', 'title' => '<span id="wpnt-notes-unread-count" class="' . esc_attr($classes) . '"> <span class="noticon noticon-notification"></span> </span>', 'meta' => array('html' => '<div id="wpnt-notes-panel2" style="display:none" lang="' . esc_attr($wpcom_locale) . '" dir="' . (is_rtl() ? 'rtl' : 'ltr') . '"><div class="wpnt-notes-panel-header"><span class="wpnt-notes-header">' . __('Notifications', 'jetpack') . '</span><span class="wpnt-notes-panel-link"></span></div></div>', 'class' => 'menupop'), 'parent' => 'top-secondary')); }
/** * private functions for admin page : the language list * @since 0.9.0 * * @update 0.9.5 : two default languages if taxonomy languages is empty * @update 1.8.8 : fixes slug of defaults * @update 1.8.9.1 : visible = * * @updated 2.6 : style * @updated 2.7.1 : default full name * @updated 2.11.2 : detailled counter in title */ function available_languages_row() { global $wpdb; /*list of languages*/ $listlanguages = get_terms_of_groups_lite($this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC'); if (empty($listlanguages)) { /*create two default lines with the default language (as in config)*/ /* language of WP */ $term = 'en_US'; $args = array('alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' => 'en_us'); $term_data = $this->safe_lang_term_creation($term, $args); if (!is_wp_error($term_data)) { wp_set_object_terms($term_data['term_id'], 'the-langs-group', TAXOLANGSGROUP); } else { $inserted = $this->safe_insert_in_language_group($term_data, 0); } $term = $this->default_lang; $desc = isset($this->examples_list[$term]) ? $this->examples_list[$term] : $this->default_lang; $desc_array = explode(' (', $desc); $desc = $desc_array[0]; $slug = strtolower($this->default_lang); // 2.3.1 $wplang = $this->get_WPLANG(); if ('' == $wplang || $this->default_lang == 'en_US' || $this->default_lang == '') { $term = 'fr_FR'; $desc = 'French'; $slug = 'fr_fr'; } $args = array('alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); $term_data = $this->safe_lang_term_creation($term, $args); if (!is_wp_error($term_data)) { wp_set_object_terms($term_data['term_id'], 'the-langs-group', TAXOLANGSGROUP); } else { $inserted = $this->safe_insert_in_language_group($term_data, 0); } $listlanguages = get_terms_of_groups_lite($this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC'); } $trclass = ''; foreach ($listlanguages as $language) { $trclass = defined('DOING_AJAX') && DOING_AJAX || ' alternate' == $trclass ? '' : ' alternate'; $language->count = number_format_i18n($language->count); // count for each CPT $counts = array(); $title = array(); $custompoststype = $this->authorized_custom_post_type(true); // 2.13.2 b foreach ($custompoststype as $key => $customtype) { $counts[$key] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->term_relationships}, {$wpdb->posts} WHERE {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id AND post_status = 'publish' AND term_taxonomy_id = %d AND post_type = %s", $language->term_id, $key)); $title[] = $customtype['name'] . ' = ' . $counts[$key]; } $title = implode(' | ', $title); $posts_count = $language->count > 0 ? '<a title= "' . $title . '" href="edit.php?lang=' . $language->slug . '">' . $language->count . '</a>' : $language->count; /* edit link*/ // nounce added $link = wp_nonce_url("?action=edit&page=language_page&term_id=" . $language->term_id, "edit-" . $language->term_id); $edit = "<a href='" . $link . "' >" . __('Edit') . "</a> |"; /* delete link*/ // nounce added $link = wp_nonce_url("?action=delete&page=language_page&term_id=" . $language->term_id, "delete-" . $language->term_id); $edit .= " <a href='" . $link . "' class='delete'>" . __('Delete') . "</a>"; $h = isset($this->xili_settings['lang_features'][$language->slug]['hidden']) && $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ? " " : "✔"; $h .= isset($this->xili_settings['lang_features'][$language->slug]['charset']) && $this->xili_settings['lang_features'][$language->slug]['charset'] != '' ? " +" : ""; $is_mo = !empty($language->name) && array_key_exists($language->name, (array) $this->available_languages()); $mo_available_for_dashboard = $is_mo ? "✔" : ""; $line = '<tr id="lang-' . $language->term_id . '" class="lang-' . $language->slug . $trclass . '" >' . '<th scope="row" class="lang-id" ><span class="lang-flag">' . $language->term_id . '<span></th>' . '<td>' . $language->name . '</td>'; $cur_locale = GP_Locales::by_field('wp_locale', $language->name); if ($cur_locale) { $native = $cur_locale->native_name; } else { $cur_locale = GP_Locales::by_slug($language->slug); $native = $cur_locale ? $cur_locale->native_name . ' *' : ''; } if ($this->alias_mode) { $alias_val = $this->lang_slug_qv_trans($language->slug) == $language->slug && 2 != strlen($language->slug) ? ' ? ' : $this->lang_slug_qv_trans($language->slug); $key_slug = array_keys($this->langs_slug_shortqv_array, $alias_val); if (count($key_slug) == 1) { $line .= '<td>' . $alias_val . '</td>'; } else { $line .= '<td><span class="red-alert">' . $alias_val . '</span></td>'; } } $line .= '<td>' . $language->description . '</td>' . '<td>' . $native . '</td>' . '<td>' . $language->slug . '</td>' . '<td>' . $language->term_order . '</td>' . '<td class="col-center" >' . $h . '</td>' . '<td class="col-center" >' . $mo_available_for_dashboard . '</td>' . '<td class="col-center" >' . $posts_count . '</td>' . '<td class="col-center" >' . $edit . "</td>\n\t</tr>\n"; echo $line; } }
/** * since 2.6 * */ function init_vars() { // type of languages list see options in xili_language_list or navmenu - third param = title for option $this->langs_list_options = array(array('', __('Nav to home', 'xili-language'), __('Links redirect to home.', 'xili-language')), array('typeone', __('Nav to home (w/o cur lang.)', 'xili-language'), __('Current language is not inserted and links redirect to home.', 'xili-language')), array('typeonenew', __('Nav to Singular (w/o cur lang.)', 'xili-language'), __('Current language is not inserted and links redirect to post or page if exists in other languages.', 'xili-language')), array('navmenu', __('Nav Menu', 'xili-language'), __('List of all languages are inserted and links redirect to home.', 'xili-language')), array('navmenu-a', __('Nav Menu (w/o current lang.)', 'xili-language'), __('Current language is not inserted and links redirect to home.', 'xili-language')), array('navmenu-1', __('Nav Menu Singular', 'xili-language'), __('List of all languages are inserted and links redirect to post or page if exists in other languages.', 'xili-language')), array('navmenu-1a', __('Nav Menu Singular (w/o current lang.)', 'xili-language'), __('Current language is not inserted and links redirect to post or page if exists in other languages.', 'xili-language')), array('navmenu-1ao', __('Nav Menu Singular (w/o curr. lang and if exists)', 'xili-language'), __('Current language is not inserted and links appears and redirect to post or page if exists in other languages.', 'xili-language'))); /* default values */ $wplang = $this->get_WPLANG(); if ('' != $wplang && (strlen($wplang) == 5 || strlen($wplang) == 2)) { // for japanese $this->default_lang = $wplang; } else { $this->default_lang = 'en_US'; } // cache_domain added to avoid annoying caches 2.8.4 $cache_suffix = $this->class_admin ? "_ad" : ""; $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false, 'slug' => 'the-langs-group', 'cache_domain' => 'core1' . $cache_suffix)); if (array() == $thegroup) { /* update langs group 0.9.8 and if from start 2.3.1 */ $args = array('alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' => 'the-langs-group'); wp_insert_term('the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */ $list_languages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all', 'cache_domain' => 'core1' . $cache_suffix)); if (array() == $list_languages) { /*create two default lines with the default language (as in config)*/ /* language of WP */ if (!class_exists('GP_Locales')) { require_once $this->plugin_path . 'xili-includes/locales.php'; // thanks hnygard 20141212 } $term = 'en_US'; $args = array('alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' => 'en_us'); $term_data = $this->safe_lang_term_creation($term, $args); if (!is_wp_error($term_data)) { wp_set_object_terms($term_data['term_id'], 'the-langs-group', TAXOLANGSGROUP); $this->xili_settings['lang_features']['en_us'] = array('charset' => "", 'hidden' => ""); } else { $inserted = $this->safe_insert_in_language_group($term_data, 0); } $term = $this->default_lang; $locale_2 = GP_Locales::by_field('wp_locale', $term); $desc = $locale_2 ? $locale_2->english_name : $this->default_lang; $desc_array = explode(' (', $desc); $desc = $desc_array[0]; $slug = strtolower($this->default_lang); // 2.3.1 $wp_lang = $this->get_WPLANG(); if ($wp_lang == '' || $this->default_lang == 'en_US' || $this->default_lang == '') { $term = 'fr_FR'; $desc = 'french'; $slug = 'fr_fr'; } $args = array('alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); $term_data = $this->safe_lang_term_creation($term, $args); if (!is_wp_error($term_data)) { wp_set_object_terms($term_data['term_id'], 'the-langs-group', TAXOLANGSGROUP); $this->xili_settings['lang_features'][$slug] = array('charset' => "", 'hidden' => ""); } else { $inserted = $this->safe_insert_in_language_group($term_data, 0); } update_option('xili_language_settings', $this->xili_settings); $list_languages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all', 'cache_domain' => 'core2' . $cache_suffix)); } foreach ($list_languages as $language) { wp_set_object_terms($language->term_id, 'the-langs-group', TAXOLANGSGROUP); } $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false, 'slug' => 'the-langs-group', 'get' => 'all', 'cache_domain' => 'core2' . $cache_suffix)); } else { // if created by XD - update $list_languages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all', 'cache_domain' => 'core2' . $cache_suffix)); $i = 0; foreach ($list_languages as $language) { if (!isset($this->xili_settings['lang_features'][$language->slug])) { $this->xili_settings['lang_features'][$language->slug] = array('charset' => "", 'hidden' => ""); $i++; } } if ($i > 0) { update_option('xili_language_settings', $this->xili_settings); } } $this->langs_group_id = $thegroup[0]->term_id; $this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id; if ($this->langs_group_id > 0) { $this->xili_settings['langs_group_id'] = $this->langs_group_id; $this->xili_settings['langs_group_tt_id'] = $this->langs_group_tt_id; update_option('xili_language_settings', $this->xili_settings); // 2.15.1 } if (is_child_theme()) { // 1.8.1 - 1.8.5 if ($this->xili_settings['langs_in_root_theme'] == 'root') { $this->get_template_directory = get_template_directory(); } else { $this->get_template_directory = get_stylesheet_directory(); } $this->get_parent_theme_directory = get_template_directory(); } else { $this->get_template_directory = get_template_directory(); $this->get_parent_theme_directory = ''; } $this->get_lang_slug_ids(); // default array of languages slug=>id and slug=>name // 2.4.2 if ($this->show_page_on_front) { $this->get_show_page_on_front_array(); } /* here because taxonomy is registered : since 1.5.3 */ $this->default_slug = $this->get_default_slug(); /*no constant for wpmu */ if (!is_multisite() && !defined('DEFAULTSLUG')) { define('DEFAULTSLUG', $this->default_slug); } /* for backward compatibility */ // if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */ if (is_rtl()) { $this->default_dir = 'rtl'; } // $dir; 2.16.6 // 1.8.4 if (array() == $this->xili_settings['available_langs']) { $this->xili_settings['available_langs'] = $this->get_lang_ids(); update_option('xili_language_settings', $this->xili_settings); } }