Example #1
0
/**
 * starting in 3.8.14 visitors information belongs in the vistor table, not the users table, start
 * the migration.  This migration could take a very long time so it's done as a cron
 *
 * @access private
 * @since 3.8.14
 *
 */
function _wpsc_meta_migrate_anonymous_users()
{
    global $wpdb;
    // get the users table auto increment value, and set the visitor meta auto increment to match.
    // we do this so that new customer cookies don't collide with existing customer cookies after
    // the migration.  Note we can't use max of user id because users may have been deleted.
    $sql = 'SHOW TABLE STATUS WHERE NAME = "' . $wpdb->users . '"';
    $status = $wpdb->get_results($sql);
    $wpdb->query('ALTER TABLE ' . $wpdb->wpsc_visitors . ' AUTO_INCREMENT = ' . $status[0]->Auto_increment);
    wp_suspend_cache_addition(true);
    $role = get_role('wpsc_anonymous');
    if ($role) {
        remove_role('wpsc_anonymous', __('Anonymous', 'wp-e-commerce'));
    }
    wp_schedule_single_event(time() + 5, 'wpsc_migrate_anonymous_user_cron');
}
 /**
  * Dispatch the actions
  */
 public function dispatch()
 {
     set_time_limit(7200);
     // Timeout = 2 hours
     // Suspend the cache during the migration to avoid exhausted memory problem
     wp_suspend_cache_addition(true);
     wp_suspend_cache_invalidation(true);
     // Default values
     $this->plugin_options = array('automatic_empty' => 0, 'url' => null, 'hostname' => 'localhost', 'port' => 3306, 'database' => null, 'username' => 'root', 'password' => '', 'prefix' => 'jos_', 'introtext' => 'in_content', 'archived_posts' => 'not_imported', 'skip_media' => 0, 'first_image' => 'as_is_and_featured', 'import_external' => 0, 'import_duplicates' => 0, 'force_media_import' => 0, 'meta_keywords_in_tags' => 0, 'import_as_pages' => 0, 'timeout' => 5);
     $options = get_option('fgj2wp_options');
     if (is_array($options)) {
         $this->plugin_options = array_merge($this->plugin_options, $options);
     }
     // Check if the upload directory is writable
     $upload_dir = wp_upload_dir();
     if (!is_writable($upload_dir['basedir'])) {
         $this->display_admin_error(__('The wp-content directory must be writable.', 'fgj2wp'));
     }
     if (isset($_POST['empty'])) {
         // Delete content
         if (check_admin_referer('empty', 'fgj2wp_nonce')) {
             // Security check
             if ($this->empty_database($_POST['empty_action'])) {
                 // Empty WP database
                 $this->display_admin_notice(__('WordPress content removed', 'fgj2wp'));
             } else {
                 $this->display_admin_error(__('Couldn\'t remove content', 'fgj2wp'));
             }
             wp_cache_flush();
         }
     } elseif (isset($_POST['save'])) {
         // Save database options
         $this->save_plugin_options();
         $this->display_admin_notice(__('Settings saved', 'fgj2wp'));
     } elseif (isset($_POST['test'])) {
         // Save database options
         $this->save_plugin_options();
         // Test the database connection
         if (check_admin_referer('parameters_form', 'fgj2wp_nonce')) {
             // Security check
             $this->test_database_connection();
         }
     } elseif (isset($_POST['import'])) {
         // Save database options
         $this->save_plugin_options();
         // Automatic empty
         if ($this->plugin_options['automatic_empty']) {
             if ($this->empty_database('all')) {
                 $this->display_admin_notice(__('WordPress content removed', 'fgj2wp'));
             } else {
                 $this->display_admin_error(__('Couldn\'t remove content', 'fgj2wp'));
             }
             wp_cache_flush();
         }
         // Import content
         if (check_admin_referer('parameters_form', 'fgj2wp_nonce')) {
             // Security check
             $this->import();
         }
     } elseif (isset($_POST['remove_cat_prefix'])) {
         // Remove the prefixes from the categories
         if (check_admin_referer('remove_cat_prefix', 'fgj2wp_nonce')) {
             // Security check
             $result = $this->remove_category_prefix();
             $this->display_admin_notice(__('Prefixes removed from categories', 'fgj2wp'));
         }
     } elseif (isset($_POST['modify_links'])) {
         // Modify internal links
         if (check_admin_referer('modify_links', 'fgj2wp_nonce')) {
             // Security check
             $result = $this->modify_links();
             $this->display_admin_notice(sprintf(_n('%d internal link modified', '%d internal links modified', $result['links_count'], 'fgj2wp'), $result['links_count']));
         }
     }
     $this->display_admin_page();
     // Display the admin page
 }
function relevanssi_populate_array($matches)
{
    global $relevanssi_post_array, $relevanssi_post_types, $wpdb;
    if (function_exists('wp_suspend_cache_addition')) {
        wp_suspend_cache_addition(true);
    }
    $ids = array();
    foreach ($matches as $match) {
        array_push($ids, $match->doc);
    }
    $ids = implode(',', $ids);
    $posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE id IN ({$ids})");
    foreach ($posts as $post) {
        $relevanssi_post_array[$post->ID] = $post;
        $relevanssi_post_types[$post->ID] = $post->post_type;
    }
    if (function_exists('wp_suspend_cache_addition')) {
        wp_suspend_cache_addition(false);
    }
}
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since  1.0
  * @global object $give_logs Give Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     $give_logs = new Give_Logging();
     // Prevent the queries from getting cached.
     // Without this there are occasional memory issues for some installs.
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $log_query = array('log_type' => 'gateway_error', 'paged' => $paged);
     $logs = $give_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $logs_data[] = array('ID' => $log->ID, 'ID_label' => '<span class=\'give-item-label give-item-label-gray\'>' . $log->ID . '</span>', 'payment_id' => $log->post_parent, 'error' => 'error', 'gateway' => give_get_payment_gateway($log->post_parent), 'date' => $log->post_date);
         }
     }
     return $logs_data;
 }
Example #5
0
 /**
  * @ticket 34138
  */
 public function test_comment_objects_should_be_fetched_from_database_when_suspend_cache_addition()
 {
     $suspend = wp_suspend_cache_addition();
     wp_suspend_cache_addition(true);
     $c = self::factory()->comment->create(array('comment_post_ID' => self::$post_id));
     $q = new WP_Comment_Query(array('post_id' => self::$post_id));
     wp_suspend_cache_addition($suspend);
     $found = wp_list_pluck($q->comments, 'comment_ID');
     $this->assertEqualSets(array($c), $found);
 }
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since 1.4
  * @global object $edd_logs EDD Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     global $edd_logs;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $log_query = array('log_type' => 'gateway_error', 'paged' => $paged);
     $logs = $edd_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $logs_data[] = array('ID' => $log->ID, 'payment_id' => $log->post_parent, 'error' => 'error', 'gateway' => edd_get_payment_gateway($log->post_parent), 'date' => $log->post_date);
         }
     }
     return $logs_data;
 }
 /**
  * Prevents W3TC from adding to the cache after modifying data
  *
  * @access public
  * @return void
  */
 function w3tc_suspend_cache_addition_post()
 {
     wp_suspend_cache_addition();
 }
