Increment group cache prefix (invalidates cache).
public static incr_cache_prefix ( string $group ) | ||
$group | string |
/** * Remove all zones */ public static function remove_mock_zones() { global $wpdb; $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_methods;"); $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_locations;"); $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zones;"); WC_Cache_Helper::incr_cache_prefix('shipping_zones'); }
/** * Save settings. */ public function save() { global $current_section, $wpdb; if (!$current_section) { $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); } elseif (!empty($_POST['tax_rate_country'])) { $this->save_tax_rates(); } WC_Cache_Helper::incr_cache_prefix('taxes'); }
/** * Cleanup sessions. */ public function cleanup_sessions() { global $wpdb; if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) { // Delete expired sessions $wpdb->query($wpdb->prepare("DELETE FROM {$this->_table} WHERE session_expiry < %d", time())); // Invalidate cache WC_Cache_Helper::incr_cache_prefix(WC_SESSION_CACHE_GROUP); } }
/** * Save zone data to the database. */ public function save() { $name = $this->get_zone_name(); if (empty($name)) { $this->set_zone_name($this->generate_zone_name()); } if (null === $this->get_id()) { $this->create(); } else { $this->update(); } $this->save_locations(); WC_Cache_Helper::incr_cache_prefix('shipping_zones'); // Increments the transient version to invalidate cache. WC_Cache_Helper::get_transient_version('shipping', true); }
/** * Updates locations (postcode and city). * * Internal use only. * * @since 2.3.0 * @access private * * @param int $tax_rate_id * @param string $type * @return string */ private static function _update_tax_rate_locations($tax_rate_id, $values, $type) { global $wpdb; $tax_rate_id = absint($tax_rate_id); $wpdb->query($wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d AND location_type = %s;\n\t\t\t\t", $tax_rate_id, $type)); if (sizeof($values) > 0) { $sql = "( '" . implode("', {$tax_rate_id}, '" . esc_sql($type) . "' ),( '", array_map('esc_sql', $values)) . "', {$tax_rate_id}, '" . esc_sql($type) . "' )"; $wpdb->query("\n\t\t\t\tINSERT INTO {$wpdb->prefix}woocommerce_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES {$sql};\n\t\t\t\t"); } WC_Cache_Helper::incr_cache_prefix('taxes'); }
/** * Actually executes a a tool. * * @param string $tool * @return array */ public function execute_tool($tool) { global $wpdb; $ran = true; switch ($tool) { case 'clear_transients': wc_delete_product_transients(); wc_delete_shop_order_transients(); WC_Cache_Helper::get_transient_version('shipping', true); $message = __('Product Transients Cleared', 'woocommerce'); break; case 'clear_expired_transients': /* * Deletes all expired transients. The multi-table delete syntax is used. * to delete the transient record from table a, and the corresponding. * transient_timeout record from table b. * * Based on code inside core's upgrade_network() function. */ $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\tWHERE a.option_name LIKE %s\n\t\t\t\t\tAND a.option_name NOT LIKE %s\n\t\t\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\t\t\tAND b.option_value < %d"; $rows = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time())); $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\tWHERE a.option_name LIKE %s\n\t\t\t\t\tAND a.option_name NOT LIKE %s\n\t\t\t\t\tAND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )\n\t\t\t\t\tAND b.option_value < %d"; $rows2 = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', time())); $message = sprintf(__('%d Transients Rows Cleared', 'woocommerce'), $rows + $rows2); break; case 'reset_roles': // Remove then re-add caps and roles WC_Install::remove_roles(); WC_Install::create_roles(); $message = __('Roles successfully reset', 'woocommerce'); break; case 'recount_terms': $product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent')); _wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false); $product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent')); _wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false); $message = __('Terms successfully recounted', 'woocommerce'); break; case 'clear_sessions': $wpdb->query("TRUNCATE {$wpdb->prefix}woocommerce_sessions"); wp_cache_flush(); $message = __('Sessions successfully cleared', 'woocommerce'); break; case 'install_pages': WC_Install::create_pages(); return __('All missing WooCommerce pages was installed successfully.', 'woocommerce'); break; case 'delete_taxes': $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;"); $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;"); WC_Cache_Helper::incr_cache_prefix('taxes'); $message = __('Tax rates successfully deleted', 'woocommerce'); break; case 'reset_tracking': delete_option('woocommerce_allow_tracking'); WC_Admin_Notices::add_notice('tracking'); $message = __('Usage tracking settings successfully reset.', 'woocommerce'); break; default: $tools = $this->get_tools(); if (isset($tools[$tool]['callback'])) { $callback = $tools[$tool]['callback']; $return = call_user_func($callback); if ($return === false) { $callback_string = is_array($callback) ? get_class($callback[0]) . '::' . $callback[1] : $callback; $ran = false; $message = sprintf(__('There was an error calling %s', 'woocommerce'), $callback_string); } else { $message = __('Tool ran.', 'woocommerce'); } } else { $ran = false; $message = __('There was an error calling this tool. There is no callback present.', 'woocommerce'); } break; } return array('success' => $ran, 'message' => $message); }
/** * Save meta box data. * * @param int $post_id * @param WP_Post $post */ public static function save($post_id, $post) { global $wpdb; // Ensure coupon code is correctly formatted $post->post_title = apply_filters('woocommerce_coupon_code', $post->post_title); $wpdb->update($wpdb->posts, array('post_title' => $post->post_title), array('ID' => $post_id)); // Check for dupe coupons $coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\tFROM {$wpdb->posts}\n\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t ", $post->post_title, $post_id)); if ($coupon_found) { WC_Admin_Meta_Boxes::add_error(__('Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce')); } // Add/Replace data to array $type = wc_clean($_POST['discount_type']); $amount = wc_format_decimal($_POST['coupon_amount']); $usage_limit = empty($_POST['usage_limit']) ? '' : absint($_POST['usage_limit']); $usage_limit_per_user = empty($_POST['usage_limit_per_user']) ? '' : absint($_POST['usage_limit_per_user']); $limit_usage_to_x_items = empty($_POST['limit_usage_to_x_items']) ? '' : absint($_POST['limit_usage_to_x_items']); $individual_use = isset($_POST['individual_use']) ? 'yes' : 'no'; $expiry_date = wc_clean($_POST['expiry_date']); $free_shipping = isset($_POST['free_shipping']) ? 'yes' : 'no'; $exclude_sale_items = isset($_POST['exclude_sale_items']) ? 'yes' : 'no'; $minimum_amount = wc_format_decimal($_POST['minimum_amount']); $maximum_amount = wc_format_decimal($_POST['maximum_amount']); $customer_email = array_filter(array_map('trim', explode(',', wc_clean($_POST['customer_email'])))); $product_ids = implode(',', array_filter(array_map('intval', explode(',', $_POST['product_ids'])))); $exclude_product_ids = implode(',', array_filter(array_map('intval', explode(',', $_POST['exclude_product_ids'])))); $product_categories = isset($_POST['product_categories']) ? array_map('intval', $_POST['product_categories']) : array(); $exclude_product_categories = isset($_POST['exclude_product_categories']) ? array_map('intval', $_POST['exclude_product_categories']) : array(); // Save update_post_meta($post_id, 'discount_type', $type); update_post_meta($post_id, 'coupon_amount', $amount); update_post_meta($post_id, 'individual_use', $individual_use); update_post_meta($post_id, 'product_ids', $product_ids); update_post_meta($post_id, 'exclude_product_ids', $exclude_product_ids); update_post_meta($post_id, 'usage_limit', $usage_limit); update_post_meta($post_id, 'usage_limit_per_user', $usage_limit_per_user); update_post_meta($post_id, 'limit_usage_to_x_items', $limit_usage_to_x_items); update_post_meta($post_id, 'expiry_date', $expiry_date); update_post_meta($post_id, 'free_shipping', $free_shipping); update_post_meta($post_id, 'exclude_sale_items', $exclude_sale_items); update_post_meta($post_id, 'product_categories', $product_categories); update_post_meta($post_id, 'exclude_product_categories', $exclude_product_categories); update_post_meta($post_id, 'minimum_amount', $minimum_amount); update_post_meta($post_id, 'maximum_amount', $maximum_amount); update_post_meta($post_id, 'customer_email', $customer_email); // Clear cache WC_Cache_Helper::incr_cache_prefix('coupons'); do_action('woocommerce_coupon_options_save', $post_id); }
/** * Save zone data to the database. */ public function save() { if (!$this->get_zone_id()) { $this->create(); } else { $this->update(); } $this->save_locations(); WC_Cache_Helper::incr_cache_prefix('shipping_zones'); // Increments the transient version to invalidate cache. WC_Cache_Helper::get_transient_version('shipping', true); }
/** * Clear all transients cache for order data. * * @param int|WC_Order $order */ function wc_delete_shop_order_transients($order = 0) { if (is_numeric($order)) { $order = wc_get_order($order); } $reports = WC_Admin_Reports::get_reports(); $transients_to_clear = array('wc_admin_report'); foreach ($reports as $report_group) { foreach ($report_group['reports'] as $report_key => $report) { $transients_to_clear[] = 'wc_report_' . $report_key; } } foreach ($transients_to_clear as $transient) { delete_transient($transient); } // Clear money spent for user associated with order if (is_a($order, 'WC_Order')) { $order_id = $order->get_id(); delete_user_meta($order->get_customer_id(), '_money_spent'); delete_user_meta($order->get_customer_id(), '_order_count'); } else { $order_id = 0; } // Increments the transient version to invalidate cache WC_Cache_Helper::get_transient_version('orders', true); // Do the same for regular cache WC_Cache_Helper::incr_cache_prefix('orders'); do_action('woocommerce_delete_shop_order_transients', $order_id); }
/** * Update Meta Data in the database. * @since 2.6.0 */ protected function save_meta_data() { global $wpdb; $db_info = $this->_get_db_info(); $all_meta_ids = array_map('absint', $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT " . $db_info['meta_id_field'] . " FROM " . $db_info['table'] . "\n\t\t\tWHERE " . $db_info['object_id_field'] . " = %d", $this->get_id()) . "\n\t\t\tAND meta_key NOT IN ('" . implode("','", array_map('esc_sql', $this->get_internal_meta_keys())) . "')\n\t\t\tAND meta_key NOT LIKE 'wp\\_%%';\n\t\t")); $set_meta_ids = array(); foreach ($this->_meta_data as $array_key => $meta) { if (empty($meta->id)) { $new_meta_id = add_metadata($this->_meta_type, $this->get_id(), $meta->key, $meta->value, false); $set_meta_ids[] = $new_meta_id; $this->_meta_data[$array_key]->id = $new_meta_id; } else { update_metadata_by_mid($this->_meta_type, $meta->id, $meta->value, $meta->key); $set_meta_ids[] = absint($meta->id); } } // Delete no longer set meta data $delete_meta_ids = array_diff($all_meta_ids, $set_meta_ids); foreach ($delete_meta_ids as $meta_id) { delete_metadata_by_mid($this->_meta_type, $meta_id); } if (!empty($this->_cache_group)) { WC_Cache_Helper::incr_cache_prefix($this->_cache_group); } $this->read_meta_data(); }
/** * Clear all transients cache for order data. * * @param int $post_id (default: 0) */ function wc_delete_shop_order_transients($post_id = 0) { $post_id = absint($post_id); $transients_to_clear = array(); // Clear report transients $reports = WC_Admin_Reports::get_reports(); foreach ($reports as $report_group) { foreach ($report_group['reports'] as $report_key => $report) { $transients_to_clear[] = 'wc_report_' . $report_key; } } // clear API report transient $transients_to_clear[] = 'wc_admin_report'; // Clear transients where we have names foreach ($transients_to_clear as $transient) { delete_transient($transient); } // Clear money spent for user associated with order if ($post_id && ($user_id = get_post_meta($post_id, '_customer_user', true))) { delete_user_meta($user_id, '_money_spent'); delete_user_meta($user_id, '_order_count'); } // Increments the transient version to invalidate cache WC_Cache_Helper::get_transient_version('orders', true); // Do the same for regular cache WC_Cache_Helper::incr_cache_prefix('orders'); do_action('woocommerce_delete_shop_order_transients', $post_id); }
/** * Handles output of tools. */ public static function status_tools() { global $wpdb; $tools = self::get_tools(); if (!empty($_GET['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'debug_action')) { switch ($_GET['action']) { case 'clear_transients': wc_delete_product_transients(); wc_delete_shop_order_transients(); WC_Cache_Helper::get_transient_version('shipping', true); echo '<div class="updated inline"><p>' . __('Product Transients Cleared', 'woocommerce') . '</p></div>'; break; case 'clear_expired_transients': /* * Deletes all expired transients. The multi-table delete syntax is used. * to delete the transient record from table a, and the corresponding. * transient_timeout record from table b. * * Based on code inside core's upgrade_network() function. */ $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\t\tWHERE a.option_name LIKE %s\n\t\t\t\t\t\tAND a.option_name NOT LIKE %s\n\t\t\t\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\t\t\t\tAND b.option_value < %d"; $rows = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time())); $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\t\tWHERE a.option_name LIKE %s\n\t\t\t\t\t\tAND a.option_name NOT LIKE %s\n\t\t\t\t\t\tAND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )\n\t\t\t\t\t\tAND b.option_value < %d"; $rows2 = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', time())); echo '<div class="updated inline"><p>' . sprintf(__('%d Transients Rows Cleared', 'woocommerce'), $rows + $rows2) . '</p></div>'; break; case 'reset_roles': // Remove then re-add caps and roles WC_Install::remove_roles(); WC_Install::create_roles(); echo '<div class="updated inline"><p>' . __('Roles successfully reset', 'woocommerce') . '</p></div>'; break; case 'recount_terms': $product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent')); _wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false); $product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent')); _wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false); echo '<div class="updated inline"><p>' . __('Terms successfully recounted', 'woocommerce') . '</p></div>'; break; case 'clear_sessions': $wpdb->query("TRUNCATE {$wpdb->prefix}woocommerce_sessions"); wp_cache_flush(); echo '<div class="updated inline"><p>' . __('Sessions successfully cleared', 'woocommerce') . '</p></div>'; break; case 'install_pages': WC_Install::create_pages(); echo '<div class="updated inline"><p>' . __('All missing WooCommerce pages was installed successfully.', 'woocommerce') . '</p></div>'; break; case 'delete_taxes': $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;"); $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;"); WC_Cache_Helper::incr_cache_prefix('taxes'); echo '<div class="updated inline"><p>' . __('Tax rates successfully deleted', 'woocommerce') . '</p></div>'; break; case 'reset_tracking': delete_option('woocommerce_allow_tracking'); WC_Admin_Notices::add_notice('tracking'); echo '<div class="updated inline"><p>' . __('Usage tracking settings successfully reset.', 'woocommerce') . '</p></div>'; break; default: $action = esc_attr($_GET['action']); if (isset($tools[$action]['callback'])) { $callback = $tools[$action]['callback']; $return = call_user_func($callback); if ($return === false) { $callback_string = is_array($callback) ? get_class($callback[0]) . '::' . $callback[1] : $callback; echo '<div class="error inline"><p>' . sprintf(__('There was an error calling %s', 'woocommerce'), $callback_string) . '</p></div>'; } } break; } } // Display message if settings settings have been saved if (isset($_REQUEST['settings-updated'])) { echo '<div class="updated inline"><p>' . __('Your changes have been saved.', 'woocommerce') . '</p></div>'; } include_once 'views/html-admin-page-status-tools.php'; }
/** * Update Meta Data in the database. * @since 2.6.0 */ protected function save_meta_data() { foreach ($this->_meta_data as $array_key => $meta) { if (is_null($meta->value)) { if (!empty($meta->id)) { delete_metadata_by_mid($this->_meta_type, $meta->id); } } elseif (empty($meta->id)) { $new_meta_id = add_metadata($this->_meta_type, $this->get_id(), $meta->key, $meta->value, false); $this->_meta_data[$array_key]->id = $new_meta_id; } else { update_metadata_by_mid($this->_meta_type, $meta->id, $meta->value, $meta->key); } } if (!empty($this->_cache_group)) { WC_Cache_Helper::incr_cache_prefix($this->_cache_group); } $this->read_meta_data(); }
/** * Update Meta Data in the database. * @since 2.6.0 */ public function save_meta_data() { if (!$this->data_store || is_null($this->meta_data)) { return; } foreach ($this->meta_data as $array_key => $meta) { if (is_null($meta->value)) { if (!empty($meta->id)) { $this->data_store->delete_meta($this, $meta); } } elseif (empty($meta->id)) { $new_meta_id = $this->data_store->add_meta($this, $meta); $this->meta_data[$array_key]->id = $new_meta_id; } else { $this->data_store->update_meta($this, $meta); } } if (!empty($this->cache_group)) { WC_Cache_Helper::incr_cache_prefix($this->cache_group); } $this->read_meta_data(true); }
/** * Deletes a shipping zone from the database. * * @since 2.7.0 * @param WC_Shipping_Zone * @param array $args Array of args to pass to the delete method. * @return bool result */ public function delete(&$zone, $args = array()) { if ($zone->get_id()) { global $wpdb; $wpdb->delete($wpdb->prefix . 'woocommerce_shipping_zone_methods', array('zone_id' => $zone->get_id())); $wpdb->delete($wpdb->prefix . 'woocommerce_shipping_zone_locations', array('zone_id' => $zone->get_id())); $wpdb->delete($wpdb->prefix . 'woocommerce_shipping_zones', array('zone_id' => $zone->get_id())); WC_Cache_Helper::incr_cache_prefix('shipping_zones'); $zone->set_id(null); } }