function widget($args, $instance)
 {
     $cache = wp_cache_get('widget_nice_opening_hours', 'widget');
     if (!is_array($cache)) {
         $cache = array();
     }
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     ob_start();
     $settings = array_fill_keys($this->settings, '');
     extract($args, EXTR_SKIP);
     $instance = wp_parse_args($instance, $settings);
     extract($instance, EXTR_SKIP);
     echo $before_widget;
     if ($title != '') {
         echo $before_title . apply_filters('widget_title', $title, $instance, $this->id_base) . $after_title;
     }
     // get times and do the magic!
     echo nice_opening_hours();
     echo $after_widget;
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set('widget_nice_opening_hours', $cache, 'widget');
 }
 function get_terms_in_found_set()
 {
     if (isset($this->terms_in_found_set)) {
         return $this->terms_in_found_set;
     }
     $matching_post_ids = $this->facets->get_matching_post_ids();
     // if there aren't any matching post ids, we don't need to query
     if (!$matching_post_ids) {
         return array();
     }
     //end if
     $cache_key = md5(serialize($matching_post_ids));
     if (!($this->terms_in_found_set = wp_cache_get($cache_key, 'scrib-facet-post-author'))) {
         global $wpdb;
         $terms = $wpdb->get_results('SELECT post_author , COUNT(*) AS hits FROM ' . $wpdb->posts . ' WHERE ID IN (' . implode(',', $matching_post_ids) . ') GROUP BY post_author LIMIT 1000 /* generated in Facet_Post_Author::get_terms_in_found_set() */');
         $this->terms_in_found_set = array();
         foreach ($terms as $term) {
             $userdata = get_userdata($term->post_author);
             if (empty($userdata->display_name)) {
                 continue;
             }
             $this->terms_in_found_set[] = (object) array('facet' => $this->name, 'slug' => $userdata->user_nicename, 'name' => $userdata->display_name, 'description' => $userdata->user_description, 'term_id' => $term->post_author, 'count' => $term->hits);
         }
         wp_cache_set($cache_key, $this->terms_in_found_set, 'scrib-facet-post-author', $this->ttl);
     }
     return $this->terms_in_found_set;
 }
Beispiel #3
0
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;
}
Beispiel #4
0
/**
 * To retrive AnsPress option 		
 * @param  string $key   Name of option to retrive,
 *                       Keep it blank to get all options of AnsPress
 * @param  string $value Enter value to update existing option
 * @return string         
 * @since 0.1
 */
function ap_opt($key = false, $value = null)
{
    $settings = wp_cache_get('ap_opt', 'options');
    if ($settings === false) {
        $settings = get_option('anspress_opt');
        if (!$settings) {
            $settings = array();
        }
        $settings = $settings + ap_default_options();
        wp_cache_set('ap_opt', $settings, 'options');
    }
    if (!is_null($value)) {
        $settings[$key] = $value;
        update_option('anspress_opt', $settings);
        // clear cache if option updated
        wp_cache_delete('ap_opt', 'options');
        return;
    }
    if (false === $key) {
        return $settings;
    }
    if (isset($settings[$key])) {
        return $settings[$key];
    } else {
        return NULL;
    }
    return false;
}
Beispiel #5
0
 function widget($args, $instance)
 {
     $cache = wp_cache_get($this->className, 'widget');
     if (!is_array($cache)) {
         $cache = array();
     }
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = null;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     ob_start();
     extract($args, EXTR_SKIP);
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     echo $before_widget;
     if ($title) {
         echo $before_title, $title, $after_title;
     }
     if (isset($instance['list'])) {
         echo ciGetPracticeAreasTitlesList($instance['maxPracticeAreas']);
     } else {
         echo ciGetPracticeAreasHTML($instance['maxPracticeAreas'], 0, $instance['maxCharLength']);
     }
     echo $after_widget;
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set($this->className, $cache, 'widget');
 }