Example #8
0
function relevanssi_build_index($extend = false)
{
    if (function_exists('wp_suspend_cache_addition')) {
        wp_suspend_cache_addition(true);
    }
    // Thanks to Julien Mession
    global $wpdb, $relevanssi_variables;
    $relevanssi_table = $relevanssi_variables['relevanssi_table'];
    if (!ini_get('safe_mode')) {
        set_time_limit(0);
    }
    $post_types = array();
    $types = get_option("relevanssi_index_post_types");
    if (!is_array($types)) {
        $types = array();
    }
    foreach ($types as $type) {
        array_push($post_types, "'{$type}'");
    }
    if (count($post_types) > 0) {
        $restriction = " AND post.post_type IN (" . implode(', ', $post_types) . ') ';
    } else {
        $restriction = "";
    }
    $valid_status_array = apply_filters('relevanssi_valid_status', array('publish', 'draft', 'private', 'pending', 'future'));
    if (is_array($valid_status_array) && count($valid_status_array) > 0) {
        $valid_status = array();
        foreach ($valid_status_array as $status) {
            $valid_status[] = "'{$status}'";
        }
        $valid_status = implode(',', $valid_status);
    } else {
        // this really should never happen
        $valid_status = "'publish', 'draft', 'private', 'pending', 'future'";
    }
    $n = 0;
    $size = 0;
    if (!$extend) {
        // truncate table first
        $wpdb->query("TRUNCATE TABLE {$relevanssi_table}");
        if (function_exists('relevanssi_index_taxonomies')) {
            if (get_option('relevanssi_index_taxonomies') == 'on') {
                relevanssi_index_taxonomies();
            }
        }
        if (function_exists('relevanssi_index_users')) {
            if (get_option('relevanssi_index_users') == 'on') {
                relevanssi_index_users();
            }
        }
        $q = "SELECT post.ID\n\t\tFROM {$wpdb->posts} post\n\t\tLEFT JOIN {$wpdb->posts} parent ON (post.post_parent=parent.ID)\n\t\tWHERE\n\t\t\t(post.post_status IN ({$valid_status})\n\t\t\tOR\n\t\t\t(post.post_status='inherit'\n\t\t\t\tAND(\n\t\t\t\t\t(parent.ID is not null AND (parent.post_status IN ({$valid_status})))\n\t\t\t\t\tOR (post.post_parent=0)\n\t\t\t\t)\n\t\t\t))\n\t\t{$restriction}";
        update_option('relevanssi_index', '');
    } else {
        // extending, so no truncate and skip the posts already in the index
        $limit = get_option('relevanssi_index_limit', 200);
        if (is_numeric($limit) && $limit > 0) {
            $size = $limit;
            $limit = " LIMIT {$limit}";
        } else {
            $limit = "";
        }
        $q = "SELECT post.ID\n\t\tFROM {$wpdb->posts} post\n\t\tLEFT JOIN {$wpdb->posts} parent ON (post.post_parent=parent.ID)\n\t\tLEFT JOIN {$relevanssi_table} r ON (post.ID=r.doc)\n\t\tWHERE\n\t\tr.doc is null\n\t\tAND\n\t\t\t(post.post_status IN ({$valid_status})\n\t\t\tOR\n\t\t\t(post.post_status='inherit'\n\t\t\t\tAND(\n\t\t\t\t\t(parent.ID is not null AND (parent.post_status IN ({$valid_status})))\n\t\t\t\t\tOR (post.post_parent=0)\n\t\t\t\t)\n\t\t\t)\n\t\t)\n\t\t{$restriction} {$limit}";
    }
    $custom_fields = relevanssi_get_custom_fields();
    do_action('relevanssi_pre_indexing_query');
    $content = $wpdb->get_results($q);
    foreach ($content as $post) {
        $n += relevanssi_index_doc($post->ID, false, $custom_fields, true);
        // n calculates the number of insert queries
        // $bypassglobalpost set to true, because at this point global $post should be NULL, but in some cases it is not
    }
    $wpdb->query("ANALYZE TABLE {$relevanssi_table}");
    // To prevent empty indices
    echo '<div id="message" class="updated fade"><p>' . __($size == 0 || count($content) < $size ? "Indexing complete!" : "More to index...", "relevanssi") . '</p></div>';
    update_option('relevanssi_indexed', 'done');
    // We always want to run this on init, if the index is finishd building.
    $D = $wpdb->get_var("SELECT COUNT(DISTINCT(relevanssi.doc)) FROM {$relevanssi_table} AS relevanssi");
    update_option('relevanssi_doc_count', $D);
    if (function_exists('wp_suspend_cache_addition')) {
        wp_suspend_cache_addition(false);
    }
    // Thanks to Julien Mession
}
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since 1.4
  * @global object $edd_logs EDD Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     global $edd_logs;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $download = empty($_GET['s']) ? $this->get_filtered_download() : null;
     $log_query = array('post_parent' => $download, 'log_type' => 'sale', 'paged' => $paged, 'meta_query' => $this->get_meta_query());
     $logs = $edd_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $payment_id = get_post_meta($log->ID, '_edd_log_payment_id', true);
             // Make sure this payment hasn't been deleted
             if (get_post($payment_id)) {
                 $user_info = edd_get_payment_meta_user_info($payment_id);
                 $cart_items = edd_get_payment_meta_cart_details($payment_id);
                 $amount = 0;
                 if (is_array($cart_items) && is_array($user_info)) {
                     foreach ($cart_items as $item) {
                         if ($item['id'] == $log->post_parent) {
                             $amount = isset($item['item_price']) ? $item['item_price'] : $item['price'];
                             break;
                         }
                     }
                     $logs_data[] = array('ID' => $log->ID, 'payment_id' => $payment_id, 'download' => $log->post_parent, 'amount' => $amount, 'user_id' => $user_info['id'], 'user_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'date' => get_post_field('post_date', $payment_id));
                 }
             }
         }
     }
     return $logs_data;
 }
Example #10
0
 function wpestate_listing_pins_with_reservation($args = '', $jump = 0, $book_from, $book_to)
 {
     wp_suspend_cache_addition(true);
     set_time_limit(0);
     $counter = 0;
     $unit = get_option('wp_estate_measure_sys', '');
     $currency = get_option('wp_estate_currency_symbol', '');
     $where_currency = get_option('wp_estate_where_currency_symbol', '');
     $cache = get_option('wp_estate_cache', '');
     $place_markers = array();
     $markers = array();
     if ($cache == 'yes') {
         if (!get_transient('prop_list_cached')) {
             if ($args == '') {
                 $args = array('post_type' => 'estate_property', 'post_status' => 'publish', 'nopaging' => 'true', 'cache_results' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false);
             }
             $prop_selection = new WP_Query($args);
             set_transient('prop_list_cached', $prop_selection, 60 * 60 * 3);
             //store data for 3h
         } else {
             $prop_selection = get_transient('prop_list_cached');
             // retrive cached data
         }
         wp_reset_query();
     } else {
         if ($args == '') {
             $args = array('post_type' => 'estate_property', 'post_status' => 'publish', 'nopaging' => 'true', 'cache_results' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false);
         }
         $prop_selection = new WP_Query($args);
         wp_reset_query();
     }
     //end cache
     $custom_advanced_search = get_option('wp_estate_custom_advanced_search', '');
     $show_slider_price = get_option('wp_estate_show_slider_price', '');
     $has_slider = 0;
     while ($prop_selection->have_posts()) {
         $prop_selection->the_post();
         $counter++;
         if (wpestate_check_booking_valability($book_from, $book_to, get_the_ID())) {
             $markers[] = wpestate_pin_unit_creation(get_the_ID(), $currency, $where_currency, $counter);
         }
         //    print_r($place_markers)  ;
     }
     wp_reset_query();
     wp_suspend_cache_addition(false);
     if (get_option('wp_estate_readsys', '') == 'yes' && $jump == 0) {
         $path = get_template_directory() . '/pins.txt';
         wpestate_otto_write_tofile($path, json_encode($markers));
     } else {
         return json_encode($markers);
     }
 }
 public function display_callback($args, $widget_args = array())
 {
     $widget_args = wp_parse_args($widget_args, array('widget' => null, 'instance' => null));
     $widget = $widget_args['widget'];
     $widget->id = $args['widget_id'];
     /**
      * Filter the settings for a particular widget instance.
      *
      * Returning false will effectively short-circuit display of the widget.
      *
      * @since 2.8.0
      *
      * @param array     $instance The current widget instance's settings.
      * @param WP_Widget $this     The current widget instance.
      * @param array     $args     An array of default widget arguments.
      */
     $instance = apply_filters('widget_display_callback', $widget_args['instance'], $widget, $args);
     if (false === $instance) {
         return;
     }
     $was_cache_addition_suspended = wp_suspend_cache_addition();
     if ($widget->is_preview() && !$was_cache_addition_suspended) {
         wp_suspend_cache_addition(true);
     }
     $widget->widget($args, $instance);
     if ($widget->is_preview()) {
         wp_suspend_cache_addition($was_cache_addition_suspended);
     }
 }
 /**
  * Util: Execute the widget as would normally happen had we not
  * short-circuited the default process.
  *
  * @see WP_Widget::display_callback()
  *
  * @param $instance
  * @param $widget
  * @param $args
  */
 function override_widget_display($instance, $widget, $args)
 {
     $was_cache_addition_suspended = wp_suspend_cache_addition();
     if ($widget->is_preview() && !$was_cache_addition_suspended) {
         wp_suspend_cache_addition(true);
     }
     $widget->widget($args, $instance);
     if ($widget->is_preview()) {
         wp_suspend_cache_addition($was_cache_addition_suspended);
     }
 }
