/** * 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'); }
public static function register_post_types() { if (post_type_exists('food_menu')) { return; } do_action('restaurantpress_register_post_type'); register_post_type('food_menu', apply_filters('restaurantpress_register_post_type_food_menu', array('labels' => array('name' => __('Menu Items', 'restaurantpress'), 'singular_name' => __('Menu Item', 'restaurantpress'), 'menu_name' => _x('Menu Items', 'Admin menu name', 'restaurantpress'), 'all_items' => __('All Menu Items', 'restaurantpress'), 'add_new' => __('Add Menu Item', 'restaurantpress'), 'add_new_item' => __('Add New Menu Item', 'restaurantpress'), 'edit' => __('Edit', 'restaurantpress'), 'edit_item' => __('Edit Menu Item', 'restaurantpress'), 'new_item' => __('New Menu Item', 'restaurantpress'), 'view' => __('View Menu Item', 'restaurantpress'), 'view_item' => __('View Menu Item', 'restaurantpress'), 'search_items' => __('Search Menu Items', 'restaurantpress'), 'not_found' => __('No Menu Items found', 'restaurantpress'), 'not_found_in_trash' => __('No Menu Items found in trash', 'restaurantpress'), 'parent' => __('Parent Menu Item', 'restaurantpress'), 'featured_image' => __('Menu Item Image', 'restaurantpress'), 'set_featured_image' => __('Set menu image', 'restaurantpress'), 'remove_featured_image' => __('Remove menu image', 'restaurantpress'), 'use_featured_image' => __('Use as menu image', 'restaurantpress')), 'description' => __('This is where you can add new menu items to your restaurant.', 'restaurantpress'), 'public' => true, 'show_ui' => true, 'capability_type' => 'food_menu', 'map_meta_cap' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'hierarchical' => false, 'query_var' => true, 'rewrite' => array('slug' => 'menu-item', 'with_front' => false, 'feeds' => true), 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'publicize', 'wpcom-markdown'), 'has_archive' => true, 'show_in_nav_menus' => true))); register_post_type('food_group', apply_filters('restaurantpress_register_post_type_food_group', array('labels' => array('name' => __('Groups', 'restaurantpress'), 'singular_name' => __('Group', 'restaurantpress'), 'menu_name' => _x('Groups', 'Admin menu name', 'restaurantpress'), 'add_new' => __('Add Group', 'restaurantpress'), 'add_new_item' => __('Add New Group', 'restaurantpress'), 'edit' => __('Edit', 'restaurantpress'), 'edit_item' => __('Edit Group', 'restaurantpress'), 'new_item' => __('New Group', 'restaurantpress'), 'view' => __('View Groups', 'restaurantpress'), 'view_item' => __('View Group', 'restaurantpress'), 'search_items' => __('Search Groups', 'restaurantpress'), 'not_found' => __('No Groups found', 'restaurantpress'), 'not_found_in_trash' => __('No Groups found in trash', 'restaurantpress'), 'parent' => __('Parent Group', 'restaurantpress')), 'description' => __('This is where you can add new group for your food menu.', 'restaurantpress'), 'public' => false, 'show_ui' => true, 'capability_type' => 'food_group', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => current_user_can('manage_restaurantpress') ? 'restaurantpress' : true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title'), 'show_in_nav_menus' => false, 'show_in_admin_bar' => true))); } /** * Add Menu Items Support to Jetpack Omnisearch. */ public static function support_jetpack_omnisearch() { if (class_exists('Jetpack_Omnisearch_Posts')) { new Jetpack_Omnisearch_Posts('food_menu'); } } /** * Added Menu Items for Jetpack related posts. * @param array $post_types * @return array */ public static function rest_api_allowed_post_types($post_types) { $post_types[] = 'food_menu'; return $post_types; } } RP_Post_Types::init();