示例#1
0
 /**
  * Returns the language of a term
  *
  * @since 0.1
  *
  * @param int|string $value    term id or term slug
  * @param string     $taxonomy optional taxonomy needed when the term slug is passed as first parameter
  * @return bool|object PLL_Language object, false if no language is associated to that term
  */
 public function get_language($value, $taxonomy = '')
 {
     if (is_numeric($value)) {
         $term_id = $value;
     } elseif (is_string($value) && $taxonomy) {
         $term_id = wpcom_vip_get_term_by('slug', $value, $taxonomy)->term_id;
     }
     // get the language and make sure it is a PLL_Language object
     return isset($term_id) && ($lang = $this->get_object_term($term_id, 'term_language')) ? $this->model->get_language($lang->term_id) : false;
 }
<?php

/**
 * The template for displaying archive pages.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package HSInsider
 */
get_header();
$term = wpcom_vip_get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
/**
* If the taxonomy term exists, do stuff
*/
if (is_object($term)) {
    ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main container-fluid" role="main">
			<header class="hero jumbotron blogroll archive-header row">
				<?php 
    $school_address = hsinsider_get_school_meta('address');
    $school = hsinsider_get_school();
    //Defaults
    $school_marker = 'none';
    if (!empty($school_address)) {
        $school_marker = array('school' => $school->name, 'address' => $school_address);
        $school_marker = json_encode($school_marker);
    }
    ?>
				<section class="col-xs-12">
function wpcom_vip_get_nav_menu_object($menu)
{
    if (!$menu) {
        return false;
    }
    $menu_obj = get_term($menu, 'nav_menu');
    if (!$menu_obj) {
        $menu_obj = wpcom_vip_get_term_by('slug', $menu, 'nav_menu');
    }
    if (!$menu_obj) {
        $menu_obj = wpcom_vip_get_term_by('name', $menu, 'nav_menu');
    }
    if (!$menu_obj) {
        $menu_obj = false;
    }
    return $menu_obj;
}
 /**
  * Log Order minor status changes ( pending / on-hold / failed / processing / completed / refunded / cancelled )
  *
  * @action woocommerce_order_status_changed
  *
  * @param int $order_id
  * @param string $old
  * @param string $new
  */
 public function callback_woocommerce_order_status_changed($order_id, $old, $new)
 {
     // Don't track customer actions
     if (!is_admin()) {
         return;
     }
     $old_status = wp_stream_is_vip() ? wpcom_vip_get_term_by('slug', $old, 'shop_order_status') : get_term_by('slug', $old, 'shop_order_status');
     $new_status = wp_stream_is_vip() ? wpcom_vip_get_term_by('slug', $new, 'shop_order_status') : get_term_by('slug', $new, 'shop_order_status');
     // Don't track new statuses
     if (!$old_status) {
         return;
     }
     $message = esc_html_x('%1$s status changed from %2$s to %3$s', '1. Order title, 2. Old status, 3. New status', 'stream');
     $order = new \WC_Order($order_id);
     $order_title = esc_html__('Order number', 'stream') . ' ' . esc_html($order->get_order_number());
     $order_type_name = esc_html__('order', 'stream');
     $new_status_name = strtolower($new_status->name);
     $old_status_name = strtolower($old_status->name);
     $this->log($message, array('post_title' => $order_title, 'old_status_name' => $old_status_name, 'new_status_name' => $new_status_name, 'singular_name' => $order_type_name, 'new_status' => $new, 'old_status' => $old, 'revision_id' => null), $order_id, 'shop_order', $new_status_name);
 }
/**
 * Retrieve adjacent post.
 *
 * Can either be next or previous post. The logic for excluding terms is handled within PHP, for performance benefits.
 * Props to Elliott Stocks
 *
 * @global wpdb $wpdb
 *
 * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Note - only the first term will be used from wp_get_object_terms().
 * @param int 	       $excluded_term  Optional. The term to exclude.
 * @param bool         $previous       Optional. Whether to retrieve previous post.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 *
 * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
 */
function wpcom_vip_get_adjacent_post($in_same_term = false, $excluded_term = '', $previous = true, $taxonomy = 'category', $adjacent = '')
{
    global $wpdb;
    if (!($post = get_post()) || !taxonomy_exists($taxonomy)) {
        return null;
    }
    $join = '';
    $where = '';
    $current_post_date = $post->post_date;
    if (!is_int($excluded_term && !empty($excluded_term))) {
        $term = wpcom_vip_get_term_by('name', $excluded_term, $taxonomy);
        $excluded_term = $term->ID;
    }
    if ($in_same_term) {
        if (is_object_in_taxonomy($post->post_type, $taxonomy)) {
            $term_array = get_the_terms($post->ID, $taxonomy);
            $term_array = array_map('intval', $term_array);
            if (!empty($term_array) && !is_wp_error($term_array)) {
                $term_array = get_the_terms($post->ID, $taxonomy);
                $term_array_ids = wp_list_pluck($term_array, 'term_id');
                // Remove any exclusions from the term array to include.
                $term_array_ids = array_diff($term_array_ids, (array) $excluded_term);
                $term_array_ids = array_map('intval', $term_array_ids);
                $term_id_to_search = apply_filters('wpcom_vip_limit_adjacent_post_term_id', array_pop($term_array_ids), $term_array_ids, $excluded_term, $taxonomy, $previous);
                if (!empty($term_id_to_search)) {
                    //allow filters to short circuit by returning a empty like value
                    $join = " INNER JOIN {$wpdb->term_relationships} AS tr ON p.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
                    //Only join if we are sure there is a term
                    $where = $wpdb->prepare("AND tt.taxonomy = %s AND tt.term_id IN (%d)  ", $taxonomy, $term_id_to_search);
                    //
                }
            }
        }
    }
    $op = $previous ? '<' : '>';
    $order = $previous ? 'DESC' : 'ASC';
    $limit = 1;
    // We need 5 posts so we can filter the excluded term later on
    if (!empty($excluded_term)) {
        $limit = 5;
    }
    $sort = "ORDER BY p.post_date {$order} LIMIT {$limit}";
    $where = $wpdb->prepare("WHERE p.post_date {$op} %s AND p.post_type = %s AND p.post_status = 'publish' {$where}", $current_post_date, $post->post_type);
    $query = "SELECT p.ID FROM {$wpdb->posts} AS p {$join} {$where} {$sort}";
    $found_post = '';
    // blank instead of false so not found is cached.
    $query_key = 'wpcom_vip_adjacent_post_' . md5($query);
    $cached_result = wp_cache_get($query_key);
    if (false !== $cached_result) {
        return get_post($cached_result);
    }
    if (empty($excluded_term)) {
        $result = $wpdb->get_var($query);
    } else {
        $result = $wpdb->get_results($query);
    }
    // Find the first post which doesn't have an excluded term
    if (!empty($excluded_term)) {
        foreach ($result as $result_post) {
            $post_terms = get_the_terms($result_post, $taxonomy);
            $terms_array = wp_list_pluck($post_terms, 'term_id');
            if (!in_array($excluded_term, $terms_array)) {
                $found_post = $result_post->ID;
                break;
            }
        }
    } else {
        $found_post = $result;
    }
    $cache_time = 6 * HOUR_IN_SECONDS;
    if ($found_post !== '') {
        $cache_time = 15 * MINUTE_IN_SECONDS;
    }
    wp_cache_set($query_key, $found_post, '', $cache_time);
    if ($found_post !== '') {
        $found_post = get_post($found_post);
    }
    return $found_post;
}
示例#6
0
function hsinsider_author_school_link($class = 'school')
{
    $term_id = hsinsider_get_the_author_meta('school');
    if (empty($term_id)) {
        return false;
    }
    $term = wpcom_vip_get_term_by('id', $term_id, 'school');
    if (empty($term)) {
        return false;
    }
    $term_link = wpcom_vip_get_term_link($term, $term->taxonomy);
    if (empty($term_link) || is_wp_error($term_link)) {
        return false;
    }
    echo '<a href="' . esc_url($term_link) . '" class="' . esc_attr($class) . '">' . esc_html($term->name) . '</a>';
}
示例#7
0
 /**
  * Twenty Fourteen
  * Rewrites the function Featured_Content::get_featured_post_ids()
  *
  * @since 1.4
  *
  * @param array $ids featured posts ids
  * @return array modified featured posts ids ( include all languages )
  */
 public function twenty_fourteen_featured_content_ids($featured_ids)
 {
     if (!did_action('pll_init') || false !== $featured_ids) {
         return $featured_ids;
     }
     $settings = Featured_Content::get_setting();
     if (!($term = wpcom_vip_get_term_by('name', $settings['tag-name'], 'post_tag'))) {
         return $featured_ids;
     }
     // Get featured tag translations
     $tags = PLL()->model->term->get_translations($term->term_id);
     $ids = array();
     // Query for featured posts in all languages
     // One query per language to get the correct number of posts per language
     foreach ($tags as $tag) {
         $_ids = get_posts(array('lang' => 0, 'fields' => 'ids', 'numberposts' => Featured_Content::$max_posts, 'tax_query' => array(array('taxonomy' => 'post_tag', 'terms' => (int) $tag))));
         $ids = array_merge($ids, $_ids);
     }
     $ids = array_map('absint', $ids);
     set_transient('featured_content_ids', $ids);
     return $ids;
 }
 /**
  * Logic for Tidal meta data
  *
  * @param null   $default    Default value of null.
  * @param int    $object_id  ID of the object metadata is for.
  * @param string $meta_key   Metadata key
  * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
  * @param bool   $unique     Optional, default is false. Whether the specified metadata key should be
  *                           unique for the object. If true, and the object already has a value for the specified
  *                           metadata key, no change will be made.
  *
  * @return null|bool Null to add meta data, true to continue
  */
 function filter_add_post_metadata($default, $object_id, $meta_key, $meta_value, $unique)
 {
     $post = get_post($object_id);
     // Handle contributor usernames
     if ($this::post_type == $post->post_type && $this::username_meta == $meta_key) {
         $query = new WP_Query(array('post_type' => $this::post_type, 'meta_query' => array(array('key' => $this::username_meta, 'value' => $meta_value))));
         // If username already exist, shortcircuit add metadata
         if (!empty($query->posts)) {
             return true;
         }
         // If username meta key already exists, update meta value and associated Tidal term
         if ($username = get_post_meta($object_id, $meta_key, true)) {
             update_post_meta($object_id, $meta_key, $meta_value);
             if (function_exists('wpcom_vip_get_term_by')) {
                 $term = wpcom_vip_get_term_by('slug', $post->post_name, $this::taxonomy);
             } else {
                 $term = get_term_by('slug', $post->post_name, $this::taxonomy);
             }
             if ($term) {
                 wp_update_term($term->ID, $this::taxonomy, array('slug' => $meta_value));
             }
             return true;
         }
     }
     // Handle contributor meta
     if ($this::tidal_contributor_meta == $meta_key) {
         // Short circuit if the contributor does not exist
         if (function_exists('wpcom_vip_get_term_by')) {
             $term = wpcom_vip_get_term_by('slug', $meta_value, $this::taxonomy);
         } else {
             $term = get_term_by('slug', $meta_value, $this::taxonomy);
         }
         if (!$term) {
             return true;
         }
         // If contributor meta already exists, update the meta value
         if ($contributor_id = get_post_meta($object_id, $meta_key, true)) {
             if ($contributor_id != $meta_value) {
                 update_post_meta($object_id, $meta_key, $meta_value);
             }
             return true;
         }
     }
     // Check if Tidal ID exists for Tidal-contributed posts
     if ($this::tidal_id_meta == $meta_key) {
         $query = new WP_Query(array('posts_per_page' => 1, 'meta_query' => array(array('key' => $this::tidal_id_meta, 'value' => $meta_value))));
         // If Tidal ID already exist, shortcircuit add metadata
         if (!empty($query->posts)) {
             return true;
         }
     }
     return $default;
 }
/**
 * Generate the schedule for the schedule page. Based on a shortcode. Pass in the ID, and get the schedule for both days.
 */
function mf_schedule($atts)
{
    extract(shortcode_atts(array(), $atts));
    $output = '';
    $location = isset($atts['location']) ? sanitize_text_field($atts['location']) : '';
    $faire = isset($atts['faire']) ? sanitize_text_field($atts['faire']) : '';
    if (!empty($location)) {
        $term = wpcom_vip_get_term_by('id', $location, 'location');
        $url = get_term_link($term);
        if (!is_wp_error($url)) {
            $output .= '<a href="' . esc_url(home_url('/stage-schedule/?location=' . $term->slug)) . '" class="pull-right" style="position:relative; top:7px;"><img src="' . get_stylesheet_directory_uri() . '/images/print-ico.png" alt="' . __('Print this schedule', 'make-mini-mf') . '" /></a>';
            $output .= '<h2><a href="' . esc_url($url) . '">' . esc_html($term->name) . '</a></h2>';
            $output .= mf_stage_description($term);
        }
    }
    $query = wp_cache_get($location . '_saturday_schedule');
    if (!isset($term->slug)) {
        return;
    }
    if ($query == false) {
        $args = array('location' => sanitize_title($term->slug), 'post_type' => 'event-items', 'orderby' => 'meta_value', 'meta_key' => 'mfei_start', 'order' => 'asc', 'posts_per_page' => '30', 'faire' => $faire, 'meta_query' => array(array('key' => 'mfei_day', 'value' => 'Saturday')));
        $query = new WP_Query($args);
        wp_cache_set($location . '_saturday_schedule', $query, '', 300);
    }
    if ($query->found_posts >= 1) {
        $output .= '<table class="table table-striped table-bordered table-schedule">';
        if ($faire == 'world-maker-faire-new-york-2013') {
            $output .= '<thead><tr><th colspan="2">September 21st, 2013</th></tr></thead>';
        }
        while ($query->have_posts()) {
            $query->the_post();
            $meta = get_post_meta(get_the_ID());
            $sched_post = get_post($meta['mfei_record'][0]);
            $json = json_decode(mf_convert_newlines(str_replace("\\'", "'", $sched_post->post_content)));
            $day = $meta['mfei_day'][0] ? $meta['mfei_day'][0] : '';
            $start = $meta['mfei_start'][0] ? $meta['mfei_start'][0] : '';
            $stop = $meta['mfei_stop'][0] ? $meta['mfei_stop'][0] : '';
            $output .= '<tr>';
            $output .= '<td width="150" style="max-width:150px;">';
            $output .= '<h5>' . esc_html($day) . '</h5>';
            $output .= '<p>' . esc_html($start) . ' &mdash; ' . esc_html($stop) . '</p>';
            if (isset($json->presenter_photo) or isset($json->project_photo) or isset($json->presentation_photo) or isset($json->performer_photo) or has_post_thumbnail(get_the_ID())) {
                if (get_the_post_thumbnail()) {
                    $output .= '<div class="pull-left thumbnail"><a href="';
                    $output .= get_permalink($sched_post) . '">';
                    $output .= get_the_post_thumbnail(get_the_ID(), 'schedule-thumb');
                    $output .= '</a></div>';
                } elseif (isset($json->presenter_photo[0]) && !is_array($json->presenter_photo[0]) && strlen($json->presenter_photo[0]) > 5) {
                    $output .= '<div class="pull-left thumbnail"><a href="';
                    $output .= get_permalink($sched_post) . '">';
                    $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url($json->presenter_photo[0], 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />';
                    $output .= '</a></div>';
                } else {
                    $output .= '<div class="pull-left thumbnail"><a href="';
                    $output .= get_permalink($sched_post) . '">';
                    $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url(mf_get_the_maker_image($json), 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />';
                    $output .= '</a></div>';
                }
            }
            $output .= '</td>';
            $output .= '<td>';
            $output .= '<h3><a href="' . get_permalink($sched_post) . '">' . get_the_title($sched_post->ID) . '</a></h3>';
            if (!empty($json->presenter_name)) {
                $names = $json->presenter_name;
                $names_output = '';
                foreach ($names as $name) {
                    $names_output .= ', ' . $name;
                }
                $output .= '<h4>' . substr($names_output, 2) . '</h4>';
            }
            if (!empty($json->short_description)) {
                $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->short_description, "\n"))));
            } elseif (!empty($json->public_description)) {
                $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->public_description, "\n"))));
            }
            if (!empty($meta['mfei_coverage'][0])) {
                $output .= '<p><a href="' . esc_url($meta['mfei_coverage'][0]) . '" class="btn btn-mini btn-primary">Watch Video</a></p>';
            }
            // $output .= '<ul class="unstyled">';
            // $terms = get_the_terms( $sched_post->ID, array( 'category', 'post_tag' ) );
            // if (!empty($terms)) {
            // 	$output .= '<li>Topics: ';
            // 	$the_terms = '';
            // 	foreach ($terms as $idx => $term) {
            // 		$the_terms .= ', <a href="' . esc_url( get_term_link( $term ) ) . '">' . $term->name . '</a>';
            // 	}
            // 	$output .= substr( $the_terms, 2 );
            // 	$output .= '</li>';
            // }
            // $output .= '</ul>';
            $output .= '</td>';
            $output .= '</tr>';
        }
        $output .= '</table>';
    }
    wp_reset_postdata();
    // Roll the schedule for Sunday.
    if ($query->found_posts >= 1) {
        $query = wp_cache_get($location . '_sunday_schedule');
        if ($query == false) {
            $args = array('location' => sanitize_title($term->slug), 'post_type' => 'event-items', 'orderby' => 'meta_value', 'meta_key' => 'mfei_start', 'order' => 'asc', 'posts_per_page' => '30', 'faire' => $faire, 'meta_query' => array(array('key' => 'mfei_day', 'value' => 'Sunday')));
            $query = new WP_Query($args);
            wp_cache_set($location . '_sunday_schedule', $query, '', 300);
        }
        $output .= '<table class="table table-striped table-bordered table-schedule">';
        if ($faire == 'world-maker-faire-new-york-2013') {
            $output .= '<thead><tr><th colspan="2">September 22nd, 2013</th></tr></thead>';
        }
        while ($query->have_posts()) {
            $query->the_post();
            $meta = get_post_meta(get_the_ID());
            $sched_post = get_post($meta['mfei_record'][0]);
            $json = json_decode(str_replace("\\'", "'", $sched_post->post_content));
            $day = $meta['mfei_day'][0] ? $meta['mfei_day'][0] : '';
            $start = $meta['mfei_start'][0] ? $meta['mfei_start'][0] : '';
            $stop = $meta['mfei_stop'][0] ? $meta['mfei_stop'][0] : '';
            $output .= '<tr>';
            $output .= '<td width="150">';
            $output .= '<h5>' . esc_html($day) . '</h5>';
            $output .= '<p>' . esc_html($start) . ' &mdash; ' . esc_html($stop) . '</p>';
            if (isset($json->presenter_photo) or isset($json->project_photo) or isset($json->presentation_photo) or isset($json->performer_photo) or has_post_thumbnail(get_the_ID())) {
                if (get_the_post_thumbnail()) {
                    $output .= '<div class="pull-left thumbnail"><a href="';
                    $output .= get_permalink($sched_post) . '">';
                    $output .= get_the_post_thumbnail(get_the_ID(), 'schedule-thumb');
                    $output .= '</a></div>';
                } elseif (isset($json->presenter_photo[0]) && !is_array($json->presenter_photo[0]) && strlen($json->presenter_photo[0]) > 5) {
                    $output .= '<div class="pull-left thumbnail"><a href="';
                    $output .= get_permalink($sched_post) . '">';
                    $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url($json->presenter_photo[0], 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />';
                    $output .= '</a></div>';
                } else {
                    $output .= '<div class="pull-left thumbnail"><a href="';
                    $output .= get_permalink($sched_post) . '">';
                    $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url(mf_get_the_maker_image($json), 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />';
                    $output .= '</a></div>';
                }
            }
            $output .= '</td>';
            $output .= '<td>';
            $output .= '<h3><a href="' . get_permalink($sched_post) . '">' . get_the_title($sched_post->ID) . '</a></h3>';
            if (!empty($json->presenter_name)) {
                $names = $json->presenter_name;
                $names_output = '';
                foreach ($names as $name) {
                    $names_output .= ', ' . $name;
                }
                $output .= '<h4>' . substr($names_output, 2) . '</h4>';
            }
            if (!empty($json->short_description)) {
                $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->short_description, "\n"))));
            } elseif (!empty($json->public_description)) {
                $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->public_description, "\n"))));
            }
            if (!empty($meta['mfei_coverage'][0])) {
                $output .= '<p><a href="' . esc_url($meta['mfei_coverage'][0]) . '" class="btn btn-mini btn-primary">Watch Video</a></p>';
            }
            // $output .= '<ul class="unstyled">';
            // $terms = get_the_terms( $sched_post->ID, array( 'category', 'post_tag' ) );
            // if (!empty($terms)) {
            // 	$output .= '<li>Topics: ';
            // 	$the_terms = '';
            // 	foreach ($terms as $idx => $term) {
            // 		$the_terms .= ', <a href="' . get_term_link( $term ) . '">' . $term->name . '</a>';
            // 	}
            // 	$output .= substr( $the_terms, 2 );
            // 	$output .= '</li>';
            // }
            // $output .= '</ul>';
            $output .= '</td>';
            $output .= '</tr>';
        }
        $output .= '</table>';
    }
    wp_reset_postdata();
    return $output;
}
/**
 * Optimized version of get_term_link that adds caching for slug-based lookups.
 *
 * Returns permalink for a taxonomy term archive, or a WP_Error object if the term does not exist.
 *
 * @param int|string|object $term The term object / term ID / term slug whose link will be retrieved.
 * @param string $taxonomy The taxonomy slug. NOT required if you pass the term object in the first parameter
 *
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function wpcom_vip_get_term_link($term, $taxonomy)
{
    // ID- or object-based lookups already result in cached lookups, so we can ignore those.
    if (is_numeric($term) || is_object($term)) {
        return get_term_link($term, $taxonomy);
    }
    $term_object = wpcom_vip_get_term_by('slug', $term, $taxonomy);
    return get_term_link($term_object);
}
/**
 * Insert analytics code onto the post page
 */
