Ejemplo n.º 1
0
function fflcommerce_roles_init()
{
    global $wp_roles;
    if (class_exists('WP_Roles')) {
        if (!isset($wp_roles)) {
            $wp_roles = new WP_Roles();
        }
    }
    if (is_object($wp_roles)) {
        // Customer role
        add_role('customer', __('Customer', 'fflcommerce'), array('read' => true, 'edit_posts' => false, 'delete_posts' => false));
        // Shop manager role
        add_role('shop_manager', __('Shop Manager', 'fflcommerce'), array('read' => true, 'read_private_pages' => true, 'read_private_posts' => true, 'edit_users' => true, 'edit_posts' => true, 'edit_pages' => true, 'edit_published_posts' => true, 'edit_published_pages' => true, 'edit_private_pages' => true, 'edit_private_posts' => true, 'edit_others_posts' => true, 'edit_others_pages' => true, 'publish_posts' => true, 'publish_pages' => true, 'delete_posts' => true, 'delete_pages' => true, 'delete_private_pages' => true, 'delete_private_posts' => true, 'delete_published_pages' => true, 'delete_published_posts' => true, 'delete_others_posts' => true, 'delete_others_pages' => true, 'manage_categories' => true, 'manage_links' => true, 'moderate_comments' => true, 'unfiltered_html' => true, 'upload_files' => true, 'export' => true, 'import' => true));
        $capabilities = fflcommerce_get_core_capabilities();
        foreach ($capabilities as $cap_group) {
            foreach ($cap_group as $cap) {
                $wp_roles->add_cap('administrator', $cap);
                $wp_roles->add_cap('shop_manager', $cap);
            }
        }
    }
}
 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('fflcommerce_addons_data');
                 delete_transient('fflcommerce_report_coupon_usage');
                 delete_transient('fflcommerce_report_customer_list');
                 delete_transient('fflcommerce_report_customers');
                 delete_transient('fflcommerce_report_low_in_stock');
                 delete_transient('fflcommerce_report_most_stocked');
                 delete_transient('fflcommerce_report_out_of_stock');
                 delete_transient('fflcommerce_report_sales_by_category');
                 delete_transient('fflcommerce_report_sales_by_date');
                 delete_transient('fflcommerce_report_sales_by_product');
                 delete_transient('fflcommerce_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>' . __('FFL Commerce transients cleared', 'fflcommerce') . '</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', 'fflcommerce'), $rows + $rows2) . '</p></div>';
                 break;
             case 'reset_roles':
                 // Remove then re-add caps and roles
                 /** @var $wp_roles WP_Roles */
                 global $wp_roles;
                 $capabilities = fflcommerce_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
                 fflcommerce_roles_init();
                 echo '<div class="updated"><p>' . __('Roles successfully reset', 'fflcommerce') . '</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', 'fflcommerce') . '</p></div>';
                 break;
             case 'delete_taxes':
                 $options = FFLCommerce_Base::get_options();
                 $options->set('fflcommerce_tax_rates', '');
                 $options->update_options();
                 echo '<div class="updated"><p>' . __('Tax rates successfully deleted', 'fflcommerce') . '</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', 'fflcommerce'), get_class($callback[0]), $callback[1]) . '</p></div>';
                         } else {
                             echo '<div class="error"><p>' . sprintf(__('There was an error calling %s', 'fflcommerce'), $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.', 'fflcommerce') . '</p></div>';
     }
     $template = fflcommerce_locate_template('admin/status/tools');
     /** @noinspection PhpIncludeInspection */
     include $template;
 }