Example #13
0
 function leyka_update_campaigns_total_funded()
 {
     set_time_limit(3600);
     wp_suspend_cache_addition(true);
     $campaigns = get_posts(array('post_type' => Leyka_Campaign_Management::$post_type, 'nopaging' => true, 'post_status' => 'any'));
     foreach ($campaigns as $campaign) {
         $campaign = new Leyka_Campaign($campaign);
         $campaign->update_total_funded_amount();
     }
     wp_suspend_cache_addition(false);
 }
 /**
  * Set a number of optimsiations to make sure the plugin is usable on lower end setups.
  *
  * We stop plugins trying to cache, or compress the output since that causes everything to be
  * held in memory and causes memory issues. We also tell WP not to add loaded objects to the
  * cache since on setups without a persistent object store that would result in everything being
  * in memory again.
  */
 private function set_optimisations()
 {
     global $wpdb;
     // Don't cache feed under WP Super-Cache
     define('DONOTCACHEPAGE', true);
     // Cater for large stores
     $wpdb->hide_errors();
     @set_time_limit(0);
     while (ob_get_level()) {
         @ob_end_clean();
     }
     // Suspend cache addition to stop WP trying to hold everything in memory.
     // Note: wp_suspend_cache_addition is buggy prior to WP 3.4.
     if (version_compare(get_bloginfo('version'), '3.4', '>=')) {
         wp_suspend_cache_addition(true);
     }
 }
 /**
  * Add new history note to user(s)
  * @param string $title Note title
  * @param string $contents Note contents
  * @param integer $type Term ID of primary note type
  * @param integer $subtype Term ID of secondary note type
  * @param array $user_ids List of user IDs to add note to
  * @param boolean $action_required Whether the note should be marked as requiring action
  */
 public static function add_note($title, $contents, $type, $subtype, array $user_ids, array $args = array(), $action_required = false)
 {
     // Some performance changes
     //         global $wpdb;
     //         $wpdb->query('SET autocommit = 0;');
     wp_suspend_cache_addition(true);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     $data = array('post_type' => 'bb_note', 'post_title' => $title, 'post_content' => $contents, 'post_status' => 'publish', 'tax_input' => array('bb_note_type' => array($type, $subtype)));
     $data = array_merge_recursive($data, $args);
     unset($title, $contents, $type, $subtype, $args);
     foreach ($user_ids as $user_id) {
         $start = microtime(true);
         $data['post_author'] = $user_id;
         $new_post = wp_insert_post($data);
         if ($action_required) {
             add_post_meta($new_post, '_bbc_action_required', 'true');
         }
         unset($new_post);
     }
     // Set performance settings back to defaults
     //         $wpdb->query('COMMIT;');
     //         $wpdb->query('SET autocommit = 1;');
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     return true;
 }
Example #16
0
 /**
  * Validate data for the widget.
  *
  * @param string $name
  * @return JsonResponse
  */
 public function validate($name)
 {
     $widgetType = $this->getWidgetType($name);
     $old_instance = [];
     $new_instance = $this->request->post->getArray("widget-{$widgetType->id_base}.0");
     // Prevent caching.
     $cache_state = \wp_suspend_cache_addition();
     \wp_suspend_cache_addition(true);
     // Update widget by using its own method.
     $instance = $widgetType->update($new_instance, $old_instance);
     // Restore caching.
     \wp_suspend_cache_addition($cache_state);
     // Apply widget filters.
     // TODO: We might want to add the filters back; for now we just assume that widget works like the_widget().
     //$instance = \apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $widgetType);
     if ($instance === false) {
         throw new \RuntimeException('Filter prevented widget from being saved.', 403);
     }
     // Create configuration from the defaults.
     $data = new Config(['type' => 'widget', 'widget' => $name, 'title' => $this->request->post['title'] ?: $widgetType->name]);
     $data->set('options.widget', $instance);
     $data->def('options.enabled', 1);
     return new JsonResponse(['item' => $data->toArray()]);
 }
 /**
  * Adds data to the cache if it doesn't already exist.
  *
  * @uses WP_Object_Cache::_exists Checks to see if the cache already has data.
  * @uses WP_Object_Cache::set Sets the data after the checking the cache
  *		contents existence.
  *
  * @param int|string $key What to call the contents in the cache
  * @param mixed $data The contents to store in the cache
  * @param string $group Where to group the cache contents
  * @param int $expire When to expire the cache contents
  * @return bool False if cache key and group already exist, true on success
  */
 public function add($key, $data, $group = 'default', $expire = 0)
 {
     if (empty($group)) {
         $group = 'default';
     }
     if (function_exists('wp_suspend_cache_addition') && wp_suspend_cache_addition()) {
         return false;
     }
     if ($this->_exists($key, $group)) {
         return false;
     }
     return $this->set($key, $data, $group, (int) $expire);
 }
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since  1.0
  * @global object $give_logs Give Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     global $give_logs;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $give_form = empty($_GET['s']) ? $this->get_filtered_give_form() : null;
     $user = $this->get_filtered_user();
     $log_query = array('post_parent' => $give_form, 'log_type' => 'sale', 'paged' => $paged, 'meta_query' => $this->get_meta_query());
     $logs = $give_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $payment_id = get_post_meta($log->ID, '_give_log_payment_id', true);
             // Make sure this payment hasn't been deleted
             if (get_post($payment_id)) {
                 $user_info = give_get_payment_meta_user_info($payment_id);
                 $payment_meta = give_get_payment_meta($payment_id);
                 $payment_amount = give_get_payment_amount($payment_id);
                 $logs_data[] = array('ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>', 'payment_id' => $payment_id, 'form' => $log->post_parent, 'amount' => $payment_amount, 'user_id' => $user_info['id'], 'user_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'date' => get_post_field('post_date', $payment_id));
             }
         }
     }
     return $logs_data;
 }
 function _wpsc_meta_migrate_anonymous_user_worker()
 {
     global $wpdb;
     $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
     $key_pattern = "{$blog_prefix}_wpsc_";
     wp_suspend_cache_addition(true);
     $sql = 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_login LIKE "\\_%" AND user_email = "" AND user_login = user_nicename AND user_login = display_name LIMIT 100';
     $user_ids = $wpdb->get_col($sql, 0);
     // Create an array to store users to be removed.
     $bin = array();
     foreach ($user_ids as $user_id) {
         $wpdb->query('INSERT INTO ' . $wpdb->wpsc_visitors . '(`id`) VALUES ( ' . $user_id . ' )');
         wpsc_set_visitor_expiration($user_id, DAY_IN_SECONDS);
         $meta = get_user_meta($user_id);
         foreach ($meta as $key => $value) {
             if (strpos($key, $key_pattern) === FALSE) {
                 continue;
             }
             $short_key = str_replace($key_pattern, '', $key);
             if ($short_key !== 'cart') {
                 wpsc_add_visitor_meta($user_id, $short_key, $value[0]);
             } else {
                 $wpsc_user_cart = maybe_unserialize(base64_decode($value[0]));
                 if (!$wpsc_user_cart instanceof wpsc_cart) {
                     $wpsc_user_cart = new wpsc_cart();
                 } else {
                     continue;
                 }
             }
         }
         $comment_count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments . ' WHERE user_id = ' . $user_id);
         if (!count_user_posts($user_id) && !$comment_count) {
             //wp_delete_user( $user_id );
             // Add user to bin.
             $bin[] = $user_id;
         }
     }
     // Remove users.
     if (!empty($bin)) {
         // Convert $bin to string.
         $bin = implode(',', $bin);
         $wpdb->query('DELETE FROM ' . $wpdb->users . ' WHERE ID IN (' . $bin . ')');
         $wpdb->query('DELETE FROM ' . $wpdb->usermeta . ' WHERE user_id IN (' . $bin . ')');
     }
     wp_suspend_cache_addition(false);
     exit(0);
 }