function sranalytics_insert_js()
{
    global $post;
    // Do not show SimpleReach tags by default
    $sranalytics_show_beacon = false;
    // Get the options
    $sranalytics_pid = get_option('sranalytics_pid');
    $sranalytics_show_on_tac_pages = get_option('sranalytics_show_on_tac_pages');
    $sranalytics_show_on_wp_pages = get_option('sranalytics_show_on_wp_pages');
    $sranalytics_show_on_attachment_pages = get_option('sranalytics_show_on_attachment_pages');
    $sranalytics_show_everywhere = get_option('sranalytics_show_everywhere');
    $sranalytics_force_http = get_option('sranalytics_force_http');
    $sranalytics_disable_iframe_loading = get_option('sranalytics_disable_iframe_loading');
    // Try and check the validity of the PID
    if (empty($sranalytics_pid) || 24 != strlen($sranalytics_pid)) {
        return False;
    }
    // Show everywhere
    if ($sranalytics_show_everywhere) {
        $sranalytics_show_beacon = true;
    }
    //Show on attachment pages if option set
    if (is_attachment() && $sranalytics_show_on_attachment_pages) {
        $sranalytics_show_beacon = true;
    }
    // Ensure we show on post pages
    if (is_single() && !is_attachment()) {
        $sranalytics_show_beacon = true;
    }
    // Ensure we show on WP pages if we are supposed to
    if (is_page() && $sranalytics_show_on_wp_pages) {
        $sranalytics_show_beacon = true;
    }
    // Ensure we show on WP pages if we are supposed to
    if (is_page() && $sranalytics_show_on_wp_pages) {
        $sranalytics_show_beacon = true;
    }
    $post_id = $post->ID;
    // If the post isn't published yet, don't show the __reach_config
    // attachments don't have published status though so always show for them.
    if ('publish' != $post->post_status && !is_attachment()) {
        return False;
    }
    // default case of a regular post
    $title = $post->post_title;
    $authors = array(get_author_name($post->post_author));
    $tags = wp_get_post_tags($post->ID, array('fields' => 'names'));
    $channels = wp_get_post_categories($post->ID, array('fields' => 'slugs'));
    $published_date = $post->post_date_gmt;
    $canonical_url = get_permalink($post->ID);
    // Show the tags if we are on a tag/author/category page and we are supposed to
    if ((is_category() || is_author() || is_tag()) && ($sranalytics_show_on_tac_pages || $sranalytics_show_everywhere)) {
        $sranalytics_show_beacon = true;
        $channels = array();
        $authors = array();
        $tags = array();
        //handle archive-style pages. WordPress has a different pattern for retrieving each one
        if (is_tag()) {
            $tag_name = single_cat_title('', false);
            if (function_exists('wpcom_vip_get_term_by')) {
                $tag = wpcom_vip_get_term_by('name', $tag_name, 'post_tag');
            } else {
                $tag = get_term_by('name', $tag_name, 'post_tag');
            }
            $tag_url = get_tag_link($tag->term_id);
            $title = "Tag: {$tag_name}";
            $tags[] = $tag_name;
            $canonical_url = $tag_url;
        } elseif (is_author()) {
            $author_id = get_the_author_meta('ID');
            $author_name = get_the_author();
            $title = "Author: {$author_name}";
            $authors[] = $author_name;
            $canonical_url = get_author_posts_url($author_id);
        } elseif (is_category()) {
            $channel_name = single_cat_title('', false);
            $category_id = get_cat_ID($channel_name);
            $title = "Category: {$channel_name}";
            $channels[] = $channel_name;
            $canonical_url = get_category_link($category_id);
        } else {
            // We should NEVER get here
            $title = "Unkown Page Type";
        }
        // If we are on a page, then we need to add it
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        if ($paged > 1) {
            $title = "{$title} - Page {$paged}";
        }
    }
    // Handle the homepage properly if we are supposed to fire on it
    if ((is_home() || is_page('home')) && $sranalytics_show_everywhere) {
        $title = "Homepage";
        $channels = array();
        $authors = array();
        $tags = array();
        $canonical_url = get_home_url();
    }
    //force https to http if option is checked
    if ($sranalytics_force_http) {
        $pattern = '/^https:\\/\\//';
        $canonical_url = preg_replace($pattern, "http://", $canonical_url);
    }
    //prepare and escape all JS variables
    $javascript_array = array('version' => SRANALYTICS_PLUGIN_VERSION, 'pid' => esc_js($sranalytics_pid), 'iframe' => esc_js($sranalytics_disable_iframe_loading), 'title' => esc_js(apply_filters('sranalytics_title', $title)), 'url' => esc_js(apply_filters('sranalytics_url', $canonical_url)), 'date' => esc_js(apply_filters('sranalytics_date', $published_date)), 'channels' => array_map('esc_js', apply_filters('sranalytics_channels', $channels)), 'tags' => array_map('esc_js', apply_filters('sranalytics_tags', $tags)), 'authors' => array_map('esc_js', apply_filters('sranalytics_authors', $authors)));
    // Get the JS ready to go
    if ($sranalytics_show_beacon) {
        wp_register_script('sranalytics', plugins_url('javascripts/sranalytics.js', __FILE__));
        wp_localize_script('sranalytics', 'sranalytics', $javascript_array);
        wp_enqueue_script('sranalytics');
    } else {
        return false;
    }
}
示例#12
0
 /**
  * Creates a new maker in the makers listings and returns the makers ID
  * @param  array $user The data passed from Gigya for use in the maker creation
  * @return integer
  */
 private function create_maker($user, $uid)
 {
     // Handle our user name
     if (!empty($user['firstName']) && !empty($user['lastName'])) {
         $user_name = $user['firstName'] . ' ' . $user['lastName'];
     } elseif (!empty($user['firstName']) && empty($user['lastName'])) {
         $user_name = $user['firstName'];
     } elseif (empty($user['firstName']) && empty($user['lastName']) && !empty($user['nickname'])) {
         $user_name = $user['nickname'];
     } else {
         $user_name = 'Undefined Username';
     }
     // We need the term ID of the current faire taxonomy
     $current_faire = wpcom_vip_get_term_by('slug', MF_CURRENT_FAIRE, 'faire');
     // Our user doesn't exist, that means we need to sync them up, create a maker account and log them in.
     $maker = array('post_title' => sanitize_text_field($user_name), 'post_content' => !empty($user['bio']) ? wp_filter_post_kses($user['bio']) : '', 'post_status' => 'publish', 'post_type' => 'maker', 'tax_input' => array('faire' => absint($current_faire->term_id)));
     $maker_id = wp_insert_post($maker);
     // If an error happens, we want to report that back before running any post meta updates.
     if (is_wp_error($maker_id)) {
         return 0;
     }
     // We'll want to add some custom fields. Let's do that.
     // ****************************************************
     // Add the maker email
     $user_email = isset($user['email']) && !empty($user['email']) ? $user['email'] : '';
     update_post_meta(absint($maker_id), 'email', sanitize_email($user_email));
     // Add the maker photo
     $user_photo = isset($user['photoURL']) && !empty($user['photoURL']) ? $user['photoURL'] : '';
     update_post_meta(absint($maker_id), 'photo_url', esc_url($user_photo));
     // Add the maker website field, even though this field will be blank on creation
     update_post_meta(absint($maker_id), 'website', '');
     // Add the maker video field, even though this field will be blank on creation
     update_post_meta(absint($maker_id), 'video', '');
     // Add the Maker Gigya ID
     update_post_meta(absint($maker_id), 'guid', sanitize_text_field($uid));
     return $maker_id;
 }
