public function screen() { $Shopp = Shopp::object(); if (!current_user_can('shopp_settings_checkout')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $purchasetable = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $next = sDB::query("SELECT IF ((MAX(id)) > 0,(MAX(id)+1),1) AS id FROM {$purchasetable} LIMIT 1"); $next_setting = shopp_setting('next_order_id'); if ($next->id > $next_setting) { $next_setting = $next->id; } $term_recount = false; if (!empty($_POST['save'])) { check_admin_referer('shopp-setup-management'); $next_order_id = $_POST['settings']['next_order_id'] = intval($_POST['settings']['next_order_id']); if ($next_order_id >= $next->id) { if (sDB::query("ALTER TABLE {$purchasetable} AUTO_INCREMENT=" . sDB::escape($next_order_id))) { $next_setting = $next_order_id; } } $_POST['settings']['order_shipfee'] = Shopp::floatval($_POST['settings']['order_shipfee']); // Recount terms when this setting changes if (isset($_POST['settings']['inventory']) && $_POST['settings']['inventory'] != shopp_setting('inventory')) { $term_recount = true; } shopp_set_formsettings(); $this->notice(Shopp::__('Management settings saved.'), 'notice', 20); } if ($term_recount) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } $states = array(__('Map the label to an order state:', 'Shopp') => array_merge(array('' => ''), Lookup::txnstatus_labels())); $statusLabels = shopp_setting('order_status'); $statesLabels = shopp_setting('order_states'); $reasonLabels = shopp_setting('cancel_reasons'); if (empty($reasonLabels)) { $reasonLabels = array(__('Not as described or expected', 'Shopp'), __('Wrong size', 'Shopp'), __('Found better prices elsewhere', 'Shopp'), __('Product is missing parts', 'Shopp'), __('Product is defective or damaaged', 'Shopp'), __('Took too long to deliver', 'Shopp'), __('Item out of stock', 'Shopp'), __('Customer request to cancel', 'Shopp'), __('Item discontinued', 'Shopp'), __('Other reason', 'Shopp')); } $promolimit = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '15', '20', '25'); $lowstock = shopp_setting('lowstock_level'); if (empty($lowstock)) { $lowstock = 0; } include $this->ui('management.php'); }
public function updates() { $builtin_path = SHOPP_PATH . '/templates'; $theme_path = sanitize_path(STYLESHEETPATH . '/shopp'); if (Shopp::str_true($this->form('theme_templates')) && !is_dir($theme_path)) { $this->form['theme_templates'] = 'off'; $this->notice(Shopp::__("Shopp theme templates can't be used because they don't exist."), 'error'); } if (empty($this->form('catalog_pagination'))) { $this->form['catalog_pagination'] = 0; } // Recount terms when this setting changes if ($this->form('outofstock_catalog') != shopp_setting('outofstock_catalog')) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } shopp_set_formsettings(); $this->notice(Shopp::__('Presentation settings saved.'), 'notice', 20); }
/** * Updates the amount of terms in taxonomy. * * If there is a taxonomy callback applied, then it will be called for updating * the count. * * The default action is to count what the amount of terms have the relationship * of term ID. Once that is done, then update the database. * * @since 2.3.0 * * @staticvar array $_deferred * * @param int|array $terms The term_taxonomy_id of the terms. * @param string $taxonomy The context of the term. * @return bool If no terms will return false, and if successful will return true. */ function wp_update_term_count($terms, $taxonomy, $do_deferred = false) { static $_deferred = array(); if ($do_deferred) { foreach ((array) array_keys($_deferred) as $tax) { wp_update_term_count_now($_deferred[$tax], $tax); unset($_deferred[$tax]); } } if (empty($terms)) { return false; } if (!is_array($terms)) { $terms = array($terms); } if (wp_defer_term_counting()) { if (!isset($_deferred[$taxonomy])) { $_deferred[$taxonomy] = array(); } $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms)); return true; } return wp_update_term_count_now($terms, $taxonomy); }
/** * Save the meta when the post is saved * * @since 1.0.0 * * @param $post_id ID of the post e.g. '1' * * @return mixed */ public function mark_posts_save($post_id) { // Check if our nonce is set. if (!isset($_POST['mark_posts_inner_meta_box_nonce'])) { return $post_id; } $nonce = $_POST['mark_posts_inner_meta_box_nonce']; // Verify that the nonce is valid. if (!wp_verify_nonce($nonce, 'mark_posts_inner_meta_box')) { return $post_id; } // If this is an autosave, our form has not been submitted, // so we don't want to do anything. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check the user's permissions. if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } /* OK, its safe for us to mark_posts_save the data now. */ // Sanitize the user input. $mydata = sanitize_text_field($_POST['mark_posts_term_id']); $myterm = get_term($mydata, 'marker'); // Update the meta field. update_post_meta($post_id, 'mark_posts_term_id', $mydata); // Update taxonomy count @wp_update_term_count_now($mydata, 'marker'); // Clear transient dashboard stats delete_transient('marker_posts_stats'); }
/** * Update all taxonomies. * This should only ever be called from a cron job scheduled by EasyRecipeScheduler because it can potentially take quite a while */ function updateAll() { /** @var wpdb $wpdb */ global $wpdb; /** * If we are already running, don't do it again */ if ($this->scheduler->isRunning()) { return; } /** * Set as running * Set a "timeout" of 10 minutes. This will prevent it being re-run for 10 minutes if the current run terminates abnormally for any reason */ $this->scheduler->setRunning(10 * 60); $q = "SELECT ID FROM {$wpdb->posts} WHERE post_type NOT IN ('attachment','index','nav_menu_item')"; $postIDs = $wpdb->get_col($q); $this->countTerms['cuisine'] = array(); $this->countTerms['course'] = array(); foreach ($postIDs as $postID) { $post = WP_Post::get_instance($postID); $this->update($post, false); } /** * Update any term counts that we may have adjusted */ if (count($this->countTerms['cuisine']) > 0) { wp_update_term_count_now(array_unique(array_keys($this->countTerms['cuisine'])), 'cuisine'); } if (count($this->countTerms['course']) > 0) { wp_update_term_count_now(array_unique(array_keys($this->countTerms['course'])), 'course'); } /** * Mark the taxonomies as having been created */ $settings = EasyRecipeSettings::getInstance(); $settings->taxonomiesCreated = true; $settings->update(); /** * Mark this job as complete */ $this->scheduler->terminate(); }
public function presentation() { if (!current_user_can('shopp_settings_presentation')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $builtin_path = SHOPP_PATH . '/templates'; $theme_path = sanitize_path(STYLESHEETPATH . '/shopp'); $term_recount = false; if (!empty($_POST['save'])) { check_admin_referer('shopp-settings-presentation'); $updated = __('Shopp presentation settings saved.', 'Shopp'); if (isset($_POST['settings']['theme_templates']) && $_POST['settings']['theme_templates'] == 'on' && !is_dir($theme_path)) { $_POST['settings']['theme_templates'] = 'off'; $updated = __('Shopp theme templates can\'t be used because they don\'t exist.', 'Shopp'); } if (empty($_POST['settings']['catalog_pagination'])) { $_POST['settings']['catalog_pagination'] = 0; } // Recount terms when this setting changes if (isset($_POST['settings']['outofstock_catalog']) && $_POST['settings']['outofstock_catalog'] != shopp_setting('outofstock_catalog')) { $term_recount = true; } shopp_set_formsettings(); $this->notice(Shopp::__('Presentation settings saved.'), 'notice', 20); } if ($term_recount) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } // Copy templates to the current WordPress theme if (!empty($_POST['install'])) { check_admin_referer('shopp-settings-presentation'); copy_shopp_templates($builtin_path, $theme_path); } $status = 'available'; if (!is_dir($theme_path)) { $status = 'directory'; } else { if (!is_writable($theme_path)) { $status = 'permissions'; } else { $builtin = array_filter(scandir($builtin_path), 'filter_dotfiles'); $theme = array_filter(scandir($theme_path), 'filter_dotfiles'); if (empty($theme)) { $status = 'ready'; } else { if (array_diff($builtin, $theme)) { $status = 'incomplete'; } } } } $category_views = array('grid' => __('Grid', 'Shopp'), 'list' => __('List', 'Shopp')); $row_products = array(2, 3, 4, 5, 6, 7); $productOrderOptions = ProductCategory::sortoptions(); $productOrderOptions['custom'] = __('Custom', 'Shopp'); $orderOptions = array('ASC' => __('Order', 'Shopp'), 'DESC' => __('Reverse Order', 'Shopp'), 'RAND' => __('Shuffle', 'Shopp')); $orderBy = array('sortorder' => __('Custom arrangement', 'Shopp'), 'created' => __('Upload date', 'Shopp')); include $this->ui('presentation.php'); }
/** * Renders the shipping settings screen and processes updates * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function shipping() { if (!current_user_can('shopp_settings_shipping')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $sub = 'settings'; $term_recount = false; if (shopp_setting_enabled('shipping')) { $sub = 'rates'; } if (isset($_GET['sub']) && in_array($_GET['sub'], array_keys($this->subscreens))) { $sub = $_GET['sub']; } if (!empty($_POST['save']) && empty($_POST['module'])) { check_admin_referer('shopp-settings-shipping'); $_POST['settings']['order_shipfee'] = Shopp::floatval($_POST['settings']['order_shipfee']); // Recount terms when this setting changes if (isset($_POST['settings']['inventory']) && $_POST['settings']['inventory'] != shopp_setting('inventory')) { $term_recount = true; } shopp_set_formsettings(); $updated = __('Shipping settings saved.', 'Shopp'); } // Handle ship rates UI if ('rates' == $sub && 'on' == shopp_setting('shipping')) { return $this->shiprates(); } if ($term_recount) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } $base = shopp_setting('base_operations'); $regions = Lookup::regions(); $region = $regions[$base['region']]; $useRegions = shopp_setting('shipping_regions'); $areas = Lookup::country_areas(); if (is_array($areas[$base['country']]) && $useRegions == 'on') { $areas = array_keys($areas[$base['country']]); } else { $areas = array($base['country'] => $base['name']); } unset($countries, $regions); $carrierdata = Lookup::shipcarriers(); $serviceareas = array('*', substr($base['country'], 0, 2)); foreach ($carrierdata as $c => $record) { if (!in_array($record->areas, $serviceareas)) { continue; } $carriers[$c] = $record->name; } unset($carrierdata); $shipping_carriers = shopp_setting('shipping_carriers'); if (empty($shipping_carriers)) { $shipping_carriers = array_keys($carriers); } $rates = shopp_setting('shipping_rates'); if (!empty($rates)) { ksort($rates); } $lowstock = shopp_setting('lowstock_level'); if (empty($lowstock)) { $lowstock = 0; } include $this->ui('shipping.php'); }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_defer_term_counting(false); wp_defer_comment_counting(false); wp_cache_flush(); $taxonomies = get_taxonomies(); foreach ($taxonomies as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); $args = array('hide_empty' => 0, 'fields' => 'ids'); $terms = get_terms($tax, $args); if (is_array($terms) && !empty($terms)) { wp_update_term_count_now($terms, $tax); } } do_action('import_end'); }
public function upgrade_120() { // 1.2 schema changes $db_version = ShoppSettings::dbversion(); if ($db_version < 1120) { $this->upschema('schema-120.sql'); } global $wpdb; // Clear the shopping session table $shopping_table = ShoppDatabaseObject::tablename('shopping'); sDB::query("DELETE FROM {$shopping_table}"); if ($db_version <= 1140) { $summary_table = ShoppDatabaseObject::tablename('summary'); // Force summaries to rebuild sDB::query("UPDATE {$summary_table} SET modified='0000-00-00 00:00:01'"); } $purchase_table = ShoppDatabaseObject::tablename('purchase'); sDB::query("UPDATE {$purchase_table} SET txnstatus='captured' WHERE txnstatus='CHARGED'"); sDB::query("UPDATE {$purchase_table} SET txnstatus='voided' WHERE txnstatus='VOID'"); if ($db_version <= 1130) { // Move settings to meta table $meta_table = ShoppDatabaseObject::tablename('meta'); $setting_table = ShoppDatabaseObject::tablename('setting'); sDB::query("INSERT INTO {$meta_table} (context, type, name, value, created, modified) SELECT 'shopp', 'setting', name, value, created, modified FROM {$setting_table}"); // Clean up unnecessary duplicate settings shopp_rmv_setting('data_model'); shopp_rmv_setting('updates'); shopp_rmv_setting('shopp_setup'); shopp_rmv_setting('maintenance'); // Re-load the Shopp settings registry ShoppSettings()->load(); shopp_set_setting('maintenance', 'on'); $db_version = intval(shopp_setting('db_version')); // Force inventory in 1.2 on to mimic 1.1 behavior (inventory tracking always on) shopp_set_setting('inventory', 'on'); // Convert Shopp 1.1.x shipping settings to Shopp 1.2-compatible settings $active_shipping = array(); $regions = Lookup::regions(); $countries = Lookup::countries(); $areas = Lookup::country_areas(); $calcnaming = array('FlatRates::order' => 'OrderRates', 'FlatRates::item' => 'ItemRates', 'FreeOption' => 'FreeOption', 'ItemQuantity::range' => 'ItemQuantity', 'OrderAmount::range' => 'OrderAmount', 'OrderWeight::range' => 'OrderWeight'); $shipping_rates = shopp_setting('shipping_rates'); foreach ((array) $shipping_rates as $id => $old) { if (isset($calcnaming[$old['method']])) { // Add to active setting registry for that calculator class $calcname = $calcnaming[$old['method']]; if (!isset(${$calcname}) && !is_array(${$calcname})) { ${$calcname} = array(); } ${$calcname}[] = true; $active_shipping[$calcname] = ${$calcname}; // Define the setting name $settingid = end(array_keys(${$calcname})); $setting_name = $calcname . '-' . $settingid; } else { // Not a calculator, must be a shipping rate provider module, add it to the active roster $active_shipping[$old['name']] = true; continue; } $new = array(); $new['label'] = $old['name']; list($new['mindelivery'], $new['maxdelivery']) = explode('-', $old['delivery']); $new['fallback'] = 'off'; // Not used in legacy settings $oldkeys = array_keys($old); $old_destinations = array_diff($oldkeys, array('name', 'delivery', 'method', 'max')); $table = array(); foreach ($old_destinations as $old_dest) { $_ = array(); if ('Worldwide' == $old_dest) { $d = '*'; } $region = array_search($old_dest, $regions); if (false !== $region) { $d = "{$region}"; } if (isset($countries[$old_dest])) { $country = $countries[$old_dest]; $region = $country['region']; $d = "{$region}, {$old_dest}"; } foreach ($areas as $countrykey => $countryarea) { $areakeys = array_keys($countryarea); $area = array_search($old_dest, $areakeys); if (false !== $area) { $country = $countrykey; $region = $countries[$countrykey]['region']; $area = $areakeys[$area]; $d = "{$region}, {$country}, {$area}"; break; } } $_['destination'] = $d; $_['postcode'] = '*'; // Postcodes are new in 1.2, hardcode to wildcard if (isset($old['max']) && !empty($old['max'])) { // Capture tiered rates $_['tiers'] = array(); $prior = 1; foreach ($old['max'] as $index => $oldthreshold) { $tier = array('threshold' => 0, 'rate' => 0); if (in_array($oldthreshold, array('+', '>'))) { $tier['threshold'] = $prior + 1; } elseif (1 == $oldthreshold) { $tier['threshold'] = 1; } else { $tier['threshold'] = $prior + 1; } $prior = $oldthreshold; $tier['rate'] = $old[$old_dest][$index]; $_['tiers'][] = $tier; } } else { $_['rate'] = $old[$old_dest][0]; } // Capture flat rates $table[] = $_; } $new['table'] = $table; shopp_set_setting($setting_name, $new); // Save the converted settings } // End foreach($shipping_rates) to convert old shipping calculator setting format shopp_set_setting('active_shipping', $active_shipping); // Save the active shipping options } if ($db_version <= 1121) { $address_table = ShoppDatabaseObject::tablename('address'); $billing_table = ShoppDatabaseObject::tablename('billing'); $shipping_table = ShoppDatabaseObject::tablename('shipping'); // Move billing address data to the address table sDB::query("INSERT INTO {$address_table} (customer, type, address, xaddress, city, state, country, postcode, created, modified)\n\t\t\t\t\t\tSELECT customer, 'billing', address, xaddress, city, state, country, postcode, created, modified FROM {$billing_table}"); sDB::query("INSERT INTO {$address_table} (customer, type, address, xaddress, city, state, country, postcode, created, modified)\n\t\t\t\t\t\tSELECT customer, 'shipping', address, xaddress, city, state, country, postcode, created, modified FROM {$shipping_table}"); } // Migrate to WP custom posts & taxonomies if ($db_version <= 1131) { // Copy products to posts $catalog_table = ShoppDatabaseObject::tablename('catalog'); $product_table = ShoppDatabaseObject::tablename('product'); $price_table = ShoppDatabaseObject::tablename('price'); $summary_table = ShoppDatabaseObject::tablename('summary'); $meta_table = ShoppDatabaseObject::tablename('meta'); $category_table = ShoppDatabaseObject::tablename('category'); $tag_table = ShoppDatabaseObject::tablename('tag'); $purchased_table = ShoppDatabaseObject::tablename('purchased'); $index_table = ShoppDatabaseObject::tablename('index'); $post_type = 'shopp_product'; // Create custom post types from products, temporarily use post_parent for link to original product entry sDB::query("INSERT INTO {$wpdb->posts} (post_type, post_name, post_title, post_excerpt, post_content, post_status, post_date, post_date_gmt, post_modified, post_modified_gmt, post_parent)\n\t\t\t\t\t\t\tSELECT '{$post_type}', slug, name, summary, description, status, created, created, modified, modified, id FROM {$product_table}"); // Update purchased table product column with new Post ID so sold counts can be updated sDB::query("UPDATE {$purchased_table} AS pd JOIN {$wpdb->posts} AS wp ON wp.post_parent=pd.product AND wp.post_type='{$post_type}' SET pd.product=wp.ID"); // Update product links for prices and meta sDB::query("UPDATE {$price_table} AS price JOIN {$wpdb->posts} AS wp ON price.product=wp.post_parent SET price.product=wp.ID WHERE wp.post_type='{$post_type}'"); sDB::query("UPDATE {$meta_table} AS meta JOIN {$wpdb->posts} AS wp ON meta.parent=wp.post_parent AND wp.post_type='{$post_type}' AND meta.context='product' SET meta.parent=wp.ID"); sDB::query("UPDATE {$index_table} AS i JOIN {$wpdb->posts} AS wp ON i.product=wp.post_parent AND wp.post_type='{$post_type}' SET i.product=wp.ID"); // Preliminary summary data sDB::query("INSERT INTO {$summary_table} (product, featured, variants, addons, modified)\n\t\t\t\t\t\t SELECT wp.ID, p.featured, p.variations, p.addons, '0000-00-00 00:00:01'\n\t\t\t\t\t\t FROM {$product_table} AS p\n\t\t\t\t\t\t JOIN {$wpdb->posts} as wp ON p.id=wp.post_parent AND wp.post_type='{$post_type}'"); // Move product options column to meta setting sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value)\n\t\t\t\t\t\tSELECT wp.ID, 'product', 'meta', 'options', options\n\t\t\t\t\t\tFROM {$product_table} AS p\n\t\t\t\t\t\tJOIN {$wpdb->posts} AS wp ON p.id=wp.post_parent AND wp.post_type='{$post_type}'"); // Migrate Shopp categories and tags to WP taxonomies // Are there tag entries in the meta table? Old dev data present use meta table tags. No? use tags table. $dev_migration = $db_version >= 1120; // Copy categories and tags to WP taxonomies $tag_current_table = $dev_migration ? "{$meta_table} WHERE context='catalog' AND type='tag'" : $tag_table; $terms = sDB::query("(SELECT id, 'shopp_category' AS taxonomy, name, parent, description, slug FROM {$category_table})\n\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t(SELECT id, 'shopp_tag' AS taxonomy, name, 0 AS parent, '' AS description, name AS slug FROM {$tag_current_table}) ORDER BY id", 'array'); // Prep category images for the move $category_image_offset = 65535; sDB::query("UPDATE {$meta_table} set parent=parent+{$category_image_offset} WHERE context='category' AND type='image'"); $mapping = array(); $children = array(); $tt_ids = array(); foreach ($terms as $term) { $term_id = (int) $term->id; $taxonomy = $term->taxonomy; if (!isset($mapping[$taxonomy])) { $mapping[$taxonomy] = array(); } if (!isset($children[$taxonomy])) { $children[$taxonomy] = array(); } $name = $term->name; $parent = $term->parent; $description = $term->description; $slug = strpos($term->slug, ' ') === false ? $term->slug : sanitize_title_with_dashes($term->slug); $term_group = 0; if ($exists = sDB::query("SELECT term_id, term_group FROM {$wpdb->terms} WHERE slug = '{$slug}'", 'array')) { $term_group = $exists[0]->term_group; $id = $exists[0]->term_id; $num = 2; do { $alternate = sDB::escape($slug . "-" . $num++); $alternate_used = sDB::query("SELECT slug FROM {$wpdb->terms} WHERE slug='{$alternate}'"); } while ($alternate_used); $slug = $alternate; if (empty($term_group)) { $term_group = sDB::query("SELECT MAX(term_group) AS term_group FROM {$wpdb->terms} GROUP BY term_group", 'auto', 'col', 'term_group'); sDB::query("UPDATE {$wpdb->terms} SET term_group='{$term_group}' WHERE term_id='{$id}'"); } } // Move the term into the terms table $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->terms} (name, slug, term_group) VALUES (%s, %s, %d)", $name, $slug, $term_group)); $mapping[$taxonomy][$term_id] = (int) $wpdb->insert_id; // Map the old id to the new id $term_id = $mapping[$taxonomy][$term_id]; // Update the working id to the new id if (!isset($tt_ids[$taxonomy])) { $tt_ids[$taxonomy] = array(); } if ('shopp_category' == $taxonomy) { // If the parent term has already been added to the terms table, set the new parent id if (isset($mapping[$taxonomy][$parent])) { $parent = $mapping[$taxonomy][$parent]; } else { // Parent hasn't been created, keep track of children for the parent to do a mass update when the parent term record is created if (!isset($children[$taxonomy][$parent])) { $children[$taxonomy][$parent] = array(); } $children[$taxonomy][$parent][] = $term_id; } if (!empty($children[$taxonomy][$term->id])) { // If there are children already created for this term, update their parent to our new id $wpdb->query("UPDATE {$wpdb->term_taxonomy} SET parent={$term_id} WHERE term_id IN (" . join(', ', $children[$taxonomy][$term->id]) . ")"); } // Associate the term to the proper taxonomy and parent terms $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->term_taxonomy} (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, 0)); $tt_ids[$taxonomy][$term_id] = (int) $wpdb->insert_id; if (!empty($term_id)) { // Move category settings to meta $metafields = array('spectemplate', 'facetedmenus', 'variations', 'pricerange', 'priceranges', 'specs', 'options', 'prices'); foreach ($metafields as $field) { sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value)\n\t\t\t\t\t\t\t\t\t\t\tSELECT {$term_id}, 'category', 'meta', '{$field}', {$field}\n\t\t\t\t\t\t\t\t\t\t\tFROM {$category_table}\n\t\t\t\t\t\t\t\t\t\t\tWHERE id={$term->id}"); } // Update category images to new term ids sDB::query("UPDATE {$meta_table} set parent='{$term_id}' WHERE parent='" . ((int) $term->id + $category_image_offset) . "' AND context='category' AND type='image'"); } } if ('shopp_tag' == $taxonomy) { $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->term_taxonomy} (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, 0)); $tt_ids[$taxonomy][$term_id] = (int) $wpdb->insert_id; } } update_option('shopp_category_children', ''); // Re-catalog custom post type_products term relationships (new taxonomical catalog) from old Shopp catalog table $wp_taxonomies = array(0 => 'shopp_category', 1 => 'shopp_tag', 'category' => 'shopp_category', 'tag' => 'shopp_tag'); $cols = 'wp.ID AS product, c.parent, c.type'; $where = "type='category' OR type='tag'"; if ($db_version >= 1125) { $cols = 'wp.ID AS product, c.parent, c.taxonomy, c.type'; $where = "taxonomy=0 OR taxonomy=1"; } $rels = sDB::query("SELECT {$cols} FROM {$catalog_table} AS c LEFT JOIN {$wpdb->posts} AS wp ON c.product=wp.post_parent AND wp.post_type='{$post_type}' WHERE {$where}", 'array'); foreach ((array) $rels as $r) { $object_id = $r->product; $taxonomy = $wp_taxonomies[$db_version >= 1125 ? $r->taxonomy : $r->type]; $term_id = $mapping[$taxonomy][$r->parent]; if (!isset($tt_ids[$taxonomy])) { continue; } if (!isset($tt_ids[$taxonomy][$term_id])) { continue; } $tt_id = $tt_ids[$taxonomy][$term_id]; if (empty($tt_id)) { continue; } sDB::query("INSERT {$wpdb->term_relationships} (object_id, term_taxonomy_id) VALUES ({$object_id}, {$tt_id})"); } if (isset($tt_ids['shopp_category'])) { wp_update_term_count_now($tt_ids['shopp_category'], 'shopp_category'); } if (isset($tt_ids['shopp_tag'])) { wp_update_term_count_now($tt_ids['shopp_tag'], 'shopp_tag'); } // Clear custom post type parents sDB::query("UPDATE {$wpdb->posts} SET post_parent=0 WHERE post_type='{$post_type}'"); } // END if ($db_version <= 1131) if ($db_version <= 1133) { // Ditch old WP pages for pseudorific new ones $search = array(); $shortcodes = array('[catalog]', '[cart]', '[checkout]', '[account]'); foreach ($shortcodes as $string) { $search[] = "post_content LIKE '%{$string}%'"; } $results = sDB::query("SELECT ID, post_title AS title, post_name AS slug, post_content FROM {$wpdb->posts} WHERE post_type='page' AND (" . join(" OR ", $search) . ")", 'array'); $pages = $trash = array(); foreach ($results as $post) { $trash[] = $post->ID; foreach ($shortcodes as $code) { if (strpos($post->post_content, $code) === false) { continue; } $pagename = trim($code, '[]'); $pages[$pagename] = array('title' => $post->title, 'slug' => $post->slug); } // end foreach $shortcodes } // end foreach $results shopp_set_setting('storefront_pages', $pages); sDB::query("UPDATE {$wpdb->posts} SET post_name=CONCAT(post_name, '-deprecated'), post_status='trash' where ID IN (" . join(', ', $trash) . ")"); } // Move needed price table columns to price meta records if ($db_version <= 1135) { $meta_table = ShoppDatabaseObject::tablename('meta'); $price_table = ShoppDatabaseObject::tablename('price'); // Move 'options' to meta 'options' record sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value, created, modified)\n\t\t\t\t\t\tSELECT id, 'price', 'meta', 'options', options, created, modified FROM {$price_table}"); // Merge 'weight', 'dimensions' and 'donation' columns to a price 'settings' record sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value, created, modified)\n\t\t\t\t\t\t\tSELECT id, 'price', 'meta', 'settings',\n\t\t\t\t\t\t\tCONCAT('a:2:{s:10:\"dimensions\";',\n\t\t\t\t\t\t\t\tIF(weight = 0 AND dimensions = '0', 'a:0:{}',\n\t\t\t\t\t\t\t\t\tIF(dimensions = '0',\n\t\t\t\t\t\t\t\t\t\tCONCAT(\n\t\t\t\t\t\t\t\t\t\t\t'a:1:{s:6:\"weight\";s:', CHAR_LENGTH(weight), ':\"', weight, '\";}'\n\t\t\t\t\t\t\t\t\t\t), dimensions\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t), 's:8:\"donation\";', IF(donation='', 'N;', donation), '}'\n\t\t\t\t\t\t\t), created, modified FROM {$price_table}"); } // END if ($db_version <= 1135) if ($db_version <= 1145) { // Update purchase gateway property to use gateway class names // for proper order event handling on 1.1-generated orders $gateways = array('PayPal Standard' => 'PayPalStandard', 'PayPal Expresss' => 'PayPalExpress', 'PayPal Pro' => 'PayPalPro', '2Checkout.com' => '_2Checkout', 'Authorize.Net' => 'AuthorizeNet', 'Google Checkout' => 'GoogleCheckout', 'HSBC ePayments' => 'HSBCepayments', 'iDeal Mollie' => 'iDealMollie', 'Manual Processing' => 'ManualProcessing', 'Merchant Warrior' => 'MerchantWarrior', 'Offline Payment' => 'OfflinePayment', 'PayPal Payflow Pro' => 'PayflowPro', 'Test Mode' => 'TestMode'); foreach ($gateways as $name => $classname) { sDB::query("UPDATE {$purchase_table} SET gateway='{$classname}' WHERE gateway='{$name}'"); } } // END if ($db_version <= 1145) if ($db_version <= 1148) { $price_table = ShoppDatabaseObject::tablename('price'); sDB::query("UPDATE {$price_table} SET optionkey=(options*7001) WHERE context='addon'"); } if ($db_verison <= 1150) { $meta_table = ShoppDatabaseObject::tablename('meta'); sDB::query("DELETE {$meta_table} FROM {$meta_table} LEFT OUTER JOIN (SELECT MAX(id) AS keepid FROM {$meta_table} WHERE context='category' AND type='meta' GROUP BY parent, name) AS keepRowTable ON {$meta_table}.id = keepRowTable.keepid WHERE keepRowTable.keepid IS NULL AND context='category' AND type='meta'"); } }
/** * Renders the shipping settings screen and processes updates * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function shipping() { if (!current_user_can('shopp_settings_shipping')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $sub = 'settings'; $term_recount = false; if (shopp_setting_enabled('shipping')) { $sub = 'rates'; } if (isset($_GET['sub']) && in_array($_GET['sub'], array_keys($this->subscreens))) { $sub = $_GET['sub']; } if (!empty($_POST['save']) && empty($_POST['module'])) { check_admin_referer('shopp-settings-shipping'); $_POST['settings']['order_shipfee'] = Shopp::floatval($_POST['settings']['order_shipfee']); // Recount terms when this setting changes if (isset($_POST['settings']['inventory']) && $_POST['settings']['inventory'] != shopp_setting('inventory')) { $term_recount = true; } shopp_set_formsettings(); $updated = __('Shipping settings saved.', 'Shopp'); } // Handle ship rates UI if ('rates' == $sub && 'on' == shopp_setting('shipping')) { return $this->shiprates(); } if ($term_recount) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } $carrierdata = Lookup::shipcarriers(); $serviceareas = array('*', ShoppBaseLocale()->code()); foreach ($carrierdata as $c => $record) { if (!in_array($record->areas, $serviceareas)) { continue; } $carriers[$c] = $record->name; } unset($carrierdata); $shipping_carriers = shopp_setting('shipping_carriers'); if (empty($shipping_carriers)) { $shipping_carriers = array_keys($carriers); } $imperial = 'imperial' == ShoppBaseLocale()->units(); $weights = $imperial ? array('oz' => Shopp::__('ounces (oz)'), 'lb' => Shopp::__('pounds (lbs)')) : array('g' => Shopp::__('gram (g)'), 'kg' => Shopp::__('kilogram (kg)')); $weightsmenu = menuoptions($weights, shopp_setting('weight_unit'), true); $dimensions = $imperial ? array('in' => Shopp::__('inches (in)'), 'ft' => Shopp::__('feet (ft)')) : array('cm' => Shopp::__('centimeters (cm)'), 'm' => Shopp::__('meters (m)')); $dimsmenu = menuoptions($dimensions, shopp_setting('dimension_unit'), true); $rates = shopp_setting('shipping_rates'); if (!empty($rates)) { ksort($rates); } $lowstock = shopp_setting('lowstock_level'); if (empty($lowstock)) { $lowstock = 0; } include $this->ui('shipping.php'); }
/** * Import the web links categories * * @return int Number of imported categories */ private function import_categories() { $cat_count = 0; $taxonomy = 'link_category'; $this->categories = array(); $categories = $this->plugin->get_component_categories('com_weblinks', 'cl'); if (is_array($categories)) { $terms = array(); foreach ($categories as $category) { $obj_cat = get_term_by('slug', $category['name'], $taxonomy); if ($obj_cat !== false) { $this->categories[$category['name']] = $obj_cat->term_id; continue; // Do not import already imported category } // Insert the category $new_category = array('cat_name' => $category['title'], 'category_description' => $category['description'], 'category_nicename' => $category['name'], 'taxonomy' => $taxonomy); // Hook before inserting the category $new_category = apply_filters('fgj2wp_pre_insert_category', $new_category, $category); $cat_id = wp_insert_category($new_category, true); if (!is_a($cat_id, 'WP_Error')) { $cat_count++; $terms[] = $cat_id; $this->categories[$category['name']] = $cat_id; } else { $this->plugin->display_admin_error(__('Error:', 'fgj2wp') . ' ' . print_r($cat_id, true)); continue; } // Hook after inserting the category do_action('fgj2wp_post_insert_category', $cat_id, $category); } // Update cache if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); $this->plugin->clean_cache($terms); } } return $cat_count; }
/** * Recount the items for a taxonomy * * @return boolean */ private function terms_tax_count($taxonomy) { $terms = get_terms(array($taxonomy)); // Get the term taxonomies $terms_taxonomies = array(); foreach ($terms as $term) { $terms_taxonomies[] = $term->term_taxonomy_id; } if (!empty($terms_taxonomies)) { return wp_update_term_count_now($terms_taxonomies, $taxonomy); } else { return true; } }
/** * Bulk insert rows into the term_relationships table * @param array List of post IDs (or oother object IDs) * @param array List of term IDs * @param mixed WP taxonomy object * @return bool Success of insert */ function assign_terms($object_ids = array(), $term_taxonomy_ids = array(), $taxonomy = false) { global $wpdb; if (empty($object_ids) || empty($term_taxonomy_ids) || empty($taxonomy)) { return false; } $wpdb->query("SET unique_checks=0"); // Insert the the relationships from post_ids => $defaults $query = "INSERT INTO `{$wpdb->term_relationships}` (\n object_id, term_taxonomy_id\n ) VALUES"; foreach ($term_taxonomy_ids as $term_taxonomy_id) { foreach ($object_ids as $object_id) { $query .= $wpdb->prepare("(%d, %d),", $object_id, $term_taxonomy_id); } } $query = rtrim($query, ','); $a = $wpdb->query($query); // Commit the changes $wpdb->query("SET unique_checks=1"); // Update the "total" count for each term that was affected wp_update_term_count_now($term_taxonomy_ids, $taxonomy->name); return true; }