cptui_listings

Output the content for the "Registered Types/Taxes" page.

Description

cptui_listings(); 

Usage

  1. if ( !function_exists( 'cptui_listings' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/inc/listings.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = cptui_listings(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/inc/listings.php  
  1. function cptui_listings() { 
  2. ?> 
  3. <div class="wrap cptui-listings"> 
  4. <?php 
  5. /** 
  6. * Fires right inside the wrap div for the listings screen. 
  7. * @since 1.3.0 
  8. */ 
  9. ?> 
  10.  
  11. <h1><?php esc_html_e( 'Post Types and Taxonomies registered by Custom Post Type UI.', 'custom-post-type-ui' ); ?></h1> 
  12. <?php 
  13. $post_types = cptui_get_post_type_data(); 
  14. echo '<h2 id="post-types">' . esc_html__( 'Post Types', 'custom-post-type-ui' ) . '</h2>'; 
  15. if ( ! empty( $post_types ) ) { 
  16. ?> 
  17. <p><?php printf( esc_html__( 'CPTUI registered post types count total: %d', 'custom-post-type-ui' ), count( $post_types ) ); ?></p> 
  18.  
  19. <?php 
  20.  
  21. $post_type_table_heads = array( 
  22. __( 'Post Type', 'custom-post-type-ui' ),  
  23. __( 'Settings', 'custom-post-type-ui' ),  
  24. __( 'Supports', 'custom-post-type-ui' ),  
  25. __( 'Taxonomies', 'custom-post-type-ui' ),  
  26. __( 'Labels', 'custom-post-type-ui' ),  
  27. __( 'Template Hierarchy', 'custom-post-type-ui' ),  
  28. ); 
  29.  
  30. /** 
  31. * Fires before the listing of registered post type data. 
  32. * @since 1.1.0 
  33. */ 
  34. ?> 
  35. <table class="wp-list-table widefat post-type-listing"> 
  36. <thead> 
  37. <tr> 
  38. <?php 
  39. foreach ( $post_type_table_heads as $head ) { 
  40. echo '<th>' . esc_html( $head ) . '</th>'; 
  41. } ?> 
  42. </tr> 
  43. </thead> 
  44. <tbody> 
  45. <?php 
  46. $counter = 1; 
  47. foreach ( $post_types as $post_type => $post_type_settings ) { 
  48.  
  49. $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate'; 
  50.  
  51. $strings = array(); 
  52. $supports = array(); 
  53. $taxonomies = array(); 
  54. $archive = ''; 
  55. foreach ( $post_type_settings as $settings_key => $settings_value ) { 
  56. if ( 'labels' === $settings_key ) { 
  57. continue; 
  58.  
  59. if ( is_string( $settings_value ) ) { 
  60. $strings[ $settings_key ] = $settings_value; 
  61. } else { 
  62. if ( 'supports' === $settings_key ) { 
  63. $supports[ $settings_key ] = $settings_value; 
  64.  
  65. if ( 'taxonomies' === $settings_key ) { 
  66. $taxonomies[ $settings_key ] = $settings_value; 
  67.  
  68. // In case they are not associated from the post type settings. 
  69. if ( empty( $taxonomies['taxonomies'] ) ) { 
  70. $taxonomies['taxonomies'] = get_object_taxonomies( $post_type ); 
  71. $archive = get_post_type_archive_link( $post_type ); 
  72. ?> 
  73. <tr class="<?php echo esc_attr( $rowclass ); ?>"> 
  74. <?php 
  75. $edit_path = 'admin.php?page=cptui_manage_post_types&action=edit&cptui_post_type=' . $post_type; 
  76. $post_type_link_url = ( is_network_admin() ) ? network_admin_url( $edit_path ) : admin_url( $edit_path ); ?> 
  77. <td> 
  78. <?php 
  79. printf( 
  80. '<a href="%s">%s</a><br/> 
  81. <a href="%s">%s</a><br/>',  
  82. esc_attr( $post_type_link_url ),  
  83. sprintf( 
  84. esc_html__( 'Edit %s', 'custom-post-type-ui' ),  
  85. esc_html( $post_type ) 
  86. ),  
  87. esc_attr( admin_url( 'admin.php?page=cptui_tools&action=get_code#' . $post_type ) ),  
  88. esc_html__( 'Get code', 'custom-post-type-ui' ) 
  89. ); 
  90.  
  91. if ( $archive ) { 
  92. ?> 
  93. <a href="<?php echo esc_attr( get_post_type_archive_link( $post_type ) ); ?>"><?php esc_html_e( 'View frontend archive', 'custom-post-type-ui' ); ?></a> 
  94. <?php } ?> 
  95. </td> 
  96. <td> 
  97. <?php 
  98. foreach ( $strings as $key => $value ) { 
  99. printf( '<strong>%s:</strong> ', esc_html( $key ) ); 
  100. if ( in_array( $value, array( '1', '0' ) ) ) { 
  101. echo esc_html( disp_boolean( $value ) ); 
  102. } else { 
  103. echo ( ! empty( $value ) ) ? esc_html( $value ) : '""'; 
  104. echo '<br/>'; 
  105. } ?> 
  106. </td> 
  107. <td> 
  108. <?php 
  109. foreach ( $supports['supports'] as $support ) { 
  110. echo esc_html( $support ) . '<br/>'; 
  111. } ?> 
  112. </td> 
  113. <td> 
  114. <?php 
  115. if ( ! empty( $taxonomies['taxonomies'] ) ) { 
  116. foreach ( $taxonomies['taxonomies'] as $taxonomy ) { 
  117. echo esc_html( $taxonomy ) . '<br/>'; 
  118. } else { 
  119. printf( 
  120. '<span aria-hidden="true">*</span><span class="screen-reader-text">%s</span>',  
  121. esc_html__( 'No associated taxonomies', 'custom-post-type-ui' ) 
  122. ); 
  123. ?> 
  124. </td> 
  125. <td> 
  126. <?php 
  127. $maybe_empty = array_filter( $post_type_settings['labels'] ); 
  128. if ( ! empty( $maybe_empty ) ) { 
  129. foreach ( $post_type_settings['labels'] as $key => $value ) { 
  130. if ( 'parent' === $key && array_key_exists( 'parent_item_colon', $post_type_settings['labels'] ) ) { 
  131. continue; 
  132. printf( 
  133. '%s: %s<br/>',  
  134. esc_html( $key ),  
  135. esc_html( $value ) 
  136. ); 
  137. } else { 
  138. printf( 
  139. '<span aria-hidden="true">*</span><span class="screen-reader-text">%s</span>',  
  140. esc_html__( 'No custom labels to display', 'custom-post-type-ui' ) 
  141. ); 
  142. ?> 
  143. </td> 
  144. <td> 
  145. <p><strong><?php esc_html_e( 'Archives file name examples.', 'custom-post-type-ui' ); ?></strong><br/> 
  146. archive-<?php echo esc_html( $post_type ); ?>.php<br/> 
  147. archive.php<br/> 
  148. index.php 
  149. </p> 
  150.  
  151. <p><strong><?php esc_html_e( 'Single Posts file name examples.', 'custom-post-type-ui' ); ?></strong><br/> 
  152. single-<?php echo esc_html( $post_type ); ?>-post_slug.php (WP 4.4+) *<br/> 
  153. single-<?php echo esc_html( $post_type ); ?>.php<br/> 
  154. single.php<br/> 
  155. singular.php (WP 4.3+)<br/> 
  156. index.php 
  157. </p> 
  158.  
  159. <p> 
  160. <?php esc_html_e( '*Replace "post_slug" with the slug of the actual post slug.', 'custom-post-type-ui' ); ?> 
  161. </p> 
  162.  
  163. <p><?php 
  164. printf( 
  165. '<a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">%s</a>',  
  166. esc_html__( 'Template hierarchy Theme Handbook', 'custom-post-type-ui' ) 
  167. ); ?> 
  168. </p> 
  169. </td> 
  170. </tr> 
  171.  
  172. <?php 
  173. $counter++; 
  174. ?> 
  175. </tbody> 
  176. <tfoot> 
  177. <tr> 
  178. <?php 
  179. foreach ( $post_type_table_heads as $head ) { 
  180. echo '<th>' . esc_html( $head ) . '</th>'; 
  181. } ?> 
  182. </tr> 
  183. </tfoot> 
  184. </table> 
  185. <?php 
  186. /** 
  187. * Fires after the listing of registered post type data. 
  188. * @since 1.3.0 
  189. */ 
  190. } else { 
  191.  
  192. /** 
  193. * Fires when there are no registered post types to list. 
  194. * @since 1.3.0 
  195. */ 
  196.  
  197. $taxonomies = cptui_get_taxonomy_data(); 
  198. echo '<h2 id="taxonomies">' . esc_html__( 'Taxonomies', 'custom-post-type-ui' ) . '</h2>'; 
  199. if ( ! empty( $taxonomies ) ) { 
  200. ?> 
  201. <p><?php printf( esc_html__( 'CPTUI registered taxonomies count total: %d', 'custom-post-type-ui' ), count( $taxonomies ) ); ?></p> 
  202.  
  203. <?php 
  204.  
  205. $taxonomy_table_heads = array( 
  206. __( 'Taxonomy', 'custom-post-type-ui' ),  
  207. __( 'Settings', 'custom-post-type-ui' ),  
  208. __( 'Post Types', 'custom-post-type-ui' ),  
  209. __( 'Labels', 'custom-post-type-ui' ),  
  210. __( 'Template Hierarchy', 'custom-post-type-ui' ),  
  211. ); 
  212.  
  213. /** 
  214. * Fires before the listing of registered taxonomy data. 
  215. * @since 1.1.0 
  216. */ 
  217. ?> 
  218. <table class="wp-list-table widefat taxonomy-listing"> 
  219. <thead> 
  220. <tr> 
  221. <?php 
  222. foreach ( $taxonomy_table_heads as $head ) { 
  223. echo '<th>' . esc_html( $head ) . '</th>'; 
  224. } ?> 
  225. </tr> 
  226. </thead> 
  227. <tbody> 
  228. <?php 
  229. $counter = 1; 
  230. foreach ( $taxonomies as $taxonomy => $taxonomy_settings ) { 
  231.  
  232. $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate'; 
  233.  
  234. $strings = array(); 
  235. $object_types = array(); 
  236. foreach ( $taxonomy_settings as $settings_key => $settings_value ) { 
  237. if ( 'labels' === $settings_key ) { 
  238. continue; 
  239.  
  240. if ( is_string( $settings_value ) ) { 
  241. $strings[ $settings_key ] = $settings_value; 
  242. } else { 
  243. if ( 'object_types' === $settings_key ) { 
  244. $object_types[ $settings_key ] = $settings_value; 
  245.  
  246. // In case they are not associated from the post type settings. 
  247. if ( empty( $object_types['object_types'] ) ) { 
  248. $types = get_taxonomy( $taxonomy ); 
  249. $object_types['object_types'] = $types->object_type; 
  250. ?> 
  251. <tr class="<?php echo esc_attr( $rowclass ); ?>"> 
  252. <?php 
  253. $edit_path = 'admin.php?page=cptui_manage_taxonomies&action=edit&cptui_taxonomy=' . $taxonomy; 
  254. $taxonomy_link_url = ( is_network_admin() ) ? network_admin_url( $edit_path ) : admin_url( $edit_path ); ?> 
  255. <td> 
  256. <?php printf( 
  257. '<a href="%s">%s</a><br/> 
  258. <a href="%s">%s</a>',  
  259. esc_attr( $taxonomy_link_url ),  
  260. sprintf( 
  261. esc_html__( 'Edit %s', 'custom-post-type-ui' ),  
  262. esc_html( $taxonomy ) 
  263. ),  
  264. esc_attr( admin_url( 'admin.php?page=cptui_tools&action=get_code#' . $taxonomy ) ),  
  265. esc_html__( 'Get code', 'custom-post-type-ui' ) 
  266. ); ?> 
  267. </td> 
  268. <td> 
  269. <?php 
  270. foreach ( $strings as $key => $value ) { 
  271. printf( '<strong>%s:</strong> ', esc_html( $key ) ); 
  272. if ( in_array( $value, array( '1', '0' ) ) ) { 
  273. echo esc_html( disp_boolean( $value ) ); 
  274. } else { 
  275. echo ( ! empty( $value ) ) ? esc_html( $value ) : '""'; 
  276. echo '<br/>'; 
  277. } ?> 
  278. </td> 
  279. <td> 
  280. <?php 
  281. if ( ! empty( $object_types['object_types'] ) ) { 
  282. foreach ( $object_types['object_types'] as $type ) { 
  283. echo esc_html( $type ) . '<br/>'; 
  284. } ?> 
  285. </td> 
  286. <td> 
  287. <?php 
  288. $maybe_empty = array_filter( $taxonomy_settings['labels'] ); 
  289. if ( ! empty( $maybe_empty ) ) { 
  290. foreach ( $taxonomy_settings['labels'] as $key => $value ) { 
  291. printf( 
  292. '%s: %s<br/>',  
  293. esc_html( $key ),  
  294. esc_html( $value ) 
  295. ); 
  296. } else { 
  297. printf( 
  298. '<span aria-hidden="true">*</span><span class="screen-reader-text">%s</span>',  
  299. esc_html__( 'No custom labels to display', 'custom-post-type-ui' ) 
  300. ); 
  301. ?> 
  302. </td> 
  303. <td> 
  304. <p><strong><?php esc_html_e( 'Archives file name examples.', 'custom-post-type-ui' ); ?></strong><br /> 
  305. taxonomy-<?php echo esc_html( $taxonomy ); ?>-term_slug.php *<br /> 
  306. taxonomy-<?php echo esc_html( $taxonomy ); ?>.php<br /> 
  307. taxonomy.php<br /> 
  308. archive.php<br /> 
  309. index.php 
  310. </p> 
  311.  
  312. <p> 
  313. <?php esc_html_e( '*Replace "term_slug" with the slug of the actual taxonomy term.', 'custom-post-type-ui' ); ?> 
  314. </p> 
  315. <p><?php 
  316. printf( 
  317. '<a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">%s</a>',  
  318. esc_html__( 'Template hierarchy Theme Handbook', 'custom-post-type-ui' ) 
  319. ); ?></p> 
  320. </td> 
  321. </tr> 
  322.  
  323. <?php 
  324. $counter++; 
  325. ?> 
  326. </tbody> 
  327. <tfoot> 
  328. <tr> 
  329. <?php 
  330. foreach ( $taxonomy_table_heads as $head ) { 
  331. echo '<th>' . esc_html( $head ) . '</th>'; 
  332. } ?> 
  333. </tr> 
  334. </tfoot> 
  335. </table> 
  336. <?php 
  337. /** 
  338. * Fires after the listing of registered taxonomy data. 
  339. * @since 1.3.0 
  340. */ 
  341.  
  342. } else { 
  343.  
  344. /** 
  345. * Fires when there are no registered taxonomies to list. 
  346. * @since 1.3.0 
  347. */ 
  348. ?> 
  349.  
  350. </div> 
  351. <?php