function get_galleries($ids = array())
{
    $galleries = wp_cache_get('galleries', THEME_NAME);
    if (!$galleries) {
        $options = array('post_type' => 'property_gallery', 'post_status' => 'publish', 'post__in' => $ids, 'posts_per_page' => PHP_INT_MAX);
        $galleries = get_posts($options);
        foreach ($galleries as &$gallery) {
            $_content = $gallery->post_content;
            $gallery_images_ids = array();
            $featured_image = null;
            preg_match('/\\[gallery ids="(.*?)"\\]/', $_content, $matches);
            $gallery->images = array();
            $gallery->featured_image = null;
            if (!empty($matches[1])) {
                $gallery_images_ids = explode(',', $matches[1]);
                $featured_image = wp_get_attachment_image_src($gallery_images_ids[0], 'properties-gallery-normal');
                $_gallery = array();
                foreach ($gallery_images_ids as $id) {
                    $image = wp_get_attachment_image_src($id, 'properties-gallery-normal');
                    $_gallery[] = $image;
                }
                $gallery->images = $_gallery;
                $gallery->featured_image = $featured_image;
            }
        }
        // Save galleries if there is a permanent cache installed
        wp_cache_set('galleries', $galleries, THEME_NAME);
    }
    return $galleries;
}
function acf_get_value($post_id, $field)
{
    // try cache
    $found = false;
    $cache = wp_cache_get("load_value/post_id={$post_id}/name={$field['name']}", 'acf', false, $found);
    if ($found) {
        return $cache;
    }
    // load value
    $value = acf_get_metadata($post_id, $field['name']);
    // if value was duplicated, it may now be a serialized string!
    $value = maybe_unserialize($value);
    // no value? try default_value
    if ($value === null && isset($field['default_value'])) {
        $value = $field['default_value'];
    }
    // filter for 3rd party customization
    $value = apply_filters("acf/load_value", $value, $post_id, $field);
    $value = apply_filters("acf/load_value/type={$field['type']}", $value, $post_id, $field);
    $value = apply_filters("acf/load_value/name={$field['name']}", $value, $post_id, $field);
    $value = apply_filters("acf/load_value/key={$field['key']}", $value, $post_id, $field);
    //update cache
    wp_cache_set("load_value/post_id={$post_id}/name={$field['name']}", $value, 'acf');
    // return
    return $value;
}
 function testGetPostNavFromCache()
 {
     wp_cache_set('navigation-1', array('test' => 2), 'comicpress');
     $post_2 = (object) array('ID' => 2);
     wp_insert_post((array) $post_2);
     $this->assertEquals(array('test' => $post_2), $this->nav->get_post_nav((object) array('ID' => 1)));
 }
function hsinsider_get_lead_art($post = null)
{
    if (empty($post)) {
        global $post;
    }
    if (has_post_thumbnail()) {
        $featured_id = get_post_thumbnail_id($post->ID);
        $the_query = wp_cache_get($featured_id . '_attachment');
        if ($the_query == false) {
            /**
             * Query for the Featured Image Caption
             */
            $args = array('p' => $featured_id, 'post_type' => 'attachment');
            $the_query = new WP_Query($args);
            // Set the cache to expire the data after 300 seconds
            wp_cache_set($featured_id . '_attachment', $the_query, '', 300);
        }
        if ($the_query->have_posts()) {
            while ($the_query->have_posts()) {
                $the_query->the_post();
                $featured_caption = get_the_excerpt();
            }
        }
        wp_reset_postdata();
        $featured_url = wp_get_attachment_url($featured_id);
        $featured_html = '<figure><img src="' . esc_url($featured_url) . '" class="attachment-post-thumbnail size-post-thumbnail wp-post-image img-responsive"/><figcaption class="wp-caption-text">' . esc_html($featured_caption) . '</figcaption></figure>';
        echo $featured_html;
    }
}
 public function widget($args, $instance)
 {
     $cache = wp_cache_get('widget_willow_recent_posts', 'widget');
     if (!is_array($cache)) {
         $cache = array();
     }
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     $title = apply_filters('widget_title', $instance['title']);
     if (empty($instance['number']) || !($number = absint($instance['number']))) {
         $number = 5;
     }
     $show_date = isset($instance['show_date']) ? $instance['show_date'] : false;
     global $wp_query;
     $temp = $wp_query;
     $wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => $number, 'ignore_sticky_posts' => 1));
     ob_start();
     echo $args['before_widget'];
     echo !empty($title) ? $args['before_title'] . $title . $args['after_title'] : '';
     include locate_template('loop-widget-posts.php');
     echo $args['after_widget'];
     $cache[$args['widget_id']] = ob_get_flush();
     $wp_query = $temp;
     wp_reset_postdata();
     wp_cache_set('widget_willow_recent_posts', $cache, 'widget');
 }
