/**
  * 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_($_, $assoc_args)
 {
     // Get all page types.
     $types = papi_get_all_content_types();
     // Create type item with the fields that
     // will be displayed.
     $types = array_map(function ($type) {
         $is_page_type = papi_is_page_type($type);
         return ['id' => $type->get_id(), 'name' => $type->name, 'post_type' => $is_page_type ? implode(', ', $type->post_type) : 'n/a', 'template' => $is_page_type ? $type->template : 'n/a', 'type' => $type->get_type(), 'number_of_pages' => $is_page_type ? papi_get_number_of_pages($type->get_id()) : 'n/a'];
     }, $types);
     // Render types as a table.
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($types);
 }
Esempio n. 2
0
    if (empty($page_type->template)) {
        _e('Page Type has no template file', 'papi');
    } else {
        if (!current_user_can('edit_themes') || defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
            echo esc_html($page_type->template);
        } else {
            $theme_dir = get_template_directory();
            $theme_name = basename($theme_dir);
            $url = admin_url('theme-editor.php?file=' . $page_type->template . '&theme=' . $theme_name);
            if (file_exists($theme_dir . '/' . $page_type->template)) {
                papi_render_html_tag('a', ['href' => esc_attr($url), esc_html($page_type->template)]);
            } else {
                _e('Template file does not exist', 'papi');
            }
        }
    }
    ?>
				</td>
				<td>
					<?php 
    echo esc_html(papi_get_number_of_pages($page_type->get_id()));
    ?>
				</td>
			</tr>
		<?php 
}
?>
		</tbody>
	</table>
</div>