Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!function_exists("pre_posttype")):
- function pre_posttype() {
- $types = array(
- "pre_selection" => array(
- "single" => "Selection",
- "description" => "A Selection of items which will appear on the front-page",
- "public" => false,
- "publicly_queryable" => true,
- "show_ui" => true,
- "show_in_nav_menus" => false,
- "show_in_menu" => true,
- "show_in_admin_bar" => false,
- "menu_position" => 30,
- "menu_icon" => "dashicons-visibility",
- "hierachical" => false,
- "supports" => array("title", "editor")
- ),
- "pre_project" => array(
- "single" => "Project",
- "description" => "(Programming-) Projects which this Website shows",
- "public" => true,
- "show_ui" => true,
- "show_in_nav_menus" => true,
- "show_in_menu" => true,
- "show_in_admin_bar" => true,
- "menu_position" => 31,
- "menu_icon" => "dashicons-category",
- "hierachical" => false,
- "supports" => array("title", "editor", "thumbnail")
- ),
- "pre_template" => array(
- "single" => "Template",
- "description" => "Template-Project for streaming",
- "public" => true,
- "show_ui" => true,
- "show_in_nav_menus" => true,
- "show_in_menu" => true,
- "show_in_admin_bar" => true,
- "menu_position" => 32,
- "hierachical" => false,
- "supports" => array("title", "editor")
- )
- );
- foreach ($types as $name => $t) {
- # Saving SINGLE and MULTI in variables and unsetting them, to avoid problems since we merge and post it
- # When neither is set, we'll create them from the name
- $s = isset($t["single"]) ? $t["single"] : (ucfirst(strtolower(strpos($name, "_") ? substr(strpos($name, "_")+1) : $name)));
- $m = isset($t["multi"]) ? $t["multi"] : (strcasecmp($s{strlen($s)-1},"s") ? $s : "{$s}s");
- # Un-setting extra values so they won't show up on the wp-registering and may screw shit up.
- unset($t["multi"], $t["single"]);
- register_post_type($name, PreLib::merge_all($t, array(
- # Defaults which will be applied when nothing is specified
- "label" => $m,
- "labels" => array(
- "name" => $m,
- "singular_name" => $s,
- "add_new" => "Add New",
- "add_new_item" => "Add new {$s}",
- "edit_item" => "Edit {$s}",
- "new_item" => "New {$s}",
- "view_item" => "View {$s}",
- "search_items" => "Search {$s}",
- "not_found" => "Nothing Found",
- "not_found_in_trash" => "Nothing found in Trash",
- "parent_item_colon" => "Parent {$s}",
- "all_items" => "All {$m}",
- "archives" => "{$s} Archives",
- "insert_into_item" => "Insert into {$s}",
- "uploaded_to_this_item" => "Uploaded to this {$s}",
- "menu_name" => $m,
- "update_item" => "Update {$s}",
- ),
- "capability_type" => array(
- strtolower($s),
- strtolower($m)
- ),
- "rewrite" => array(
- "slug" => strtolower($s)
- ),
- "query_var" => $s,
- "rest_base" => strtolower($s)
- )));
- }
- }
- endif;
- add_action("init", "pre_posttype");
- /* Merge all Function from the PreLib class */
- public static function merge_all() {
- # If there are less than 2 arrays we can't merge
- if (func_num_args() < 2) throw new invalidargumentexception("This method requires at least two or more arrays as arguments!");
- # Always the first
- $main = func_get_arg(0);
- # 2nd or all others
- $sub = func_num_args() == 2 ? func_get_arg(1) : array_slice(func_get_args(), 1, func_num_args());
- # Array check
- if (!is_array($main) || !is_array($sub)) throw new invalidargumentexception("This method requires all arguments to be arrays!");
- if (func_num_args() > 2) {
- # Iterate through all subs and call this method one after another
- foreach ($sub as $s) $main = merge_all($main, $s);
- return $main;
- }
- foreach ($sub as $key => $val) {
- # Main has same val as sub, next
- if ($main[$key] == $val) continue;
- # Main doesn't have the key, so set it
- if (!isset($main[$key])) {
- $main[$key] = $sub[$key];
- continue;
- }
- # Merge all sub-arrays as well
- if (is_array($val) && is_array($main[$key])) $main[$key] = merge_all($main[$key], $val);
- }
- return $main;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement