Example #1
4
/**
 * 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;
             }
         }
     }
 }
/**
 * Database changes required for Smart Coupons
 *
 * Add option 'smart_coupon_email_subject' if not exists
 * Enable 'Auto Generation' for Store Credit (discount_type: 'smart_coupon') not having any customer_email
 * Disable 'apply_before_tax' for all Store Credit (discount_type: 'smart_coupon')
 */
function smart_coupon_activate()
{
    global $wpdb, $blog_id;
    if (is_multisite()) {
        $blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}", 0);
    } else {
        $blog_ids = array($blog_id);
    }
    if (!get_option('smart_coupon_email_subject')) {
        add_option('smart_coupon_email_subject');
    }
    foreach ($blog_ids as $blog_id) {
        if (file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php') && is_plugin_active('woocommerce/woocommerce.php')) {
            $wpdb_obj = clone $wpdb;
            $wpdb->blogid = $blog_id;
            $wpdb->set_prefix($wpdb->base_prefix);
            $query = "SELECT postmeta.post_id FROM {$wpdb->prefix}postmeta as postmeta WHERE postmeta.meta_key = 'discount_type' AND postmeta.meta_value = 'smart_coupon' AND postmeta.post_id IN\n\t\t\t\t\t(SELECT p.post_id FROM {$wpdb->prefix}postmeta AS p WHERE p.meta_key = 'customer_email' AND p.meta_value = 'a:0:{}') ";
            $results = $wpdb->get_col($query);
            foreach ($results as $result) {
                update_post_meta($result, 'auto_generate_coupon', 'yes');
            }
            // To disable apply_before_tax option for Gift Certificates / Store Credit.
            $post_id_tax_query = "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = 'discount_type' AND meta_value = 'smart_coupon'";
            $tax_post_ids = $wpdb->get_col($post_id_tax_query);
            foreach ($tax_post_ids as $tax_post_id) {
                update_post_meta($tax_post_id, 'apply_before_tax', 'no');
            }
            $wpdb = clone $wpdb_obj;
        }
    }
    if (!is_network_admin() && !isset($_GET['activate-multi'])) {
        set_transient('_smart_coupons_activation_redirect', 1, 30);
    }
}
Example #4
0
function mm_ab_test_inclusion_none()
{
    if (is_admin() && false === get_transient('mm_test', false)) {
        $duration = WEEK_IN_SECONDS * 4;
        set_transient('mm_test', array('key' => 'none'), $duration);
    }
}
/**
 * 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);
    }
}
Example #6
0
/**
 * Install
 *
 * Runs on plugin install to populates the settings fields for those plugin
 * pages. After successful install, the user is redirected to the MASHSB Welcome
 * screen.
 *
 * @since 2.0
 * @global $wpdb
 * @global $mashsb_options
 * @global $wp_version
 * @return void
 */
function mashsb_install()
{
    global $wpdb, $mashsb_options, $wp_version;
    // Add Upgraded From Option
    $current_version = get_option('mashsb_version');
    if ($current_version) {
        update_option('mashsb_version_upgraded_from', $current_version);
    }
    // Update the current version
    update_option('mashsb_version', MASHSB_VERSION);
    // Add plugin installation date and variable for rating div
    add_option('mashsb_installDate', date('Y-m-d h:i:s'));
    add_option('mashsb_RatingDiv', 'no');
    if (!get_option('mashsb_update_notice')) {
        add_option('mashsb_update_notice', 'no');
    }
    /* Setup some default options
     * Store our initial social networks in separate option row.
     * For easier modification and to prevent some trouble
     */
    $networks = array('Facebook', 'Twitter', 'Subscribe');
    if (is_plugin_inactive('mashshare-networks/mashshare-networks.php')) {
        update_option('mashsb_networks', $networks);
    }
    // Bail if activating from network, or bulk
    if (is_network_admin() || isset($_GET['activate-multi'])) {
        return;
    }
    // Add the transient to redirect / not for multisites
    set_transient('_mashsb_activation_redirect', true, 30);
}
 /**
  * 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 bbconnect_create_search_post()
{
    // RUN A SECURITY CHECK
    if (!wp_verify_nonce($_POST['bbconnect_report_nonce'], 'bbconnect-report-nonce')) {
        die('terribly sorry.');
    }
    global $current_user;
    if (!empty($_POST)) {
        $post = array('post_content' => serialize($_POST['data']['search']), 'post_title' => $_POST['data']['postTitle'], 'post_status' => 'publish', 'post_type' => 'savedsearch', 'post_author' => $current_user->ID);
        $wp_error = wp_insert_post($post, $wp_error);
        if (!is_array($wp_error)) {
            add_post_meta($wp_error, 'private', $_POST['data']['privateV']);
            add_post_meta($wp_error, 'segment', $_POST['data']['segment']);
            add_post_meta($wp_error, 'category', $_POST['data']['category']);
            if (false === $recently_saved) {
                $recently_saved = array();
            }
            set_transient('bbconnect_' . $current_user->ID . '_last_saved', $wp_error, 3600);
            echo '<div class="updated update-nag"  style="width:95%; border-left: 4px solid #7ad03a;"><p>Search has been saved as <a href="/post.php?post=' . $wp_error . '&action=edit">savedsearch-' . $wp_error . '</a></p></div>' . "\n";
        } else {
            echo '<div class="updated"><p>Search has not been saved' . var_dump($wp_error) . '</a></p></div>' . "\n";
        }
    }
    die;
}
Example #9
0
/**
 * 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;
}
Example #10
0
 /**
  * @see wm_add_notice
  */
 public static function add_notice($message, $type = 'info', $title = null, $backtrace = false)
 {
     $message = rtrim(ucfirst(trim((string) $message)), '.') . '.';
     $content = wpautop($title ? "<strong class=\"wm-notice-title\">{$title}</strong><br />{$message}" : $message);
     if (false !== $backtrace) {
         if (is_array($backtrace)) {
             $content .= self::get_backtrace($backtrace);
         } else {
             if ($stack = array_slice(debug_backtrace(), 2)) {
                 if (true === $backtrace) {
                     $content .= "<ol start=\"0\" class=\"wm-notice-backtrace\">";
                     foreach ($stack as $i => $backtrace) {
                         $content .= "<li>" . self::get_backtrace($backtrace) . "</li>";
                     }
                     $content .= "</ol>";
                 } else {
                     if (isset($stack[$backtrace])) {
                         $content .= self::get_backtrace($stack[$backtrace]);
                     }
                 }
             }
         }
     }
     self::$notices[] = "<div class=\"wm-notice notice {$type}\">{$content}</div>";
     // Cache alerts until they're shown
     set_transient('wm_notices', self::$notices);
 }
