function woo_ce_return_count( $export_type = '', $args = array() ) { global $wpdb; $count_sql = null; $woocommerce_version = woo_get_woo_version(); switch( $export_type ) { case 'product': $post_type = array( 'product', 'product_variation' ); $args = array( 'post_type' => $post_type, 'posts_per_page' => 1, 'fields' => 'ids', 'suppress_filters' => 1 ); $count_query = new WP_Query( $args ); $count = $count_query->found_posts; break; case 'category': $term_taxonomy = 'product_cat'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'tag': $term_taxonomy = 'product_tag'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'brand': $term_taxonomy = apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' ); if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'order': $post_type = 'shop_order'; // Check if this is a WooCommerce 2.2+ instance (new Post Status) if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) $post_status = ( function_exists( 'wc_get_order_statuses' ) ? apply_filters( 'woo_ce_order_post_status', array_keys( wc_get_order_statuses() ) ) : 'any' ); else $post_status = apply_filters( 'woo_ce_order_post_status', woo_ce_post_statuses() ); $args = array( 'post_type' => $post_type, 'posts_per_page' => 1, 'post_status' => $post_status, 'fields' => 'ids' ); $count_query = new WP_Query( $args ); $count = $count_query->found_posts; break; case 'customer': if( $users = woo_ce_return_count( 'user' ) > 1000 ) { $count = sprintf( '~%s+', 1000 ); } else { $post_type = 'shop_order'; $args = array( 'post_type' => $post_type, 'posts_per_page' => -1, 'fields' => 'ids' ); // Check if this is a WooCommerce 2.2+ instance (new Post Status) if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) { $args['post_status'] = apply_filters( 'woo_ce_customer_post_status', array( 'wc-pending', 'wc-on-hold', 'wc-processing', 'wc-completed' ) ); } else { $args['post_status'] = apply_filters( 'woo_ce_customer_post_status', woo_ce_post_statuses() ); $args['tax_query'] = array( array( 'taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array( 'pending', 'on-hold', 'processing', 'completed' ) ), ); } $order_ids = new WP_Query( $args ); $count = $order_ids->found_posts; if( $count > 100 ) { $count = sprintf( '~%s', $count ); } else { $customers = array(); if( $order_ids->posts ) { foreach( $order_ids->posts as $order_id ) { $email = get_post_meta( $order_id, '_billing_email', true ); if( !in_array( $email, $customers ) ) $customers[$order_id] = $email; unset( $email ); } $count = count( $customers ); } } } /* if( false ) { $orders = get_posts( $args ); if( $orders ) { $customers = array(); foreach( $orders as $order ) { $order->email = get_post_meta( $order->ID, '_billing_email', true ); if( empty( $order->email ) ) { if( $order->user_id = get_post_meta( $order->ID, '_customer_user', true ) ) { $user = get_userdata( $order->user_id ); if( $user ) $order->email = $user->user_email; unset( $user ); } else { $order->email = '-'; } } if( !in_array( $order->email, $customers ) ) { $customers[$order->ID] = $order->email; $count++; } } unset( $orders, $order ); } } */ break; case 'user': if( $users = count_users() ) $count = $users['total_users']; break; case 'coupon': $post_type = 'shop_coupon'; if( post_type_exists( $post_type ) ) $count = wp_count_posts( $post_type ); break; case 'subscription': $count = 0; // Check that WooCommerce Subscriptions exists if( class_exists( 'WC_Subscriptions' ) ) { if( method_exists( 'WC_Subscriptions', 'is_large_site' ) ) { // Does this store have roughly more than 3000 Subscriptions if( false === WC_Subscriptions::is_large_site() ) { if( class_exists( 'WC_Subscriptions_Manager' ) ) { // Check that the get_all_users_subscriptions() function exists if( method_exists( 'WC_Subscriptions_Manager', 'get_all_users_subscriptions' ) ) { if( $subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions() ) { foreach( $subscriptions as $key => $user_subscription ) { if( !empty( $user_subscription ) ) { foreach( $user_subscription as $subscription ) $count++; } } unset( $subscriptions, $subscription, $user_subscription ); } } } } else { if( method_exists( 'WC_Subscriptions', 'get_total_subscription_count' ) ) $count = WC_Subscriptions::get_total_subscription_count(); else $count = "~2500"; } } } break; case 'product_vendor': $term_taxonomy = 'shop_vendor'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'commission': $post_type = 'shop_commission'; if( post_type_exists( $post_type ) ) $count = wp_count_posts( $post_type ); break; case 'shipping_class': $term_taxonomy = 'product_shipping_class'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'attribute': $attributes = ( function_exists( 'wc_get_attribute_taxonomies' ) ? wc_get_attribute_taxonomies() : array() ); $count = count( $attributes ); break; } if( isset( $count ) || $count_sql ) { if( isset( $count ) ) { if( is_object( $count ) ) { $count = (array)$count; $count = (int)array_sum( $count ); } return $count; } else { if( $count_sql ) $count = $wpdb->get_var( $count_sql ); else $count = 0; } return $count; } else { return 0; } }
/** * Let the site administrator know we are upgrading the database and provide a confirmation is complete. * * This is important to avoid the possibility of a database not upgrading correctly, but the site continuing * to function without any remedy. * * @since 1.2 */ public static function display_database_upgrade_helper() { global $woocommerce; wp_register_style('wcs-upgrade', plugins_url('/css/wcs-upgrade.css', WC_Subscriptions::$plugin_file)); wp_register_script('wcs-upgrade', plugins_url('/js/wcs-upgrade.js', WC_Subscriptions::$plugin_file), 'jquery'); $script_data = array('really_old_version' => version_compare(self::$active_version, '1.4', '<') ? 'true' : 'false', 'hooks_per_request' => self::$upgrade_limit, 'ajax_url' => admin_url('admin-ajax.php')); wp_localize_script('wcs-upgrade', 'wcs_update_script_data', $script_data); // Can't get subscription count with database structure < 1.4 if ('false' == $script_data['really_old_version']) { $subscription_count = WC_Subscriptions::get_total_subscription_count(); $estimated_duration = ceil($subscription_count / 500); } @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?> > <head> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?> ; charset=<?php echo get_option('blog_charset'); ?> " /> <title><?php _e('WooCommerce Subscriptions Update', 'woocommerce-subscriptions'); ?> </title> <?php wp_admin_css('install', true); ?> <?php wp_admin_css('ie', true); ?> <?php wp_print_styles('wcs-upgrade'); ?> <?php wp_print_scripts('jquery'); ?> <?php wp_print_scripts('wcs-upgrade'); ?> </head> <body class="wp-core-ui"> <h1 id="logo"><img alt="WooCommerce Subscriptions" width="325px" height="120px" src="<?php echo plugins_url('images/woocommerce_subscriptions_logo.png', WC_Subscriptions::$plugin_file); ?> " /></h1> <div id="update-welcome"> <h2><?php _e('Database Update Required', 'woocommerce-subscriptions'); ?> </h2> <p><?php _e('The WooCommerce Subscriptions plugin has been updated!', 'woocommerce-subscriptions'); ?> </p> <p><?php _e('Before we send you on your way, we need to update your database to the newest version. If you do not have a recent backup of your site, now is a good time to create one.', 'woocommerce-subscriptions'); ?> </p> <p><?php _e('The update process may take a little while, so please be patient.', 'woocommerce-subscriptions'); ?> </p> <form id="subscriptions-upgrade" method="get" action="<?php echo admin_url('admin.php'); ?> "> <input type="submit" class="button" value="<?php _e('Update Database', 'woocommerce-subscriptions'); ?> "> </form> </div> <div id="update-messages"> <h2><?php _e('Update in Progress', 'woocommerce-subscriptions'); ?> </h2> <?php if ('false' == $script_data['really_old_version']) { ?> <p><?php printf(__('The full update process for the %s subscriptions on your site will take approximately %s to %s minutes.', 'woocommerce-subscriptions'), $subscription_count, $estimated_duration, $estimated_duration * 2); ?> </p> <?php } ?> <p><?php _e('This page will display the results of the process as each batch of subscriptions is updated. No need to refresh or restart the process. Customers and other non-administrative users will continue to be able to browse your site without interuption while the update is in progress.', 'woocommerce-subscriptions'); ?> </p> <ol> </ol> <img id="update-ajax-loader" alt="loading..." width="16px" height="16px" src="<?php echo plugins_url('images/ajax-loader@2x.gif', WC_Subscriptions::$plugin_file); ?> " /> </div> <div id="update-complete"> <h2><?php _e('Update Complete', 'woocommerce-subscriptions'); ?> </h2> <p><?php _e('Your database has been successfully updated!', 'woocommerce-subscriptions'); ?> </p> <p class="step"><a class="button" href="<?php echo esc_url(self::$about_page_url); ?> "><?php _e('Continue', 'woocommerce-subscriptions'); ?> </a></p> </div> <div id="update-error"> <h2><?php _e('Update Error', 'woocommerce-subscriptions'); ?> </h2> <p><?php _e('There was an error with the update. Please refresh the page and try again.', 'woocommerce-subscriptions'); ?> </p> </div> </body> </html> <?php }