示例#13
0
 /**
  * Get the language code for a translatable element
  *
  * @since 2.0
  *
  * @param mixed $language_code
  * @param array $args          an array with two keys element_id => post_id or term_taxonomy_id, element_type => post type or taxonomy
  * @return string
  */
 public function wpml_element_language_code($language_code, $args)
 {
     $type = $args['element_type'];
     $id = $args['element_id'];
     $pll_type = 'post' == $type || pll_is_translated_post_type($type) ? 'post' : ('term' == $type || pll_is_translated_taxonomy($type) ? 'term' : false);
     if ('term' === $pll_type && ($term = wpcom_vip_get_term_by('term_taxonomy_id', $id))) {
         $id = $term->term_id;
     }
     return $pll_type ? call_user_func("pll_get_{$pll_type}_language", $id) : $language_code;
 }
示例#14
0
 /**
  * Parse the raw facet data from Elasticsearch into a constructive format.
  * Specifically:
  *
  *     array(
  *         'Label' => array(
  *             'type'     => [type requested],
  *             'count'    => [count requested],
  *             'taxonomy' => [taxonomy requested, if applicable],
  *             'interval' => [interval requested, if applicable],
  *             'field'    => [field requested, if applicable],
  *             'items'    => array(
  *                 array(
  *                     'query_vars' => array( [query_var] => [value] ),
  *                     'name' => [formatted string for this facet],
  *                     'count' => [number of results in this facet],
  *                 )
  *             )
  *         )
  *     )
  *
  * The returning array is mostly the data as requested in the WP args, with
  * the addition of the 'items' key. This is an array of arrays, each one
  * being a term in the facet response. The 'query_vars' can be used to
  * generate links/form fields. The name is suitable for display, and the
  * count is useful for your facet UI.
  *
  * @return array See above for further details.
  */
 public function get_facet_data()
 {
     if (empty($this->facets)) {
         return false;
     }
     $facets = $this->get_results('facets');
     if (!$facets) {
         return false;
     }
     $facet_data = array();
     foreach ($facets as $label => $facet) {
         if (empty($this->facets[$label])) {
             continue;
         }
         $facet_data[$label] = $this->facets[$label];
         $facet_data[$label]['items'] = array();
         // All taxonomy terms are going to have the same query_var
         if ('taxonomy' == $this->facets[$label]['type']) {
             $tax_query_var = $this->get_taxonomy_query_var($this->facets[$label]['taxonomy']);
             if (!$tax_query_var) {
                 continue;
             }
             $existing_term_slugs = get_query_var($tax_query_var) ? explode(',', get_query_var($tax_query_var)) : array();
         }
         $items = array();
         if (!empty($facet['buckets'])) {
             $items = (array) $facet['buckets'];
         }
         // Some facet types like date_histogram don't support the max results parameter
         if (count($items) > $this->facets[$label]['count']) {
             $items = array_slice($items, 0, $this->facets[$label]['count']);
         }
         foreach ($items as $item) {
             if (false === ($datum = apply_filters('sp_search_facet_datum', false, $item, $this->facets))) {
                 $query_vars = array();
                 switch ($this->facets[$label]['type']) {
                     case 'taxonomy':
                         if (function_exists('wpcom_vip_get_term_by')) {
                             $term = wpcom_vip_get_term_by('slug', $item['key'], $this->facets[$label]['taxonomy']);
                         } else {
                             $term = get_term_by('slug', $item['key'], $this->facets[$label]['taxonomy']);
                         }
                         if (!$term) {
                             continue 2;
                             // switch() is considered a looping structure
                         }
                         // Don't allow refinement on a term we're already refining on
                         if (in_array($term->slug, $existing_term_slugs)) {
                             continue 2;
                         }
                         $slugs = array_merge($existing_term_slugs, array($term->slug));
                         $query_vars = array($tax_query_var => implode(',', $slugs));
                         $name = $term->name;
                         break;
                     case 'post_type':
                         $post_type = get_post_type_object($item['key']);
                         if (!$post_type || $post_type->exclude_from_search) {
                             continue 2;
                             // switch() is considered a looping structure
                         }
                         $query_vars = array('post_type' => $item['key']);
                         $name = $post_type->labels->singular_name;
                         break;
                     case 'date_histogram':
                         $timestamp = $item['key'] / 1000;
                         switch ($this->facets[$label]['interval']) {
                             case 'year':
                                 $query_vars = array('year' => date('Y', $timestamp));
                                 $name = date('Y', $timestamp);
                                 break;
                             case 'month':
                                 $query_vars = array('year' => date('Y', $timestamp), 'monthnum' => date('n', $timestamp));
                                 $name = date('F Y', $timestamp);
                                 break;
                             case 'day':
                                 $query_vars = array('year' => date('Y', $timestamp), 'monthnum' => date('n', $timestamp), 'day' => date('j', $timestamp));
                                 $name = date('F j, Y', $timestamp);
                                 break;
                             default:
                                 continue 3;
                                 // switch() is considered a looping structure
                         }
                         break;
                     default:
                         //continue 2; // switch() is considered a looping structure
                 }
                 $datum = array('query_vars' => $query_vars, 'name' => $name, 'count' => $item['doc_count']);
             }
             $facet_data[$label]['items'][] = $datum;
         }
     }
     return apply_filters('sp_search_facet_data', $facet_data);
 }
 /**
  * translates tax queries
  * compatible with nested tax queries introduced in WP 4.1
  *
  * @since 1.7
  *
  * @param array $tax_queries
  * @return array translated tax queries
  */
 protected function translate_tax_query_recursive($tax_queries)
 {
     foreach ($tax_queries as $key => $q) {
         if (isset($q['taxonomy']) && $this->model->is_translated_taxonomy($q['taxonomy'])) {
             $arr = array();
             $field = isset($q['field']) && in_array($q['field'], array('slug', 'name')) ? $q['field'] : 'term_id';
             foreach ((array) $q['terms'] as $t) {
                 $arr[] = ($tag = wpcom_vip_get_term_by($field, $t, $q['taxonomy'])) && ($tr_id = $this->get_term($tag->term_id)) && !is_wp_error($tr = get_term($tr_id, $q['taxonomy'])) ? $tr->{$field} : $t;
             }
             $tax_queries[$key]['terms'] = $arr;
         } elseif (is_array($q)) {
             $tax_queries[$key] = $this->translate_tax_query_recursive($q);
         }
     }
     return $tax_queries;
 }