function inflector() { return ICanBoogie\Inflector::get(INFLECTOR_DEFAULT_LOCALE); }
private function register_taxonomy($name, $content_type, $args = null) { $inflector = ICanBoogie\Inflector::get('en'); $sanitised = str_replace(" ", "_", strtolower($name)); $human = $inflector->titleize($sanitised); $plural = $inflector->pluralize($human); $singular = $inflector->singularize($human); $default_args = array('name' => $plural, 'singular_name' => $singular, 'labels' => array('name' => $plural, 'singular_name' => $singular, 'menu_name' => $plural, 'all_items' => "All {$plural}", 'edit_item' => "Edit {$singular}", 'view_item' => "View {$singular}", 'update_item' => "Update {$singular}", 'add_new_item' => "Add new {$singular}", 'new_item_name' => "New {$singular} name", 'parent_item' => "Parent {$singular}", 'parent_item_colon' => "Parent {$singular}:", 'search_items' => "Search {$plural}", 'popular_items' => "Popular {$plural}", 'separate_items_with_commas' => "Separate {$plural} with commas", 'add_or_remove_items' => "Add or remove {$plural}", 'choose_from_most_used' => "Most used {$plural}", 'not_found' => "No {$plural} found"), 'show_in_rest' => true, 'query_var' => true); if (is_null($args) || !is_array($args)) { $args = $default_args; } else { $args = array_merge($default_args, $args); } if (is_array($content_type)) { $types = $content_type; } elseif ($content_type == 'all') { $types = get_post_types(array('public' => true)); } else { $types = [$content_type]; } register_taxonomy($sanitised, array_values($types), $args); }
<div class="wrap"> <h1>Edit <?php echo $content_type->name; ?> </h1> <?php $inflector = ICanBoogie\Inflector::get('en'); $sanitised = str_replace(" ", "_", strtolower($content_type->name)); $route = "/wp-json/wp/v2/{$inflector->pluralize($sanitised)}"; ?> <p>Available at <a href="<?php echo $route; ?> "><?php echo $route; ?> </a></p> <form action="?page=<?php echo $this->plugin_name; ?> -overview" method="POST" id="content-type"> <?php wp_nonce_field($this->plugin_name, $this->plugin_name . '-token'); ?> <input name="id" type="hidden" value="<?php echo $content_type->id; ?> "/>