Beispiel #11
0
function wpjam_get_post_thumbnail_uri($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $post_id = $post->ID;
    $post_thumbnail_uri = wp_cache_get($post_id, 'post_thumbnail_uri');
    if ($post_thumbnail_uri === false) {
        if (has_post_thumbnail($post_id)) {
            $post_thumbnail_uri = wp_get_attachment_url(get_post_meta($post_id, '_thumbnail_id', true));
        } elseif ($post_thumbnail_uri = apply_filters('wpjam_pre_post_thumbnail_uri', false, $post)) {
            // do nothing
        } elseif ($first_img = get_post_first_image(do_shortcode($post->post_content))) {
            $pre = apply_filters('pre_qiniu_remote', false, $first_img);
            $img_type = strtolower(pathinfo($first_img, PATHINFO_EXTENSION));
            if ($pre == false && wpjam_qiniutek_get_setting('remote') && get_option('permalink_structure') && strpos($first_img, LOCAL_HOST) === false && strpos($first_img, CDN_HOST) === false) {
                $img_type = $img_type == 'png' ? $img_type : 'jpg';
                $first_img = CDN_HOST . '/qiniu/' . $post_id . '/image/' . md5($first_img) . '.' . $img_type;
            }
            $post_thumbnail_uri = $first_img;
        } elseif ($post_thumbnail_uri = apply_filters('wpjam_post_thumbnail_uri', false, $post)) {
            //do nothing
        } else {
            $post_thumbnail_uri = wpjam_get_default_thumbnail_uri();
        }
        wp_cache_set($post_id, $post_thumbnail_uri, 'post_thumbnail_uri', 6000);
    }
    return $post_thumbnail_uri;
}
Beispiel #12
0
function ap_find_mentioned_users($content)
{
    global $wpdb;
    // Find all mentions in content.
    preg_match_all('/(?:[\\s.]|^)@(\\w+)/', $content, $matches);
    if (is_array($matches) && count($matches) > 0 && !empty($matches[0])) {
        $user_logins = array();
        // Remove duplicates.
        $unique_logins = array_unique($matches[0]);
        foreach ($unique_logins as $user_login) {
            $user_logins[] = sanitize_title_for_query(sanitize_user(wp_unslash($user_login), true));
        }
        if (count($user_logins) == 0) {
            return false;
        }
        $user_logins_s = "'" . implode("','", $user_logins) . "'";
        $key = md5($user_logins_s);
        $cache = wp_cache_get($key, 'ap_user_ids');
        if (false !== $cache) {
            return $cache;
        }
        $query = $wpdb->prepare("SELECT id, user_login FROM {$wpdb->users} WHERE user_login IN ({$user_logins_s})");
        $result = $wpdb->get_results($query);
        wp_cache_set($key, $result, 'ap_user_ids');
        return $result;
    }
    return false;
}
 /**
  * Get tags from current post views
  *
  * @return boolean
  */
 public static function get_tags_from_current_posts()
 {
     if (is_array(self::$posts) && count(self::$posts) > 0) {
         // Generate SQL from post id
         $postlist = implode("', '", self::$posts);
         // Generate key cache
         $key = md5(maybe_serialize($postlist));
         $results = array();
         // Get cache if exist
         $cache = wp_cache_get('generate_keywords', 'simpletags');
         if ($cache === false) {
             foreach (self::$posts as $object_id) {
                 // Get terms
                 $terms = get_object_term_cache($object_id, 'post_tag');
                 if (false === $terms) {
                     $terms = wp_get_object_terms($object_id, 'post_tag');
                 }
                 if ($terms != false) {
                     $results = array_merge($results, $terms);
                 }
             }
             $cache[$key] = $results;
             wp_cache_set('generate_keywords', $cache, 'simpletags');
         } else {
             if (isset($cache[$key])) {
                 return $cache[$key];
             }
         }
         return $results;
     }
     return array();
 }
 public static function update_translation_batch($batch_name = false, $tp_id = false)
 {
     global $wpdb;
     $batch_name = $batch_name ? $batch_name : ((bool) $tp_id === false || $tp_id === 'local' ? self::get_generic_batch_name() : TranslationProxy_Basket::get_basket_name());
     if (!$batch_name) {
         return null;
     }
     $cache_key = md5($batch_name);
     $cache_group = 'update_translation_batch';
     $cache_found = false;
     $batch_id = wp_cache_get($cache_key, $cache_group, false, $cache_found);
     if ($cache_found && $batch_id) {
         return $batch_id;
     }
     $batch_id_sql = "SELECT id FROM {$wpdb->prefix}icl_translation_batches WHERE batch_name=%s";
     $batch_id_prepared = $wpdb->prepare($batch_id_sql, array($batch_name));
     $batch_id = $wpdb->get_var($batch_id_prepared);
     if (!$batch_id) {
         $data = array('batch_name' => $batch_name, 'last_update' => date('Y-m-d H:i:s'));
         if ($tp_id) {
             if ($tp_id === 'local') {
                 $tp_id = 0;
             }
             $data['tp_id'] = $tp_id;
         }
         $wpdb->insert($wpdb->prefix . 'icl_translation_batches', $data);
         $batch_id = $wpdb->insert_id;
         wp_cache_set($cache_key, $batch_id, $cache_group);
     }
     return $batch_id;
 }
 /**
  * Reads the options from options table
  *
  * @since  1.0.0
  */
 public function refresh()
 {
     $option_key = $this->option_key();
     $settings = MS_Factory::get_option($option_key);
     MS_Factory::populate_model($this, $settings);
     wp_cache_set($option_key, $this, 'MS_Model_Option');
 }
