/**
  * Add action links to Stream drop row in admin list screen
  *
  * @filter wp_stream_action_links_{connector}
  *
  * @param array  $links  Previous links registered
  * @param Record $record Stream record
  *
  * @return array Action links
  */
 public function action_links($links, $record)
 {
     if ($record->object_id && 'deleted' !== $record->action && ($term = get_term_by('term_taxonomy_id', $record->object_id, $record->context))) {
         if (!is_wp_error($term)) {
             $tax_obj = get_taxonomy($term->taxonomy);
             $tax_label = isset($tax_obj->labels->singular_name) ? $tax_obj->labels->singular_name : null;
             if (function_exists('wp_get_split_term')) {
                 $term_id = wp_get_split_term($term->term_id, $term->taxonomy);
             }
             $term_id = empty($term_id) ? $term->term_id : $term_id;
             $links[sprintf(_x('Edit %s', 'Term singular name', 'stream'), $tax_label)] = get_edit_term_link($term_id, $term->taxonomy);
             $links[esc_html__('View', 'stream')] = wp_stream_is_vip() ? \wpcom_vip_get_term_link($term_id, $term->taxonomy) : get_term_link($term_id, $term->taxonomy);
         }
     }
     return $links;
 }
示例#2
0
/**
 * Print schools within a name range (for nav)
 */