Example #20
0
function wpsc_generate_product_feed()
{
    global $wpdb, $wp_query, $post;
    set_time_limit(0);
    // Don't build up a huge posts cache for the whole store - http://code.google.com/p/wp-e-commerce/issues/detail?id=885
    // WP 3.3+ only
    if (function_exists('wp_suspend_cache_addition')) {
        wp_suspend_cache_addition(true);
    }
    $chunk_size = apply_filters('wpsc_productfeed_chunk_size', 50);
    // Don't cache feed under WP Super-Cache
    define('DONOTCACHEPAGE', TRUE);
    $selected_category = '';
    $selected_product = '';
    $args = array('post_type' => 'wpsc-product', 'numberposts' => $chunk_size, 'offset' => 0, 'cache_results' => false);
    $args = apply_filters('wpsc_productfeed_query_args', $args);
    $self = site_url("/index.php?rss=true&amp;action=product_list{$selected_category}{$selected_product}");
    header("Content-Type: application/xml; charset=UTF-8");
    header('Content-Disposition: inline; filename="E-Commerce_Product_List.rss"');
    echo "<?xml version='1.0' encoding='UTF-8' ?>\n\r";
    echo "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'";
    $google_checkout_note = false;
    if ($_GET['xmlformat'] == 'google') {
        echo ' xmlns:g="http://base.google.com/ns/1.0"';
        // Is Google Checkout available as a payment gateway
        $selected_gateways = get_option('custom_gateway_options');
        if (in_array('google', $selected_gateways)) {
            $google_checkout_note = true;
        }
    } else {
        echo ' xmlns:product="http://www.buy.com/rss/module/productV2/"';
    }
    echo ">\n\r";
    echo "  <channel>\n\r";
    echo "    <title><![CDATA[" . get_option('blogname') . " Products]]></title>\n\r";
    echo "    <link>" . get_option('siteurl') . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php</link>\n\r";
    echo "    <description>This is the WP e-Commerce Product List RSS feed</description>\n\r";
    echo "    <generator>WP e-Commerce Plugin</generator>\n\r";
    echo "    <atom:link href='{$self}' rel='self' type='application/rss+xml' />\n\r";
    $products = get_posts($args);
    while (count($products)) {
        foreach ($products as $post) {
            setup_postdata($post);
            $purchase_link = wpsc_product_url($post->ID);
            echo "    <item>\n\r";
            if ($google_checkout_note) {
                echo "      <g:payment_notes>Google Checkout</g:payment_notes>\n\r";
            }
            echo "      <title><![CDATA[" . get_the_title() . "]]></title>\n\r";
            echo "      <link>{$purchase_link}</link>\n\r";
            echo "      <description><![CDATA[" . apply_filters('the_content', get_the_content()) . "]]></description>\n\r";
            echo "      <pubDate>" . $post->post_modified_gmt . "</pubDate>\n\r";
            echo "      <guid>{$purchase_link}</guid>\n\r";
            $image_link = wpsc_the_product_thumbnail();
            if ($image_link !== FALSE) {
                if ($_GET['xmlformat'] == 'google') {
                    echo "      <g:image_link>{$image_link}</g:image_link>\n\r";
                } else {
                    echo "      <enclosure url='{$image_link}' />\n\r";
                }
            }
            $price = wpsc_calculate_price($post->ID);
            $currargs = array('display_currency_symbol' => false, 'display_decimal_point' => true, 'display_currency_code' => false, 'display_as_html' => false);
            $price = wpsc_currency_display($price, $currargs);
            $children = get_children(array('post_parent' => $post->ID, 'post_type' => 'wpsc-product'));
            foreach ($children as $child) {
                $child_price = wpsc_calculate_price($child->ID);
                if ($price == 0 && $child_price > 0) {
                    $price = $child_price;
                } else {
                    if ($child_price > 0 && $child_price < $price) {
                        $price = $child_price;
                    }
                }
            }
            if ($_GET['xmlformat'] == 'google') {
                echo "      <g:price>" . $price . "</g:price>\n\r";
                $google_elements = array();
                $product_meta = get_post_custom($post->ID);
                if (is_array($product_meta)) {
                    foreach ($product_meta as $meta_key => $meta_value) {
                        if (stripos($meta_key, 'g:') === 0) {
                            $google_elements[$meta_key] = $meta_value;
                        }
                    }
                }
                $google_elements = apply_filters('wpsc_google_elements', array('product_id' => $post->ID, 'elements' => $google_elements));
                $google_elements = $google_elements['elements'];
                $done_condition = FALSE;
                $done_availability = FALSE;
                $done_weight = FALSE;
                if (count($google_elements)) {
                    foreach ($google_elements as $element_name => $element_values) {
                        foreach ($element_values as $element_value) {
                            echo "      <" . $element_name . ">";
                            echo "<![CDATA[" . $element_value . "]]>";
                            echo "</" . $element_name . ">\n\r";
                        }
                        if ($element_name == 'g:shipping_weight') {
                            $done_weight = TRUE;
                        }
                        if ($element_name == 'g:condition') {
                            $done_condition = TRUE;
                        }
                        if ($element_name == 'g:availability') {
                            $done_availability = true;
                        }
                    }
                }
                if (!$done_condition) {
                    echo "      <g:condition>new</g:condition>\n\r";
                }
                if (!$done_availability) {
                    if (wpsc_product_has_stock()) {
                        $product_availability = "in stock";
                    } else {
                        $product_availability = "out of stock";
                    }
                    echo " <g:availability>{$product_availability}</g:availability>";
                }
                if (!$done_weight) {
                    $wpsc_product_meta = get_product_meta($post->ID, 'product_metadata', true);
                    $weight = apply_filters('wpsc_google_shipping_weight', $wpsc_product_meta['weight'], $post->ID);
                    if ($weight && is_numeric($weight) && $weight > 0) {
                        echo "<g:shipping_weight>{$weight} pounds</g:shipping_weight>";
                    }
                }
            } else {
                echo "      <product:price>" . $price . "</product:price>\n\r";
            }
            echo "    </item>\n\r";
        }
        $args['offset'] += $chunk_size;
        $products = get_posts($args);
    }
    echo "  </channel>\n\r";
    echo "</rss>";
    exit;
}
 public function get_items_to_send($buffer, $encode = true)
 {
     // track how long we've been processing so we can avoid request timeouts
     $start_time = microtime(true);
     $upload_size = 0;
     $items_to_send = array();
     $items = $buffer->get_items();
     // set up current screen to avoid errors rendering content
     require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php';
     require_once ABSPATH . 'wp-admin/includes/screen.php';
     set_current_screen('sync');
     $skipped_items_ids = array();
     // we estimate the total encoded size as we go by encoding each item individually
     // this is expensive, but the only way to really know :/
     foreach ($items as $key => $item) {
         // Suspending cache addition help prevent overloading in memory cache of large sites.
         wp_suspend_cache_addition(true);
         /**
          * Modify the data within an action before it is serialized and sent to the server
          * For example, during full sync this expands Post ID's into full Post objects,
          * so that we don't have to serialize the whole object into the queue.
          *
          * @since 4.2.0
          *
          * @param array The action parameters
          * @param int The ID of the user who triggered the action
          */
         $item[1] = apply_filters('jetpack_sync_before_send_' . $item[0], $item[1], $item[2]);
         wp_suspend_cache_addition(false);
         if ($item[1] === false) {
             $skipped_items_ids[] = $key;
             continue;
         }
         $encoded_item = $encode ? $this->codec->encode($item) : $item;
         $upload_size += strlen($encoded_item);
         if ($upload_size > $this->upload_max_bytes && count($items_to_send) > 0) {
             break;
         }
         $items_to_send[$key] = $encoded_item;
         if (microtime(true) - $start_time > $this->max_dequeue_time) {
             break;
         }
     }
     return array($items_to_send, $skipped_items_ids, $items);
 }