function onp_updates_324_set_site_transient($transient, $value, $expiration = 0, $actions = false)
{
    global $_wp_using_ext_object_cache;
    if ($actions) {
        $value = apply_filters('pre_set_site_transient_' . $transient, $value);
    }
    if ($_wp_using_ext_object_cache) {
        $result = wp_cache_set($transient, $value, 'site-transient', $expiration);
    } else {
        $transient_timeout = '_site_transient_timeout_' . $transient;
        $transient = '_site_transient_' . $transient;
        if (false === get_site_option($transient)) {
            if ($expiration) {
                add_site_option($transient_timeout, time() + $expiration);
            }
            $result = add_site_option($transient, $value);
        } else {
            if ($expiration) {
                update_site_option($transient_timeout, time() + $expiration);
            }
            delete_site_option($transient);
            $result = update_site_option($transient, $value);
        }
    }
    if ($result && $actions) {
        do_action('set_site_transient_' . $transient);
        do_action('setted_site_transient', $transient);
    }
    return $result;
}
 public function get_gateway_data()
 {
     if (!($this->gateway_data = wp_cache_get($this->log_id, 'wpsc_checkout_form_gateway_data'))) {
         $map = array('firstname' => 'first_name', 'lastname' => 'last_name', 'address' => 'street', 'city' => 'city', 'state' => 'state', 'country' => 'country', 'postcode' => 'zip', 'phone' => 'phone');
         foreach (array('shipping', 'billing') as $type) {
             $data_key = "{$type}_address";
             $this->gateway_data[$data_key] = array();
             foreach ($map as $key => $new_key) {
                 $key = $type . $key;
                 if (isset($this->data[$key])) {
                     $value = $this->data[$key];
                     if ($new_key == 'state' && is_numeric($value)) {
                         $value = wpsc_get_state_by_id($value, 'code');
                     }
                     $this->gateway_data[$data_key][$new_key] = $value;
                 }
             }
             $name = isset($this->gateway_data[$data_key]['first_name']) ? $this->gateway_data[$data_key]['first_name'] . ' ' : '';
             $name .= isset($this->gateway_data[$data_key]['last_name']) ? $this->gateway_data[$data_key]['last_name'] : '';
             $this->gateway_data[$data_key]['name'] = trim($name);
         }
         wp_cache_set($this->log_id, $this->gateway_data, 'wpsc_checkout_form_gateway_data');
     }
     return apply_filters('wpsc_checkout_form_gateway_data', $this->gateway_data, $this->log_id);
 }
