コード例 #1
0
ファイル: taxonomy.php プロジェクト: nlemoine/papi
/**
 * Get all taxonomies Papi should work with.
 *
 * @return array
 */
function papi_get_taxonomies()
{
    $taxonomies = [];
    $entry_types = papi_get_all_entry_types(['types' => 'taxonomy']);
    foreach ($entry_types as $entry_type) {
        $taxonomies = array_merge($taxonomies, papi_to_array($entry_type->taxonomy));
    }
    return array_unique($taxonomies);
}
コード例 #2
0
 /**
  * Register options properties.
  */
 public function register()
 {
     // Fetch all options entries.
     $this->entries = papi_get_all_entry_types(['types' => 'option']);
     foreach ($this->entries as $entry) {
         foreach ($entry->get_properties() as $property) {
             $property->register('option');
         }
     }
 }
コード例 #3
0
 /**
  * Page items menu.
  *
  * This function will register all entry types
  * that has a fake post type. Like option types.
  */
 public function page_items_menu()
 {
     $entry_types = papi_get_all_entry_types(['mode' => 'exclude', 'types' => 'page']);
     foreach ($entry_types as $entry_type) {
         if (empty($entry_type->menu) || empty($entry_type->name)) {
             continue;
         }
         $slug = sprintf('papi/%s/%s', $entry_type->get_type(), $entry_type->get_id());
         add_submenu_page($entry_type->menu, $entry_type->name, $entry_type->name, $entry_type->capability, $slug, [$entry_type, 'render']);
     }
 }
コード例 #4
0
ファイル: class-papi-admin.php プロジェクト: nlemoine/papi
 /**
  * Preboot all types and setup the current type if any.
  */
 public function admin_init()
 {
     // Preload all page types.
     foreach (papi_get_post_types() as $post_type) {
         papi_get_all_entry_types(['args' => $post_type]);
     }
     if (!$this->setup_papi()) {
         return;
     }
     // Setup entry type.
     $this->entry_type->setup();
 }
コード例 #5
0
ファイル: option.php プロジェクト: wp-papi/papi
/**
 * Check if option type exists.
 *
 * @param  string $id
 *
 * @return bool
 */
function papi_option_type_exists($id)
{
    $exists = false;
    $option_types = papi_get_all_entry_types(['types' => 'option']);
    foreach ($option_types as $option_type) {
        if ($option_type->match_id($id)) {
            $exists = true;
            break;
        }
    }
    return $exists;
}
コード例 #6
0
 /**
  * List Papi types.
  *
  * ## Options
  *
  * [--<field>=<value>]
  * : Filter types based on type property.
  *
  * [--field=<field>]
  * : Prints the value of a single field for each type.
  *
  * [--fields=<fields>]
  * : Limit the output to specific type fields.
  *
  * [--format=<format>]
  * : Acceptec values: table, csv, json, count, ids. Default: table.
  *
  * ## AVAILABLE FIELDS
  *
  * These fields will be displayed by default for each type:
  *
  * * name
  * * id
  * * post_type
  * * template
  * * number_of_pages
  * * type
  *
  * Not all fields exists on a Papi type so some fields will have `n/a`
  * as value when no value can be displayed.
  *
  * ## EXAMPLES
  *
  *     wp papi type list
  *
  * @subcommand list
  */
 public function list_($args, $assoc_args)
 {
     // Get all entry types.
     $entry_types = papi_get_all_entry_types();
     if (empty($entry_types)) {
         WP_CLI::error('No Papi types exists.');
     }
     // Create type item with the fields that
     // will be displayed.
     $entry_types = array_map(function ($entry_type) {
         return ['id' => $entry_type->get_id(), 'name' => $entry_type->name, 'meta type value' => $this->get_meta_type_value($entry_type), 'template' => empty($entry_type->template) ? 'n/a' : $entry_type->template, 'type' => $entry_type->get_type(), 'db count' => $entry_type->type === 'option' ? 'n/a' : papi_get_entry_type_count($entry_type)];
     }, $entry_types);
     // Render types as a table.
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($entry_types);
 }
コード例 #7
0
 /**
  * Load property from page type.
  *
  * @param  string $slug
  * @param  string $child_slug
  *
  * @return null|object
  */
 public function get_property($slug, $child_slug = '')
 {
     $entry_type_id = papi_get_qs('page');
     if (empty($entry_type_id)) {
         $property = null;
         $entry_types = papi_get_all_entry_types(['types' => 'option']);
         foreach ($entry_types as $entry_type) {
             if ($property = $entry_type->get_property($slug, $child_slug)) {
                 break;
             }
         }
         if (is_null($property)) {
             return;
         }
         return $property;
     }
     $entry_type = papi_get_entry_type_by_id($entry_type_id);
     if ($entry_type instanceof Papi_Option_Type === false) {
         return;
     }
     if ($property = $entry_type->get_property($slug, $child_slug)) {
         return $this->prepare_property($property);
     }
 }
コード例 #8
0
 /**
  * Setup admin entry.
  */
 public function setup()
 {
     // Preload all page types.
     foreach (papi_get_post_types() as $post_type) {
         papi_get_all_entry_types(['args' => $post_type]);
     }
     return !in_array($this->post_type, ['revision', 'nav_menu_item'], true);
 }
コード例 #9
0
ファイル: class-papi-rest-api.php プロジェクト: wp-papi/papi
 /**
  * REST API init callback.
  */
 public function rest_api_init()
 {
     papi_get_all_entry_types();
 }
コード例 #10
0
ファイル: entry.php プロジェクト: nlemoine/papi
/**
 * Get entry type by identifier.
 *
 * @param  string $id
 *
 * @return Papi_Entry_Type
 */
function papi_get_entry_type_by_id($id)
{
    if (!is_string($id) || empty($id)) {
        return;
    }
    if (papi()->exists($id)) {
        return papi()->make($id);
    }
    $result = null;
    $entry_types = papi_get_all_entry_types();
    foreach ($entry_types as $entry_type) {
        if ($entry_type->match_id($id)) {
            $result = $entry_type;
            break;
        }
    }
    if (is_null($result)) {
        $path = papi_get_file_path($id);
        $result = papi_get_entry_type($path);
    }
    return $result;
}
コード例 #11
0
 /**
  * Setup hooks for all taxonomies.
  */
 public function setup_taxonomies_hooks()
 {
     $this->taxonomy_types = papi_get_all_entry_types(['types' => 'taxonomy']);
     $taxonomies = array_reduce($this->taxonomy_types, function ($taxonomies, $taxonomy_type) {
         return array_merge($taxonomies, $taxonomy_type->taxonomy);
     }, []);
     $taxonomies = array_unique($taxonomies);
     foreach ($taxonomies as $taxonomy) {
         if (is_string($taxonomy) && taxonomy_exists($taxonomy)) {
             add_action($taxonomy . '_add_form_fields', [$this, 'add_form_fields']);
         }
     }
 }
コード例 #12
0
ファイル: page.php プロジェクト: nlemoine/papi
/**
 * Get all post types Papi should work with.
 *
 * @return array
 */
function papi_get_post_types()
{
    $post_types = [];
    $page_types = papi_get_all_entry_types(['types' => ['attachment', 'page']]);
    foreach ($page_types as $page_type) {
        $post_types = array_merge($post_types, papi_to_array($page_type->post_type));
    }
    return array_unique($post_types);
}