/** * Install RP. */ public static function install() { global $wpdb; if (!defined('RP_INSTALLING')) { define('RP_INSTALLING', true); } // Ensure needed classes are loaded include_once 'admin/class-rp-admin-notices.php'; self::create_options(); self::create_tables(); self::create_roles(); // Register post types RP_Post_Types::register_post_types(); RP_Post_Types::register_taxonomies(); // Queue upgrades/setup wizard $current_rp_version = get_option('restaurantpress_version', null); $current_db_version = get_option('restaurantpress_db_version', null); $major_rp_version = substr(RP()->version, 0, strrpos(RP()->version, '.')); RP_Admin_Notices::remove_all_notices(); // No versions? This is a new install :) if (is_null($current_rp_version) && is_null($current_db_version) && apply_filters('restaurantpress_enable_setup_wizard', true)) { $has_food_items = get_posts(array('post_type' => array('food_menu', 'food_group'), 'posts_per_page' => -1, 'post_status' => 'publish', 'fields' => 'ids')); // Yes food? Let user run updater. if (!empty($has_food_items)) { RP_Admin_Notices::add_notice('update'); } } if (!is_null($current_db_version) && version_compare($current_db_version, max(array_keys(self::$db_updates)), '<')) { RP_Admin_Notices::add_notice('update'); } else { self::update_db_version(); } self::update_rp_version(); // Flush rules after install flush_rewrite_rules(); /* * 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('restaurantpress_installed'); }