Beispiel #18
0
 function get_comment_changes()
 {
     global $spec_comment_log, $current_user;
     $user_roles = $current_user->roles;
     $role = array_shift($user_roles);
     $action_id = 0;
     if (isset($_POST['action_id'])) {
         $action_id = absint($_POST['action_id']);
     }
     $time = '';
     if (isset($_POST['time'])) {
         $time = $_POST['time'];
     }
     $post_id = $_POST['post_id'];
     // Get the details from cache
     $cachekey = 'icit_spec_discus_' . $post_id . '_' . $action_id . '_' . $role;
     $encoded_json = wp_cache_get($cachekey, 'spec_discussion');
     if (empty($encoded_json)) {
         $encoded_json = $this->grab_changedcomments_json($spec_comment_log, $post_id, $time, $action_id);
         // The details weren't in cache lets add it now.
         wp_cache_set($cachekey, $encoded_json, 'spec_discussion', 20);
     }
     echo $encoded_json;
     die;
 }
/**
 * Pre-fetch member type data when initializing a Members loop.
 *
 * @since BuddyPress (2.2.0)
 *
 * @param BP_User_Query $bp_user_query BP_User_Query object.
 */
function bp_members_prefetch_member_type( BP_User_Query $bp_user_query ) {
	$uncached_member_ids = bp_get_non_cached_ids( $bp_user_query->user_ids, 'bp_member_type' );

	$member_types = bp_get_object_terms( $uncached_member_ids, 'bp_member_type', array(
		'fields' => 'all_with_object_id',
	) );

	// Rekey by user ID.
	$keyed_member_types = array();
	foreach ( $member_types as $member_type ) {
		if ( ! isset( $keyed_member_types[ $member_type->object_id ] ) ) {
			$keyed_member_types[ $member_type->object_id ] = array();
		}

		$keyed_member_types[ $member_type->object_id ][] = $member_type->name;
	}

	$cached_member_ids = array();
	foreach ( $keyed_member_types as $user_id => $user_member_types ) {
		wp_cache_set( $user_id, $user_member_types, 'bp_member_type' );
		$cached_member_ids[] = $user_id;
	}

	// Cache an empty value for users with no type.
	foreach ( array_diff( $uncached_member_ids, $cached_member_ids ) as $no_type_id ) {
		wp_cache_set( $no_type_id, '', 'bp_member_type' );
	}
}
Beispiel #20
0
 /**
  * Return monthly
  *
  * @link
  *       https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/general-template.php#L1335
  * @return string
  */
 public static function getMonthly($limit = self::LIMIT)
 {
     global $wpdb, $wp_locale;
     $last_changed = wp_cache_get('last_changed', 'posts');
     if (!$last_changed) {
         $last_changed = microtime();
         wp_cache_set('last_changed', $last_changed, 'posts');
     }
     $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as total\n\t\t\tFROM {$wpdb->posts}\n\t\t\tWHERE post_type = 'post' AND post_status = 'publish'\n\t\t\tGROUP BY YEAR(post_date), MONTH(post_date)\n\t\t\tORDER BY post_date DESC ";
     if ($limit) {
         $query .= " LIMIT {$limit}";
     }
     $key = md5($query);
     $key = "wp_get_archives:{$key}:{$last_changed}";
     if (!($results = wp_cache_get($key, 'posts'))) {
         $results = $wpdb->get_results($query);
         wp_cache_set($key, $results, 'posts');
     }
     $archives = [];
     foreach ($results as $result) {
         $url = get_month_link($result->year, $result->month);
         /* translators: 1: month name, 2: 4-digit year */
         $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
         $archives[] = new Archive($text, $url, $result->total);
     }
     return $archives;
 }
