/** * Install WC */ public static function install() { global $wpdb; if (!defined('WC_CRM_INSTALLING')) { define('WC_CRM_INSTALLING', true); } // Ensure needed classes are loaded include_once 'admin/class-wc-crm-admin-notices.php'; // Queue upgrades/setup wizard $current_wc_crm_version = get_option(WC_CRM_TOKEN . '_version', null); $current_db_version = get_option(WC_CRM_TOKEN . '_db_version', null); $major_wc_version = substr(WC_CRM()->_version, 0, strrpos(WC_CRM()->_version, '.')); $major_cur_version = substr($current_wc_crm_version, 0, strrpos($current_wc_crm_version, '.')); if (!is_null($current_wc_crm_version) && version_compare($major_cur_version, $major_wc_version, '>')) { self::remove_tables(); } self::create_tables(); self::create_roles(); WC_CRM_Admin_Notices::remove_all_notices(); // No versions? This is a new install :) if (is_null($current_wc_crm_version) && is_null($current_db_version) && apply_filters('wc_crm_enable_setup_wizard', true)) { WC_CRM_Admin_Notices::add_notice('crm_install'); set_transient('_wc_crm_activation_redirect', 1, 30); } elseif (!is_null($current_wc_crm_version) && version_compare($major_cur_version, $major_wc_version, '>')) { WC_CRM_Admin_Notices::add_notice('crm_install'); set_transient('_wc_crm_activation_redirect', 1, 30); $current_db_version = '2.6.0'; self::update_db_version($current_db_version); // No customers? Let user run wizard again.. } elseif (!get_option('wc_crm_customers_loaded')) { WC_CRM_Admin_Notices::add_notice('crm_install'); // Show welcome screen for major updates only } elseif (version_compare($current_wc_crm_version, $major_wc_version, '<')) { set_transient('_wc_crm_activation_redirect', 1, 30); } if (!is_null($current_db_version) && version_compare($current_db_version, max(array_keys(self::$db_updates)), '<')) { WC_CRM_Admin_Notices::add_notice('crm_update'); } else { self::update_db_version(); } self::update_crm_version(); /* * Deletes all expired transients. The multi-table delete syntax is used * to delete the transient record from table a, and the corresponding * transient_timeout record from table b. * * Based on code inside core's upgrade_network() function. */ $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\tAND b.option_value < %d"; $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time())); // Trigger action do_action('wc_crm_installed'); }
/** * Final step */ public function wc_crm_setup_ready() { WC_CRM_Admin_Notices::remove_notice('crm_install'); update_option('wc_crm_customers_loaded', 'yes'); ?> <h1><?php _e('WooCommerce CRM is Ready!', 'wc_crm'); ?> </h1> <div class="wc-setup-next-steps"> <div class="wc-setup-next-steps-first"> <h2><?php _e('Next Steps', 'wc_crm'); ?> </h2> <ul> <li class="setup-product"><a class="button button-primary button-large" href="<?php echo esc_url(admin_url('admin.php?page=' . WC_CRM_TOKEN)); ?> "><?php _e('View your customers!', 'wc_crm'); ?> </a></li> </ul> </div> <div class="wc-setup-next-steps-last"> <h2><?php _e('Learn More', 'wc_crm'); ?> </h2> <ul> <li class="newsletter"><a href="http://eepurl.com/Ybb5j" target="_blank"><?php _e('Subscribe to our newlsetter', 'wc_crm'); ?> </a></li> <li class="learn-more"><a href="http://actualityextensions.com/documentation/" target="_blank"><?php _e('Read more about getting started', 'wc_crm'); ?> </a></li> <li class="shop-more"><a href="http://codecanyon.net/user/actualityextensions/portfolio/" target="_blank"><?php _e('Explore our other powerful extensions', 'wc_crm'); ?> </a></li> </ul> </div> </div> <?php }
<?php /** * Admin View: Notice - Update */ if (!defined('ABSPATH')) { exit; } if (!WC_CRM_Admin_Notices::has_notice('crm_install')) { ?> <div id="message" class="updated"> <p><?php _e('<strong>WooCommerce CRM Data Update Required</strong> – We just need to update your install to the latest version', 'wc_crm'); ?> </p> <p class="submit"><a href="<?php echo esc_url(add_query_arg('do_update_wc_crm', 'true', admin_url('admin.php?page=' . WC_CRM_TOKEN . '-settings'))); ?> " class="wc-update-now button-primary"><?php _e('Run the updater', 'woocommerce'); ?> </a></p> </div> <script type="text/javascript"> jQuery( '.wc-update-now' ).click( 'click', function() { return window.confirm( '<?php echo esc_js(__('It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'woocommerce')); ?> ' ); }); </script>
/** * Handle redirects to setup/welcome page after install and updates. * * Transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters. */ public function admin_redirects() { if (!get_transient('_wc_crm_activation_redirect') || is_network_admin() || isset($_GET['activate-multi']) || !current_user_can('manage_woocommerce')) { return; } delete_transient('_wc_crm_activation_redirect'); if (!empty($_GET['page']) && in_array($_GET['page'], array(WC_CRM_TOKEN . '-setup', WC_CRM_TOKEN . '-about'))) { return; } if (defined('DOING_AJAX') && DOING_AJAX) { return; } // If the user needs to install, send them to the setup wizard if (WC_CRM_Admin_Notices::has_notice('crm_install')) { wp_safe_redirect(admin_url('index.php?page=' . WC_CRM_TOKEN . '-setup')); exit; // Otherwise, the welcome page } else { wp_safe_redirect(admin_url('index.php?page=' . WC_CRM_TOKEN . '-about')); exit; } }