Example #22
0
 /**
  * Validate data for the widget.
  *
  * @param string $name
  * @return JsonResponse
  */
 public function validate($name)
 {
     $widgetType = $this->getWidgetType($name);
     $old_instance = [];
     $new_instance = $this->request->post->getArray("widget-{$widgetType->id_base}.0");
     // Prevent caching.
     $cache_state = \wp_suspend_cache_addition();
     \wp_suspend_cache_addition(true);
     // Update widget by using its own method.
     $instance = $widgetType->update($new_instance, $old_instance);
     // Restore caching.
     \wp_suspend_cache_addition($cache_state);
     // Apply widget filters.
     // TODO: We might want to add the filters back; for now we just assume that widget works like the_widget().
     //$instance = \apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $widgetType);
     if ($instance === false) {
         throw new \RuntimeException('Filter prevented widget from being saved.', 403);
     }
     $block = $this->request->post->getArray('block');
     foreach ($block as $key => $param) {
         if ($param === '') {
             unset($block[$key]);
         }
     }
     // Create configuration from the defaults.
     $data = new Config(['type' => 'widget', 'widget' => $name, 'title' => $this->request->post['title'] ?: $widgetType->name, 'options' => ['widget' => $instance]]);
     if ($block) {
         $menuitem = ['type' => 'particle', 'particle' => 'widget', 'title' => $data['title'], 'options' => ['particle' => ['enabled' => 1, 'widget' => $data->toArray()], 'block' => $block]];
         // Fill parameters to be passed to the template file.
         $this->params['item'] = $menuitem;
         $html = $this->container['admin.theme']->render('@gantry-admin/menu/item.html.twig', $this->params);
         return new JsonResponse(['item' => $menuitem, 'html' => $html]);
     }
     return new JsonResponse(['item' => $data->toArray()]);
 }
Example #23
0
 /**
  * Adds data to the cache if it doesn't already exist.
  *
  * @uses WP_Object_Cache::_exists Checks to see if the cache already has data.
  * @uses WP_Object_Cache::set Sets the data after the checking the cache
  *		contents existence.
  *
  * @since 2.0.0
  *
  * @param int|string $key What to call the contents in the cache
  * @param mixed $data The contents to store in the cache
  * @param string $group Where to group the cache contents
  * @param int $expire When to expire the cache contents
  * @return bool False if cache key and group already exist, true on success
  */
 function add($key, $data, $group = 'default', $expire = '')
 {
     if (wp_suspend_cache_addition()) {
         return false;
     }
     if (empty($group)) {
         $group = 'default';
     }
     if ($this->_exists($key, $group)) {
         return false;
     }
     return $this->set($key, $data, $group, $expire);
 }
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since 1.2.6
  * @global object $edd_logs EDD Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 function get_logs()
 {
     global $edd_logs;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $log_query = array('log_type' => 'recommendation_sale', 'paged' => $paged, 'meta_query' => $this->get_meta_query(), 'posts_per_page' => $this->per_page, 'orderby' => 'ID');
     if (!empty($_GET['source']) && is_numeric($_GET['source'])) {
         $log_query['post_parent'] = absint($_GET['source']);
     }
     $logs = $edd_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $logs_data[] = array('id' => $log->ID, 'payment' => get_post_meta($log->ID, '_edd_log_payment_id', true), 'date' => $log->post_date, 'source' => $log->post_parent, 'download' => get_post_meta($log->ID, '_edd_log_download_id', true), 'amount' => get_post_meta($log->ID, '_edd_log_price', true));
         }
     }
     return $logs_data;
 }
Example #25
0
 /**
  * Deal with changed settings (Do NOT override).
  *
  * @since 2.8.0
  * @access public
  *
  * @param int $deprecated Not used.
  */
 public function update_callback($deprecated = 1)
 {
     global $wp_registered_widgets;
     $all_instances = $this->get_settings();
     // We need to update the data
     if ($this->updated) {
         return;
     }
     if (isset($_POST['delete_widget']) && $_POST['delete_widget']) {
         // Delete the settings for this instance of the widget
         if (isset($_POST['the-widget-id'])) {
             $del_id = $_POST['the-widget-id'];
         } else {
             return;
         }
         if (isset($wp_registered_widgets[$del_id]['params'][0]['number'])) {
             $number = $wp_registered_widgets[$del_id]['params'][0]['number'];
             if ($this->id_base . '-' . $number == $del_id) {
                 unset($all_instances[$number]);
             }
         }
     } else {
         if (isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base])) {
             $settings = $_POST['widget-' . $this->id_base];
         } elseif (isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base) {
             $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
             $settings = array($num => array());
         } else {
             return;
         }
         foreach ($settings as $number => $new_instance) {
             $new_instance = stripslashes_deep($new_instance);
             $this->_set($number);
             $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
             $was_cache_addition_suspended = wp_suspend_cache_addition();
             if ($this->is_preview() && !$was_cache_addition_suspended) {
                 wp_suspend_cache_addition(true);
             }
             $instance = $this->update($new_instance, $old_instance);
             if ($this->is_preview()) {
                 wp_suspend_cache_addition($was_cache_addition_suspended);
             }
             /**
              * Filter a widget's settings before saving.
              *
              * Returning false will effectively short-circuit the widget's ability
              * to update settings.
              *
              * @since 2.8.0
              *
              * @param array     $instance     The current widget instance's settings.
              * @param array     $new_instance Array of new widget settings.
              * @param array     $old_instance Array of old widget settings.
              * @param WP_Widget $this         The current widget instance.
              */
             $instance = apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $this);
             if (false !== $instance) {
                 $all_instances[$number] = $instance;
             }
             break;
             // run only once
         }
     }
     $this->save_settings($all_instances);
     $this->updated = true;
 }