Example #11
0
function affiliate_wp_install()
{
    // Create affiliate caps
    $roles = new Affiliate_WP_Capabilities();
    $roles->add_caps();
    $affiliate_wp_install = new stdClass();
    $affiliate_wp_install->affiliates = new Affiliate_WP_DB_Affiliates();
    $affiliate_wp_install->affiliate_meta = new Affiliate_WP_Affiliate_Meta_DB();
    $affiliate_wp_install->referrals = new Affiliate_WP_Referrals_DB();
    $affiliate_wp_install->visits = new Affiliate_WP_Visits_DB();
    $affiliate_wp_install->creatives = new Affiliate_WP_Creatives_DB();
    $affiliate_wp_install->settings = new Affiliate_WP_Settings();
    $affiliate_wp_install->affiliates->create_table();
    $affiliate_wp_install->affiliate_meta->create_table();
    $affiliate_wp_install->referrals->create_table();
    $affiliate_wp_install->visits->create_table();
    $affiliate_wp_install->creatives->create_table();
    if (!get_option('affwp_is_installed')) {
        $affiliate_area = wp_insert_post(array('post_title' => __('Affiliate Area', 'affiliate-wp'), 'post_content' => '[affiliate_area]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        $options = $affiliate_wp_install->settings->get_all();
        $options['affiliates_page'] = $affiliate_area;
        update_option('affwp_settings', $options);
    }
    update_option('affwp_is_installed', '1');
    update_option('affwp_version', AFFILIATEWP_VERSION);
    // Clear rewrite rules
    flush_rewrite_rules();
    // Bail if activating from network, or bulk
    if (is_network_admin() || isset($_GET['activate-multi'])) {
        return;
    }
    // Add the transient to redirect
    set_transient('_affwp_activation_redirect', true, 30);
}
 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);
 }
function x_demo_content_set_stage_completed($stage)
{
    $transient = get_transient('x_demo_content_stage');
    $stages = is_array($transient) ? $transient : array();
    $stages[$stage] = true;
    set_transient('x_demo_content_stage', $stages);
}
 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;
 }
 /**
  * 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());
     }
 }
Example #16
0
/**
 * 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);
}
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #19
0
 public function __construct()
 {
     $this->init_settings();
     if (isset($this->settings['storage_type'])) {
         $this->storage_type = $this->settings['storage_type'];
     }
     $this->storage = new WOOF_STORAGE($this->storage_type);
     //+++
     if (!defined('DOING_AJAX')) {
         global $wp_query;
         if (isset($wp_query->query_vars['taxonomy']) and in_array($wp_query->query_vars['taxonomy'], get_object_taxonomies('product'))) {
             //unset($_SESSION['woof_really_current_term']);
             $this->set_really_current_term();
         }
     }
     //+++
     global $wpdb;
     $attribute_taxonomies = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies");
     set_transient('wc_attribute_taxonomies', $attribute_taxonomies);
     if (!empty($attribute_taxonomies) and is_array($attribute_taxonomies)) {
         foreach ($attribute_taxonomies as $att) {
             //fixing for woo >= 2.3.2
             add_filter("woocommerce_taxonomy_args_pa_{$att->attribute_name}", array($this, 'change_woo_att_data'));
         }
     }
     //add_filter("woocommerce_taxonomy_args_pa_color", array($this, 'change_woo_att_data'));
     //add_action('init', array($this, 'price_filter_init'));
     add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
     add_action('widgets_init', array($this, 'widgets_init'));
 }
Example #20
0
 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;
 }
 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;
     }
 }
Example #22
0
 /**
  * Get github readme
  *
  * @param array $atts
  * @param string $content
  * @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;
 }
Example #23
0
/**
 * 1.3.0
 */
