public static function tally_term_counts(&$terms, $taxonomy, $args = array()) { global $wpdb, $pp_current_user; if (!$terms) { return; } $defaults = array('pad_counts' => true, 'post_type' => '', 'required_operation' => ''); $args = array_merge($defaults, (array) $args); extract($args); $term_items = array(); if ($terms) { if (!is_object(reset($terms))) { return $terms; } foreach ((array) $terms as $key => $term) { $terms_by_id[$term->term_id] =& $terms[$key]; $term_ids[$term->term_taxonomy_id] = $term->term_id; } } // Get the object and term ids and stick them in a lookup table $tax_obj = get_taxonomy($taxonomy); $object_types = $post_type ? (array) $post_type : (array) esc_sql($tax_obj->object_type); if (pp_unfiltered()) { $stati = get_post_stati(array('public' => true, 'private' => true), 'names', 'or'); $type_status_clause = "AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status IN ('" . implode("', '", $stati) . "')"; } else { global $query_interceptor; $type_status_clause = $query_interceptor->get_posts_where(array('post_types' => $object_types, 'required_operation' => $required_operation)); // need to apply term restrictions in case post is restricted by another taxonomy } if (!$required_operation) { $required_operation = pp_is_front() && !is_preview() ? 'read' : 'edit'; } $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM {$wpdb->term_relationships} INNER JOIN {$wpdb->posts} ON object_id = ID WHERE term_taxonomy_id IN ('" . implode("','", array_keys($term_ids)) . "') {$type_status_clause}"); foreach ($results as $row) { $id = $term_ids[$row->term_taxonomy_id]; $term_items[$id][$row->object_id] = isset($term_items[$id][$row->object_id]) ? ++$term_items[$id][$row->object_id] : 1; } // Touch every ancestor's lookup row for each post in each term foreach ($term_ids as $term_id) { $child = $term_id; while (!empty($terms_by_id[$child]) && ($parent = $terms_by_id[$child]->parent)) { if (!empty($term_items[$term_id])) { foreach ($term_items[$term_id] as $item_id => $touches) { $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id] : 1; } } $child = $parent; } } foreach (array_keys($terms_by_id) as $key) { $terms_by_id[$key]->count = 0; } // Transfer the touched cells foreach ((array) $term_items as $id => $items) { if (isset($terms_by_id[$id])) { $terms_by_id[$id]->count = count($items); } } }
/** * Return a shortlink for a post, page, attachment, or blog. * * @since 1.0.0 */ public function getShortlink($shortlink, $id, $context, $allow_slugs) { if (ot_get_option('bitly_service_active') == 'no') { return false; } if (is_singular() && is_preview()) { return false; } global $wp_query; $post_id = ''; if ('query' == $context && is_singular()) { $post_id = $wp_query->get_queried_object_id(); } else { if ('post' == $context) { $post = get_post($id); $post_id = $post->ID; } } if ($shortlink = get_metadata('post', $post_id, '_bitly_shortlink', true)) { return $shortlink; } if (is_front_page() && !is_paged()) { return apply_filters('bitly_front_page', false); } $url = get_permalink($post_id); $domain = ot_get_option('bitly_domain'); $this->login(ot_get_option('bitly_login')); $this->apiKey(ot_get_option('bitly_api_key')); $shortlink = $this->shorten($url, $domain); if (!empty($shortlink)) { update_metadata('post', $post_id, '_bitly_shortlink', $shortlink); return $shortlink; } return false; }
function cached_result($cache_key, $cache_group, $fn = null) { if (is_null($fn)) { $fn = $cache_group; $cache_group = ''; $namespaced = []; } if ($cache_group) { $namespaced = wp_cache_get($cache_group, 'cache_namespaces'); if ($namespaced === false) { wp_cache_set($cache_group, $namespaced = [], CACHE_NAMESPACES); } } if (!is_preview() && in_array($cache_key, $namespaced) && ($result = wp_cache_get($cache_key, $cache_group))) { return $result; } $result = call_user_func($fn); if (!is_preview()) { wp_cache_set($cache_key, $result, $cache_group); if ($cache_group) { wp_cache_set($cache_group, $namespaced + [$cache_key], CACHE_NAMESPACES); } } return $result; }
function rocket_cdn_enqueue($src) { // Don't use CDN if in admin, in login page, in register page or in a post preview if (is_admin() || is_preview() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) { return $src; } $src = set_url_scheme($src); $zone = array('all', 'css_and_js'); // Add only CSS zone if (current_filter() == 'style_loader_src') { $zone[] = 'css'; } // Add only JS zone if (current_filter() == 'script_loader_src') { $zone[] = 'js'; } if ($cnames = get_rocket_cdn_cnames($zone)) { list($src_host, $src_path) = get_rocket_parse_url($src); // Check if the link isn't external if ($src_host == parse_url(home_url(), PHP_URL_HOST) && trim($src_path, '/') != '') { $src = get_rocket_cdn_url($src, $zone); } } return $src; }
/** * Get post option value from the database * * @param null|int $post_id * @param string|null $option_id Specific option id (accepts multikey). null - all options * @param null|mixed $default_value If no option found in the database, this value will be returned * @param null|bool $get_original_value Original value is that with no translations and other changes * * @return mixed|null */ function fw_get_db_post_option($post_id = null, $option_id = null, $default_value = null, $get_original_value = null) { if (!$post_id) { /** @var WP_Post $post */ global $post; if (!$post) { return $default_value; } else { $post_id = $post->ID; } /** * Check if is Preview and use the preview post_id instead of real/current post id * * Note: WordPress changes the global $post content on preview: * 1. https://github.com/WordPress/WordPress/blob/2096b451c704715db3c4faf699a1184260deade9/wp-includes/query.php#L3573-L3583 * 2. https://github.com/WordPress/WordPress/blob/4a31dd6fe8b774d56f901a29e72dcf9523e9ce85/wp-includes/revision.php#L485-L528 */ if (is_preview()) { $preview = wp_get_post_autosave($post->ID); if (is_object($preview)) { $post_id = $preview->ID; } } } $option_id = 'fw_options' . ($option_id !== null ? '/' . $option_id : ''); return FW_WP_Meta::get('post', $post_id, $option_id, $default_value, $get_original_value); }
function storikaze_tag_at($atts, $content = null) { $timecode = strtotime($GLOBALS["storikaze_time_now"]); // Of course, if the page is being displayed in preview mode, // we want anything to show up. (This part of code may change // if there is a way to have a preview with a particular // point in time specified.) if (is_preview()) { return do_shortcode($content); } foreach ($atts as $thenom => $theval) { if ($thenom == "from") { if ($timecode < strtotime($theval)) { return ""; } } // The "to" attribute specifies a time at which the text // disappears (such as the "story still in progress" note // at the end of the TOC -- but only once you know at what // time the very last installation of the story will be // added). if ($thenom == "to") { if ($timecode > strtotime($theval)) { return ""; } } } return do_shortcode($content); }
/** * kill_frame() * * @return void **/ function kill_frame() { if (is_preview()) { return; } $home_url = strtolower(get_option('home')); echo <<<EOS <script type="text/javascript"> <!-- try { \tvar parent_location = new String(parent.location); \tvar top_location = new String(top.location); \tvar cur_location = new String(document.location); \tparent_location = parent_location.toLowerCase(); \ttop_location = top_location.toLowerCase(); \tcur_location = cur_location.toLowerCase(); \tif ( top_location != cur_location && parent_location.indexOf('{$home_url}') != 0 ) \t\ttop.location.href = document.location.href; } catch ( err ) { \ttop.location.href = document.location.href; } //--> </script> EOS; }
function is_exit() { if (is_admin() || is_feed() || is_preview() || 1 === intval(get_query_var('print')) || 1 === intval(get_query_var('printpage')) || false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini')) { return true; } return false; }
function ucc_include_custom_post_types($query) { global $wp_query; /* Don't break admin or preview pages. This is also a good place to exclude feed with !is_feed() if desired. */ if (!is_preview() && !is_admin() && !is_singular()) { $args = array('public' => true, '_builtin' => false); $output = 'names'; $operator = 'and'; $post_types = get_post_types($args, $output, $operator); /* Add 'link' and/or 'page' to array() if you want these included: * array( 'post' , 'link' , 'page' ), etc. */ $post_types = array_merge($post_types, array('post')); if ($query->is_feed) { /* Do feed processing here if you did not exclude it previously. This if/else * is not necessary if you want custom post types included in your feed. */ } else { $my_post_type = get_query_var('post_type'); if (empty($my_post_type)) { $query->set('post_type', $post_types); } } } return $query; }
/** * hook : the_content * Inspired from Unveil Lazy Load plugin : https://wordpress.org/plugins/unveil-lazy-load/ by @marubon * * @return string * @package Customizr * @since Customizr 3.3.0 */ function tc_parse_imgs( $_html ) { if( is_feed() || is_preview() || ( wp_is_mobile() && apply_filters('tc_disable_img_smart_load_mobiles', false ) ) ) return $_html; if ( strpos( $_html, 'data-src' ) !== false ) return $_html; return preg_replace_callback('#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', array( $this , 'tc_regex_callback' ) , $_html); }
/** * hook : the_content * @return string * @package Customizr * @since Customizr 3.3.0 */ function tc_parse_imgs($_html) { if (is_feed() || is_preview() || wp_is_mobile()) { return $_html; } if (strpos($_html, 'data-src') !== false) { return $_html; } return preg_replace_callback('#<img([^>]+?)src=[\'"]?([^\'"\\s>]+)[\'"]?([^>]*)>#', array($this, 'tc_regex_callback'), $_html); }
function add_dummy_image($content) { if (is_feed() || is_preview() || $this->is_smartphone()) { return $content; } if (strpos($content, 'data-src') !== false) { return $content; } $content = preg_replace_callback('#<img([^>]+?)src=[\'"]?([^\'"\\s>]+)[\'"]?([^>]*)>#', array($this, 'replace_callback'), $content); return $content; }
/** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { if (!is_preview()) { echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } echo '<div class="tm-ads-widget">'; echo $instance['ads_code']; echo '</div>'; echo $args['after_widget']; } }
function rocket_lazyload_images($html) { // Don't LazyLoad if the thumbnail is in admin, a feed or a post preview if (is_admin() || is_feed() || is_preview() || empty($html)) { return $html; } // You can stop the LalyLoad process with a hook if (!apply_filters('do_rocket_lazyload', true)) { return $html; } $html = preg_replace_callback('#<img([^>]*) src=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))([^>]*)>#', '__rocket_lazyload_replace_callback', $html); return $html; }
function _pp_flt_administrator_pad_term_counts($terms, $taxonomies, $args) { if (!defined('XMLRPC_REQUEST') && 'all' == $args['fields'] && empty($args['pp_no_filter'])) { global $pagenow; if (!is_admin() || !in_array($pagenow, array('post.php', 'post-new.php'))) { require_once PPC_ABSPATH . '/terms-query-lib_pp.php'; // pp_tally_term_counts() is PP equivalent to WP _pad_term_counts() $args['required_operation'] = pp_is_front() && !is_preview() ? 'read' : 'edit'; PP_TermsQueryLib::tally_term_counts($terms, reset($taxonomies), $args); } } return $terms; }
/** * Display the widget. * * @param array $args * @param array $instance */ public function widget($args, $instance) { $instance = $this->modify_instance($instance); $this->current_instance = $instance; $args = wp_parse_args($args, array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '')); $style = $this->get_style_name($instance); // Add any missing default values to the instance $instance = $this->add_defaults($this->form_options, $instance); $upload_dir = wp_upload_dir(); $this->clear_file_cache(); if ($style !== false) { $hash = $this->get_style_hash($instance); $css_name = $this->id_base . '-' . $style . '-' . $hash; if (isset($instance['is_preview']) && $instance['is_preview'] || is_preview()) { siteorigin_widget_add_inline_css($this->get_instance_css($instance)); } else { if (!file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css') || defined('SITEORIGIN_WIDGETS_DEBUG') && SITEORIGIN_WIDGETS_DEBUG) { // Attempt to recreate the CSS $this->save_css($instance); } if (file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css')) { wp_enqueue_style($css_name, $upload_dir['baseurl'] . '/siteorigin-widgets/' . $css_name . '.css'); } else { // Fall back to using inline CSS if we can't find the cached CSS file. siteorigin_widget_add_inline_css($this->get_instance_css($instance)); } } } else { $css_name = $this->id_base . '-base'; } $this->enqueue_frontend_scripts(); extract($this->get_template_variables($instance, $args)); // Storage hash allows $storage_hash = ''; if (!empty($this->widget_options['instance_storage'])) { $stored_instance = $this->filter_stored_instance($instance); $storage_hash = substr(md5(serialize($stored_instance)), 0, 8); if (!empty($stored_instance) && empty($instance['is_preview'])) { // Store this if we have a non empty instance and are not previewing set_transient('sow_inst[' . $this->id_base . '][' . $storage_hash . ']', $stored_instance, 7 * 86400); } } echo $args['before_widget']; echo '<div class="so-widget-' . $this->id_base . ' so-widget-' . $css_name . '">'; ob_start(); @(include siteorigin_widget_get_plugin_dir_path($this->id_base) . '/' . $this->get_template_dir($instance) . '/' . $this->get_template_name($instance) . '.php'); echo apply_filters('siteorigin_widget_template', ob_get_clean(), get_class($this), $instance, $this); echo '</div>'; echo $args['after_widget']; $this->current_instance = false; }
/** * Add HTML5 Boilerplate code for google analytics * Insert your ID in Option Theme admin panel * Print code only if value exist * @return string Return google analytics code */ function italystrap_add_google_analytics() { $analytics = isset($GLOBALS['italystrap_options']['analytics']) && $GLOBALS['italystrap_options']['analytics'] !== 0 ? esc_textarea($GLOBALS['italystrap_options']['analytics']) : ''; if (!is_preview() && !is_admin() && $analytics) { ?> <!-- Google Analytics from HTML5 Boilerplate --> <script>(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;e=o.createElement(i);r=o.getElementsByTagName(i)[0];e.src='https://www.google-analytics.com/analytics.js';r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));ga('create','<?php echo $analytics; ?> ','auto');ga('send','pageview');</script> <?php } }
/** * Get shortcode hash by it content and attributes * * @param $atts * @param $content * * @return string */ public function getHash($atts, $content) { if (vc_is_page_editable() || is_preview()) { /* We are in Frontend editor * We need to send RAW shortcode data, so hash is just json_encode of atts and content */ return urlencode(json_encode(array('tag' => $this->shortcode, 'atts' => $atts, 'content' => $content))); } /** Else * We are in preview mode (viewing page). * So hash is shortcode atts and content hash */ return sha1(serialize(array('tag' => $this->shortcode, 'atts' => $atts, 'content' => $content))); }
function add_image_tag_placeholders($content) { //プレビューやフィードモバイルなどで遅延させない if (is_feed() || is_preview() || is_mobile()) { return $content; } //既に適用させているところは処理しない if (false !== strpos($content, 'data-original')) { return $content; } //画像正規表現で置換 $content = preg_replace('#<img([^>]+?)src=[\'"]?([^\'"\\s>]+)[\'"]?([^>]*)>#', sprintf('<img${1}src="%s" data-original="${2}"${3} data-lazy="true"><noscript><img${1}src="${2}"${3}></noscript>', get_template_directory_uri() . '/images/1x1.trans.gif'), $content); //投稿本文(置換する文章) return $content; }
public static function add_image_placeholders($content) { // Don't load for feeds, previews, attachment pages, non-mobile views if (is_preview() || is_feed() || is_attachment() || function_exists('jetpack_is_mobile') && !jetpack_is_mobile()) { return $content; } // In case you want to change the placeholder image $placeholder_image = apply_filters('responsive_images_placeholder_image', self::get_url('images/1x1.trans.gif')); preg_match_all('#<img[^>]+?[\\/]?>#', $content, $images, PREG_SET_ORDER); if (empty($images)) { return $content; } foreach ($images as $image) { $attributes = wp_kses_hair($image[0], array('http', 'https')); $new_image = '<img'; $new_image_src = ''; foreach ($attributes as $attribute) { $name = $attribute['name']; $value = $attribute['value']; // Remove the width and height attributes if (in_array($name, array('width', 'height'))) { continue; } // Move the src to a data attribute and replace with a placeholder if ('src' == $name) { $new_image_src = html_entity_decode(urldecode($value)); parse_str(parse_url($new_image_src, PHP_URL_QUERY), $image_args); $new_image_src = remove_query_arg('h', $new_image_src); $new_image_src = remove_query_arg('w', $new_image_src); $new_image .= sprintf(' data-full-src="%s"', esc_url($new_image_src)); if (isset($image_args['w'])) { $new_image .= sprintf(' data-full-width="%s"', esc_attr($image_args['w'])); } if (isset($image_args['h'])) { $new_image .= sprintf(' data-full-height="%s"', esc_attr($image_args['h'])); } // replace actual src with our placeholder $value = $placeholder_image; } $new_image .= sprintf(' %s="%s"', $name, esc_attr($value)); } $new_image .= '/>'; $new_image .= sprintf('<noscript><img src="%s" /></noscript>', $new_image_src); // compat for no-js and better crawling $content = str_replace($image[0], $new_image, $content); } return $content; }
function wpgrade_callback_load_google_fonts_api_rosa() { $fonts_array = array('google_titles_font', 'google_subtitles_font', 'google_nav_font', 'google_body_font'); $families = array(); foreach ($fonts_array as $font) { $clean_font = wpgrade::get_google_font_name($font); if (!empty($clean_font)) { $families[] = $clean_font; } } $families = apply_filters('wpgrade_google_fonts', $families); if (!empty($families) || is_preview()) { //only enqueue the api is we actually have webfonts wp_enqueue_script('webfont-script'); } }
function simple_lazyload_content_filter_lazyload($content) { $skip_lazyload = apply_filters('simple_lazyload_skip_lazyload', false); // don't lazyload for feeds, previews if ($skip_lazyload || is_feed() || is_preview()) { return $content; } global $simple_lazyload_is_strict_lazyload; if ($simple_lazyload_is_strict_lazyload) { $regexp = "/<img([^<>]*)\\.(bmp|gif|jpeg|jpg|png)([^<>]*)>/i"; } else { $regexp = "/<img([^<>]*)>/i"; } $content = preg_replace_callback($regexp, "simple_lazyload_lazyimg_str_handler", $content); return $content; }
static function add_sbp_image_placeholders($content) { // Don't lazyload for feeds, previews, mobile if (is_feed() || is_preview() || function_exists('wp_is_mobile') && wp_is_mobile()) { return $content; } // Don't lazy-load if the content has already been run through previously if (false !== strpos($content, 'data-lazy-src')) { return $content; } // In case you want to change the placeholder image $sbp_placeholder_image = apply_filters('lazyload_images_placeholder_image', self::get_url('images/1x1.trans.gif')); // This is a pretty simple regex, but it works $content = preg_replace('#<img([^>]+?)src=[\'"]?([^\'"\\s>]+)[\'"]?([^>]*)>#', sprintf('<img${1}src="%s" data-lazy-src="${2}"${3}><noscript><img${1}src="${2}"${3}></noscript>', $sbp_placeholder_image), $content); return $content; }
function process_postviews() { global $user_ID, $post; if (is_int($post)) { $post = get_post($post); } if (!wp_is_post_revision($post) && !is_preview()) { if (is_single() || is_page()) { $id = intval($post->ID); $views_options = get_option('views_options'); if (!($post_views = get_post_meta($post->ID, 'views', true))) { $post_views = 0; } $should_count = false; switch (intval($views_options['count'])) { case 0: $should_count = true; break; case 1: if (empty($_COOKIE[USER_COOKIE]) && intval($user_ID) === 0) { $should_count = true; } break; case 2: if (intval($user_ID) > 0) { $should_count = true; } break; } if (intval($views_options['exclude_bots']) === 1) { $bots = array('Google Bot' => 'googlebot', 'Google Bot' => 'google', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'jeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot', 'Technorati' => 'technorati', 'Yahoo' => 'yahoo', 'Findexa' => 'findexa', 'NextLinks' => 'findlinks', 'Gais' => 'gaisbo', 'WiseNut' => 'zyborg', 'WhoisSource' => 'surveybot', 'Bloglines' => 'bloglines', 'BlogSearch' => 'blogsearch', 'PubSub' => 'pubsub', 'Syndic8' => 'syndic8', 'RadioUserland' => 'userland', 'Gigabot' => 'gigabot', 'Become.com' => 'become.com', 'Baidu' => 'baiduspider', 'so.com' => '360spider', 'Sogou' => 'spider', 'soso.com' => 'sosospider', 'Yandex' => 'yandex'); $useragent = $_SERVER['HTTP_USER_AGENT']; foreach ($bots as $name => $lookfor) { if (stristr($useragent, $lookfor) !== false) { $should_count = false; break; } } } if ($should_count && (isset($views_options['use_ajax']) && intval($views_options['use_ajax']) === 0 || (!defined('WP_CACHE') || !WP_CACHE))) { update_post_meta($id, 'views', $post_views + 1); do_action('postviews_increment_views', $post_views + 1); } } } }
public function getId($atts, $content) { if (vc_is_page_editable() || is_preview()) { /* We are in Frontend editor * We need to send RAW shortcode data, so hash is just json_encode of atts and content */ return urlencode(json_encode(array('tag' => $this->shortcode, 'atts' => $atts, 'content' => $content))); } $id_pattern = '/' . $this->grid_id_unique_name . '\\:([\\w-_]+)/'; $id_value = isset($atts['grid_id']) ? $atts['grid_id'] : ''; preg_match($id_pattern, $id_value, $id_matches); $id_to_save = '{failed_to_get_id:"' . esc_attr($id_value) . '"}'; if (!empty($id_matches)) { $id_to_save = $id_matches[1]; } return $id_to_save; }
function get_post_gallery_ids($id, $max_images = -1, $method = "array") { if (is_preview($id)) { $galleryString = get_post_meta($id, 'fg_temp_metadata', 1); } else { $galleryString = get_post_meta($id, 'fg_perm_metadata', 1); } if ($method == "string" || $max_images == "string") { return $galleryString; } else { if ($max_images == -1) { return explode(',', $galleryString); } else { return array_slice(explode(',', $galleryString), 0, $max_images); } } }
/** * Checks if we're on a singular post view and if the current post type supports the 'entry-views' * extension. If so, set the $post_id variable and load the needed JavaScript. * * @since 0.1.0 * @access private * @return void */ function entry_views_load() { global $_entry_views_post_id; /* Check if we're on a singular post view. */ if (is_singular() && !is_preview()) { /* Get the post object. */ $post = get_queried_object(); /* Check if the post type supports the 'entry-views' feature. */ if (post_type_supports($post->post_type, 'entry-views')) { /* Set the post ID for later use because we wouldn't want a custom query to change this. */ $_entry_views_post_id = get_queried_object_id(); /* Enqueue the jQuery library. */ wp_enqueue_script('jquery'); /* Load the entry views JavaScript in the footer. */ add_action('wp_footer', 'entry_views_load_scripts'); } } }
/** * Helper function for wp_link_pages(). * * @since 3.1.0 * @access private * * @global WP_Rewrite $wp_rewrite * * @param int $i Page number. * @return string Link. */ function _wp_link_page($i) { global $wp_rewrite; $post = get_post(); $query_args = array(); if (1 == $i) { $url = get_permalink(); } else { if ('' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending'))) { $url = add_query_arg('page', $i, get_permalink()); } elseif ('page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID) { $url = trailingslashit(get_permalink()) . user_trailingslashit("{$wp_rewrite->pagination_base}/" . $i, 'single_paged'); } else { $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); } } if (is_preview()) { if ('draft' !== $post->post_status && isset($_GET['preview_id'], $_GET['preview_nonce'])) { $query_args['preview_id'] = wp_unslash($_GET['preview_id']); $query_args['preview_nonce'] = wp_unslash($_GET['preview_nonce']); } $url = get_preview_post_link($post, $query_args, $url); } return '<a href="' . esc_url($url) . '">'; }
/** * Are likes visible in this context? * * Some of this code was taken and modified from sharing_display() to ensure * similar logic and filters apply here, too. */ function is_likes_visible() { global $wp_current_filter; // Used to check 'get_the_excerpt' filter global $post; // Used to apply 'sharing_show' filter // Never show on feeds or previews if (is_feed() || is_preview() || is_comments_popup()) { $enabled = false; // Not a feed or preview, so what is it? } else { if (in_the_loop()) { // If in the loop, check if the current post is likeable $enabled = $this->is_post_likeable(); } else { // Otherwise, check and see if likes are enabled sitewide $enabled = $this->is_enabled_sitewide(); } if (post_password_required()) { $enabled = false; } /** Other Checks ******************************************************/ // Do not show on excerpts if (in_array('get_the_excerpt', (array) $wp_current_filter)) { $enabled = false; // Sharing Setting Overrides **************************************** } else { // Single post if (is_singular('post')) { if (!$this->is_single_post_enabled()) { $enabled = false; } // Single page } elseif (is_page()) { if (!$this->is_single_page_enabled()) { $enabled = false; } // Attachment } elseif (is_attachment()) { if (!$this->is_attachment_enabled()) { $enabled = false; } // All other loops } elseif (!$this->is_index_enabled()) { $enabled = false; } } } // Check that the post is a public, published post. if ('attachment' == $post->post_type) { $post_status = get_post_status($post->post_parent); } else { $post_status = $post->post_status; } if ('publish' != $post_status) { $enabled = false; } // Run through the sharing filters $enabled = apply_filters('sharing_show', $enabled, $post); return (bool) apply_filters('wpl_is_likes_visible', $enabled); }
/** * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload. * * This prevents reusing the same tab for a preview when the user has navigated away. * * @since 4.3.0 */ function wp_post_preview_js() { global $post; if (!is_preview() || empty($post)) { return; } // Has to match the window name used in post_submit_meta_box() $name = 'wp-preview-' . (int) $post->ID; ?> <script> ( function() { var query = document.location.search; if ( query && query.indexOf( 'preview=true' ) !== -1 ) { window.name = '<?php echo $name; ?> '; } if ( window.addEventListener ) { window.addEventListener( 'unload', function() { window.name = ''; }, false ); } }()); </script> <?php }