Example #26
0
 function on_save_changes_settingssets()
 {
     //user permission check
     if (!current_user_can('manage_options')) {
         wp_die(__('Not allowed', 'link-library'));
     }
     //cross check the given referer
     check_admin_referer('link-library');
     $messages = array();
     $row = 0;
     $successfulimport = 0;
     $successfulupdate = 0;
     if (isset($_POST['importlinks'])) {
         wp_suspend_cache_addition(true);
         set_time_limit(600);
         global $wpdb;
         $handle = fopen($_FILES['linksfile']['tmp_name'], "r");
         if ($handle) {
             $skiprow = 1;
             while (($data = fgetcsv($handle, 5000, ",")) !== false) {
                 $row += 1;
                 if ($skiprow == 1 && isset($_POST['firstrowheaders']) && $row >= 2) {
                     $skiprow = 0;
                 } elseif (!isset($_POST['firstrowheaders'])) {
                     $skiprow = 0;
                 }
                 if (!$skiprow) {
                     if (count($data) == 16) {
                         if (!empty($data[5])) {
                             $existingcatquery = "SELECT t.term_id FROM " . $this->db_prefix() . "terms t, " . $this->db_prefix() . "term_taxonomy tt ";
                             $existingcatquery .= "WHERE t.name = '%s' AND t.term_id = tt.term_id AND tt.taxonomy = 'link_category'";
                             $existingcatqueryprepped = $wpdb->prepare($existingcatquery, esc_html($data[5]));
                             $existingcat = $wpdb->get_var($existingcatqueryprepped);
                             if (!$existingcat) {
                                 $newlinkcatdata = array("cat_name" => $data[5], "category_description" => "", "category_nicename" => esc_sql($data[5]));
                                 $newlinkcat = wp_insert_category($newlinkcatdata);
                                 $newcatarray = array("term_id" => $newlinkcat);
                                 $newcattype = array("taxonomy" => 'link_category');
                                 $wpdb->update($this->db_prefix() . 'term_taxonomy', $newcattype, $newcatarray);
                                 $newlinkcat = array($newlinkcat);
                             } else {
                                 $newlinkcat = array($existingcat);
                             }
                             $newrating = intval($data[14]);
                             if ($newrating < 0) {
                                 $newrating = 0;
                             } elseif ($newrating > 10) {
                                 $newrating = 10;
                             }
                             $newlinkid = '';
                             if (isset($_POST['updatesameurl'])) {
                                 $existing_link_query = "SELECT l.link_id FROM " . $this->db_prefix() . "links l ";
                                 $existing_link_query .= "WHERE l.link_url = '%s'";
                                 $existing_link_query_prepped = $wpdb->prepare($existing_link_query, esc_url($data[1]));
                                 $newlinkid = $wpdb->get_var($existing_link_query_prepped);
                             }
                             $newlink = array("link_name" => esc_html(stripslashes($data[0])), "link_url" => esc_url(stripslashes($data[1])), "link_rss" => esc_html(stripslashes($data[2])), "link_description" => esc_html(stripslashes($data[3])), "link_notes" => esc_html(stripslashes($data[4])), "link_category" => $newlinkcat, "link_visible" => $data[6], "link_image" => $data[11], "link_rating" => $newrating, "link_target" => $data[15]);
                             if (empty($newlinkid)) {
                                 $newlinkid = wp_insert_link($newlink);
                                 $successfulimport += 1;
                             } elseif (!empty($newlinkid)) {
                                 unset($newlink['link_url']);
                                 $newlink['link_id'] = $newlinkid;
                                 wp_update_link($newlink);
                                 $successfulupdate += 1;
                             }
                             if ($newlinkid != 0) {
                                 $extradatatable = $this->db_prefix() . "links_extrainfo";
                                 $nofollowvalue = $data[13] == 'Y' ? true : false;
                                 $existingextrainfo = "SELECT link_id FROM " . $extradatatable . " ";
                                 $existingextrainfo .= "WHERE link_id = '" . $newlinkid . "'";
                                 $existingextrainfoid = $wpdb->get_var($existingextrainfo);
                                 if (!empty($existingextrainfoid)) {
                                     $wpdb->update($extradatatable, array('link_second_url' => $data[7], 'link_telephone' => $data[8], 'link_email' => $data[9], 'link_reciprocal' => $data[10], 'link_textfield' => $data[12], 'link_no_follow' => $nofollowvalue), array('link_id' => $newlinkid));
                                 } elseif (empty($existingextrainfoid)) {
                                     $wpdb->insert($extradatatable, array('link_second_url' => $data[7], 'link_telephone' => $data[8], 'link_email' => $data[9], 'link_reciprocal' => $data[10], 'link_textfield' => $data[12], 'link_no_follow' => $nofollowvalue, 'link_id' => $newlinkid));
                                 }
                             }
                         } else {
                             $messages[] = '10';
                         }
                     } else {
                         $messages[] = '4';
                     }
                 }
             }
         }
         if (isset($_POST['firstrowheaders'])) {
             $row -= 1;
         }
         $messages[] = '9';
         wp_suspend_cache_addition(false);
     } elseif (isset($_POST['exportsettings'])) {
         $upload_dir = wp_upload_dir();
         if (is_writable($upload_dir['path'])) {
             $myFile = $upload_dir['path'] . "/SettingSet" . $_POST['settingsetid'] . "Export.csv";
             $fh = fopen($myFile, 'w') or die("can't open file");
             $sourcesettingsname = 'LinkLibraryPP' . $_POST['settingsetid'];
             $sourceoptions = get_option($sourcesettingsname);
             $headerrow = array();
             foreach ($sourceoptions as $key => $option) {
                 $headerrow[] = '"' . $key . '"';
             }
             $headerdata = join(',', $headerrow) . "\n";
             fwrite($fh, $headerdata);
             $datarow = array();
             foreach ($sourceoptions as $key => $option) {
                 $datarow[] = '"' . $option . '"';
             }
             $data = join(',', $datarow) . "\n";
             fwrite($fh, $data);
             fclose($fh);
             if (file_exists($myFile)) {
                 header('Content-Description: File Transfer');
                 header('Content-Type: application/octet-stream');
                 header('Content-Disposition: attachment; filename=' . basename($myFile));
                 header('Expires: 0');
                 header('Cache-Control: must-revalidate');
                 header('Pragma: public');
                 header('Content-Length: ' . filesize($myFile));
                 readfile($myFile);
                 exit;
             }
         } else {
             $messages[] = '6';
         }
     } elseif (isset($_POST['importsettings'])) {
         global $wpdb;
         if ($_FILES['settingsfile']['tmp_name'] != "") {
             $handle = fopen($_FILES['settingsfile']['tmp_name'], "r");
             $row = 1;
             $optionnames = "";
             $options = "";
             while (($data = fgetcsv($handle, 5000, ",")) !== false) {
                 if ($row == 1) {
                     $optionnames = $data;
                     $row++;
                 } else {
                     if ($row == 2) {
                         for ($counter = 0; $counter <= count($data) - 1; $counter++) {
                             $options[$optionnames[$counter]] = $data[$counter];
                         }
                         $row++;
                     }
                 }
             }
             if ($options != "") {
                 $settingsname = 'LinkLibraryPP' . $_POST['settingsetid'];
                 update_option($settingsname, $options);
                 $messages[] = '7';
             }
             fclose($handle);
         } else {
             $messages[] = '8';
         }
     } else {
         $settingsetid = $_POST['settingsetid'];
         $settings = $_POST['settingsetid'];
         $settingsname = 'LinkLibraryPP' . $settingsetid;
         $options = get_option($settingsname);
         $genoptions = get_option('LinkLibraryGeneral');
         foreach (array('order', 'table_width', 'num_columns', 'position', 'beforecatlist1', 'beforecatlist2', 'beforecatlist3', 'catnameoutput', 'linkaddfrequency', 'defaultsinglecat', 'rsspreviewcount', 'rssfeedinlinecount', 'linksperpage', 'catdescpos', 'catlistdescpos', 'rsspreviewwidth', 'rsspreviewheight', 'numberofrssitems', 'displayweblink', 'sourceweblink', 'showtelephone', 'sourcetelephone', 'showemail', 'sourceimage', 'sourcename', 'popup_width', 'popup_height') as $option_name) {
             if (isset($_POST[$option_name])) {
                 $options[$option_name] = str_replace("\"", "'", strtolower($_POST[$option_name]));
             }
         }
         foreach (array('categorylist', 'excludecategorylist') as $option_name) {
             if (isset($_POST[$option_name])) {
                 if ($genoptions['catselectmethod'] == 'commalist' || empty($genoptions['catselectmethod'])) {
                     $options[$option_name] = str_replace("\"", "'", strtolower($_POST[$option_name]));
                 } else {
                     if ($genoptions['catselectmethod'] == 'multiselectlist') {
                         $options[$option_name] = implode(',', $_POST[$option_name]);
                     }
                 }
             } else {
                 $options[$option_name] = '';
             }
         }
         foreach (array('linkheader', 'descheader', 'notesheader', 'linktarget', 'settingssetname', 'loadingicon', 'direction', 'linkdirection', 'linkorder', 'addnewlinkmsg', 'linknamelabel', 'linkaddrlabel', 'linkrsslabel', 'linkcatlabel', 'linkdesclabel', 'linknoteslabel', 'addlinkbtnlabel', 'newlinkmsg', 'moderatemsg', 'imagepos', 'imageclass', 'rssfeedtitle', 'rssfeeddescription', 'showonecatmode', 'linkcustomcatlabel', 'linkcustomcatlistentry', 'searchlabel', 'dragndroporder', 'cattargetaddress', 'beforeweblink', 'afterweblink', 'weblinklabel', 'beforetelephone', 'aftertelephone', 'telephonelabel', 'beforeemail', 'afteremail', 'emaillabel', 'beforelinkhits', 'afterlinkhits', 'linkreciprocallabel', 'linksecondurllabel', 'linktelephonelabel', 'linkemaillabel', 'emailcommand', 'rewritepage', 'maxlinks', 'beforedate', 'afterdate', 'beforeimage', 'afterimage', 'beforerss', 'afterrss', 'beforenote', 'afternote', 'beforelink', 'afterlink', 'beforeitem', 'afteritem', 'beforedesc', 'afterdesc', 'addbeforelink', 'addafterlink', 'beforelinkrating', 'afterlinkrating', 'linksubmitternamelabel', 'linksubmitteremaillabel', 'linksubmittercommentlabel', 'addlinkcatlistoverride', 'beforelargedescription', 'afterlargedescription', 'customcaptchaquestion', 'customcaptchaanswer', 'rssfeedaddress', 'linklargedesclabel', 'flatlist', 'searchresultsaddress', 'link_popup_text', 'linktitlecontent', 'paginationposition', 'showaddlinkrss', 'showaddlinkdesc', 'showaddlinkcat', 'showaddlinknotes', 'addlinkcustomcat', 'showaddlinkreciprocal', 'showaddlinksecondurl', 'showaddlinktelephone', 'showaddlinkemail', 'showcustomcaptcha', 'showlinksubmittername', 'showaddlinksubmitteremail', 'showlinksubmittercomment', 'showuserlargedescription', 'cat_letter_filter', 'beforefirstlink', 'afterlastlink', 'searchfieldtext', 'catfilterlabel', 'searchnoresultstext', 'addlinkdefaultcat') as $option_name) {
             if (isset($_POST[$option_name])) {
                 $options[$option_name] = str_replace("\"", "'", $_POST[$option_name]);
             }
         }
         foreach (array('hide_if_empty', 'catanchor', 'showdescription', 'shownotes', 'showrating', 'showupdated', 'show_images', 'use_html_tags', 'show_rss', 'nofollow', 'showcolumnheaders', 'show_rss_icon', 'showcategorydescheaders', 'showcategorydesclinks', 'showadmineditlinks', 'showonecatonly', 'rsspreview', 'rssfeedinline', 'rssfeedinlinecontent', 'pagination', 'hidecategorynames', 'showinvisible', 'showdate', 'showuserlinks', 'emailnewlink', 'usethumbshotsforimages', 'uselocalimagesoverthumbshots', 'addlinkreqlogin', 'showcatlinkcount', 'publishrssfeed', 'showname', 'enablerewrite', 'storelinksubmitter', 'showlinkhits', 'showcaptcha', 'showlargedescription', 'addlinknoaddress', 'featuredfirst', 'usetextareaforusersubmitnotes', 'showcatonsearchresults', 'shownameifnoimage', 'enable_link_popup', 'nocatonstartup', 'showlinksonclick', 'showinvisibleadmin', 'combineresults', 'showifreciprocalvalid', 'cat_letter_filter_autoselect', 'cat_letter_filter_showalloption', 'emailsubmitter', 'addlinkakismet') as $option_name) {
             if (isset($_POST[$option_name])) {
                 $options[$option_name] = true;
             } else {
                 $options[$option_name] = false;
             }
         }
         foreach (array('displayastable', 'divorheader') as $option_name) {
             if ($_POST[$option_name] == 'true') {
                 $options[$option_name] = true;
             } elseif ($_POST[$option_name] == 'false') {
                 $options[$option_name] = false;
             }
         }
         foreach (array('catlistwrappers') as $option_name) {
             if (isset($_POST[$option_name])) {
                 $options[$option_name] = (int) $_POST[$option_name];
             }
         }
         update_option($settingsname, $options);
         $messages[] = "1";
         global $wpdb;
         if ($options['categorylist'] != '') {
             $categoryids = explode(',', $options['categorylist']);
             foreach ($categoryids as $categoryid) {
                 $linkcatquery = "SELECT distinct t.name, t.term_id, t.slug as category_nicename, tt.description as category_description ";
                 $linkcatquery .= "FROM " . $this->db_prefix() . "terms t, " . $this->db_prefix() . "term_taxonomy tt ";
                 if (isset($_POST['hide_if_empty'])) {
                     $linkcatquery .= ", " . $this->db_prefix() . "term_relationships tr, " . $this->db_prefix() . "links l ";
                 }
                 $linkcatquery .= "WHERE t.term_id = tt.term_id AND tt.taxonomy = 'link_category'";
                 $linkcatquery .= " AND t.term_id = " . $categoryid;
                 $catnames = $wpdb->get_results($linkcatquery);
                 if (!$catnames) {
                     $messages[] = '2';
                 }
             }
         }
         if ($options['excludecategorylist'] != '') {
             $categoryids = explode(',', $options['excludecategorylist']);
             foreach ($categoryids as $categoryid) {
                 $linkcatquery = "SELECT distinct t.name, t.term_id, t.slug as category_nicename, tt.description as category_description ";
                 $linkcatquery .= "FROM " . $this->db_prefix() . "terms t, " . $this->db_prefix() . "term_taxonomy tt ";
                 if (isset($_POST['hide_if_empty'])) {
                     $linkcatquery .= ", " . $this->db_prefix() . "term_relationships tr, " . $this->db_prefix() . "links l ";
                 }
                 $linkcatquery .= "WHERE t.term_id = tt.term_id AND tt.taxonomy = 'link_category'";
                 $linkcatquery .= " AND t.term_id = " . $categoryid;
                 $catnames = $wpdb->get_results($linkcatquery);
                 if (!$catnames) {
                     $messages[] = '3';
                 }
             }
         }
         global $wp_rewrite;
         $wp_rewrite->flush_rules(false);
     }
     //lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
     $messagelist = implode(",", $messages);
     $cleanredirecturl = $this->remove_querystring_var($_POST['_wp_http_referer'], 'messages');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'currenttab');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'importrowscount');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'successimportcount');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'copy');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'reset');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'resettable');
     $cleanredirecturl = $this->remove_querystring_var($cleanredirecturl, 'source');
     $redirecturl = $cleanredirecturl;
     if (!empty($messages)) {
         $redirecturl = $cleanredirecturl . "&messages=" . $messagelist;
     }
     if ($row != 0) {
         $redirecturl .= "&importrowscount=" . $row;
     }
     if ($successfulimport != 0) {
         $redirecturl .= "&successimportcount=" . $successfulimport;
     }
     if ($successfulupdate != 0) {
         $redirecturl .= "&successupdatecount=" . $successfulupdate;
     }
     if (isset($_POST['currenttab'])) {
         $redirecturl .= "&currenttab=" . $_POST['currenttab'];
     }
     wp_redirect($redirecturl);
 }
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since 1.4
  * @global object $edd_logs EDD Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 function get_logs()
 {
     global $edd_logs, $wpdb;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $download = empty($_GET['s']) ? $this->get_filtered_download() : null;
     $log_query = array('post_parent' => $download, 'log_type' => 'file_download', 'paged' => $paged, 'meta_query' => $this->get_meta_query(), 'posts_per_page' => $this->per_page, 'update_post_meta_cache' => false, 'update_post_term_cache' => false);
     $logs = $edd_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $meta = get_post_custom($log->ID);
             $user_info = isset($meta['_edd_log_user_info']) ? maybe_unserialize($meta['_edd_log_user_info'][0]) : array();
             $payment_id = isset($meta['_edd_log_payment_id']) ? $meta['_edd_log_payment_id'][0] : false;
             $ip = $meta['_edd_log_ip'][0];
             $user_id = isset($user_info['id']) ? $user_info['id'] : false;
             if (!array_key_exists($log->post_parent, $this->queried_files)) {
                 $files = maybe_unserialize($wpdb->get_var($wpdb->prepare("SELECT meta_value from {$wpdb->postmeta} WHERE post_id = %d and meta_key = 'edd_download_files'", $log->post_parent)));
                 $this->queried_files[$log->post_parent] = $files;
             } else {
                 $files = $this->queried_files[$log->post_parent];
             }
             $file_id = (int) $meta['_edd_log_file_id'][0];
             $file_id = $file_id !== false ? $file_id : 0;
             $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null;
             if ($this->file_search && strpos(strtolower($file_name), strtolower($this->get_search())) !== false || !$this->file_search) {
                 $logs_data[] = array('ID' => $log->ID, 'download' => $log->post_parent, 'payment_id' => $payment_id, 'user_id' => $user_id ? $user_id : (isset($user_info['email']) ? $user_info['email'] : null), 'user_name' => isset($user_info['email']) ? $user_info['email'] : (isset($user_info['name']) ? $user_info['name'] : ''), 'file' => $file_name, 'ip' => $ip, 'date' => $log->post_date);
             }
         }
     }
     return $logs_data;
 }
 /**
  * Adds a value to cache.
  *
  * If the specified key already exists, the value is not stored and the function
  * returns false.
  *
  * @link    http://www.php.net/manual/en/memcached.add.php
  *
  * @param   string      $key            The key under which to store the value.
  * @param   mixed       $value          The value to store.
  * @param   string      $group          The group value appended to the $key.
  * @param   int         $expiration     The expiration time, defaults to 0.
  * @param   string      $server_key     The key identifying the server to store the value on.
  * @param   bool        $byKey          True to store in internal cache by key; false to not store by key
  * @return  bool                        Returns TRUE on success or FALSE on failure.
  */
 public function add($key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false)
 {
     /*
      * Ensuring that wp_suspend_cache_addition is defined before calling, because sometimes an advanced-cache.php
      * file will load object-cache.php before wp-includes/functions.php is loaded. In those cases, if wp_cache_add
      * is called in advanced-cache.php before any more of WordPress is loaded, we get a fatal error because
      * wp_suspend_cache_addition will not be defined until wp-includes/functions.php is loaded.
      */
     if (function_exists('wp_suspend_cache_addition') && wp_suspend_cache_addition()) {
         return false;
     }
     $derived_key = $this->buildKey($key, $group);
     $expiration = $this->sanitize_expiration($expiration);
     // If group is a non-Memcached group, save to runtime cache, not Memcached
     if (in_array($group, $this->no_mc_groups)) {
         // Add does not set the value if the key exists; mimic that here
         if (isset($this->cache[$derived_key])) {
             return false;
         }
         $this->add_to_internal_cache($derived_key, $value);
         return true;
     }
     // Save to Memcached
     if ($byKey) {
         $result = $this->m->addByKey($server_key, $derived_key, $value, $expiration);
     } else {
         $result = $this->m->add($derived_key, $value, $expiration);
     }
     // Store in runtime cache if add was successful
     if (Memcached::RES_SUCCESS === $this->getResultCode()) {
         $this->add_to_internal_cache($derived_key, $value);
     }
     return $result;
 }