function yit_update_1_3_0()
{
    /* ====== Update CPTU ====== */
    global $wpdb;
    $temp = array();
    $prefixes = array('sliders' => 'sl_', 'portfolios' => 'po_', 'feature-tabs' => 'ft_', 'teams' => 'team_');
    foreach ($prefixes as $post_type => $prefix) {
        $args = array('post_type' => $post_type, 'posts_per_page' => -1, 'post_status' => 'publish');
        $post_types = get_posts($args);
        foreach ($post_types as $the) {
            $from = substr($prefix . $the->post_name, 0, 20);
            $to = yit_avoid_duplicate(str_replace('-', '_', substr($prefix . $the->post_name, 0, 16)), $temp);
            $temp[] = $to;
            $to_parent = substr($to, 3);
            /* Update Child Post Type*/
            $wpdb->update($wpdb->posts, array('post_type' => $to), array('post_type' => $from));
            /* Update Parent Post Name */
            $wpdb->update($wpdb->posts, array('post_name' => $to_parent), array('post_name' => $the->post_name));
            /* Update Slider Name in Post Meta */
            if ('sliders' == $post_type) {
                $where = array('meta_key' => '_slider_name', 'meta_value' => $the->post_name);
                $wpdb->update($wpdb->postmeta, array('meta_value' => $to_parent), $where);
            }
        }
    }
    set_transient('cptu_1_3_0_update', true);
}
Example #24
0
 public function post_restore()
 {
     if (isset($_POST['job_id']) && isset($_POST['backup_uniqid']) && isset($_POST['_wpnonce']) && isset($_POST['method'])) {
         $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING);
         if (!wp_verify_nonce($nonce, 'my-wp-backup-restore-backup')) {
             wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup'));
         }
         $id = absint($_POST['job_id']);
         $uniqid = sanitize_key($_POST['backup_uniqid']);
         $method = filter_input(INPUT_POST, 'method', FILTER_SANITIZE_STRING);
         $backup = self::get($id, $uniqid);
         if (!isset($backup['duration'])) {
             add_settings_error('', '', __('Invalid backup id/uniqid.', 'my-wp-backup'));
             set_transient('settings_errors', get_settings_errors());
             wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1)));
         }
         if (!$backup->has_archives()) {
             // No local copy and no remote copy === DEAD END.
             if (empty($backup['destinations'])) {
                 add_settings_error('', '', __('Backup files missing.', 'my-wp-backup'));
                 set_transient('settings_errors', get_settings_errors());
                 wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1)));
             }
             if (!isset($backup['destinations'][$method])) {
                 add_settings_error('', '', sprintf(__('No backup files from %s.', 'my-wp-backup'), Job::$destinations[$method]));
                 set_transient('settings_errors', get_settings_errors());
                 wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1)));
             }
         }
         wp_schedule_single_event(time(), 'wp_backup_restore_backup', array(array($id, $uniqid, $method)));
         wp_safe_redirect($this->admin->get_page_url('backup', array('uniqid' => $uniqid, 'action' => 'viewprogress', 'id' => $id)));
     }
 }
Example #25
0
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));
}
 /**
  * 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']);
 }
Example #27
0
/**
 * 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;
}
 function redirect_to_settings()
 {
     //First preserve all errors that have been generated
     set_transient('settings_errors', get_settings_errors(), 30);
     //Call settings url
     wp_redirect($this->get_redirect_url() . '&settings-updated=true');
 }
 /**
  * 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;
 }
 public function section_main_settings()
 {
     $successMessage = '';
     $versionInfo = false;
     $orderNumberFailed = '';
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         if ($_POST['cart66-action'] == 'saveOrderNumber' && CART66_PRO) {
             $orderNumber = trim(Cart66Common::postVal('order_number'));
             Cart66Setting::setValue('order_number', $orderNumber);
             $versionInfo = get_transient('_cart66_version_request');
             if (!$versionInfo) {
                 $versionInfo = Cart66ProCommon::getVersionInfo();
                 set_transient('_cart66_version_request', $versionInfo, 43200);
             }
             if ($versionInfo) {
                 $successMessage = __("Thank you! Cart66 has been activated", "cart66");
             } else {
                 Cart66Setting::setValue('order_number', '');
                 $orderNumberFailed = true;
             }
         }
     }
     $data = array('success_message' => $successMessage, 'version_info' => $versionInfo, 'order_number_failed' => $orderNumberFailed);
     echo Cart66Common::getView('admin/settings/main.php', $data, false);
 }