public function import() { global $wf; $base_dir = MASTERPRESS_TMP_DIR; $base_url = MASTERPRESS_TMP_URL; $restore = false; if (isset($_POST["import_masterplan"])) { $masterplan = $_POST["import_masterplan"]; } else { if (isset($_POST["restore_masterplan"])) { $masterplan = $_POST["restore_masterplan"]; $base_dir = MASTERPRESS_CONTENT_MASTERPLANS_DIR; $base_url = MASTERPRESS_CONTENT_MASTERPLANS_URL; $restore = true; } } $view = MasterPress::$view; if (isset($masterplan)) { extract(self::open_masterplan($masterplan, true, $base_dir, $base_url)); if ($rep) { $icon_dest = MASTERPRESS_CONTENT_MENU_ICONS_DIR; $icon_src = $dir.WOOF_DIR_SEP."icons".WOOF_DIR_SEP; $field_type_dest = MASTERPRESS_EXTENSIONS_FIELD_TYPES_DIR; $field_type_src = $dir.WOOF_DIR_SEP."field-types".WOOF_DIR_SEP; // install field type extensions foreach ($field_types as $field_type) { $dest = $field_type_dest.$field_type["name"]; $src = $field_type_src.$field_type["name"]; if (!(file_exists($dest) && !isset($_POST["import_types_overwrite"]))) { MPU::copyr($src, $dest); } } $info = array("log" => array()); $mode = $_REQUEST["import_mode"]; if ($restore) { $mode = "replace"; } $log = &$info["log"]; $backup = isset($_REQUEST["import_backup"]); $view->rep = $rep; $view->backup = $backup; $view->mode = $mode; // first obtain the current representation $current = self::get_current_rep(); $view->current = $current; if ($backup) { // build the backup (a rollback point) $backup_filename = "_backup.pre-import.".$wf->format_date("[date-time-sortable]").".masterplan.zip"; $backup_readme = "# Backup Masterplan for ".$wf->sites()->first()->name." # + Created: ".$wf->format_date("[date-time-long]"); $backup_rep = $this->export_rep($current); $package = $this->build_package($backup_rep, $backup_filename, $backup_readme); if ($package) { $info["backup_package"] = $package; $info["backup_url"] = MASTERPRESS_CONTENT_MASTERPLANS_URL.$backup_filename; $info["backup_filename"] = $backup_filename; } } // process the representation // store all objects by key to look them up for potential removal (if mode is replace) $import = array( "post_types" => array(), "taxonomies" => array(), "shared_field_sets" => array(), "site_field_sets" => array(), "templates" => array(), "roles" => array() ); $taxonomies_by_key = array(); $shared_field_sets_by_key = array(); $shared_field_sets_by_key = array(); if (isset($rep["post_types"])) { foreach ($rep["post_types"] as $post_type) { $data = $post_type; unset($data["field_sets"], $data["id"], $data["sites"]); $name = $post_type["name"]; $insert = true; if ($model = MPM_PostType::find_by_name($name)) { $insert = false; } else { $model = new MPM_PostType(); } $model->set($data, true); if ($insert) { $model->insert(); } else { $model->update(); } // install icons if ($post_type["_builtin"] == "0" && !is_null($post_type["menu_icon"]) && $post_type["menu_icon"] != "") { copy($icon_src.$post_type["menu_icon"], $icon_dest.$post_type["menu_icon"]); } $import["post_types"][$name] = $post_type; // now run through the field sets, taking care to preserve $import["post_types"][$name]["field_sets"] = self::import_field_sets($post_type["field_sets"], " AND `type` = 'p' AND ".MPM::visibility_rlike("post_types", $name), $dir); } } if (isset($rep["taxonomies"])) { foreach ($rep["taxonomies"] as $tax) { $data = $tax; unset($data["field_sets"], $data["id"], $data["sites"]); $name = $tax["name"]; $insert = true; if ($model = MPM_Taxonomy::find_by_name($name)) { $insert = false; } else { $model = new MPM_Taxonomy(); } $model->set($data, true); if ($insert) { $model->insert(); } else { $model->update(); } // install icons if ($tax["_builtin"] == "0" && !is_null($tax["title_icon"]) && $tax["title_icon"] != "") { copy($icon_src.$tax["title_icon"], $icon_dest.$tax["title_icon"]); } $import["taxonomies"][$name] = $tax; $import["taxonomies"][$name]["field_sets"] = self::import_field_sets($tax["field_sets"], " AND `type` = 'x' AND ".MPM::visibility_rlike("taxonomies", $name), $dir); } } if (isset($rep["shared_field_sets"])) { $import["shared_field_sets"] = self::import_field_sets($rep["shared_field_sets"], " AND `type` = 's' ", $dir); } if (isset($rep["site_field_sets"])) { $import["site_field_sets"] = self::import_field_sets($rep["site_field_sets"], " AND `type` = 'w' ", $dir); } if (isset($rep["templates"])) { foreach ($rep["templates"] as $template) { $id = $template["id"]; // template models are self-creating, so no need for special handling here $model = MPM_Template::find_by_id($id); $data = $template; unset($data["field_sets"]); $model->set($data, true); $model->update(); $import["templates"][$id] = $template; if (isset($template["field_sets"])) { $import["templates"][$id]["field_sets"] = self::import_field_sets($template["field_sets"], " AND `type` = 't' AND ".MPM::visibility_rlike("templates", $id), $dir); } } } if (isset($rep["roles"])) { foreach ($rep["roles"] as $role) { if (isset($role["field_sets"])) { $name = $role["name"]; $import["roles"][$name] = $role; $import["roles"][$name]["field_sets"] = self::import_field_sets($role["field_sets"], " AND `type` = 'r' AND ".MPM::visibility_rlike("roles", $name), $dir); } } } if ($mode == "replace") { // we now need to remove anything in the current setup that ISN'T in the imported masterplan if (isset($current["post_types"])) { foreach ($current["post_types"] as $post_type) { $name = $post_type["name"]; $builtin = $post_type["_builtin"] == "1"; if (!isset($import["post_types"][$name]) && !$builtin) { $model = MPM_PostType::find_by_name($name); if ($model) { $model->delete( array( "posts" => "leave", "posts_reassign_type" => "", "field_sets" => "delete", "field_data" => "keep" )); } } else { if (isset($post_type["field_sets"])) { self::replace_field_sets($post_type["field_sets"], $import["post_types"][$name]["field_sets"]); } } } } if (isset($current["taxonomies"])) { foreach ($current["taxonomies"] as $tax) { $name = $tax["name"]; $builtin = $tax["_builtin"] == "1"; if (!isset($import["taxonomies"][$name]) && !$builtin) { $model = MPM_Taxonomy::find_by_name($name); if ($model) { $model->delete( array( "existing_terms" => "leave", "existing_terms_reassign_taxonomy" => "", "field_sets" => "delete", "field_data" => "leave" )); } } else { if (isset($tax["field_sets"])) { self::replace_field_sets($tax["field_sets"], $import["taxonomies"][$name]["field_sets"]); } } } } if (isset($current["shared_field_sets"])) { self::replace_field_sets($current["shared_field_sets"], $import["shared_field_sets"]); } if (isset($current["site_field_sets"])) { self::replace_field_sets($current["site_field_sets"], $import["site_field_sets"]); } if (isset($current["templates"])) { foreach ($current["templates"] as $template) { $id = $template["id"]; if (isset($import["templates"][$id])) { if (isset($template["field_sets"])) { self::replace_field_sets($template["field_sets"], $import["templates"][$id]["field_sets"]); } } } } if (isset($current["roles"])) { foreach ($current["roles"] as $name => $role) { if (isset($import["roles"][$name])) { if (isset($role["field_sets"])) { self::replace_field_sets($role["field_sets"], $import["roles"][$name]["field_sets"]); } } } } } // mode = replace // cleanup the unzipped folder MPU::rmdir_r($dir); if ($restore) { wp_redirect( MasterPress::admin_url( $this->key(), "manage", array("restore-complete" => "1"), false ) ); } else { wp_redirect( MasterPress::admin_url( $this->key(), "manage", array("import-complete" => "1"), false ) ); } $view->info = $info; } else { self::ajax_error(__("The Masterplan is no longer valid. Please try another file", MASTERPRESS_DOMAIN)); } } else { self::ajax_error(__("The Masterplan is no longer valid. Please try another file", MASTERPRESS_DOMAIN)); } }
public static function init() { global $meow_provider; load_plugin_textdomain( MASTERPRESS_DOMAIN, false, "masterpress/languages" ); do_action("mp_pre_init"); self::$cap_mode = get_site_option("mp_cap", "standard"); global $wf; global $wpdb; $snp = explode("/", $_SERVER["SCRIPT_NAME"]); self::$script = basename($snp[count($snp) - 1], ".php"); // Register useful libraries separately, so they may be used by themes if (WP_DEBUG || MASTERPRESS_DEBUG) { // legacy picturefill wp_register_script('mp-matchmedia', MASTERPRESS_URL.'js/src/matchmedia.js', array(), MASTERPRESS_VERSION); wp_register_script('mp-picturefill', MASTERPRESS_URL.'js/src/picturefill.js', array('jquery', 'mp-matchmedia'), MASTERPRESS_VERSION); wp_register_script('jquery-imageload', MASTERPRESS_URL.'js/src/jquery.imageload.js', array('jquery'), MASTERPRESS_VERSION); // new jQuery picturefill wp_register_script('jquery-picturefill', MASTERPRESS_URL.'js/src/jquery.picturefill.js', array('jquery', 'jquery-imageload'), MASTERPRESS_VERSION); wp_register_script('jquery-lazyload', MASTERPRESS_URL.'js/src/jquery.lazyload.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('jquery-fancybox', MASTERPRESS_URL.'js/src/jquery.fancybox-1.3.4.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('jquery-scroll-to', MASTERPRESS_URL.'js/src/jquery.scroll-to.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('jquery-metadata', MASTERPRESS_URL.'js/src/jquery.metadata.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('select2', MASTERPRESS_URL.'js/src/select2.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('codemirror', MASTERPRESS_URL.'js/src/codemirror.js', array(), MASTERPRESS_VERSION); wp_register_script('codemirror-modes', MASTERPRESS_URL.'js/codemirror.modes.min.js', array(), MASTERPRESS_VERSION); wp_register_script('mediaelement', MASTERPRESS_URL.'js/src/mediaelement-and-player.js', array(), MASTERPRESS_VERSION); wp_register_script('handlebars', MASTERPRESS_URL.'js/src/handlebars-1.0.0.beta.6.js', array(), MASTERPRESS_VERSION); wp_register_script('inflection', MASTERPRESS_URL.'js/src/inflection.js', array(), MASTERPRESS_VERSION); wp_register_script('date-js', MASTERPRESS_URL.'js/src/date.js', array(), MASTERPRESS_VERSION); wp_register_script('mp-iris', MASTERPRESS_URL.'js/src/iris.js', array('jquery', "jquery-ui-core", "jquery-ui-widget"), MASTERPRESS_VERSION); } else { // legacy picturefill (not enqueued) wp_register_script('mp-matchmedia', MASTERPRESS_URL.'js/matchmedia.min.js', array(), MASTERPRESS_VERSION); wp_register_script('mp-picturefill', MASTERPRESS_URL.'js/picturefill.min.js', array('jquery', 'mp-matchmedia'), MASTERPRESS_VERSION); wp_register_script('jquery-imageload', MASTERPRESS_URL.'js/jquery.imageload.min.js', array('jquery'), MASTERPRESS_VERSION); // new jQuery picturefill wp_register_script('jquery-picturefill', MASTERPRESS_URL.'js/jquery.picturefill.min.js', array('jquery', 'jquery-imageload'), MASTERPRESS_VERSION); wp_register_script('jquery-lazyload', MASTERPRESS_URL.'js/jquery.lazyload.min.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('jquery-fancybox', MASTERPRESS_URL.'js/jquery.fancybox-1.3.4.min.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('jquery-scroll-to', MASTERPRESS_URL.'js/jquery.scroll-to.min.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('jquery-metadata', MASTERPRESS_URL.'js/jquery.metadata.min.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('select2', MASTERPRESS_URL.'js/select2.min.js', array('jquery'), MASTERPRESS_VERSION); wp_register_script('date-js', MASTERPRESS_URL.'js/date.min.js', array(), MASTERPRESS_VERSION); wp_register_script('mediaelement', MASTERPRESS_URL.'js/mediaelement-and-player.min.js', array(), MASTERPRESS_VERSION); wp_register_script('codemirror', MASTERPRESS_URL.'js/codemirror.min.js', array(), MASTERPRESS_VERSION); wp_register_script('codemirror-modes', MASTERPRESS_URL.'js/codemirror.modes.min.js', array(), MASTERPRESS_VERSION); wp_register_script('handlebars', MASTERPRESS_URL.'js/handlebars-1.0.0.beta.6.min.js', array(), MASTERPRESS_VERSION); wp_register_script('inflection', MASTERPRESS_URL.'js/inflection.min.js', array(), MASTERPRESS_VERSION); if (!self::has_iris()) { wp_register_script('mp-iris', MASTERPRESS_URL.'js/iris.min.js', array('jquery', "jquery-ui-core", "jquery-ui-widget"), MASTERPRESS_VERSION); } } wp_register_style('jquery-fancybox', MASTERPRESS_URL.'css/fancybox.css', array(), MASTERPRESS_VERSION); wp_register_style('select2', MASTERPRESS_URL.'css/select2.css', array(), MASTERPRESS_VERSION); wp_register_style('codemirror', MASTERPRESS_URL.'css/codemirror.css', array(), MASTERPRESS_VERSION); wp_register_style('codemirror-themes', MASTERPRESS_URL.'css/codemirror.themes.min.css', array(), MASTERPRESS_VERSION); wp_register_style('mediaelement', MASTERPRESS_URL.'css/mediaelementplayer.min.css', array(), MASTERPRESS_VERSION); if ( is_admin() ) { // run an upgrade (if required) MasterPress::upgrade(); if (defined('MASTERPRESS_NO_UPLOAD_DIR')) { MPV::err( sprintf( __( "<b>Important: </b>When trying to determine the location of your uploads directory, WordPress reported the following error: <code>%s</code>That is, your WordPress installation <b>does not currently contain a writable uploads directory</b>, so MasterPress will not function correctly as it cannot create its own required sub-folders.<br>To avoid further problems, you must correct this before creating or editing anything with MasterPress.<br>", MASTERPRESS_DOMAIN ), MASTERPRESS_NO_UPLOAD_DIR ) ); } else { self::create_directories(); } add_action('admin_menu', array('MasterPress', 'admin_menu')); wp_enqueue_script("jquery-lazyload"); wp_enqueue_script("jquery-imageload"); wp_enqueue_script("jquery-picturefill"); // Add filters for specific screens if (self::$script == "options-reading") { add_filter( 'get_pages', array("MasterPress", 'add_front_page_supports' ) ); } if (self::is_user_editor()) { add_filter( 'mce_external_plugins', array( "MasterPress", 'mce_plugins' ) ); MPC::incl("user"); add_action( 'show_user_profile', array("MPC_User", "field_sets" )); add_action( 'edit_user_profile', array("MPC_User", "field_sets" )); } if (self::is_term_editor() || self::is_term_manage()) { MPC::incl("term"); if (isset($_GET["taxonomy"])) { $taxonomy = $_GET["taxonomy"]; } } if (self::is_term_editor()) { add_filter( 'mce_external_plugins', array( "MasterPress", 'mce_plugins' ) ); // add field UI hook add_action( $taxonomy."_edit_form_fields", array("MPC_Term", "field_sets"), 10, 2 ); } if (self::is_term_manage()) { add_filter( 'mce_external_plugins', array( "MasterPress", 'mce_plugins' ) ); // add field UI hook add_action( $taxonomy."_add_form_fields", array("MPC_Term", "field_sets"), 10, 2 ); } if (self::is_site_content_editor()) { MPV::incl("meta"); MPC::incl("meta"); add_filter( 'mce_external_plugins', array( "MasterPress", 'mce_plugins' ) ); } if (self::is_post_editor()) { add_filter( 'mce_external_plugins', array( "MasterPress", 'mce_plugins' ) ); add_action('add_meta_boxes', array('MPC_Post', 'post_editor_meta_boxes')); add_action('admin_init', array('MasterPress', 'admin_init')); } if (self::is_post_manage()) { add_filter("manage_posts_columns", array("MPC_Post", "define_post_columns")); add_filter("manage_pages_columns", array("MPC_Post", "define_post_columns")); add_action("manage_posts_custom_column", array("MPC_Post", "post_column_content")); add_action("manage_pages_custom_column", array("MPC_Post", "post_column_content")); add_filter('parse_query', array("MPC_Post", "filter_manage_posts")); add_filter('request', array("MPC_Post", "request")); $meow_provider->set_optimize_mode( "post_list" ); } // add save hooks add_action('edited_term', array("MPC_Meta", 'save_term_meta') ); add_action('created_term', array("MPC_Meta", 'save_term_meta') ); add_action('save_post', array("MPC_Meta", 'save_post_meta')); add_action('personal_options_update', array("MPC_Meta", 'save_user_meta')); add_action('edit_user_profile_update', array("MPC_Meta", 'save_user_meta')); add_action('save_post', array("MasterPress", 'save_post')); // add inline scripts add_action("admin_head", array("MasterPress", "inline_scripts")); add_action("admin_head", array("MasterPress", "inline_styles")); add_action("admin_head", array("MasterPress", "inline_meta")); } // cache the list of all post types $args = array(); if (is_admin()) { // only order by menu positions in the admin, as the order doesn't matter on the front-end (slightly faster) $args = array("orderby" => "menu_position,menu_sub_position"); } $post_types = MPM_PostType::find($args); MasterPress::$post_types = array(); foreach ($post_types as $post_type) { MasterPress::$post_types[$post_type->name] = $post_type; } $taxonomies = MPM_Taxonomy::find( ); MasterPress::$all_taxonomies = array(); MasterPress::$taxonomies = array(); foreach ($taxonomies as $tax) { if (!$tax->disabled) { MasterPress::$taxonomies[$tax->name] = $tax; } MasterPress::$all_taxonomies[$tax->name] = $tax; } // create necessary file directories if (is_admin()) { $combine = false; // check for a querystring force if (isset($_GET["mpft"])) { $combine = true; } // check if debug mode had been switched on, then off (javascript "make" still needs to be run manually) $opt_debug = get_option("mp_debug"); if (!MASTERPRESS_DEBUG && $opt_debug != MASTERPRESS_DEBUG) { $combine = true; } if ($opt_debug != MASTERPRESS_DEBUG) { update_option("mp_debug", MASTERPRESS_DEBUG); } if (!file_exists(MASTERPRESS_CONTENT_MPFT_CACHE_DIR."mpft-all.css")) { $combine = true; } if (!file_exists(MASTERPRESS_CONTENT_MPFT_CACHE_DIR."mpft-all.js")) { $combine = true; } if ($combine) { MPU::combine_type_styles(); MPU::combine_type_scripts(); } } if (self::is_term_manage()) { MPC::incl("term"); add_filter('get_terms_args', array("MPC_Term", "filter_manage_terms")); foreach (MasterPress::$taxonomies as $tax) { add_filter('manage_edit-'.$tax->name.'_columns', array("MPC_Term", "define_term_columns")); add_action('manage_'.$tax->name.'_custom_column', array("MPC_Term", "term_column_content"), 10, 3); } } // register post types based on database entries do_action('mp_pre_register_post_types'); self::register_post_types(); do_action('mp_register_post_types'); // register taxonomies based on database entries do_action('mp_pre_register_taxonomies'); self::register_taxonomies(); do_action('mp_pre_register_taxonomies'); // patch template support self::register_template_support(); do_action('mp_register'); // look for externally defined post types, and insert models for them in MasterPress. $reg_post_types = $wf->post_types(); $rpt_keys = array(); $pt_keys = array(); foreach ($reg_post_types as $rpt) { if (!is_woof_silent($rpt)) { $rpt_keys[$rpt->name] = $rpt; } } foreach ($post_types as $pt) { $pt_keys[$pt->name] = $pt; } $ignore_keys = array("revision", "nav_menu_item"); foreach ($rpt_keys as $key => $pt) { if (!isset($pt_keys[$key]) && !in_array($key, $ignore_keys)) { // create an external post type database entry $ept = new MPM_PostType(); // ensure that unknown properties return "null", not "WOOF_Silent" $pt->set_property_mode("standard"); $ept->set( array( "name" => $pt->name, "plural_name" => WOOF_Inflector::pluralize($pt->name), "disabled" => false, "labels" => $pt->labels, "description" => "", "publicly_queryable" => (bool) $pt->publicly_queryable, "exclude_from_search" => (bool) $pt->exclude_from_search, "show_ui" => (bool) $pt->show_ui, "show_in_menu" => (bool) $pt->show_in_menu, "menu_position" => (int) $pt->menu_position, "menu_sub_position" => 0, "menu_icon" => isset($pt->menu_icon) ? $pt->menu_icon : "", "manage_sort_order" => "post_date|desc", "capability_type" => $pt->capability_type, "capabilities" => $pt->cap_array(), "map_meta_cap" => (bool) $pt->map_meta_cap, "hierarchical" => (bool) $pt->hierarchical, "supports" => implode(",", $pt->supports_keys()), "permalink_epmask" => $pt->permalink_epmask, "has_archive" => (bool) $pt->has_archive, "rewrite" => $pt->rewrite, "query_var" => $pt->query_var, "can_export" => $pt->can_export, "show_in_nav_menus" => $pt->show_in_nav_menus, "_builtin" => false, "_external" => true, "visibility" => array("sites" => "*") ) ); $ept->insert(); } } // look for externally defined taxonomies, and insert models for them in MasterPress. $reg_tax = $wf->taxonomies(); $rt_keys = array(); $t_keys = array(); foreach ($reg_tax as $tax) { $rt_keys[$tax->name] = $tax; } foreach ($taxonomies as $tax) { $t_keys[$tax->name] = $tax; } $ignore_keys = array("nav_menu", "link_category", "post_format"); foreach ($rt_keys as $key => $tax) { if (!isset($t_keys[$key]) && !in_array($key, $ignore_keys)) { // create an external post type database entry $et = new MPM_Taxonomy(); // ensure that unknown properties return "null", not "WOOF_Silent" $tax->set_property_mode("standard"); $et->set( array( "name" => $tax->name, "plural_name" => WOOF_Inflector::pluralize($tax->name), "labels" => $tax->labels, "disabled" => false, "show_in_nav_menus" => (bool) $tax->show_in_nav_menus, "show_ui" => (bool) $tax->show_ui, "show_tagcloud" => (bool) $tax->show_tagcloud, "hierarchical" => (bool) $tax->hierarchical, "rewrite" => $tax->rewrite, "update_count_callback" => $tax->update_count_callback, "query_var" => $tax->query_var, "capabilities" => $tax->cap_array(), "object_type" => $tax->object_type, "_builtin" => false, "_external" => true ) ); $et->insert(); } } if (is_admin()) { self::dispatch(); } foreach ($wf->types() as $type) { if ($type->supports("top-level-slugs")) { add_filter("woof_".$type->name."_permalink", array("MasterPress", "woof_permalink"), 100, 2); } } // if anyone rewrites URLs, add ours to the queue add_filter( 'rewrite_rules_array', array("MasterPress", 'add_rewrite_rules' )); do_action('mp_rewrite_rules'); do_action('mp_pre_flush_rewrite_rules'); add_rewrite_tag("%mp_rest_endpoint%", '([^&]+)'); if (is_admin()) { // flush rewrite rules (only if marked as needed) MasterPress::flush_rewrite_rules(); } if (is_admin() && MasterPress::current_user_can("manage_mp_tools")) { self::tools_actions(); } do_action('mp_init'); }
public function submit() { global $wpdb; $action = MasterPress::$action; if ($action == "create" || $action == "edit") { $builtin = $_POST["_builtin"] == "true"; $external = $_POST["_external"] == "true"; if ($builtin) { $post_type = MPM_PostType::find_by_name($_POST["name"]); $post_type->supports = implode(",", $_POST["supports"]); $post_type->disabled = isset($_POST["disabled"]); $post_type->visibility = $this->get_visibility_val("sites"); $post_type->columns = $_POST["columns"]; $post_type->labels = $_POST["labels"]; $post_type->menu_icon = self::handle_icon("menu_icon", "menu_icon_select"); if ($_POST["name"] == "page" && $post_type->menu_icon == "") { $post_type->menu_icon = "menu-icon-pages.png"; // restore default icon } if ($_POST["name"] == "post" && $post_type->menu_icon == "") { $post_type->menu_icon = "menu-icon-posts.png"; // restore default icon } if ($action == "edit") { $post_type->update(MasterPress::$id); } } else if ($external) { $post_type = MPM_PostType::find_by_name($_POST["name"]); $post_type->columns = $_POST["columns"]; $post_type->menu_icon = self::handle_icon("menu_icon", "menu_icon_select"); if ($action == "edit") { $post_type->update(MasterPress::$id); } } else { $post_type = new MPM_PostType(true); // consume the post data $post_type->name = $_POST["name"]; $post_type->plural_name = $_POST["plural_name"]; $post_type->disabled = isset($_POST["disabled"]); $post_type->labels = $_POST["labels"]; $post_type->description = $_POST["description"]; $post_type->publicly_queryable = isset($_POST["publicly_queryable"]); $post_type->exclude_from_search = isset($_POST["exclude_from_search"]); $post_type->show_ui = isset($_POST["show_ui"]); $post_type->show_in_menu = isset($_POST["show_in_menu"]); $post_type->hierarchical = isset($_POST["hierarchical"]); $post_type->menu_position = $_POST["menu_position"]; $post_type->menu_sub_position = $_POST["menu_sub_position"]; $post_type->menu_icon = self::handle_icon("menu_icon", "menu_icon_select"); $post_type->manage_sort_order = $_POST["manage_sort_order"]; $cap_type = $_POST["capability_type"]; if ($cap_type == "specific") { $post_type->capability_type = $_POST["name"]; } else if ($cap_type == "custom" && trim($_POST["capability_type_custom_value"]) != "") { $post_type->capability_type = $_POST["capability_type_custom_value"]; } else { $post_type->capability_type = $cap_type; } $post_type->capabilities = MPC::post_val("capabilities"); $post_type->map_meta_cap = isset($_POST["map_meta_cap"]); $post_type->hierarchical = isset($_POST["hierarchical"]); $post_type->supports = MPC::post_implode_val("supports"); $post_type->permalink_epmask = $_POST["permalink_epmask"]; $post_type->has_archive = isset($_POST["has_archive"]); $post_type->visibility = $this->get_visibility_val("sites,post_types"); $post_type->show_in_menu = isset($_POST["show_in_menu"]); $rewrite = array( "slug" => $_POST["rewrite"]["slug"], "with_front" => isset($_POST["rewrite"]["with_front"]), "feeds" => isset($_POST["rewrite"]["feeds"]) ); $post_type->rewrite = $rewrite; $post_type->query_var = $_POST["query_var"]; $post_type->can_export = isset($_POST["can_export"]); $post_type->show_in_nav_menus = isset($_POST["show_in_nav_menus"]); $post_type->_builtin = false; $post_type->_external = $_POST["_external"] == "true"; $post_type->columns = $_POST["columns"]; if ($action == "create") { $post_type->insert(); } else if ($action == "edit") { $post_type->update(MasterPress::$id); if ($post_type->is_valid()) { global $meow_provider; $meow_provider->migrate_post_type($post_type, $_POST["name_original"]); } } } if ($post_type->is_valid() && !$external) { // auto-generate a sprite icon MPU::create_icon_sprite($post_type->menu_icon, "", true); // attach any taxonomies and shared field sets $post_type->unlink_taxonomies(); if (MPC::post_val("taxonomies") != "" && count(MPC::post_val("taxonomies"))) { $post_type->link_taxonomies( MPM_Taxonomy::find_by_name_in( $_POST["taxonomies"] ) ); } // update the menu positions of other post types $omp = MPC::post_val("other_menu_position"); $omsp = MPC::post_val("other_menu_sub_position"); if (isset($omp) && is_array($omp)) { foreach ($omp as $name => $position) { $wpdb->update(MPM::table("post-types"), array( "menu_position" => $position, "menu_sub_position" => $omsp[$name] ), array( "name" => $name ), "%d", "%s" ); } } MasterPress::flag_for_rewrite(); } return $post_type; } else if ($action == "delete") { $pt = MPM_PostType::find_by_id(MasterPress::$id); $pt->delete( array( "posts" => $_POST["posts"], "posts_reassign_type" => $_POST["posts_reassign_type"], "field_sets" => $_POST["field_sets"], "field_data" => $_POST["field_data"] ) ); MasterPress::flag_for_rewrite(); return true; } else if ($action == "create-field-set" || $action == "edit-field-set") { $field_set = new MPM_FieldSet(); // consume the post data $field_set->name = $_POST["name"]; $field_set->singular_name = $_POST["singular_name"]; $field_set->disabled = isset($_POST["disabled"]); $field_set->labels = $_POST["labels"]; $field_set->allow_multiple = isset($_POST["allow_multiple"]); $field_set->visibility = $_POST["visibility"]; $field_set->capabilities = self::handle_capabilities(); $field_set->type = "p"; // p = shared $field_set->position = $_POST["position"]; $field_set->icon = self::handle_icon("icon", "icon_select"); $field_set->expanded = isset($_POST["expanded"]); $field_set->sidebar = isset($_POST["sidebar"]); $field_set->versions = $_POST["versions"]; $field_set->visibility = $this->get_visibility_val("sites,templates,post_types"); $post_type = MPM_PostType::find_by_id(MasterPress::$parent); // inform the validation of the post type $field_set->meta("post_type", $post_type); if (MPC::is_create()) { $field_set->insert(); } else if (MPC::is_edit()) { $field_set->update(MasterPress::$id); } if ($field_set->is_valid()) { if (MPC::is_edit()) { global $meow_provider; $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]); } // update other menu positions if (isset($_POST["other_position"])) { $op = $_POST["other_position"]; if (isset($op) && is_array($op)) { foreach ($op as $id => $position) { $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); } } } } return $field_set; } else if ($action == "delete-field-set") { $fg = MPM_FieldSet::find_by_id(MasterPress::$id); if ($fg) { $field_data_action = $_POST["field_data"]; if ($field_data_action == "delete") { $fg->delete_meta(); } } $fg->delete(); return true; } else if ($action == "delete-field") { $f = MPM_Field::find_by_id(MasterPress::$id); if ($f) { $field_data_action = $_POST["field_data"]; if ($field_data_action == "delete") { $f->delete_meta(); } } $f->delete(); return true; } else if ($action == "create-field" || $action == "edit-field") { // FIELD OPERATIONS (NOT FIELD GROUPS!) $field = new MPM_Field(); // consume the post data $field->field_set_id = $_POST["parent"]; $field->name = $_POST["name"]; $field->disabled = isset($_POST["disabled"]); $field->summary_options = $_POST["summary_options"]; $field->required = isset($_POST["required"]); $field->labels = $_POST["labels"]; $field->type = $_POST["type"]; $field->icon = self::handle_icon("icon", "icon_select"); if (isset($_POST["type_options"])) { $field->type_options = $_POST["type_options"]; } $field->position = $_POST["position"]; $field->visibility = $this->get_visibility_val("sites,templates,post_types"); $field->capabilities = self::handle_capabilities(); $fg = MPM_FieldSet::find_by_id($_POST["parent"]); if (MPC::is_create()) { $field->insert(); } else if (MPC::is_edit()) { $field->update(MasterPress::$id); } if ($field->is_valid()) { // update other menu positions if (MPC::is_edit()) { global $meow_provider; $meow_provider->migrate_field_meta($field, $_POST["name_original"]); } if (isset($_POST["other_position"])) { $op = $_POST["other_position"]; if (isset($op) && is_array($op)) { foreach ($op as $id => $position) { $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); } } } } return $field; } return false; }
public static function insert_builtin() { // add the appropriate built-in post types (page and post) if required // we'll ignore menu item, attachment, and revision since there's no MasterPress tweaks applicable to those $post_type_post = MPM_PostType::find_by_name("post"); if (!$post_type_post) { $post_type_post = new MPM_PostType(); $post_type_post->set( array( "name" => "post", "plural_name" => "posts", "disabled" => false, "labels" => array( "name" => __("Posts", MASTERPRESS_DOMAIN), "singular_name" => __("Post", MASTERPRESS_DOMAIN), "add_new" => __("Add New", MASTERPRESS_DOMAIN), "add_new_item" => __("Add New Post", MASTERPRESS_DOMAIN), "edit" => __("Edit Post", MASTERPRESS_DOMAIN), "edit_item" => __("Edit Post", MASTERPRESS_DOMAIN), "new_item" => __("New Post", MASTERPRESS_DOMAIN), "view" => __("View Post", MASTERPRESS_DOMAIN), "view_item" => __("View Post", MASTERPRESS_DOMAIN), "search_items" => __("Search Posts", MASTERPRESS_DOMAIN), "not_found" => __("No posts found.", MASTERPRESS_DOMAIN), "not_found_in_trash" => __("No posts found in Trash.", MASTERPRESS_DOMAIN), "parent_item_colon" => "", "menu_name" => __("Posts", MASTERPRESS_DOMAIN) ), "description" => "", "publicly_queryable" => true, "exclude_from_search" => false, "show_ui" => true, "show_in_menu" => true, "menu_position" => 5, "menu_sub_position" => 0, "menu_icon" => "menu-icon-posts.png", "manage_sort_order" => "post_date|desc", "capability_type" => "post", "capabilities" => array(), "map_meta_cap" => true, "hierarchical" => false, "supports" => "title,editor,author,thumbnail,excerpt,trackbacks,custom-fields,comments,revisions,page-attributes,post-formats", "permalink_epmask" => "EP_PERMALINK", "has_archive" => true, "rewrite" => array( "slug" => "", "with_front" => true, "feeds" => true, "pages" => false ), "query_var" => "post", "can_export" => true, "show_in_nav_menus" => true, "_builtin" => true, "_external" => false ) ); $post_type_post->insert(); } $tax_post_tag = MPM_Taxonomy::find_by_name("post_tag"); $tax_category = MPM_Taxonomy::find_by_name("category"); if ( !$post_type_post->linked_to_taxonomy( $tax_post_tag ) ) { $post_type_post->link_taxonomy( $tax_post_tag ); } if ( !$post_type_post->linked_to_taxonomy( $tax_category ) ) { $post_type_post->link_taxonomy( $tax_category ); } $post_type_page = MPM_PostType::find_by_name("page"); if (!$post_type_page) { $post_type_page = new MPM_PostType(); $post_type_page->set( array( "name" => "page", "plural_name" => "pages", "disabled" => false, "labels" => array( "name" => __("Pages", MASTERPRESS_DOMAIN), "singular_name" => __("Page", MASTERPRESS_DOMAIN), "add_new" => __("Add New", MASTERPRESS_DOMAIN), "add_new_item" => __("Add New Page", MASTERPRESS_DOMAIN), "edit" => __("Edit Page", MASTERPRESS_DOMAIN), "edit_item" => __("Edit Page", MASTERPRESS_DOMAIN), "new_item" => __("New Page", MASTERPRESS_DOMAIN), "view" => __("View Page", MASTERPRESS_DOMAIN), "view_item" => __("View Page", MASTERPRESS_DOMAIN), "search_items" => __("Search Pages", MASTERPRESS_DOMAIN), "not_found" => __("No pages found.", MASTERPRESS_DOMAIN), "not_found_in_trash" => __("No pages found in Trash.", MASTERPRESS_DOMAIN), "parent_item_colon" => __("Parent Page", MASTERPRESS_DOMAIN), "menu_name" => __("Pages", MASTERPRESS_DOMAIN) ), "description" => "", "publicly_queryable" => true, "exclude_from_search" => false, "show_ui" => true, "show_in_menu" => true, "menu_position" => 20, "menu_sub_position" => 0, "menu_icon" => "menu-icon-pages.png", "manage_sort_order" => "menu_order|asc", "capability_type" => "page", "capabilities" => array(), "map_meta_cap" => true, "hierarchical" => true, "supports" => "title,editor,author,thumbnail,excerpt,trackbacks,custom-fields,comments,revisions,page-attributes,post-formats", "permalink_epmask" => "1", "has_archive" => true, "rewrite" => array( "slug" => "", "with_front" => false, "feeds" => false, "pages" => true ), "query_var" => "page", "can_export" => true, "show_in_nav_menus" => true, "_builtin" => true, "_external" => false ) ); $post_type_page->insert(); } $post_type_attachment = MPM_PostType::find_by_name("attachment"); if (!$post_type_attachment) { $post_type_attachment = new MPM_PostType(); $post_type_attachment->set( array( "name" => "attachment", "plural_name" => "attachments", "disabled" => false, "labels" => array( "name" => __("Media", MASTERPRESS_DOMAIN), "singular_name" => __("Media", MASTERPRESS_DOMAIN), "add_new" => __("Add New", MASTERPRESS_DOMAIN), "add_new_item" => __("Add New Post", MASTERPRESS_DOMAIN), "edit" => __("Edit Media", MASTERPRESS_DOMAIN), "edit_item" => __("Edit Media", MASTERPRESS_DOMAIN), "new_item" => __("New Post", MASTERPRESS_DOMAIN), "view" => __("View Media", MASTERPRESS_DOMAIN), "view_item" => __("View Media", MASTERPRESS_DOMAIN), "search_items" => __("Search Media", MASTERPRESS_DOMAIN), "not_found" => __("No media found.", MASTERPRESS_DOMAIN), "not_found_in_trash" => __("No media found in Trash.", MASTERPRESS_DOMAIN), "parent_item_colon" => __("Parent Post", MASTERPRESS_DOMAIN), "menu_name" => __("Media", MASTERPRESS_DOMAIN) ), "description" => "", "publicly_queryable" => true, "exclude_from_search" => false, "show_ui" => true, "show_in_menu" => true, "menu_position" => 20, "menu_sub_position" => 0, "menu_icon" => "menu-icon-media.png", "manage_sort_order" => "menu_order|asc", "capability_type" => "post", "capabilities" => array(), "map_meta_cap" => true, "hierarchical" => true, "supports" => "title,editor,author,thumbnail,excerpt,trackbacks,custom-fields,comments,revisions,page-attributes,post-formats", "permalink_epmask" => "1", "has_archive" => true, "rewrite" => array( "slug" => "", "with_front" => false, "feeds" => false, "pages" => true ), "query_var" => "page", "can_export" => true, "show_in_nav_menus" => true, "_builtin" => true, "_external" => false ) ); $post_type_attachment->insert(); } }