PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/custom-post-type-ui/inc/listings.php

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