Example #29
0
 /**
  * Adds data to the cache if it doesn't already exist.
  *
  * @uses WP_Object_Cache::_exists Checks to see if the cache already has data.
  * @uses WP_Object_Cache::set Sets the data after the checking the cache
  *		contents existence.
  *
  * @since 2.0.0
  *
  * @param int|string $key What to call the contents in the cache
  * @param mixed $data The contents to store in the cache
  * @param string $group Where to group the cache contents
  * @param int $expire When to expire the cache contents
  * @return bool False if cache key and group already exist, true on success
  */
 function add($key, $data, $group = 'default', $expire = '')
 {
     if (wp_suspend_cache_addition()) {
         return false;
     }
     if (empty($group)) {
         $group = 'default';
     }
     $id = $key;
     if ($this->multisite && !isset($this->global_groups[$group])) {
         $id = $this->blog_prefix . $key;
     }
     if ($this->_exists($id, $group)) {
         return false;
     }
     return $this->set($key, $data, $group, $expire);
 }
 /**
  * Adds data to the cache, if the cache key does not already exist.
  *
  * @param int|string $key   The cache key to use for retrieval later
  * @param mixed      $var   The data to add to the cache store
  * @param string     $group The group to add the cache to
  * @param int        $ttl   When the cache data should be expired
  *
  * @return bool False if cache key and group already exist, true on success
  */
 public function add($key, $var, $group = 'default', $ttl = 0)
 {
     if (wp_suspend_cache_addition()) {
         return false;
     }
     $key = $this->_key($key, $group);
     if (!$this->apc_available || $this->_is_non_persistent_group($group)) {
         return $this->_add_np($key, $var);
     }
     return $this->_add($key, $var, $ttl);
 }