retesere20

Untitled

Jan 14th, 2018
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function set_props( $args ) {
  2. $args = wp_parse_args( $args );
  3.  
  4. /**
  5. * Filters the arguments for registering a post type.
  6. *
  7. * @since 4.4.0
  8. *
  9. * @param array $args Array of arguments for registering a post type.
  10. * @param string $post_type Post type key.
  11. */
  12. $args = apply_filters( 'register_post_type_args', $args, $this->name );
  13.  
  14. $has_edit_link = ! empty( $args['_edit_link'] );
  15.  
  16. // Args prefixed with an underscore are reserved for internal use.
  17. $defaults = array(
  18. 'labels' => array(),
  19. 'description' => '',
  20. 'public' => false,
  21. 'hierarchical' => false,
  22. 'exclude_from_search' => null,
  23. 'publicly_queryable' => null,
  24. 'show_ui' => null,
  25. 'show_in_menu' => null,
  26. 'show_in_nav_menus' => null,
  27. 'show_in_admin_bar' => null,
  28. 'menu_position' => null,
  29. 'menu_icon' => null,
  30. 'capability_type' => 'post',
  31. 'capabilities' => array(),
  32. 'map_meta_cap' => null,
  33. 'supports' => array(),
  34. 'register_meta_box_cb' => null,
  35. 'taxonomies' => array(),
  36. 'has_archive' => false,
  37. 'rewrite' => true,
  38. 'query_var' => true,
  39. 'can_export' => true,
  40. 'delete_with_user' => null,
  41. 'show_in_rest' => false,
  42. 'rest_base' => false,
  43. 'rest_controller_class' => false,
  44. '_builtin' => false,
  45. '_edit_link' => 'post.php?post=%d',
  46. );
  47.  
  48. $args = array_merge( $defaults, $args );
  49.  
  50. $args['name'] = $this->name;
  51.  
  52. // If not set, default to the setting for public.
  53. if ( null === $args['publicly_queryable'] ) {
  54. $args['publicly_queryable'] = $args['public'];
  55. }
  56.  
  57. // If not set, default to the setting for public.
  58. if ( null === $args['show_ui'] ) {
  59. $args['show_ui'] = $args['public'];
  60. }
  61.  
  62. // If not set, default to the setting for show_ui.
  63. if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
  64. $args['show_in_menu'] = $args['show_ui'];
  65. }
  66.  
  67. // If not set, default to the whether the full UI is shown.
  68. if ( null === $args['show_in_admin_bar'] ) {
  69. $args['show_in_admin_bar'] = (bool) $args['show_in_menu'];
  70. }
  71.  
  72. // If not set, default to the setting for public.
  73. if ( null === $args['show_in_nav_menus'] ) {
  74. $args['show_in_nav_menus'] = $args['public'];
  75. }
  76.  
  77. // If not set, default to true if not public, false if public.
  78. if ( null === $args['exclude_from_search'] ) {
  79. $args['exclude_from_search'] = ! $args['public'];
  80. }
  81.  
  82. // Back compat with quirky handling in version 3.0. #14122.
  83. if ( empty( $args['capabilities'] ) && null === $args['map_meta_cap'] && in_array( $args['capability_type'], array( 'post', 'page' ) ) ) {
  84. $args['map_meta_cap'] = true;
  85. }
  86.  
  87. // If not set, default to false.
  88. if ( null === $args['map_meta_cap'] ) {
  89. $args['map_meta_cap'] = false;
  90. }
  91.  
  92. // If there's no specified edit link and no UI, remove the edit link.
  93. if ( ! $args['show_ui'] && ! $has_edit_link ) {
  94. $args['_edit_link'] = '';
  95. }
  96.  
  97. $this->cap = get_post_type_capabilities( (object) $args );
  98. unset( $args['capabilities'] );
  99.  
  100. if ( is_array( $args['capability_type'] ) ) {
  101. $args['capability_type'] = $args['capability_type'][0];
  102. }
  103.  
  104. if ( false !== $args['query_var'] ) {
  105. if ( true === $args['query_var'] ) {
  106. $args['query_var'] = $this->name;
  107. } else {
  108. $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
  109. }
  110. }
  111.  
  112. if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
  113. if ( ! is_array( $args['rewrite'] ) ) {
  114. $args['rewrite'] = array();
  115. }
  116. if ( empty( $args['rewrite']['slug'] ) ) {
  117. $args['rewrite']['slug'] = $this->name;
  118. }
  119. if ( ! isset( $args['rewrite']['with_front'] ) ) {
  120. $args['rewrite']['with_front'] = true;
  121. }
  122. if ( ! isset( $args['rewrite']['pages'] ) ) {
  123. $args['rewrite']['pages'] = true;
  124. }
  125. if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) {
  126. $args['rewrite']['feeds'] = (bool) $args['has_archive'];
  127. }
  128. if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
  129. if ( isset( $args['permalink_epmask'] ) ) {
  130. $args['rewrite']['ep_mask'] = $args['permalink_epmask'];
  131. } else {
  132. $args['rewrite']['ep_mask'] = EP_PERMALINK;
  133. }
  134. }
  135. }
  136.  
  137. foreach ( $args as $property_name => $property_value ) {
  138. $this->$property_name = $property_value;
  139. }
  140.  
  141. $this->labels = get_post_type_labels( $this );
  142. $this->label = $this->labels->name;
  143. }
RAW Paste Data