/** * Pings http://api.genesistheme.com/ asking if a new version of this theme is * available. * * If not, it returns false. * * If so, the external server passes serialized data back to this function, * which gets unserialized and returned for use. * * @since 1.1.0 * * @uses genesis_get_option() * @uses PARENT_THEME_VERSION Genesis version string * * @global string $wp_version WordPress version string * @return mixed Unserialized data, or false on failure */ function genesis_update_check() { global $wp_version; /** If updates are disabled */ if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) { return false; } /** Get time of last update check */ $genesis_update = get_transient('genesis-update'); /** If it has expired, do an update check */ if (!$genesis_update) { $url = 'http://api.genesistheme.com/update-themes/'; $options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'wp_version' => $wp_version, 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};"))); $response = wp_remote_post($url, $options); $genesis_update = wp_remote_retrieve_body($response); /** If an error occurred, return FALSE, store for 1 hour */ if ('error' == $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) { set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60); return false; } /** Else, unserialize */ $genesis_update = maybe_unserialize($genesis_update); /** And store in transient for 24 hours */ set_transient('genesis-update', $genesis_update, 60 * 60 * 24); } /** If we're already using the latest version, return false */ if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) { return false; } return $genesis_update; }
/** * Prevent caching on dynamic pages. * * @access public * @return void */ public function init() { if (false === ($wc_page_uris = get_transient('woocommerce_cache_excluded_uris'))) { if (woocommerce_get_page_id('cart') < 1 || woocommerce_get_page_id('checkout') < 1 || woocommerce_get_page_id('myaccount') < 1) { return; } $wc_page_uris = array(); $cart_page = get_post(woocommerce_get_page_id('cart')); $checkout_page = get_post(woocommerce_get_page_id('checkout')); $account_page = get_post(woocommerce_get_page_id('myaccount')); $wc_page_uris[] = '/' . $cart_page->post_name; $wc_page_uris[] = '/' . $checkout_page->post_name; $wc_page_uris[] = '/' . $account_page->post_name; $wc_page_uris[] = 'p=' . $cart_page->ID; $wc_page_uris[] = 'p=' . $checkout_page->ID; $wc_page_uris[] = 'p=' . $account_page->ID; set_transient('woocommerce_cache_excluded_uris', $wc_page_uris); } if (is_array($wc_page_uris)) { foreach ($wc_page_uris as $uri) { if (strstr($_SERVER['REQUEST_URI'], $uri)) { $this->nocache(); break; } } } }
function get_photos($id, $count = 8) { if (empty($id)) { return false; } $transient_key = md5('favethemes_flickr_cache_' . $id . $count); $cached = get_transient($transient_key); if (!empty($cached)) { return $cached; } $output = array(); $rss = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $id . '&lang=en-us&format=rss_200'; $rss = fetch_feed($rss); if (is_wp_error($rss)) { //check for group feed $rss = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $id . '&lang=en-us&format=rss_200'; $rss = fetch_feed($rss); } if (!is_wp_error($rss)) { $maxitems = $rss->get_item_quantity($count); $rss_items = $rss->get_items(0, $maxitems); foreach ($rss_items as $item) { $temp = array(); $temp['img_url'] = esc_url($item->get_permalink()); $temp['title'] = esc_html($item->get_title()); $content = $item->get_content(); preg_match_all("/<IMG.+?SRC=[\"']([^\"']+)/si", $content, $sub, PREG_SET_ORDER); $photo_url = str_replace("_m.jpg", "_t.jpg", $sub[0][1]); $temp['img_src'] = esc_url($photo_url); $output[] = $temp; } set_transient($transient_key, $output, 60 * 60 * 24); } return $output; }
public static function check_update($plugin_path, $plugin_slug, $plugin_url, $offering, $key, $version, $option) { $version_info = function_exists('get_site_transient') ? get_site_transient("gforms_userregistration_version") : get_transient("gforms_userregistration_version"); //making the remote request for version information if (!$version_info) { //Getting version number $version_info = self::get_version_info($offering, $key, $version); self::set_version_info($version_info); } if ($version_info == -1) { return $option; } if (empty($option->response[$plugin_path])) { $option->response[$plugin_path] = new stdClass(); } //Empty response means that the key is invalid. Do not queue for upgrade if (!$version_info["is_valid_key"] || version_compare($version, $version_info["version"], '>=')) { unset($option->response[$plugin_path]); } else { $option->response[$plugin_path]->url = $plugin_url; $option->response[$plugin_path]->slug = $plugin_slug; $option->response[$plugin_path]->package = str_replace("{KEY}", $key, $version_info["url"]); $option->response[$plugin_path]->new_version = $version_info["version"]; $option->response[$plugin_path]->id = "0"; } return $option; }
function moxie_press_endpoint_data() { global $wp_query; // get query vars $json = $wp_query->get('json'); $name = $wp_query->get('name'); // use this template redirect only if json is requested if ($json != 'true') { return; } // build the query $movie_data = array(); // default args $args = array('post_type' => 'movie', 'posts_per_page' => 100); if ($name != '') { $args['name'] = $name; } // add name if provided in query // check if this particular request is cached, if not, perform the query if (false === ($moxie_cached_request = get_transient('moxie_cached_request_' . json_encode($args)))) { $moxie_cached_request = new WP_Query($args); set_transient('moxie_cached_request_' . json_encode($args), $moxie_cached_request); } // prepare the object we want to send as response if ($moxie_cached_request->have_posts()) { while ($moxie_cached_request->have_posts()) { $moxie_cached_request->the_post(); $id = get_the_ID(); $movie_data[] = array('id' => $id, 'title' => get_the_title(), 'poster_url' => get_post_meta($id, 'moxie_press_poster_url', true), 'rating' => get_post_meta($id, 'moxie_press_rating', true), 'year' => get_post_meta($id, 'moxie_press_year', true), 'short_description' => get_post_meta($id, 'moxie_press_description', true), 'mdbid' => get_post_meta($id, 'moxie_press_mdbid', true)); } wp_reset_postdata(); } // send json data using built-in WP function wp_send_json(array('data' => $movie_data)); }
function cache_in_progress($reportid) { global $tzobj; $r = intval(substr($reportid, 5)); /* *** skip the 'users' and take the rest */ $inprogress = get_transient('amr_users_cache_' . $r); if (!$inprogress) { $this->log_cache_event('Cache record, but no transient yet? ' . $reportid); return false; } $status = ausers_get_option('amr-users-cache-status'); //var_dump($status); if (isset($status[$reportid]['start']) and !isset($status[$reportid]['end'])) { $now = time(); $diff = $now - $status[$reportid]['start']; if ($diff > 60 * 5) { $d = date_create(strftime('%c', $status[$reportid]['start'])); date_timezone_set($d, $tzobj); $text = sprintf(__('Report %s started %s ago', 'amr-users'), $reportid, human_time_diff($status[$reportid]['start'], time())); $text .= ' ' . __('Something may be wrong - delete cache status, try again, check server logs and/or memory limit', 'amr-users'); $this->log_cache_event($text); $fun = '<a href="http://upload.wikimedia.org/wikipedia/commons/1/12/Apollo13-wehaveaproblem_edit_1.ogg" >' . __('Houston, we have a problem', 'amr-users') . '</a>'; $text = $fun . '<br/>' . $text; amr_users_message($text); return false; } else { return true; } } else { return false; } }
function fix_in_wpadmin($config, $force_all_checks = false) { $exs = new SelfTestExceptions(); $fix_on_event = false; if (w3_is_multisite() && w3_get_blog_id() != 0) { if (get_transient('w3tc_config_changes') != ($md5_string = $config->get_md5())) { $fix_on_event = true; set_transient('w3tc_config_changes', $md5_string, 3600); } } // call plugin-related handlers foreach ($this->get_handlers($config) as $h) { try { $h->fix_on_wpadmin_request($config, $force_all_checks); if ($fix_on_event) { $this->fix_on_event($config, 'admin_request'); } } catch (SelfTestExceptions $ex) { $exs->push($ex); } } if (count($exs->exceptions()) > 0) { throw $exs; } }
function purge_transients($older_than = '7 days', $safemode = true) { global $wpdb; $older_than_time = strtotime('-' . $older_than); if ($older_than_time > time() || $older_than_time < 1) { return false; } $transients = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT REPLACE(option_name, '_transient_timeout_', '') AS transient_name \n\t\t\t\t\tFROM {$wpdb->options} \n\t\t\t\t\tWHERE option_name LIKE '\\_transient\\_timeout\\__%%'\n\t\t\t\t\t\tAND option_value < %s\n\t\t\t", $older_than_time)); if ($safemode) { foreach ($transients as $transient) { get_transient($transient); } } else { $options_names = array(); foreach ($transients as $transient) { $options_names[] = '_transient_' . $transient; $options_names[] = '_transient_timeout_' . $transient; } if ($options_names) { $options_names = array_map(array($wpdb, 'escape'), $options_names); $options_names = "'" . implode("','", $options_names) . "'"; $result = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name IN ({$options_names})"); if (!$result) { return false; } } } return $transients; }
/** * Retrive the list of groupings associated with a list id * * @param string $list_id List id for which groupings should be returned * @return array $groups_data Data about the groups */ public function get_groupings($list_id = '') { global $edd_options; if (!empty($edd_options['eddmc_api'])) { $grouping_data = get_transient('edd_mailchimp_groupings_' . $list_id); if (false === $grouping_data) { if (!class_exists('EDD_MailChimp_API')) { require_once EDD_MAILCHIMP_PATH . '/includes/MailChimp.class.php'; } $api = new EDD_MailChimp_API(trim($edd_options['eddmc_api'])); $grouping_data = $api->call('lists/interest-groupings', array('id' => $list_id)); set_transient('edd_mailchimp_groupings_' . $list_id, $grouping_data, 24 * 24 * 24); } $groups_data = array(); if ($grouping_data && !isset($grouping_data->status)) { foreach ($grouping_data as $grouping) { $grouping_id = $grouping->id; $grouping_name = $grouping->name; foreach ($grouping->groups as $groups) { $group_name = $groups->name; $groups_data["{$list_id}|{$grouping_id}|{$group_name}"] = $grouping_name . ' - ' . $group_name; } } } } return $groups_data; }
/** * Get details about a specific video by GUID: * * @param $guid string * @return object */ function videopress_get_video_details($guid) { if (!videopress_is_valid_guid($guid)) { return new WP_Error('bad-guid-format', __('Invalid Video GUID!', 'jetpack')); } $version = '1.1'; $endpoint = sprintf('/videos/%1$s', $guid); $query_url = sprintf('https://public-api.wordpress.com/rest/v%1$s%2$s', $version, $endpoint); // Look for data in our transient. If nothing, let's make a new query. $data_from_cache = get_transient('jetpack_videopress_' . $guid); if (false === $data_from_cache) { $response = wp_remote_get(esc_url_raw($query_url)); $data = json_decode(wp_remote_retrieve_body($response)); // Cache the response for an hour. set_transient('jetpack_videopress_' . $guid, $data, HOUR_IN_SECONDS); } else { $data = $data_from_cache; } /** * Allow functions to modify fetched video details. * * This filter allows third-party code to modify the return data * about a given video. It may involve swapping some data out or * adding new parameters. * * @since 4.0.0 * * @param object $data The data returned by the WPCOM API. See: https://developer.wordpress.com/docs/api/1.1/get/videos/%24guid/ * @param string $guid The GUID of the VideoPress video in question. */ return apply_filters('videopress_get_video_details', $data, $guid); }
/** * The API call */ function wpl_instagram_response($userid = null, $count = 6, $columns = 3) { if (intval($userid) === 0) { return '<p>No user ID specified.</p>'; } $transient_var = 'biw_' . $userid . '_' . $count; if (false === ($items = get_transient($transient_var))) { $response = wp_remote_get('https://api.instagram.com/v1/users/' . $userid . '/media/recent/?client_id=' . BIW_CLIENT_ID . '&count=' . esc_attr($count)); $response_body = json_decode($response['body']); //echo '<pre>'; print_r( $response_body ); echo '</pre>'; if ($response_body->meta->code !== 200) { return '<p>Incorrect user ID specified.</p>'; } $items_as_objects = $response_body->data; $items = array(); foreach ($items_as_objects as $item_object) { $item['link'] = $item_object->link; $item['src'] = $item_object->images->low_resolution->url; $items[] = $item; } set_transient($transient_var, $items, 60 * 60); } $output = '<ul class="photo-tiles large-block-grid-3 medium-block-grid-6 small-block-grid-3">'; foreach ($items as $item) { $link = $item['link']; $image = $item['src']; $output .= '<li class="photo-tile"><a href="' . esc_url($link) . '"><img src="' . esc_url($image) . '" /></a></li>'; } $output .= '</ul>'; return $output; }
/** * Show Theme changes. Code adapted from W3 Total Cache. * * @return void */ function wplms_update_message($args) { $transient_name = 'wplms_upgrade_notice_' . $args['Version']; if (false === ($upgrade_notice = get_transient($transient_name))) { $response = wp_remote_get('https://s3.amazonaws.com/WPLMS/readme.txt'); if (!is_wp_error($response) && !empty($response['body'])) { // Output Upgrade Notice $matches = null; $regexp = '~==\\s*Upgrade Notice\\s*==\\s*=\\s*(.*)\\s*=(.*)(=\\s*' . preg_quote(WC_VERSION) . '\\s*=|$)~Uis'; $upgrade_notice = ''; if (preg_match($regexp, $response['body'], $matches)) { $version = trim($matches[1]); $notices = (array) preg_split('~[\\r\\n]+~', trim($matches[2])); if (version_compare(WC_VERSION, $version, '<')) { $upgrade_notice .= '<div class="wplms_plugin_upgrade_notice">'; foreach ($notices as $index => $line) { $upgrade_notice .= wp_kses_post(preg_replace('~\\[([^\\]]*)\\]\\(([^\\)]*)\\)~', '<a href="${2}">${1}</a>', $line)); } $upgrade_notice .= '</div> '; } } set_transient($transient_name, $upgrade_notice, DAY_IN_SECONDS); } } echo wp_kses_post($upgrade_notice); }
function prepare_items() { //First, lets decide how many records per page to show $per_page = 20; $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); //$this->process_bulk_action(); global $wpdb; global $aio_wp_security; $logged_in_users = AIOWPSecurity_Utility::is_multisite_install() ? get_site_transient('users_online') : get_transient('users_online'); if ($logged_in_users !== FALSE) { foreach ($logged_in_users as $key => $val) { $userdata = get_userdata($val['user_id']); $username = $userdata->user_login; $val['username'] = $username; $logged_in_users[$key] = $val; } } else { $logged_in_users = array(); //If no transient found set to empty array } $data = $logged_in_users; $current_page = $this->get_pagenum(); $total_items = count($data); $data = array_slice($data, ($current_page - 1) * $per_page, $per_page); $this->items = $data; $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); }
/** * Plugin compatibility checker * * Here current theme is checked for compatibility with WP PRODUCT ADDER. * * @version 1.1.2 * @package ecommerce-product-catalog/functions * @author Norbert Dreszer */ function al_product_adder_admin_notices_styles() { if (current_user_can('activate_plugins')) { if (!is_advanced_mode_forced()) { $template = get_option('template'); $integration_type = get_integration_type(); if (!empty($_GET['hide_al_product_adder_support_check'])) { update_option('product_adder_theme_support_check', $template); return; } if (get_option('product_adder_theme_support_check') !== $template && current_user_can('delete_others_products')) { product_adder_theme_check_notice(); } } if (is_ic_catalog_admin_page()) { $product_count = ic_products_count(); if ($product_count > 5) { if (false === get_transient('implecode_hide_plugin_review_info')) { implecode_plugin_review_notice(); set_transient('implecode_hide_plugin_translation_info', 1, WEEK_IN_SECONDS); } else { if (false === get_transient('implecode_hide_plugin_translation_info') && !is_english_catalog_active()) { implecode_plugin_translation_notice(); } } } else { if (false === get_transient('implecode_hide_plugin_review_info')) { set_transient('implecode_hide_plugin_review_info', 1, WEEK_IN_SECONDS); } } } } }
function fetch_feed($username, $slice = 8) { $barcelona_remote_url = esc_url('http://instagram.com/' . trim(strtolower($username))); $barcelona_transient_key = 'barcelona_instagram_feed_' . sanitize_title_with_dashes($username); $slice = absint($slice); if (false === ($barcelona_result_data = get_transient($barcelona_transient_key))) { $barcelona_remote = wp_remote_get($barcelona_remote_url); if (is_wp_error($barcelona_remote) || 200 != wp_remote_retrieve_response_code($barcelona_remote)) { return new WP_Error('not-connected', esc_html__('Unable to communicate with Instagram.', 'barcelona')); } preg_match('#window\\.\\_sharedData\\s\\=\\s(.*?)\\;\\<\\/script\\>#', $barcelona_remote['body'], $barcelona_match); if (!empty($barcelona_match)) { $barcelona_data = json_decode(end($barcelona_match), true); if (is_array($barcelona_data) && isset($barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes'])) { $barcelona_result_data = $barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes']; } } if (is_array($barcelona_result_data)) { set_transient($barcelona_transient_key, $barcelona_result_data, 60 * 60 * 2); } } if (empty($barcelona_result_data)) { return new WP_Error('no-images', esc_html__('Instagram did not return any images.', 'barcelona')); } return array_slice($barcelona_result_data, 0, $slice); }
/** * Give the user options for how to handle their legacy Stream records * * @action admin_notices * @return void */ public static function show_migrate_notice() { if (!isset($_GET['migrate_action']) && WP_Stream::is_connected() && WP_Stream_Admin::is_stream_screen() && !empty(self::$record_count) && false === get_transient(self::MIGRATE_DELAY_TRANSIENT)) { return true; } return false; }
/** * Returns an array of photos on a WP_Error. */ private function get_photos($args = array()) { $transient_key = md5('aquick-flickr-cache-' . print_r($args, true)); $cached = get_transient($transient_key); if ($cached) { return $cached; } $username = isset($args['username']) ? $args['username'] : ''; $tags = isset($args['tags']) ? $args['tags'] : ''; $count = isset($args['count']) ? absint($args['count']) : 10; $query = array('tagmode' => 'any', 'tags' => $tags); // If username is an RSS feed if (preg_match('#^https?://api\\.flickr\\.com/services/feeds/photos_public\\.gne#', $username)) { $url = parse_url($username); $url_query = array(); wp_parse_str($url['query'], $url_query); $query = array_merge($query, $url_query); } else { $user = $this->request('flickr.people.findByUsername', array('username' => $username)); if (is_wp_error($user)) { return $user; } $user_id = $user->user->id; $query['id'] = $user_id; } $photos = $this->request_feed('photos_public', $query); if (!$photos) { return new WP_Error('error', __('Could not fetch photos.', AZ_THEME_NAME)); } $photos = array_slice($photos, 0, $count); set_transient($transient_key, $photos, apply_filters('quick_flickr_widget_cache_timeout', 3600)); return $photos; }
function ngfb_get_sharing_buttons($ids = array(), $atts = array()) { global $ngfb; if ($ngfb->is_avail['ssb']) { if ($ngfb->is_avail['cache']['transient']) { $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_url:' . $ngfb->util->get_sharing_url() . '_ids:' . implode('_', $ids) . '_atts:' . implode('_', $atts) . ')'; $cache_id = $ngfb->cf['lca'] . '_' . md5($cache_salt); $cache_type = 'object cache'; $ngfb->debug->log($cache_type . ': transient salt ' . $cache_salt); $html = get_transient($cache_id); if ($html !== false) { $ngfb->debug->log($cache_type . ': html retrieved from transient ' . $cache_id); return $ngfb->debug->get_html() . $html; } } $html = '<!-- ' . $ngfb->cf['lca'] . ' sharing buttons begin -->' . $ngfb->sharing->get_js('sharing-buttons-header', $ids) . $ngfb->sharing->get_html($ids, $atts) . $ngfb->sharing->get_js('sharing-buttons-footer', $ids) . '<!-- ' . $ngfb->cf['lca'] . ' sharing buttons end -->'; if ($ngfb->is_avail['cache']['transient']) { set_transient($cache_id, $html, $ngfb->cache->object_expire); $ngfb->debug->log($cache_type . ': html saved to transient ' . $cache_id . ' (' . $ngfb->cache->object_expire . ' seconds)'); } } else { $html = '<!-- ' . $ngfb->cf['lca'] . ' sharing sharing buttons disabled -->'; } return $ngfb->debug->get_html() . $html; }
/** * Send request to the WPRC server only with retries * * @param string method * @param mixed arguments to send */ public function sendWPRCRequestWithRetries($method, $args, $timeout = 5) { $url = WPRC_SERVER_URL; $send_result = false; $failed = 0; $timer = get_transient('wprc_report_failed_timer'); if ($timer != false && $timer != '' && $timer != null) { $timer = intval($timer); } else { $timer = 0; } $timenow = time(); if ($timer - $timenow > 0) { return false; } // discard report while ($send_result === false && $failed < 2) { $send_result = $this->sendRequest($method, $url, $args, $timeout); if ($send_result === false) { $failed++; if ($failed < 2) { usleep(rand(100, 300)); } // wait 1 to 3 seconds } } if ($send_result === false) { set_transient('wprc_report_failed_timer', time() + 5 * 60 * 60); } else { // reset flags set_transient('wprc_report_failed_timer', 0); } return $send_result; }
function pre_http_request($content, $r, $url) { $key = $this->getKey($url, $r); $this->r(sprintf('request transient key: %s<br />request url: %s,<br />request args: %s', $key, $url, print_r($r, true)), false, 'Request Details'); // If caching isn't set, return. if (!$this->getCacheTime($r)) { $this->r('Not cached because the `cache` parameter is not set or cacheTime() method says no cache'); return false; } $response = maybe_unserialize(get_transient($key)); $this->flushCache($url, $r); if (strtoupper($r['method'] !== 'GET') || current_user_can('manage_options') && isset($_REQUEST['cache']) || !$response || is_wp_error($response) || $response && $response['response']['code'] !== 200) { if (strtoupper($r['method'] !== 'GET')) { // If something's been PUT or POSTed to the same endpoint, let's reset the cache for that. $this->r('not cached due to method not GET'); } elseif (current_user_can('manage_options') && isset($_REQUEST['cache'])) { $this->r('not cached due to overrides'); } elseif (!$response || is_wp_error($response)) { $this->r('not cached due to no response (or error response)'); $this->r($response, false, '$response:'); } else { $this->r(sprintf('not cached due to response code being %s', $response['response']['code'])); } return false; } if ($this->debug) { $this->r($response, false, 'Response (Cached)'); } return $response; }
static function init() { self::$messages = get_transient(self::getTransientKey()); if (!array(self::$messages)) { self::$messages = array(); } }
/** * Get GitHub readme or file. * * @param array $atts * * @return string */ public function _eg_shortcode_readme($atts) { $atts = shortcode_atts(array('repo' => 'johnie/embedgithub', 'file' => false, 'trim' => 0), $atts); $transient = 'embedgithub_' . $atts['repo'] . '_' . $atts['file'] . '_' . $atts['trim']; if (false === ($html = get_transient($transient))) { if ($atts['file']) { $url = 'https://api.github.com/repos/' . $atts['repo'] . '/contents/' . $atts['file']; } else { $url = 'https://api.github.com/repos/' . $atts['repo'] . '/readme'; } $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'WordPress'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); $json = json_decode($data); $markdown = base64_decode($json->content); if ($atts['trim'] > 0) { $markdown = implode("\n", array_slice(explode("\n", $markdown), $atts['trim'])); } $html = Markdown::defaultTransform($markdown); set_transient($transient, $html, 12 * HOUR_IN_SECONDS); } return $html; }
/** * Creates blank index.php and .htaccess files * * This function runs approximately once per month in order to ensure all folders * have their necessary protection files * * @since 1.1.5 * * @param bool $force * @param bool $method */ function edd_create_protection_files($force = false, $method = false) { if (false === get_transient('edd_check_protection_files') || $force) { $upload_path = edd_get_upload_dir(); // Make sure the /edd folder is created wp_mkdir_p($upload_path); // Top level .htaccess file $rules = edd_get_htaccess_rules($method); if (edd_htaccess_exists()) { $contents = @file_get_contents($upload_path . '/.htaccess'); if ($contents !== $rules || !$contents) { // Update the .htaccess rules if they don't match @file_put_contents($upload_path . '/.htaccess', $rules); } } elseif (wp_is_writable($upload_path)) { // Create the file if it doesn't exist @file_put_contents($upload_path . '/.htaccess', $rules); } // Top level blank index.php if (!file_exists($upload_path . '/index.php') && wp_is_writable($upload_path)) { @file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.'); } // Now place index.php files in all sub folders $folders = edd_scan_folders($upload_path); foreach ($folders as $folder) { // Create index.php, if it doesn't exist if (!file_exists($folder . 'index.php') && wp_is_writable($folder)) { @file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// Silence is golden.'); } } // Check for the files once per day set_transient('edd_check_protection_files', true, 3600 * 24); } }
/** * Query twitter's API * * @uses $this->get_bearer_token() to retrieve token if not working * * @param string $query Insert the query in the format "count=1&include_entities=true&include_rts=true&screen_name=micc1983! * @param array $query_args Array of arguments: Resource type (string) and cache duration (int) * @param bool $stop Stop the query to avoid infinite loop * * @return bool|object Return an object containing the result */ public function query($query, $query_args = array(), $stop = false) { if ($this->has_error) { return false; } if (is_array($query_args) && !empty($query_args)) { $this->query_args = array_merge($this->query_args, $query_args); } $transient_name = 'wta_' . md5($query); if (false !== ($data = get_transient($transient_name))) { return json_decode($data); } $args = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array('Authorization' => 'Bearer ' . $this->bearer_token, 'Accept-Encoding' => 'gzip'), 'body' => null, 'cookies' => array()); $response = wp_remote_get('https://api.twitter.com/1.1/' . $this->query_args['type'] . '.json?' . $query, $args); if (is_wp_error($response) || 200 != $response['response']['code']) { if (!$stop) { $this->bearer_token = $this->get_bearer_token(); return $this->query($query, $this->query_args, true); } else { return $this->bail(__('Bearer Token is good, check your query', 'wp_twitter_api'), $response); } } set_transient($transient_name, $response['body'], $this->query_args['cache']); return json_decode($response['body']); }
/** * This function calibrefx_update_check is to ... */ function calibrefx_update_check() { global $wp_version; /** Get time of last update check */ $calibrefx_update = get_transient('calibrefx-update'); /** If it has expired, do an update check */ if (!$calibrefx_update) { $url = 'http://api.calibrefx.com/themes-update/'; $options = apply_filters('calibrefx_update_remote_post_options', array('body' => array('theme_name' => 'calibrefx', 'theme_version' => FRAMEWORK_VERSION, 'url' => home_url(), 'wp_version' => $wp_version, 'php_version' => phpversion(), 'user-agent' => "WordPress/{$wp_version};"))); $response = wp_remote_post($url, $options); $calibrefx_update = wp_remote_retrieve_body($response); /** If an error occurred, return FALSE, store for 48 hour */ if ('error' == $calibrefx_update || is_wp_error($calibrefx_update) || !is_serialized($calibrefx_update)) { set_transient('calibrefx-update', array('new_version' => FRAMEWORK_VERSION), 60 * 60 * 48); return false; } /** Else, unserialize */ $calibrefx_update = maybe_unserialize($calibrefx_update); /** And store in transient for 48 hours */ set_transient('calibrefx-update', $calibrefx_update, 60 * 60 * 48); } /** If we're already using the latest version, return false */ if (version_compare(FRAMEWORK_VERSION, $calibrefx_update['new_version'], '>=')) { return false; } return $calibrefx_update; }
/** * Remove propertyhive notes from wp_count_comments(). * @since 1.0.0 * @param object $stats * @param int $post_id * @return object */ public static function wp_count_comments($stats, $post_id) { global $wpdb; if (0 === $post_id) { $stats = get_transient('ph_count_comments'); if (!$stats) { $stats = array(); $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type != 'propertyhive_note' GROUP BY comment_approved", ARRAY_A); $total = 0; $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); foreach ((array) $count as $row) { // Don't count post-trashed toward totals if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) { $total += $row['num_comments']; } if (isset($approved[$row['comment_approved']])) { $stats[$approved[$row['comment_approved']]] = $row['num_comments']; } } $stats['total_comments'] = $total; $stats['all'] = $total; foreach ($approved as $key) { if (empty($stats[$key])) { $stats[$key] = 0; } } $stats = (object) $stats; set_transient('ph_count_comments', $stats); } } return $stats; }
function mm_ux_log($args = array()) { $url = "https://ssl.google-analytics.com/collect"; global $title; if (empty($_SERVER['REQUEST_URI'])) { return; } $path = explode('wp-admin', $_SERVER['REQUEST_URI']); if (empty($path) || empty($path[1])) { $path = array("", " "); } $defaults = array('v' => '1', 'tid' => 'UA-39246514-3', 't' => 'pageview', 'cid' => md5(get_option('siteurl')), 'uid' => md5(get_option('siteurl') . get_current_user_id()), 'cn' => 'mojo_wp_plugin', 'cs' => 'mojo_wp_plugin', 'cm' => 'plugin_admin', 'ul' => get_locale(), 'dp' => $path[1], 'sc' => '', 'ua' => @$_SERVER['HTTP_USER_AGENT'], 'dl' => $path[1], 'dh' => get_option('siteurl'), 'dt' => $title, 'ec' => '', 'ea' => '', 'el' => '', 'ev' => ''); if (isset($_SERVER['REMOTE_ADDR'])) { $defaults['uip'] = $_SERVER['REMOTE_ADDR']; } $params = wp_parse_args($args, $defaults); $test = get_transient('mm_test', ''); if (isset($test['key']) && isset($test['name'])) { $params['cm'] = $params['cm'] . "_" . $test['name'] . "_" . $test['key']; } //use test account for testing if (defined('WP_DEBUG') && WP_DEBUG) { $params['tid'] = 'UA-19617272-27'; } $z = wp_rand(0, 1000000000); $query = http_build_query(array_filter($params)); $args = array('body' => $query, 'method' => 'POST', 'blocking' => false); $url = add_query_arg(array('z' => $z), $url); wp_remote_post($url, $args); }
function launch() { $theme_options = _WSH()->option(); $theme_options_url = admin_url('themes.php?page=' . SH_NAME . '_option'); $this->purchase_code = sh_set($theme_options, 'sh_purchase_code'); $this->purchase_user = sh_set($theme_options, 'sh_purchase_user'); if (function_exists('wp_get_theme')) { $this->theme_data = wp_get_theme(get_option('template')); $this->theme_version = $this->theme_data->Version; } else { $this->theme_data = get_theme_data(get_template_directory() . '/style.css'); $this->theme_version = $this->theme_data['Version']; } $this->theme_base = get_option('template'); if (!$this->purchase_code && !$this->purchase_user) { $this->errors[] = sprintf(__('<strong>%s Theme Notice:</strong> Please enter a valid <a href="%s">purchase code and themeforest username</a> to get automatic theme update', SH_NAME), $this->theme_data['Name'], $theme_options_url); } add_action('admin_notices', array($this, '_admin_notice')); if ($this->errors) { return; } /**************************************************/ //Uncomment below to find the theme slug that will need to be setup on the api server //var_dump($theme_base); add_filter('pre_set_site_transient_update_themes', array($this, 'check_for_update')); // Take over the Theme info screen on WP multisite add_filter('themes_api', array($this, 'my_theme_api_call'), 10, 3); if (is_admin()) { $this->current = get_transient('update_themes'); } }
/** * Widget * * @return void * @since 1.0 */ function widget($args, $instance) { if (false == ($cache = get_transient('edd_widgets_archives'))) { // get the title and apply filters $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : ''); // get show count boolean $show_count = isset($instance['show_count']) && $instance['show_count'] === 1 ? 1 : 0; // start collecting the output $out = ""; // check if there is a title if ($title) { // add the title to the ouput $out .= $args['before_title'] . $title . $args['after_title']; } $out .= "<ul>\n"; // add download post type to archives add_filter('getarchives_where', array(&$this, 'getarchives_where_filter'), 10, 2); add_filter('month_link', array($this, 'month_link'), 10, 3); // output the archives $out .= wp_get_archives(array('echo' => 0, 'show_post_count' => $show_count)); // remove filter remove_filter('getarchives_where', array(&$this, 'getarchives_where_filter'), 10, 2); remove_filter('month_link', array($this, 'month_link'), 10, 3); // finish the list $out .= "</ul>\n"; // set the widget's containers $cache = $args['before_widget'] . $out . $args['after_widget']; // store the result on a temporal transient set_transient('edd_widgets_archives', $cache); } echo $cache; }
/** * s2Member's PayPal IPN handler (inner processing routine). * * @package s2Member\PayPal * @since 110720 * * @param array $vars Required. An array of defined variables passed by {@link s2Member\PayPal\c_ws_plugin__s2member_paypal_notify_in::paypal_notify()}. * @return array|bool The original ``$paypal`` array passed in (extracted) from ``$vars``, or false when conditions do NOT apply. */ public static function cp($vars = array()) { extract($vars, EXTR_OVERWRITE | EXTR_REFS); // Extract all vars passed in from: ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. if (!empty($paypal["txn_type"]) && preg_match("/^virtual_terminal\$/i", $paypal["txn_type"])) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_paypal_notify_before_virtual_terminal", get_defined_vars()); unset($__refs, $__v); if (!get_transient($transient_ipn = "s2m_ipn_" . md5("s2member_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) { $paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `virtual_terminal` )."; $processing = $during = true; // Yes, we ARE processing this. $paypal["s2member_log"][] = "The `txn_type` does not require any action on the part of s2Member."; foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_paypal_notify_during_virtual_terminal", get_defined_vars()); unset($__refs, $__v); } else { $paypal["s2member_log"][] = "Not processing. Duplicate IPN."; $paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `virtual_terminal` )."; $paypal["s2member_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored."; } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_paypal_notify_after_virtual_terminal", get_defined_vars()); unset($__refs, $__v); return apply_filters("c_ws_plugin__s2member_paypal_notify_in_virtual_terminal", $paypal, get_defined_vars()); } else { return apply_filters("c_ws_plugin__s2member_paypal_notify_in_virtual_terminal", false, get_defined_vars()); } }