Beispiel #21
0
function get_field($field_name, $post_id = false)
{
    global $post, $acf;
    if (!$post_id) {
        $post_id = $post->ID;
    } elseif ($post_id == "options") {
        $post_id = 999999999;
    }
    // return cache
    $cache = wp_cache_get('acf_get_field_' . $post_id . '_' . $field_name);
    if ($cache) {
        return $cache;
    }
    // default
    $value = "";
    // get value
    $field_key = get_post_meta($post_id, '_' . $field_name, true);
    if ($field_key != "") {
        // we can load the field properly!
        $field = $acf->get_acf_field($field_key);
        $value = $acf->get_value_for_api($post_id, $field);
    } else {
        // just load the text version
        $value = get_post_meta($post_id, $field_name, true);
    }
    // no value?
    if ($value == "") {
        $value = false;
    }
    // update cache
    wp_cache_set('acf_get_field_' . $post_id . '_' . $field_name, $value);
    return $value;
}
Beispiel #22
0
 function GalleryGallery($data = array())
 {
     global $wpdb;
     $this->plugin_name = basename(dirname(dirname(__FILE__)));
     $this->table = $wpdb->prefix . strtolower($this->pre) . "_" . $this->controller;
     if (is_admin()) {
         $this->check_table($this->model);
     }
     if (!empty($data)) {
         foreach ($data as $dkey => $dval) {
             $this->{$dkey} = stripslashes_deep($dval);
             switch ($dkey) {
                 case 'id':
                     $slidescountquery = "SELECT COUNT(`id`) FROM `" . $wpdb->prefix . strtolower($this->pre) . "_galleriesslides` WHERE `gallery_id` = '" . $dval . "'";
                     $query_hash = md5($slidescountquery);
                     if ($oc_slidescount = wp_cache_get($query_hash, 'slideshowgallery')) {
                         $this->slidescount = $oc_slidescount;
                     } else {
                         $this->slidescount = $wpdb->get_var($slidescountquery);
                         wp_cache_set($query_hash, $this->slidescount, 'slideshowgallery', 0);
                     }
                     break;
             }
         }
     }
     return true;
 }
    function widget($args, $instance)
    {
        $cache = wp_cache_get('widget_dt_slider', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($args['widget_id'])) {
            $args['widget_id'] = $this->id;
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('', 'engine') : $instance['title'], $instance, $this->id_base);
        $category = empty($instance['category']) ? '' : $instance['category'];
        $qty = empty($instance['qty']) ? '3' : $instance['qty'];
        $excerpt_length = empty($instance['excerpt_length']) ? '0' : $instance['excerpt_length'];
        $r = new WP_Query(array('posts_per_page' => $qty, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__in' => explode(',', $category)));
        if ($r->have_posts()) {
            ?>
		<?php 
            echo $before_widget;
            echo do_shortcode('[engine_slider title="' . $title . '" category="' . $category . '" qty="' . $qty . '" autoplay="0" random="0" thumb_size="small" excerpt_length="' . $excerpt_length . '"]');
            echo $after_widget;
            // Reset the global $the_post as this query will have stomped on it
            wp_reset_postdata();
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('widget_dt_slider', $cache, 'widget');
    }
 public static function render($slug, $data = array(), $cache = false)
 {
     if (is_string($data)) {
         $data = array('name' => $data);
     }
     $cache = self::_maybe_prevent_caching($slug, $data, $cache);
     $data = wp_parse_args($data, array('name' => '', 'return' => false));
     $return = $data['return'];
     unset($data['return']);
     if ($cache) {
         $cache = self::_get_cache_key($slug, $data);
         if ($cache) {
             $output = wp_cache_get($cache, 'templateparts');
             if (false !== $output) {
                 $output = self::_add_output_html_comments($output, $slug, true);
                 if ($return) {
                     return $output;
                 }
                 echo $output;
                 return;
             }
         }
     }
     $templates = array();
     if (!empty($data['name'])) {
         $templates[] = $slug . '-' . $data['name'] . '.php';
     }
     $templates[] = $slug . '.php';
     $filename = locate_template($templates, false, false);
     if (!$filename) {
         WPStarterTheme\Base\Theme::_doing_it_wrong(__METHOD__, sprintf(__('The template %s does not exist.', 'wp-starter-theme'), $filename));
         return;
     }
     ob_start();
     $require_once = true;
     switch ($slug) {
         case 'header':
             do_action('get_header', $data['name']);
             break;
         case 'footer':
             do_action('get_footer', $data['name']);
             break;
         case 'sidebar':
             do_action('get_sidebar', $data['name']);
             break;
         default:
             do_action('get_template_part_' . $slug, $slug, $data['name']);
             $require_once = false;
     }
     self::_load_template($filename, $data, $require_once);
     $output = ob_get_clean();
     if ($cache) {
         wp_cache_set($cache, $output, 'templateparts', self::CACHE_DURATION);
     }
     $output = self::_add_output_html_comments($output, $slug);
     if ($return) {
         return $output;
     }
     echo $output;
 }
function get_topic($id, $cache = true)
{
    global $bbdb;
    if (!is_numeric($id)) {
        list($slug, $sql) = bb_get_sql_from_slug('topic', $id);
        $id = wp_cache_get($slug, 'bb_topic_slug');
    }
    // not else
    if (is_numeric($id)) {
        $id = (int) $id;
        $sql = "topic_id = {$id}";
    }
    if (0 === $id || !$sql) {
        return false;
    }
    // &= not =&
    $cache &= 'AND topic_status = 0' == ($where = apply_filters('get_topic_where', 'AND topic_status = 0'));
    if (($cache || !$where) && is_numeric($id) && false !== ($topic = wp_cache_get($id, 'bb_topic'))) {
        return $topic;
    }
    // $where is NOT bbdb:prepared
    $topic = $bbdb->get_row("SELECT * FROM {$bbdb->topics} WHERE {$sql} {$where}");
    $topic = bb_append_meta($topic, 'topic');
    if ($cache) {
        wp_cache_set($topic->topic_id, $topic, 'bb_topic');
        wp_cache_add($topic->topic_slug, $topic->topic_id, 'bb_topic_slug');
    }
    return $topic;
}
 /**
  * Get a product.
  *
  * @param mixed $product_id (default: false)
  * @param array $deprecated
  * @return WC_Product|bool Product object or null if the product cannot be loaded.
  */
 public function get_product($product_id = false, $deprecated = array())
 {
     $product_id = $this->get_product_id($product_id);
     if (!$product_id) {
         return false;
     }
     $product_type = $this->get_product_type($product_id);
     $classname = $this->get_classname_from_product_type($product_type);
     // backwards compat filter
     $post_type = 'variation' === $product_type ? 'product_variation' : 'product';
     $classname = apply_filters('woocommerce_product_class', $classname, $product_type, $post_type, $product_id);
     if (!$classname) {
         return false;
     }
     if (!class_exists($classname)) {
         $classname = 'WC_Product_Simple';
     }
     try {
         // Try to get from cache, otherwise create a new object,
         $product = wp_cache_get('product-' . $product_id, 'products');
         if (!is_a($product, 'WC_Product')) {
             $product = new $classname($product_id);
             wp_cache_set('product-' . $product_id, $product, 'products');
         }
         return $product;
     } catch (Exception $e) {
         return false;
     }
 }
 function filter_woocommerce_ajax_params($woocommerce_params)
 {
     global $sitepress, $post;
     $value = array();
     $value = $woocommerce_params;
     if ($sitepress->get_current_language() !== $sitepress->get_default_language()) {
         $value['ajax_url'] = add_query_arg('lang', ICL_LANGUAGE_CODE, $woocommerce_params['ajax_url']);
         $value['checkout_url'] = add_query_arg('action', 'woocommerce-checkout', $value['ajax_url']);
     }
     if (!isset($post->ID)) {
         return $value;
     }
     $ch_pages = wp_cache_get('ch_pages', 'wcml_ch_pages');
     if (empty($ch_pages)) {
         $ch_pages = array('checkout_page_id' => get_option('woocommerce_checkout_page_id'), 'pay_page_id' => get_option('woocommerce_pay_page_id'), 'cart_page_id' => get_option('woocommerce_cart_page_id'));
         $ch_pages['translated_checkout_page_id'] = apply_filters('translate_object_id', $ch_pages['checkout_page_id'], 'page', false);
         $ch_pages['translated_pay_page_id'] = apply_filters('translate_object_id', $ch_pages['pay_page_id'], 'page', false);
         $ch_pages['translated_cart_page_id'] = apply_filters('translate_object_id', $ch_pages['cart_page_id'], 'page', false);
     }
     wp_cache_set('ch_pages', $ch_pages, 'wcml_ch_pages');
     if ($ch_pages['translated_cart_page_id'] == $post->ID) {
         $value['is_cart'] = 1;
         $value['cart_url'] = get_permalink($ch_pages['translated_cart_page_id']);
     } else {
         if ($ch_pages['translated_checkout_page_id'] == $post->ID || $ch_pages['checkout_page_id'] == $post->ID) {
             $value['is_checkout'] = 1;
             $_SESSION['wpml_globalcart_language'] = $sitepress->get_current_language();
         } else {
             if ($ch_pages['translated_pay_page_id'] == $post->ID) {
                 $value['is_pay_page'] = 1;
             }
         }
     }
     return $value;
 }
 public function widget($args, $instance)
 {
     $cache = array();
     if (!$this->is_preview()) {
         $cache = wp_cache_get($this->cache_key, 'widget');
     }
     if (!is_array($cache)) {
         $cache = array();
     }
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo balanceTags($cache[$args['widget_id']]);
         return;
     }
     ob_start();
     $default = array('title' => 'Filter By:', 'show_attribute' => '', 'st_search_fields' => '', 'style' => 'dark');
     $instance = wp_parse_args($instance, $default);
     echo st()->load_template('rental/filter', null, array('instance' => $instance));
     if (!$this->is_preview()) {
         $cache[$args['widget_id']] = ob_get_flush();
         wp_cache_set($this->cache_key, $cache, 'widget');
     } else {
         ob_end_flush();
     }
 }
 public function query()
 {
     global $wpdb;
     $read_unread = '';
     if ($this->args['unread'] && $this->args['read']) {
         $read_unread .= "apmeta_type = 'notification' OR apmeta_type = 'unread_notification'";
     } elseif ($this->args['read']) {
         $read_unread .= "apmeta_type = 'notification'";
     } else {
         $read_unread .= "apmeta_type = 'unread_notification'";
     }
     $query = $wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS apmeta_id as id, apmeta_userid as user_id, apmeta_actionid as affected_user_id, apmeta_param as type, apmeta_value as args, apmeta_type as is_unread, apmeta_date as date FROM " . $wpdb->prefix . "ap_meta WHERE (" . $read_unread . ") AND apmeta_actionid = %d ORDER BY CASE apmeta_type WHEN 'unread_notification' THEN 1 ELSE -1 END DESC, apmeta_date DESC LIMIT %d,%d", $this->args['user_id'], $this->offset, $this->per_page);
     $this->cache_key = md5($query);
     $result = wp_cache_get($this->cache_key, 'ap');
     $this->total_count = wp_cache_get($this->cache_key . '_count', 'ap');
     if ($result === false) {
         $result = $wpdb->get_results($query);
         wp_cache_set($this->cache_key, $result, 'ap');
         $this->total_count = $wpdb->get_var(apply_filters('ap_notification_found_rows', "SELECT FOUND_ROWS()", $this));
         wp_cache_set($this->cache_key . '_count', $this->total_count, 'ap');
     }
     $this->notifications = $result;
     $this->total_pages = ceil($this->total_count / $this->per_page);
     $this->count = count($result);
 }
 function widget()
 {
     // Check if obj exists in cache
     $users = wp_cache_get('active_users');
     if ($users == false) {
         // Generate the query
         $users = get_users(array('role' => 'student'));
         // Cache the results
         wp_cache_set('active_users', $users, '', 300);
     }
     //$users = get_users( array( 'role' => 'student' ) );
     $users_for_counts = array();
     foreach ($users as $user) {
         $users_for_counts[] = $user->ID;
     }
     // Check if obj exists in cache
     $counts = wp_cache_get('user_count');
     if ($counts == false) {
         // Generate the obj
         $counts = count_many_users_posts($users_for_counts);
         // Cache the results
         wp_cache_set('user_count', $counts, '', 300);
     }
     arsort($counts);
     $counts = array_slice($counts, 0, 5, true);
     echo 'There are currently <strong>' . intval(count($users)) . '</strong> students with HS Insider accounts.';
     echo '<p><strong>Most-active students:</strong></p><ul>';
     foreach ($counts as $user_id => $count) {
         echo '<li><a href="' . esc_url(get_author_posts_url($user_id)) . '" target=_blank>' . esc_html(get_the_author_meta('display_name', $user_id)) . '</a>: (<strong>' . intval($count) . '</strong>)</li>';
     }
     echo '</ul>';
 }