/** * Runs the installer. * * @access public * @return void */ function do_install_woocommerce() { global $woocommerce_settings, $woocommerce; // Do install woocommerce_default_options(); woocommerce_tables_install(); woocommerce_init_roles(); // Register post types $woocommerce->init_taxonomy(); // Add default taxonomies woocommerce_default_taxonomies(); // Cron jobs wp_clear_scheduled_hook('woocommerce_scheduled_sales'); wp_clear_scheduled_hook('woocommerce_cancel_unpaid_orders'); wp_clear_scheduled_hook('woocommerce_cleanup_sessions'); $ve = get_option('gmt_offset') > 0 ? '+' : '-'; wp_schedule_event(strtotime('tomorrow ' . $ve . get_option('gmt_offset') . ' HOURS'), 'daily', 'woocommerce_scheduled_sales'); $held_duration = get_option('woocommerce_hold_stock_minutes', null); if (is_null($held_duration)) { $held_duration = '60'; } if ($held_duration != '') { wp_schedule_single_event(time() + absint($held_duration) * 60, 'woocommerce_cancel_unpaid_orders'); } wp_schedule_event(time(), 'twicedaily', 'woocommerce_cleanup_sessions'); // Install files and folders for uploading files and prevent hotlinking $upload_dir = wp_upload_dir(); $files = array(array('base' => $upload_dir['basedir'] . '/woocommerce_uploads', 'file' => '.htaccess', 'content' => 'deny from all'), array('base' => $upload_dir['basedir'] . '/woocommerce_uploads', 'file' => 'index.html', 'content' => ''), array('base' => WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs', 'file' => '.htaccess', 'content' => 'deny from all'), array('base' => WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs', 'file' => 'index.html', 'content' => '')); foreach ($files as $file) { if (wp_mkdir_p($file['base']) && !file_exists(trailingslashit($file['base']) . $file['file'])) { if ($file_handle = @fopen(trailingslashit($file['base']) . $file['file'], 'w')) { fwrite($file_handle, $file['content']); fclose($file_handle); } } } // Clear transient cache $woocommerce->clear_product_transients(); // Recompile LESS styles if they are custom if (get_option('woocommerce_frontend_css') == 'yes') { $colors = get_option('woocommerce_frontend_css_colors'); if (!empty($colors['primary']) && !empty($colors['secondary']) && !empty($colors['highlight']) && !empty($colors['content_bg']) && !empty($colors['subtext']) && ($colors['primary'] != '#ad74a2' || $colors['secondary'] != '#f7f6f7' || $colors['highlight'] != '#85ad74' || $colors['content_bg'] != '#ffffff' || $colors['subtext'] != '#777777')) { woocommerce_compile_less_styles(); } } // Queue upgrades $current_version = get_option('woocommerce_version', null); $current_db_version = get_option('woocommerce_db_version', null); if (version_compare($current_db_version, '2.0.9', '<') && null !== $current_db_version) { update_option('_wc_needs_update', 1); } else { update_option('woocommerce_db_version', $woocommerce->version); } // Update version update_option('woocommerce_version', $woocommerce->version); // Flush rewrite rules flush_rewrite_rules(); }
/** * woocommerce_status_tools function. * * @access public * @return void */ function woocommerce_status_tools() { global $woocommerce, $wpdb; $tools = apply_filters('woocommerce_debug_tools', array('clear_transients' => array('name' => __('WC Transients', 'woocommerce'), 'button' => __('Clear transients', 'woocommerce'), 'desc' => __('This tool will clear the product/shop transients cache.', 'woocommerce')), 'clear_expired_transients' => array('name' => __('Expired Transients', 'woocommerce'), 'button' => __('Clear expired transients', 'woocommerce'), 'desc' => __('This tool will clear ALL expired transients from Wordpress.', 'woocommerce')), 'recount_terms' => array('name' => __('Term counts', 'woocommerce'), 'button' => __('Recount terms', 'woocommerce'), 'desc' => __('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce')), 'reset_roles' => array('name' => __('Capabilities', 'woocommerce'), 'button' => __('Reset capabilities', 'woocommerce'), 'desc' => __('This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce')), 'clear_sessions' => array('name' => __('Customer Sessions', 'woocommerce'), 'button' => __('Clear all sessions', 'woocommerce'), 'desc' => __('<strong class="red">Warning</strong> This tool will delete all customer session data from the database, including any current live carts.', 'woocommerce')))); if (!empty($_GET['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'debug_action')) { switch ($_GET['action']) { case "clear_transients": $woocommerce->clear_product_transients(); echo '<div class="updated"><p>' . __('Product Transients Cleared', 'woocommerce') . '</p></div>'; break; case "clear_expired_transients": // http://w-shadow.com/blog/2012/04/17/delete-stale-transients/ $rows = $wpdb->query("\n\t\t\t\t\tDELETE\n\t\t\t\t\t\ta, b\n\t\t\t\t\tFROM\n\t\t\t\t\t\t{$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ta.option_name LIKE '_transient_%' AND\n\t\t\t\t\t\ta.option_name NOT LIKE '_transient_timeout_%' AND\n\t\t\t\t\t\tb.option_name = CONCAT(\n\t\t\t\t\t\t\t'_transient_timeout_',\n\t\t\t\t\t\t\tSUBSTRING(\n\t\t\t\t\t\t\t\ta.option_name,\n\t\t\t\t\t\t\t\tCHAR_LENGTH('_transient_') + 1\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND b.option_value < UNIX_TIMESTAMP()\n\t\t\t\t"); $rows2 = $wpdb->query("\n\t\t\t\t\tDELETE\n\t\t\t\t\t\ta, b\n\t\t\t\t\tFROM\n\t\t\t\t\t\t{$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ta.option_name LIKE '_site_transient_%' AND\n\t\t\t\t\t\ta.option_name NOT LIKE '_site_transient_timeout_%' AND\n\t\t\t\t\t\tb.option_name = CONCAT(\n\t\t\t\t\t\t\t'_site_transient_timeout_',\n\t\t\t\t\t\t\tSUBSTRING(\n\t\t\t\t\t\t\t\ta.option_name,\n\t\t\t\t\t\t\t\tCHAR_LENGTH('_site_transient_') + 1\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND b.option_value < UNIX_TIMESTAMP()\n\t\t\t\t"); echo '<div class="updated"><p>' . sprintf(__('%d Transients Rows Cleared', 'woocommerce'), $rows + $rows2) . '</p></div>'; break; case "reset_roles": // Remove then re-add caps and roles woocommerce_remove_roles(); woocommerce_init_roles(); echo '<div class="updated"><p>' . __('Roles successfully reset', 'woocommerce') . '</p></div>'; break; case "recount_terms": $product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent')); _woocommerce_term_recount($product_cats, get_taxonomy('product_cat'), false, false); $product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent')); _woocommerce_term_recount($product_cats, get_taxonomy('product_tag'), false, false); echo '<div class="updated"><p>' . __('Terms successfully recounted', 'woocommerce') . '</p></div>'; break; case "clear_sessions": $wpdb->query("\n\t\t\t\t\tDELETE FROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%'\n\t\t\t\t"); wp_cache_flush(); break; default: $action = esc_attr($_GET['action']); if (isset($tools[$action]['callback'])) { $callback = $tools[$action]['callback']; $return = call_user_func($callback); if ($return === false) { if (is_array($callback)) { echo '<div class="error"><p>' . sprintf(__('There was an error calling %s::%s', 'woocommerce'), get_class($callback[0]), $callback[1]) . '</p></div>'; } else { echo '<div class="error"><p>' . sprintf(__('There was an error calling %s', 'woocommerce'), $callback) . '</p></div>'; } } } } } ?> <table class="wc_status_table widefat" cellspacing="0"> <thead class="tools"> <tr> <th colspan="2"><?php _e('Tools', 'woocommerce'); ?> </th> </tr> </thead> <tbody class="tools"> <?php foreach ($tools as $action => $tool) { ?> <tr> <td><?php echo esc_html($tool['name']); ?> </td> <td> <p> <a href="<?php echo wp_nonce_url(admin_url('admin.php?page=woocommerce_status&tab=tools&action=' . $action), 'debug_action'); ?> " class="button"><?php echo esc_html($tool['button']); ?> </a> <span class="description"><?php echo wp_kses_post($tool['desc']); ?> </span> </p> </td> </tr> <?php } ?> </tbody> </table> <?php }