예제 #1
0
 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':
                 delete_transient('jigoshop_addons_data');
                 delete_transient('jigoshop_report_coupon_usage');
                 delete_transient('jigoshop_report_customer_list');
                 delete_transient('jigoshop_report_customers');
                 delete_transient('jigoshop_report_low_in_stock');
                 delete_transient('jigoshop_report_most_stocked');
                 delete_transient('jigoshop_report_out_of_stock');
                 delete_transient('jigoshop_report_sales_by_category');
                 delete_transient('jigoshop_report_sales_by_date');
                 delete_transient('jigoshop_report_sales_by_product');
                 delete_transient('jigoshop_widget_cache');
                 $query = new WP_User_Query(array('fields' => 'ids'));
                 $users = $query->get_results();
                 foreach ($users as $user) {
                     delete_transient('jigo_usercart_' . $user);
                 }
                 echo '<div class="updated"><p>' . __('Jigoshop transients cleared', 'jigoshop') . '</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\t\tDELETE\n\t\t\t\t\t\t\ta, b\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t{$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ta.option_name LIKE '_transient_%' AND\n\t\t\t\t\t\t\ta.option_name NOT LIKE '_transient_timeout_%' AND\n\t\t\t\t\t\t\tb.option_name = CONCAT(\n\t\t\t\t\t\t\t\t'_transient_timeout_',\n\t\t\t\t\t\t\t\tSUBSTRING(\n\t\t\t\t\t\t\t\t\ta.option_name,\n\t\t\t\t\t\t\t\t\tCHAR_LENGTH('_transient_') + 1\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tAND b.option_value < UNIX_TIMESTAMP()\n\t\t\t\t\t");
                 $rows2 = $wpdb->query("\n\t\t\t\t\t\tDELETE\n\t\t\t\t\t\t\ta, b\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t{$wpdb->options} a, {$wpdb->options} b\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ta.option_name LIKE '_site_transient_%' AND\n\t\t\t\t\t\t\ta.option_name NOT LIKE '_site_transient_timeout_%' AND\n\t\t\t\t\t\t\tb.option_name = CONCAT(\n\t\t\t\t\t\t\t\t'_site_transient_timeout_',\n\t\t\t\t\t\t\t\tSUBSTRING(\n\t\t\t\t\t\t\t\t\ta.option_name,\n\t\t\t\t\t\t\t\t\tCHAR_LENGTH('_site_transient_') + 1\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tAND b.option_value < UNIX_TIMESTAMP()\n\t\t\t\t\t");
                 echo '<div class="updated"><p>' . sprintf(__('%d transients rows cleared', 'jigoshop'), $rows + $rows2) . '</p></div>';
                 break;
             case 'reset_roles':
                 // Remove then re-add caps and roles
                 /** @var $wp_roles WP_Roles */
                 global $wp_roles;
                 $capabilities = jigoshop_get_core_capabilities();
                 foreach ($capabilities as $cap_group) {
                     foreach ($cap_group as $cap) {
                         $wp_roles->remove_cap('administrator', $cap);
                         $wp_roles->remove_cap('shop_manager', $cap);
                     }
                 }
                 remove_role('customer');
                 remove_role('shop_manager');
                 // Add roles back
                 jigoshop_roles_init();
                 echo '<div class="updated"><p>' . __('Roles successfully reset', 'jigoshop') . '</p></div>';
                 break;
             case 'recount_terms':
                 $product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent'));
                 _update_post_term_count($product_cats, get_taxonomy('product_cat'));
                 $product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent'));
                 _update_post_term_count($product_tags, get_taxonomy('product_tag'));
                 echo '<div class="updated"><p>' . __('Terms successfully recounted', 'jigoshop') . '</p></div>';
                 break;
             case 'delete_taxes':
                 $options = Jigoshop_Base::get_options();
                 $options->set('jigoshop_tax_rates', '');
                 $options->update_options();
                 echo '<div class="updated"><p>' . __('Tax rates successfully deleted', 'jigoshop') . '</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) {
                         if (is_array($callback)) {
                             echo '<div class="error"><p>' . sprintf(__('There was an error calling %s::%s', 'jigoshop'), get_class($callback[0]), $callback[1]) . '</p></div>';
                         } else {
                             echo '<div class="error"><p>' . sprintf(__('There was an error calling %s', 'jigoshop'), $callback) . '</p></div>';
                         }
                     }
                 }
                 break;
         }
     }
     // Display message if settings settings have been saved
     if (isset($_REQUEST['settings-updated'])) {
         echo '<div class="updated"><p>' . __('Your changes have been saved.', 'jigoshop') . '</p></div>';
     }
     $template = jigoshop_locate_template('admin/status/tools');
     /** @noinspection PhpIncludeInspection */
     include $template;
 }
예제 #2
0
function jigoshop_init()
{
    // Override default translations with custom .mo's found in wp-content/languages/jigoshop first.
    load_textdomain('jigoshop', WP_LANG_DIR . '/jigoshop/jigoshop-' . get_locale() . '.mo');
    load_plugin_textdomain('jigoshop', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'jigoshop_admin_bar_links');
    do_action('before_jigoshop_init');
    // instantiate options -after- loading text domains
    $options = Jigoshop_Base::get_options();
    jigoshop_post_type();
    // register taxonomies
    new jigoshop_cron();
    // -after- text domains and Options instantiation allows settings translations
    jigoshop_set_image_sizes();
    // called -after- our Options are loaded
    // add Singletons here so that the taxonomies are loaded before calling them.
    jigoshop_session::instance();
    // Start sessions if they aren't already
    jigoshop::instance();
    // Utility functions, uses sessions
    jigoshop_customer::instance();
    // Customer class, sorts session data such as location
    // Jigoshop will instantiate gateways and shipping methods on this same 'init' action hook
    // with a very low priority to ensure text domains are loaded first prior to installing any external options
    jigoshop_shipping::instance();
    // Shipping class. loads shipping methods
    jigoshop_payment_gateways::instance();
    // Payment gateways class. loads payment methods
    jigoshop_cart::instance();
    // Cart class, uses sessions
    add_filter('mce_external_plugins', 'jigoshop_register_shortcode_editor');
    add_filter('mce_buttons', 'jigoshop_register_shortcode_buttons');
    if (!is_admin()) {
        /* Catalog Filters */
        add_filter('loop-shop-query', create_function('', 'return array("orderby" => "' . $options->get('jigoshop_catalog_sort_orderby') . '","order" => "' . $options->get('jigoshop_catalog_sort_direction') . '");'));
        add_filter('loop_shop_columns', create_function('', 'return ' . $options->get('jigoshop_catalog_columns') . ';'));
        add_filter('loop_shop_per_page', create_function('', 'return ' . $options->get('jigoshop_catalog_per_page') . ';'));
        jigoshop_catalog_query::instance();
        // front end queries class
        jigoshop_request_api::instance();
        // front end request api for URL's
    }
    jigoshop_roles_init();
    do_action('jigoshop_initialize_plugins');
}