function hsinsider_school_range($start = 'A', $end = 'Z')
{
    $schools = get_terms('school', array('hide_empty' => false));
    foreach ($schools as $school) {
        if (substr($school->name, 0, 1) < $start || substr($school->name, 0, 1) > $end) {
            continue;
        }
        $link = wpcom_vip_get_term_link($school, $school->taxonomy);
        echo '<li><a href="' . esc_url($link) . '">' . esc_html($school->name) . '</a></li>';
    }
}
function chartbeat_dashboard_widget_function()
{
    ?>
	<div id="chartbeatGauge"></div>
	<div id="chartbeatRefsTable" class="chartbeatWidget">
		<table id="chartbeatLinks" class="chartbeatTable">
			<thead>
			<tr>
				<th colspan=2 class="chartbeatLabel">Top Referrers</th>
			</tr>
			</thead>
			<tbody></tbody>
		</table>
		<table id="chartbeatSearch" class="chartbeatTable">
			<thead>
			<tr>
				<th colspan=2 class="chartbeatLabel">Top Search</th>
			</tr>
			</thead>
			<tbody></tbody>
		</table>
		<div class="clear"></div>
	</div>
	<div id="chartbeatGraph" class="chartbeatWidget clear">
		<div class="chartbeatLabel">Visits - Last 3 Day</div>
		<div id="chartbeatHist">
			<div id="annotations"></div>
		</div>
	</div>
	<script type="text/javascript">
		<?php 
    add_filter('posts_where', 'chartbeat_filter_where_last_three_days');
    ?>
		var events = [];
		// Get published post Events
			<?php 
    $the_query = wp_cache_get('chartbeat_published_widget');
    if ($the_query === false) {
        $args = array('post_type' => array('post'), 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC');
        $the_query = new WP_Query($args);
        wp_cache_set('chartbeat_published_widget', $the_query, 'default', 1 * HOUR_IN_SECONDS);
    }
    $domain = apply_filters('chartbeat_config_domain', chartbeat_get_display_url(get_option('home')));
    while ($the_query->have_posts()) {
        $the_query->the_post();
        $tstamp = get_the_time('Y,n-1,j,G,i');
        if (!empty($tstamps[$tstamp])) {
            continue;
        }
        $tstamps[$tstamp] = true;
        $category = get_the_category();
        if (!empty($category[0])) {
            $category_link = wpcom_vip_get_term_link($category[0]->cat_ID, 'category');
        }
        ?>
var ev = {domain:'<?php 
        echo esc_js(chartbeat_get_display_url($domain));
        ?>
',title:'<?php 
        echo esc_js(get_the_title());
        ?>
',
				value:'<?php 
        echo esc_js(chartbeat_get_display_url($category_link));
        ?>
', group_name:'<?php 
        echo esc_js(chartbeat_get_display_url(get_page_link()));
        ?>
',
				t: new Date(<?php 
        echo the_time('Y,n-1,j,G,i');
        ?>
).getTime()/1000,group_type:'page',num_referrers:10,id:'<?php 
        echo esc_js(get_the_ID());
        ?>
',type:'wp',data:{action_type:"create"}};
		events.push(ev);
		<?php 
    }
    wp_reset_postdata();
    ?>

		// Get revisions
			<?php 
    $the_query = wp_cache_get('chartbeat_revision_widget');
    if ($the_query === false) {
        $args = array('post_type' => array('revision'), 'post_status' => 'inherit', 'orderby' => 'date', 'order' => 'ASC');
        $the_query = new WP_Query($args);
        wp_cache_set('chartbeat_revision_widget', $the_query, 'default', 1 * HOUR_IN_SECONDS);
    }
    while ($the_query->have_posts()) {
        $the_query->the_post();
        $tstamp = get_the_time('Y,n-1,j,G,i');
        if (!empty($tstamps[$tstamp])) {
            continue;
        }
        $tstamps[$tstamp] = true;
        $category = get_the_category();
        if (!empty($category[0])) {
            $category_link = wpcom_vip_get_term_link($category[0]->cat_ID, 'category');
        }
        ?>
var ev = {domain:'<?php 
        echo esc_js(chartbeat_get_display_url($domain));
        ?>
',title:'<?php 
        echo esc_js(get_the_title());
        ?>
',
				value:'<?php 
        echo esc_js(chartbeat_get_display_url($category_link));
        ?>
',group_name:'<?php 
        echo esc_js(chartbeat_get_display_url(get_page_link()));
        ?>
',
				t: new Date(<?php 
        echo the_time('Y,n-1,j,G,i');
        ?>
).getTime()/1000,group_type:'page',num_referrers:10,id:'<?php 
        echo esc_js(get_the_ID());
        ?>
',type:'wp',data:{action_type:"update"}};
		events.push(ev);
		<?php 
    }
    wp_reset_postdata();
    remove_filter('posts_where', 'chartbeat_filter_where_last_three_days');
    ?>

		function loadChartBeatWidgets(){
			new CBDashboard('chartbeatGauge','chartbeatRefsTable','chartbeatHist',200,"<?php 
    echo esc_js(chartbeat_get_display_url($domain));
    ?>
","<?php 
    echo esc_js(get_option('chartbeat_apikey'));
    ?>
",events);
		};

		var currOnload = window.onload;
		window.onload = (typeof window.onload != 'function') ? loadChartBeatWidgets : function() { oldonload(); loadChartBeatWidgets(); };
	</script>
	<?php 
}
示例#4
0
 function icl_link_to_element($id, $type = 'post', $text = '', $args = array(), $anchor = '', $echo = true, $return_original_if_missing = true)
 {
     if ('tag' == $type) {
         $type = 'post_tag';
     }
     $pll_type = 'post' == $type || pll_is_translated_post_type($type) ? 'post' : ('term' == $type || pll_is_translated_taxonomy($type) ? 'term' : false);
     if ($pll_type && ($lang = pll_current_language()) && ($tr_id = PLL()->model->{$pll_type}->get_translation($id, $lang)) && PLL()->links->current_user_can_read($tr_id)) {
         $id = $tr_id;
     } elseif (!$return_original_if_missing) {
         return '';
     }
     if (post_type_exists($type)) {
         $link = get_permalink($id);
         if (empty($text)) {
             $text = get_the_title($id);
         }
     } elseif (taxonomy_exists($type)) {
         $link = wpcom_vip_get_term_link($id, $type);
         if (empty($text) && ($term = get_term($id, $type)) && !empty($term) && !is_wp_error($term)) {
             $text = $term->name;
         }
     }
     if (empty($link) || is_wp_error($link)) {
         return '';
     }
     if (!empty($args)) {
         $link .= (false === strpos($link, '?') ? '?' : '&') . http_build_query($args);
     }
     if (!empty($anchor)) {
         $link .= '#' . $anchor;
     }
     $link = sprintf('<a href="%s">%s</a>', esc_url($link), esc_html($text));
     if ($echo) {
         echo $link;
     }
     return $link;
 }
示例#5
0
 private static function get_canonical_url()
 {
     global $wp_rewrite;
     $queried_object = get_queried_object();
     $canonical = '';
     if (isset($queried_object->post_type)) {
         if (!($canonical = self::get_seo_meta('canonical', get_queried_object_id())) || is_null($canonical)) {
             $canonical = get_permalink($queried_object->ID);
             // Fix paginated pages
             if (get_query_var('page') > 1) {
                 $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page'));
             }
         }
     } else {
         if (is_search()) {
             $canonical = get_search_link();
         } else {
             if (is_front_page()) {
                 $canonical = home_url('/');
             } else {
                 if (is_home() && 'page' === get_option('show_on_front')) {
                     $canonical = get_permalink(get_option('page_for_posts'));
                 } else {
                     if (is_tax() || is_tag() || is_category()) {
                         if (function_exists('wpcom_vip_get_term_link')) {
                             $canonical = wpcom_vip_get_term_link($queried_object, $queried_object->taxonomy);
                         } else {
                             $canonical = get_term_link($queried_object, $queried_object->taxonomy);
                         }
                     } else {
                         if (function_exists('get_post_type_archive_link') && is_post_type_archive()) {
                             $canonical = get_post_type_archive_link(get_post_type());
                         } else {
                             if (is_author()) {
                                 $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
                             } else {
                                 if (is_archive()) {
                                     if (is_date()) {
                                         if (is_day()) {
                                             $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                                         } else {
                                             if (is_month()) {
                                                 $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                                             } else {
                                                 if (is_year()) {
                                                     $canonical = get_year_link(get_query_var('year'));
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($canonical && get_query_var('paged') > 1) {
             $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged'));
         }
     }
     return apply_filters('vseo_canonical_url', $canonical);
 }
示例#6
0
 /**
  * returns the url of the translation ( if exists ) of the current page
  *
  * @since 0.1
  *
  * @param object $language
  * @return string
  */
 public function get_translation_url($language)
 {
     global $wp_query;
     if (false !== ($translation_url = $this->cache->get('translation_url:' . $language->slug))) {
         return $translation_url;
     }
     // make sure that we have the queried object
     // see https://wordpress.org/support/topic/patch-for-fixing-a-notice
     $queried_object_id = $wp_query->get_queried_object_id();
     /**
      * Filter the translation url before Polylang attempts to find one
      * Internally used by Polylang for the static front page and posts page
      *
      * @since 1.8
      *
      * @param string $url               empty or the url of the translation of teh current page
      * @param object $language          language of the translation
      * @param int    $queried_object_id queried object id
      */
     if (!($url = apply_filters('pll_pre_translation_url', '', $language, $queried_object_id))) {
         $qv = $wp_query->query_vars;
         $hide = $this->options['default_lang'] == $language->slug && $this->options['hide_default'];
         // post and attachment
         if (is_single() && ($this->options['media_support'] || !is_attachment()) && ($id = $this->model->post->get($queried_object_id, $language)) && $this->current_user_can_read($id)) {
             $url = get_permalink($id);
         } elseif (is_page() && ($id = $this->model->post->get($queried_object_id, $language)) && $this->current_user_can_read($id)) {
             $url = get_page_link($id);
         } elseif (is_search()) {
             $url = $this->get_archive_url($language);
             // special case for search filtered by translated taxonomies: taxonomy terms are translated in the translation url
             if (!empty($wp_query->tax_query->queries)) {
                 foreach ($wp_query->tax_query->queries as $tax_query) {
                     if (!empty($tax_query['taxonomy']) && $this->model->is_translated_taxonomy($tax_query['taxonomy'])) {
                         $tax = get_taxonomy($tax_query['taxonomy']);
                         $terms = get_terms($tax->name, array('fields' => 'id=>slug'));
                         // filtered by current language
                         foreach ($tax_query['terms'] as $slug) {
                             $term_id = array_search($slug, $terms);
                             // what is the term_id corresponding to taxonomy term?
                             if ($term_id && ($term_id = $this->model->term->get_translation($term_id, $language))) {
                                 // get the translated term_id
                                 $term = get_term($term_id, $tax->name);
                                 $url = str_replace($slug, $term->slug, $url);
                             }
                         }
                     }
                 }
             }
         } elseif ((is_category() || is_tag() || is_tax()) && ($term = get_queried_object()) && $this->model->is_translated_taxonomy($term->taxonomy)) {
             $lang = $this->model->term->get_language($term->term_id);
             if (!$lang || $language->slug == $lang->slug) {
                 $url = wpcom_vip_get_term_link($term, $term->taxonomy);
                 // self link
             } elseif ($tr_id = $this->model->term->get_translation($term->term_id, $language)) {
                 $tr_term = get_term($tr_id, $term->taxonomy);
                 // check if translated term ( or children ) have posts
                 if ($tr_term && ($tr_term->count || is_taxonomy_hierarchical($term->taxonomy) && array_sum(wp_list_pluck(get_terms($term->taxonomy, array('child_of' => $tr_term->term_id, 'lang' => $language->slug)), 'count')))) {
                     $url = wpcom_vip_get_term_link($tr_term, $term->taxonomy);
                 }
             }
         } elseif (is_post_type_archive()) {
             if ($this->model->is_translated_post_type($qv['post_type']) && $this->model->count_posts($language, array('post_type' => $qv['post_type']))) {
                 $url = $this->get_archive_url($language);
             }
         } elseif (is_archive()) {
             $keys = array('post_type', 'm', 'year', 'monthnum', 'day', 'author', 'author_name');
             $keys = array_merge($keys, $this->model->get_filtered_taxonomies_query_vars());
             // check if there are existing translations before creating the url
             if ($this->model->count_posts($language, array_intersect_key($qv, array_flip($keys)))) {
                 $url = $this->get_archive_url($language);
             }
         } elseif (is_front_page()) {
             $url = $this->get_home_url($language);
         }
     }
     /**
      * Filter the translation url of the current page before Polylang caches it
      *
      * @since 1.1.2
      *
      * @param null|string $url      the translation url, null if none was found
      * @param string      $language the language code of the translation
      */
     $translation_url = apply_filters('pll_translation_url', isset($url) && !is_wp_error($url) ? $url : null, $language->slug);
     $this->cache->set('translation_url:' . $language->slug, $translation_url);
     return $translation_url;
 }