Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PodsInit often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PodsInit, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class PodsInit { |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @var PodsInit |
||
| 9 | */ |
||
| 10 | static $instance = null; |
||
|
|
|||
| 11 | |||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | static $no_conflict = array(); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | static $content_types_registered = array(); |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var PodsComponents |
||
| 24 | */ |
||
| 25 | static $components; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var PodsMeta |
||
| 29 | */ |
||
| 30 | static $meta; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var PodsI18n |
||
| 34 | */ |
||
| 35 | static $i18n; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var PodsAdmin |
||
| 39 | */ |
||
| 40 | static $admin; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var mixed|void |
||
| 44 | */ |
||
| 45 | static $version; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var mixed|void |
||
| 49 | */ |
||
| 50 | static $version_last; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var mixed|void |
||
| 54 | */ |
||
| 55 | static $db_version; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Upgrades to trigger (last installed version => upgrade version) |
||
| 59 | * |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | static $upgrades = array( |
||
| 63 | '1.0.0' => '2.0.0' |
||
| 64 | //'2.0.0' => '2.1.0' |
||
| 65 | ); |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Whether an Upgrade for 1.x has happened |
||
| 69 | * |
||
| 70 | * @var bool |
||
| 71 | */ |
||
| 72 | static $upgraded; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Whether an Upgrade is needed |
||
| 76 | * |
||
| 77 | * @var bool |
||
| 78 | */ |
||
| 79 | static $upgrade_needed = false; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Singleton handling for a basic pods_init() request |
||
| 83 | * |
||
| 84 | * @return \PodsInit |
||
| 85 | * |
||
| 86 | * @since 2.3.5 |
||
| 87 | */ |
||
| 88 | public static function init() { |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Setup and Initiate Pods |
||
| 99 | * |
||
| 100 | * @return \PodsInit |
||
| 101 | * |
||
| 102 | * @license http://www.gnu.org/licenses/gpl-2.0.html |
||
| 103 | * @since 1.8.9 |
||
| 104 | */ |
||
| 105 | function __construct() { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Load the plugin textdomain and set default constants |
||
| 139 | */ |
||
| 140 | public function plugins_loaded() { |
||
| 141 | |||
| 142 | if ( ! defined( 'PODS_LIGHT' ) ) { |
||
| 143 | define( 'PODS_LIGHT', false ); |
||
| 144 | } |
||
| 145 | |||
| 146 | if ( ! defined( 'PODS_TABLELESS' ) ) { |
||
| 147 | define( 'PODS_TABLELESS', false ); |
||
| 148 | } |
||
| 149 | |||
| 150 | load_plugin_textdomain( 'pods' ); |
||
| 151 | |||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Load Pods Components |
||
| 156 | */ |
||
| 157 | public function load_components() { |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Load Pods Meta |
||
| 171 | */ |
||
| 172 | public function load_meta() { |
||
| 176 | |||
| 177 | /** |
||
| 178 | * |
||
| 179 | */ |
||
| 180 | public function load_i18n() { |
||
| 181 | |||
| 182 | self::$i18n = pods_i18n(); |
||
| 183 | } |
||
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * Set up the Pods core |
||
| 188 | */ |
||
| 189 | public function core() { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Register Scripts and Styles |
||
| 251 | */ |
||
| 252 | public function register_assets() { |
||
| 253 | |||
| 254 | if ( ! wp_style_is( 'jquery-ui', 'registered' ) ) { |
||
| 255 | wp_register_style( 'jquery-ui', PODS_URL . 'ui/css/smoothness/jquery-ui.custom.css', array(), '1.8.16' ); |
||
| 256 | } |
||
| 257 | |||
| 258 | wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' ); |
||
| 259 | |||
| 260 | if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) { |
||
| 261 | wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' ); |
||
| 262 | } |
||
| 263 | |||
| 264 | if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) { |
||
| 265 | wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' ); |
||
| 266 | } |
||
| 267 | |||
| 268 | wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array( |
||
| 269 | 'jquery', |
||
| 270 | 'pods-i18n', |
||
| 271 | 'pods-json', |
||
| 272 | 'jquery-qtip2' |
||
| 273 | ), PODS_VERSION, true ); |
||
| 274 | |||
| 275 | wp_register_style( 'pods-form', PODS_URL . 'ui/css/pods-form.css', array(), PODS_VERSION ); |
||
| 276 | |||
| 277 | wp_register_style( 'pods-cleditor', PODS_URL . 'ui/css/jquery.cleditor.css', array(), '1.3.0' ); |
||
| 278 | wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' ); |
||
| 279 | |||
| 280 | wp_register_style( 'pods-codemirror', PODS_URL . 'ui/css/codemirror.css', array(), '4.8' ); |
||
| 281 | wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '4.8', true ); |
||
| 282 | wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/addon/mode/loadmode.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 283 | wp_register_script( 'pods-codemirror-overlay', PODS_URL . 'ui/js/codemirror/addon/mode/overlay.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 284 | wp_register_script( 'pods-codemirror-hints', PODS_URL . 'ui/js/codemirror/addon/mode/show-hint.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 285 | wp_register_script( 'pods-codemirror-mode-xml', PODS_URL . 'ui/js/codemirror/mode/xml/xml.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 286 | wp_register_script( 'pods-codemirror-mode-html', PODS_URL . 'ui/js/codemirror/mode/htmlmixed/htmlmixed.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 287 | wp_register_script( 'pods-codemirror-mode-css', PODS_URL . 'ui/js/codemirror/mode/css/css.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 288 | |||
| 289 | if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) { |
||
| 290 | wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/css/jquery.ui.timepicker.css', array(), '1.1.1' ); |
||
| 291 | } |
||
| 292 | |||
| 293 | if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) { |
||
| 294 | wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/jquery.ui.timepicker.min.js', array( |
||
| 295 | 'jquery', |
||
| 296 | 'jquery-ui-core', |
||
| 297 | 'jquery-ui-datepicker', |
||
| 298 | 'jquery-ui-slider' |
||
| 299 | ), '1.1.1' ); |
||
| 300 | } |
||
| 301 | |||
| 302 | wp_register_style( 'pods-select2', PODS_URL . 'ui/js/select2/select2.css', array(), '3.3.1' ); |
||
| 303 | wp_register_script( 'pods-select2', PODS_URL . 'ui/js/select2/select2.min.js', array( 'jquery', 'pods-i18n' ), '3.3.1' ); |
||
| 304 | |||
| 305 | wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' ); |
||
| 306 | |||
| 307 | // Marionette dependencies for MV fields |
||
| 308 | wp_register_script( 'marionette', PODS_URL . 'ui/js/marionette/backbone.marionette.js', array( 'backbone' ), '2.4.4', true ); |
||
| 309 | wp_register_script( 'backbone.babysitter', PODS_URL . 'ui/js/marionette/backbone.babysitter.min.js', array( 'backbone' ), '0.1.10', true ); |
||
| 310 | wp_register_script( 'backbone.radio', PODS_URL . 'ui/js/marionette/backbone.radio.min.js', array( 'backbone' ), '1.0.2', true ); |
||
| 311 | wp_register_script( 'marionette.radio.shim', PODS_URL . 'ui/js/marionette/marionette.radio.shim.js', array( |
||
| 312 | 'marionette', |
||
| 313 | 'backbone.radio' |
||
| 314 | ), '1.0.2', true ); |
||
| 315 | wp_register_script( 'marionette.state', PODS_URL. 'ui/js/marionette/marionette.state.js', array( 'marionette' ), '1.0.1', true ); |
||
| 316 | |||
| 317 | // MV stuff |
||
| 318 | wp_register_script( |
||
| 319 | 'pods-mv-fields', |
||
| 320 | PODS_URL . 'ui/fields-mv/js/pods-mv-fields.min.js', |
||
| 321 | array( |
||
| 322 | 'jquery', |
||
| 323 | 'jquery-ui-core', |
||
| 324 | 'jquery-ui-sortable', |
||
| 325 | 'pods-i18n', |
||
| 326 | 'marionette', |
||
| 327 | 'media-views', |
||
| 328 | 'media-models' |
||
| 329 | ), |
||
| 330 | PODS_VERSION, |
||
| 331 | true |
||
| 332 | ); |
||
| 333 | wp_register_style( 'pods-flex', PODS_URL . 'ui/css/pods-flex.css', array(), PODS_VERSION ); |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Register internal Post Types |
||
| 338 | */ |
||
| 339 | public function register_pods() { |
||
| 340 | |||
| 341 | $args = array( |
||
| 342 | 'label' => 'Pods', |
||
| 343 | 'labels' => array( 'singular_name' => 'Pod' ), |
||
| 344 | 'public' => false, |
||
| 345 | 'can_export' => false, |
||
| 346 | 'query_var' => false, |
||
| 347 | 'rewrite' => false, |
||
| 348 | 'capability_type' => 'pods_pod', |
||
| 349 | 'has_archive' => false, |
||
| 350 | 'hierarchical' => false, |
||
| 351 | 'supports' => array( 'title', 'author' ), |
||
| 352 | 'menu_icon' => 'dashicons-pods' |
||
| 353 | ); |
||
| 354 | |||
| 355 | $args = self::object_label_fix( $args, 'post_type' ); |
||
| 356 | |||
| 357 | register_post_type( '_pods_pod', apply_filters( 'pods_internal_register_post_type_pod', $args ) ); |
||
| 358 | |||
| 359 | $args = array( |
||
| 360 | 'label' => 'Pod Fields', |
||
| 361 | 'labels' => array( 'singular_name' => 'Pod Field' ), |
||
| 362 | 'public' => false, |
||
| 363 | 'can_export' => false, |
||
| 364 | 'query_var' => false, |
||
| 365 | 'rewrite' => false, |
||
| 366 | 'capability_type' => 'pods_pod', |
||
| 367 | 'has_archive' => false, |
||
| 368 | 'hierarchical' => true, |
||
| 369 | 'supports' => array( 'title', 'editor', 'author' ), |
||
| 370 | 'menu_icon' => 'dashicons-pods' |
||
| 371 | ); |
||
| 372 | |||
| 373 | $args = self::object_label_fix( $args, 'post_type' ); |
||
| 374 | |||
| 375 | register_post_type( '_pods_field', apply_filters( 'pods_internal_register_post_type_field', $args ) ); |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Include Admin |
||
| 380 | */ |
||
| 381 | public function admin_init() { |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Register Post Types and Taxonomies |
||
| 388 | */ |
||
| 389 | public function setup_content_types( $force = false ) { |
||
| 390 | |||
| 391 | if ( empty( self::$version ) ) { |
||
| 392 | return; |
||
| 393 | } |
||
| 394 | |||
| 395 | $post_types = PodsMeta::$post_types; |
||
| 396 | $taxonomies = PodsMeta::$taxonomies; |
||
| 397 | |||
| 398 | $existing_post_types = get_post_types(); |
||
| 399 | $existing_taxonomies = get_taxonomies(); |
||
| 400 | |||
| 401 | $pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' ); |
||
| 402 | |||
| 403 | $cpt_positions = array(); |
||
| 404 | |||
| 405 | if ( empty( $pods_cpt_ct ) && ( ! empty( $post_types ) || ! empty( $taxonomies ) ) ) { |
||
| 406 | $force = true; |
||
| 407 | } elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['post_types'] ) && ! empty( $post_types ) ) { |
||
| 408 | $force = true; |
||
| 409 | } elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['taxonomies'] ) && ! empty( $taxonomies ) ) { |
||
| 410 | $force = true; |
||
| 411 | } |
||
| 412 | |||
| 413 | if ( false === $pods_cpt_ct || $force ) { |
||
| 414 | /** |
||
| 415 | * @var WP_Query |
||
| 416 | */ |
||
| 417 | global $wp_query; |
||
| 418 | |||
| 419 | $reserved_query_vars = array( |
||
| 420 | 'post_type', |
||
| 421 | 'taxonomy', |
||
| 422 | 'output' |
||
| 423 | ); |
||
| 424 | |||
| 425 | if ( is_object( $wp_query ) ) { |
||
| 426 | $reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) ); |
||
| 427 | } |
||
| 428 | |||
| 429 | $pods_cpt_ct = array( |
||
| 430 | 'post_types' => array(), |
||
| 431 | 'taxonomies' => array() |
||
| 432 | ); |
||
| 433 | |||
| 434 | $pods_post_types = $pods_taxonomies = array(); |
||
| 435 | $supported_post_types = $supported_taxonomies = array(); |
||
| 436 | |||
| 437 | foreach ( $post_types as $post_type ) { |
||
| 438 | // Post Type exists already |
||
| 439 | View Code Duplication | if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) { |
|
| 440 | continue; |
||
| 441 | } elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) { |
||
| 442 | continue; |
||
| 443 | } elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) { |
||
| 444 | continue; |
||
| 445 | } |
||
| 446 | |||
| 447 | $post_type['options']['name'] = $post_type['name']; |
||
| 448 | $post_type = array_merge( $post_type, (array) $post_type['options'] ); |
||
| 449 | |||
| 450 | $post_type_name = pods_v_sanitized( 'name', $post_type ); |
||
| 451 | |||
| 452 | // Labels |
||
| 453 | $cpt_label = esc_html( pods_v( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'name', $post_type ) ) ), true ) ); |
||
| 454 | $cpt_singular = esc_html( pods_v( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'label', $post_type, $post_type_name, null, true ) ) ), true ) ); |
||
| 455 | |||
| 456 | $cpt_labels = array(); |
||
| 457 | $cpt_labels['name'] = $cpt_label; |
||
| 458 | $cpt_labels['singular_name'] = $cpt_singular; |
||
| 459 | $cpt_labels['menu_name'] = pods_v( 'menu_name', $post_type, '', true ); |
||
| 460 | $cpt_labels['name_admin_bar'] = pods_v( 'name_admin_bar', $post_type, '', true ); |
||
| 461 | $cpt_labels['add_new'] = pods_v( 'label_add_new', $post_type, '', true ); |
||
| 462 | $cpt_labels['add_new_item'] = pods_v( 'label_add_new_item', $post_type, '', true ); |
||
| 463 | $cpt_labels['new_item'] = pods_v( 'label_new_item', $post_type, '', true ); |
||
| 464 | $cpt_labels['edit'] = pods_v( 'label_edit', $post_type, '', true ); |
||
| 465 | $cpt_labels['edit_item'] = pods_v( 'label_edit_item', $post_type, '', true ); |
||
| 466 | $cpt_labels['view'] = pods_v( 'label_view', $post_type, '', true ); |
||
| 467 | $cpt_labels['view_item'] = pods_v( 'label_view_item', $post_type, '', true ); |
||
| 468 | $cpt_labels['all_items'] = pods_v( 'label_all_items', $post_type, '', true ); |
||
| 469 | $cpt_labels['search_items'] = pods_v( 'label_search_items', $post_type, '', true ); |
||
| 470 | $cpt_labels['not_found'] = pods_v( 'label_not_found', $post_type, '', true ); |
||
| 471 | $cpt_labels['not_found_in_trash'] = pods_v( 'label_not_found_in_trash', $post_type, '', true ); |
||
| 472 | $cpt_labels['parent'] = pods_v( 'label_parent', $post_type, '', true ); |
||
| 473 | $cpt_labels['parent_item_colon'] = pods_v( 'label_parent_item_colon', $post_type, '', true ); |
||
| 474 | $cpt_labels['archives'] = pods_v( 'label_archives', $post_type, '', true ); |
||
| 475 | $cpt_labels['insert_into_item'] = pods_v( 'label_insert_into_item', $post_type, '', true ); |
||
| 476 | $cpt_labels['uploaded_to_this_item'] = pods_v( 'label_uploaded_to_this_item', $post_type, '', true ); |
||
| 477 | $cpt_labels['featured_image'] = pods_v( 'label_featured_image', $post_type, '', true ); |
||
| 478 | $cpt_labels['set_featured_image'] = pods_v( 'label_set_featured_image', $post_type, '', true ); |
||
| 479 | $cpt_labels['remove_featured_image'] = pods_v( 'label_remove_featured_image', $post_type, '', true ); |
||
| 480 | $cpt_labels['use_featured_image'] = pods_v( 'label_use_featured_image', $post_type, '', true ); |
||
| 481 | $cpt_labels['filter_items_list'] = pods_v( 'label_filter_items_list', $post_type, '', true ); |
||
| 482 | $cpt_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $post_type, '', true ); |
||
| 483 | $cpt_labels['items_list'] = pods_v( 'label_items_list', $post_type, '', true ); |
||
| 484 | |||
| 485 | // Supported |
||
| 486 | $cpt_supported = array( |
||
| 487 | 'title' => (boolean) pods_v( 'supports_title', $post_type, false ), |
||
| 488 | 'editor' => (boolean) pods_v( 'supports_editor', $post_type, false ), |
||
| 489 | 'author' => (boolean) pods_v( 'supports_author', $post_type, false ), |
||
| 490 | 'thumbnail' => (boolean) pods_v( 'supports_thumbnail', $post_type, false ), |
||
| 491 | 'excerpt' => (boolean) pods_v( 'supports_excerpt', $post_type, false ), |
||
| 492 | 'trackbacks' => (boolean) pods_v( 'supports_trackbacks', $post_type, false ), |
||
| 493 | 'custom-fields' => (boolean) pods_v( 'supports_custom_fields', $post_type, false ), |
||
| 494 | 'comments' => (boolean) pods_v( 'supports_comments', $post_type, false ), |
||
| 495 | 'revisions' => (boolean) pods_v( 'supports_revisions', $post_type, false ), |
||
| 496 | 'page-attributes' => (boolean) pods_v( 'supports_page_attributes', $post_type, false ), |
||
| 497 | 'post-formats' => (boolean) pods_v( 'supports_post_formats', $post_type, false ) |
||
| 498 | ); |
||
| 499 | |||
| 500 | // Custom Supported |
||
| 501 | $cpt_supported_custom = pods_v_sanitized( 'supports_custom', $post_type, '' ); |
||
| 502 | |||
| 503 | if ( ! empty( $cpt_supported_custom ) ) { |
||
| 504 | $cpt_supported_custom = explode( ',', $cpt_supported_custom ); |
||
| 505 | $cpt_supported_custom = array_filter( array_unique( $cpt_supported_custom ) ); |
||
| 506 | |||
| 507 | foreach ( $cpt_supported_custom as $cpt_support ) { |
||
| 508 | $cpt_supported[ $cpt_support ] = true; |
||
| 509 | } |
||
| 510 | } |
||
| 511 | |||
| 512 | // Genesis Support |
||
| 513 | if ( function_exists( 'genesis' ) ) { |
||
| 514 | $cpt_supported['genesis-seo'] = (boolean) pods_var( 'supports_genesis_seo', $post_type, false ); |
||
| 515 | $cpt_supported['genesis-layouts'] = (boolean) pods_var( 'supports_genesis_layouts', $post_type, false ); |
||
| 516 | $cpt_supported['genesis-simple-sidebars'] = (boolean) pods_var( 'supports_genesis_simple_sidebars', $post_type, false ); |
||
| 517 | } |
||
| 518 | |||
| 519 | // YARPP Support |
||
| 520 | if ( defined( 'YARPP_VERSION' ) ) { |
||
| 521 | $cpt_supported['yarpp_support'] = (boolean) pods_var( 'supports_yarpp_support', $post_type, false ); |
||
| 522 | } |
||
| 523 | |||
| 524 | // Jetpack Support |
||
| 525 | if ( class_exists( 'Jetpack' ) ) { |
||
| 526 | $cpt_supported['supports_jetpack_publicize'] = (boolean) pods_var( 'supports_jetpack_publicize', $post_type, false ); |
||
| 527 | $cpt_supported['supports_jetpack_markdown'] = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false ); |
||
| 528 | } |
||
| 529 | |||
| 530 | // WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :( |
||
| 531 | $cpt_supports = array(); |
||
| 532 | |||
| 533 | if ( ! pods_version_check( 'wp', '3.5' ) ) { |
||
| 534 | $cpt_supports = array( '_bug_fix_pre_35' ); |
||
| 535 | } |
||
| 536 | |||
| 537 | foreach ( $cpt_supported as $cpt_support => $supported ) { |
||
| 538 | if ( true === $supported ) { |
||
| 539 | $cpt_supports[] = $cpt_support; |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | if ( empty( $cpt_supports ) && pods_version_check( 'wp', '3.5' ) ) { |
||
| 544 | $cpt_supports = false; |
||
| 545 | } |
||
| 546 | |||
| 547 | // Rewrite |
||
| 548 | $cpt_rewrite = (boolean) pods_var( 'rewrite', $post_type, true ); |
||
| 549 | $cpt_rewrite_array = array( |
||
| 550 | 'slug' => pods_var( 'rewrite_custom_slug', $post_type, str_replace( '_', '-', $post_type_name ), null, true ), |
||
| 551 | 'with_front' => (boolean) pods_var( 'rewrite_with_front', $post_type, true ), |
||
| 552 | 'feeds' => (boolean) pods_var( 'rewrite_feeds', $post_type, (boolean) pods_var( 'has_archive', $post_type, false ) ), |
||
| 553 | 'pages' => (boolean) pods_var( 'rewrite_pages', $post_type, true ) |
||
| 554 | ); |
||
| 555 | |||
| 556 | if ( false !== $cpt_rewrite ) { |
||
| 557 | $cpt_rewrite = $cpt_rewrite_array; |
||
| 558 | } |
||
| 559 | |||
| 560 | $capability_type = pods_var( 'capability_type', $post_type, 'post' ); |
||
| 561 | |||
| 562 | if ( 'custom' == $capability_type ) { |
||
| 563 | $capability_type = pods_var( 'capability_type_custom', $post_type, 'post' ); |
||
| 564 | } |
||
| 565 | |||
| 566 | $show_in_menu = (boolean) pods_var( 'show_in_menu', $post_type, true ); |
||
| 567 | |||
| 568 | if ( $show_in_menu && 0 < strlen( pods_var_raw( 'menu_location_custom', $post_type ) ) ) { |
||
| 569 | $show_in_menu = pods_var_raw( 'menu_location_custom', $post_type ); |
||
| 570 | } |
||
| 571 | |||
| 572 | $menu_icon = pods_var( 'menu_icon', $post_type, null, null, true ); |
||
| 573 | |||
| 574 | if ( ! empty( $menu_icon ) ) { |
||
| 575 | $menu_icon = pods_evaluate_tags( $menu_icon ); |
||
| 576 | } |
||
| 577 | |||
| 578 | // Register Post Type |
||
| 579 | $pods_post_types[ $post_type_name ] = array( |
||
| 580 | 'label' => $cpt_label, |
||
| 581 | 'labels' => $cpt_labels, |
||
| 582 | 'description' => esc_html( pods_var_raw( 'description', $post_type ) ), |
||
| 583 | 'public' => (boolean) pods_var( 'public', $post_type, true ), |
||
| 584 | 'publicly_queryable' => (boolean) pods_var( 'publicly_queryable', $post_type, (boolean) pods_var( 'public', $post_type, true ) ), |
||
| 585 | 'exclude_from_search' => (boolean) pods_var( 'exclude_from_search', $post_type, ( (boolean) pods_var( 'public', $post_type, true ) ? false : true ) ), |
||
| 586 | 'show_ui' => (boolean) pods_var( 'show_ui', $post_type, (boolean) pods_var( 'public', $post_type, true ) ), |
||
| 587 | 'show_in_menu' => $show_in_menu, |
||
| 588 | 'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $post_type, (boolean) pods_var( 'public', $post_type, true ) ), |
||
| 589 | 'show_in_admin_bar' => (boolean) pods_var( 'show_in_admin_bar', $post_type, (boolean) pods_var( 'show_in_menu', $post_type, true ) ), |
||
| 590 | 'menu_position' => (int) pods_var( 'menu_position', $post_type, 0, null, true ), |
||
| 591 | 'menu_icon' => $menu_icon, |
||
| 592 | 'capability_type' => $capability_type, |
||
| 593 | //'capabilities' => $cpt_capabilities, |
||
| 594 | 'map_meta_cap' => (boolean) pods_var( 'capability_type_extra', $post_type, true ), |
||
| 595 | 'hierarchical' => (boolean) pods_var( 'hierarchical', $post_type, false ), |
||
| 596 | 'supports' => $cpt_supports, |
||
| 597 | //'register_meta_box_cb' => array($this, 'manage_meta_box'), |
||
| 598 | //'permalink_epmask' => EP_PERMALINK, |
||
| 599 | 'has_archive' => pods_v( 'has_archive_slug', $post_type, (boolean) pods_v( 'has_archive', $post_type, false ), true ), |
||
| 600 | 'rewrite' => $cpt_rewrite, |
||
| 601 | 'query_var' => ( false !== (boolean) pods_var( 'query_var', $post_type, true ) ? pods_var( 'query_var_string', $post_type, $post_type_name, null, true ) : false ), |
||
| 602 | 'can_export' => (boolean) pods_var( 'can_export', $post_type, true ) |
||
| 603 | ); |
||
| 604 | |||
| 605 | // YARPP doesn't use 'supports' array option (yet) |
||
| 606 | if ( ! empty( $cpt_supports['yarpp_support'] ) ) { |
||
| 607 | $pods_post_types[ $post_type_name ]['yarpp_support'] = true; |
||
| 608 | } |
||
| 609 | |||
| 610 | // Prevent reserved query_var issues |
||
| 611 | if ( in_array( $pods_post_types[ $post_type_name ]['query_var'], $reserved_query_vars ) ) { |
||
| 612 | $pods_post_types[ $post_type_name ]['query_var'] = 'post_type_' . $pods_post_types[ $post_type_name ]['query_var']; |
||
| 613 | } |
||
| 614 | |||
| 615 | if ( 25 == $pods_post_types[ $post_type_name ]['menu_position'] ) { |
||
| 616 | $pods_post_types[ $post_type_name ]['menu_position'] ++; |
||
| 617 | } |
||
| 618 | |||
| 619 | if ( $pods_post_types[ $post_type_name ]['menu_position'] < 1 || in_array( $pods_post_types[ $post_type_name ]['menu_position'], $cpt_positions ) ) { |
||
| 620 | unset( $pods_post_types[ $post_type_name ]['menu_position'] ); |
||
| 621 | } else { |
||
| 622 | $cpt_positions[] = $pods_post_types[ $post_type_name ]['menu_position']; |
||
| 623 | |||
| 624 | // This would be nice if WP supported floats in menu_position |
||
| 625 | // $pods_post_types[ $post_type_name ][ 'menu_position' ] = $pods_post_types[ $post_type_name ][ 'menu_position' ] . '.1'; |
||
| 626 | } |
||
| 627 | |||
| 628 | // Taxonomies |
||
| 629 | $cpt_taxonomies = array(); |
||
| 630 | $_taxonomies = get_taxonomies(); |
||
| 631 | $_taxonomies = array_merge_recursive( $_taxonomies, $pods_taxonomies ); |
||
| 632 | $ignore = array( 'nav_menu', 'link_category', 'post_format' ); |
||
| 633 | |||
| 634 | View Code Duplication | foreach ( $_taxonomies as $taxonomy => $label ) { |
|
| 635 | if ( in_array( $taxonomy, $ignore ) ) { |
||
| 636 | continue; |
||
| 637 | } |
||
| 638 | |||
| 639 | if ( false !== (boolean) pods_var( 'built_in_taxonomies_' . $taxonomy, $post_type, false ) ) { |
||
| 640 | $cpt_taxonomies[] = $taxonomy; |
||
| 641 | |||
| 642 | if ( isset( $supported_post_types[ $taxonomy ] ) && ! in_array( $post_type_name, $supported_post_types[ $taxonomy ] ) ) { |
||
| 643 | $supported_post_types[ $taxonomy ][] = $post_type_name; |
||
| 644 | } |
||
| 645 | } |
||
| 646 | } |
||
| 647 | |||
| 648 | if ( isset( $supported_taxonomies[ $post_type_name ] ) ) { |
||
| 649 | $supported_taxonomies[ $post_type_name ] = array_merge( (array) $supported_taxonomies[ $post_type_name ], $cpt_taxonomies ); |
||
| 650 | } else { |
||
| 651 | $supported_taxonomies[ $post_type_name ] = $cpt_taxonomies; |
||
| 652 | } |
||
| 653 | } |
||
| 654 | |||
| 655 | foreach ( $taxonomies as $taxonomy ) { |
||
| 656 | // Taxonomy Type exists already |
||
| 657 | View Code Duplication | if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) { |
|
| 658 | continue; |
||
| 659 | } elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) { |
||
| 660 | continue; |
||
| 661 | } elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) { |
||
| 662 | continue; |
||
| 663 | } |
||
| 664 | |||
| 665 | $taxonomy['options']['name'] = $taxonomy['name']; |
||
| 666 | $taxonomy = array_merge( $taxonomy, (array) $taxonomy['options'] ); |
||
| 667 | |||
| 668 | $taxonomy_name = pods_var( 'name', $taxonomy ); |
||
| 669 | |||
| 670 | // Labels |
||
| 671 | $ct_label = esc_html( pods_v( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'name', $taxonomy ) ) ), true ) ); |
||
| 672 | $ct_singular = esc_html( pods_v( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'label', $taxonomy, pods_v( 'name', $taxonomy ), null, true ) ) ), true ) ); |
||
| 673 | |||
| 674 | $ct_labels = array(); |
||
| 675 | $ct_labels['name'] = $ct_label; |
||
| 676 | $ct_labels['singular_name'] = $ct_singular; |
||
| 677 | $ct_labels['menu_name'] = pods_v( 'menu_name', $taxonomy, '', true ); |
||
| 678 | $ct_labels['search_items'] = pods_v( 'label_search_items', $taxonomy, '', true ); |
||
| 679 | $ct_labels['popular_items'] = pods_v( 'label_popular_items', $taxonomy, '', true ); |
||
| 680 | $ct_labels['all_items'] = pods_v( 'label_all_items', $taxonomy, '', true ); |
||
| 681 | $ct_labels['parent_item'] = pods_v( 'label_parent_item', $taxonomy, '', true ); |
||
| 682 | $ct_labels['parent_item_colon'] = pods_v( 'label_parent_item_colon', $taxonomy, '', true ); |
||
| 683 | $ct_labels['edit_item'] = pods_v( 'label_edit_item', $taxonomy, '', true ); |
||
| 684 | $ct_labels['update_item'] = pods_v( 'label_update_item', $taxonomy, '', true ); |
||
| 685 | $ct_labels['view_item'] = pods_v( 'label_view_item', $taxonomy, '', true ); |
||
| 686 | $ct_labels['add_new_item'] = pods_v( 'label_add_new_item', $taxonomy, '', true ); |
||
| 687 | $ct_labels['new_item_name'] = pods_v( 'label_new_item_name', $taxonomy, '', true ); |
||
| 688 | $ct_labels['separate_items_with_commas'] = pods_v( 'label_separate_items_with_commas', $taxonomy, '', true ); |
||
| 689 | $ct_labels['add_or_remove_items'] = pods_v( 'label_add_or_remove_items', $taxonomy, '', true ); |
||
| 690 | $ct_labels['choose_from_most_used'] = pods_v( 'label_choose_from_the_most_used', $taxonomy, '', true ); |
||
| 691 | $ct_labels['not_found'] = pods_v( 'label_not_found', $taxonomy, '', true ); |
||
| 692 | $ct_labels['no_terms'] = pods_v( 'label_no_terms', $taxonomy, '', true ); |
||
| 693 | $ct_labels['items_list'] = pods_v( 'label_items_list', $taxonomy, '', true ); |
||
| 694 | $ct_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $taxonomy, '', true ); |
||
| 695 | |||
| 696 | // Rewrite |
||
| 697 | $ct_rewrite = (boolean) pods_var( 'rewrite', $taxonomy, true ); |
||
| 698 | $ct_rewrite_array = array( |
||
| 699 | 'slug' => pods_var( 'rewrite_custom_slug', $taxonomy, str_replace( '_', '-', $taxonomy_name ), null, true ), |
||
| 700 | 'with_front' => (boolean) pods_var( 'rewrite_with_front', $taxonomy, true ), |
||
| 701 | 'hierarchical' => (boolean) pods_var( 'rewrite_hierarchical', $taxonomy, (boolean) pods_var( 'hierarchical', $taxonomy, false ) ) |
||
| 702 | ); |
||
| 703 | |||
| 704 | if ( false !== $ct_rewrite ) { |
||
| 705 | $ct_rewrite = $ct_rewrite_array; |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Default tax capabilities |
||
| 710 | * @see https://codex.wordpress.org/Function_Reference/register_taxonomy |
||
| 711 | */ |
||
| 712 | $capability_type = pods_var( 'capability_type', $taxonomy, 'default' ); |
||
| 713 | $tax_capabilities = array(); |
||
| 714 | |||
| 715 | if ( 'custom' == $capability_type ) { |
||
| 716 | $capability_type = pods_var( 'capability_type_custom', $taxonomy, 'default' ); |
||
| 717 | if ( ! empty( $capability_type ) && 'default' != $capability_type ) { |
||
| 718 | $capability_type .= '_terms'; |
||
| 719 | $tax_capabilities = array( |
||
| 720 | 'manage_terms' => 'manage_' . $capability_type, |
||
| 721 | 'edit_terms' => 'edit_' . $capability_type, |
||
| 722 | 'delete_terms' => 'delete_' . $capability_type, |
||
| 723 | 'assign_terms' => 'assign_' . $capability_type, |
||
| 724 | ); |
||
| 725 | } |
||
| 726 | } |
||
| 727 | |||
| 728 | // Register Taxonomy |
||
| 729 | $pods_taxonomies[ $taxonomy_name ] = array( |
||
| 730 | 'label' => $ct_label, |
||
| 731 | 'labels' => $ct_labels, |
||
| 732 | 'public' => (boolean) pods_var( 'public', $taxonomy, true ), |
||
| 733 | 'show_ui' => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ), |
||
| 734 | 'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ), |
||
| 735 | 'show_tagcloud' => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ), |
||
| 736 | 'show_tagcloud_in_edit' => (boolean) pods_var( 'show_tagcloud_in_edit', $taxonomy, (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ) ), |
||
| 737 | 'show_in_quick_edit' => (boolean) pods_var( 'show_in_quick_edit', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ), |
||
| 738 | 'hierarchical' => (boolean) pods_var( 'hierarchical', $taxonomy, false ), |
||
| 739 | //'capability_type' => $capability_type, |
||
| 740 | 'capabilities' => $tax_capabilities, |
||
| 741 | //'map_meta_cap' => (boolean) pods_var( 'capability_type_extra', $taxonomy, true ), |
||
| 742 | 'update_count_callback' => pods_var( 'update_count_callback', $taxonomy, null, null, true ), |
||
| 743 | 'query_var' => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ), |
||
| 744 | 'rewrite' => $ct_rewrite, |
||
| 745 | 'show_admin_column' => (boolean) pods_var( 'show_admin_column', $taxonomy, false ), |
||
| 746 | 'sort' => (boolean) pods_var( 'sort', $taxonomy, false ), |
||
| 747 | ); |
||
| 748 | |||
| 749 | if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) { |
||
| 750 | $pods_taxonomies[ $taxonomy_name ]['query_var'] = pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ); |
||
| 751 | }; |
||
| 752 | |||
| 753 | // Prevent reserved query_var issues |
||
| 754 | if ( in_array( $pods_taxonomies[ $taxonomy_name ]['query_var'], $reserved_query_vars ) ) { |
||
| 755 | $pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var']; |
||
| 756 | } |
||
| 757 | |||
| 758 | // Integration for Single Value Taxonomy UI |
||
| 759 | if ( function_exists( 'tax_single_value_meta_box' ) ) { |
||
| 760 | $pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false ); |
||
| 761 | $pods_taxonomies[ $taxonomy_name ]['required'] = (boolean) pods_var( 'single_value_required', $taxonomy, false ); |
||
| 762 | } |
||
| 763 | |||
| 764 | // Post Types |
||
| 765 | $ct_post_types = array(); |
||
| 766 | $_post_types = get_post_types(); |
||
| 767 | $_post_types = array_merge_recursive( $_post_types, $pods_post_types ); |
||
| 768 | $ignore = array( 'revision' ); |
||
| 769 | |||
| 770 | View Code Duplication | foreach ( $_post_types as $post_type => $options ) { |
|
| 771 | if ( in_array( $post_type, $ignore ) ) { |
||
| 772 | continue; |
||
| 773 | } |
||
| 774 | |||
| 775 | if ( false !== (boolean) pods_var( 'built_in_post_types_' . $post_type, $taxonomy, false ) ) { |
||
| 776 | $ct_post_types[] = $post_type; |
||
| 777 | |||
| 778 | if ( isset( $supported_taxonomies[ $post_type ] ) && ! in_array( $taxonomy_name, $supported_taxonomies[ $post_type ] ) ) { |
||
| 779 | $supported_taxonomies[ $post_type ][] = $taxonomy_name; |
||
| 780 | } |
||
| 781 | } |
||
| 782 | } |
||
| 783 | |||
| 784 | if ( isset( $supported_post_types[ $taxonomy_name ] ) ) { |
||
| 785 | $supported_post_types[ $taxonomy_name ] = array_merge( $supported_post_types[ $taxonomy_name ], $ct_post_types ); |
||
| 786 | } else { |
||
| 787 | $supported_post_types[ $taxonomy_name ] = $ct_post_types; |
||
| 788 | } |
||
| 789 | } |
||
| 790 | |||
| 791 | $pods_post_types = apply_filters( 'pods_wp_post_types', $pods_post_types ); |
||
| 792 | $pods_taxonomies = apply_filters( 'pods_wp_taxonomies', $pods_taxonomies ); |
||
| 793 | |||
| 794 | $supported_post_types = apply_filters( 'pods_wp_supported_post_types', $supported_post_types ); |
||
| 795 | $supported_taxonomies = apply_filters( 'pods_wp_supported_taxonomies', $supported_taxonomies ); |
||
| 796 | |||
| 797 | foreach ( $pods_taxonomies as $taxonomy => $options ) { |
||
| 798 | $ct_post_types = null; |
||
| 799 | |||
| 800 | if ( isset( $supported_post_types[ $taxonomy ] ) && ! empty( $supported_post_types[ $taxonomy ] ) ) { |
||
| 801 | $ct_post_types = $supported_post_types[ $taxonomy ]; |
||
| 802 | } |
||
| 803 | |||
| 804 | $pods_cpt_ct['taxonomies'][ $taxonomy ] = array( |
||
| 805 | 'post_types' => $ct_post_types, |
||
| 806 | 'options' => $options |
||
| 807 | ); |
||
| 808 | } |
||
| 809 | |||
| 810 | foreach ( $pods_post_types as $post_type => $options ) { |
||
| 811 | if ( isset( $supported_taxonomies[ $post_type ] ) && ! empty( $supported_taxonomies[ $post_type ] ) ) { |
||
| 812 | $options['taxonomies'] = $supported_taxonomies[ $post_type ]; |
||
| 813 | } |
||
| 814 | |||
| 815 | $pods_cpt_ct['post_types'][ $post_type ] = $options; |
||
| 816 | } |
||
| 817 | |||
| 818 | pods_transient_set( 'pods_wp_cpt_ct', $pods_cpt_ct ); |
||
| 819 | } |
||
| 820 | |||
| 821 | foreach ( $pods_cpt_ct['taxonomies'] as $taxonomy => $options ) { |
||
| 822 | if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy, self::$content_types_registered['taxonomies'] ) ) { |
||
| 823 | continue; |
||
| 824 | } |
||
| 825 | |||
| 826 | $ct_post_types = $options['post_types']; |
||
| 827 | $options = $options['options']; |
||
| 828 | |||
| 829 | $options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy ); |
||
| 830 | $options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy ); |
||
| 831 | |||
| 832 | $options = self::object_label_fix( $options, 'taxonomy' ); |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Hide tagcloud compatibility |
||
| 836 | * @todo check https://core.trac.wordpress.org/ticket/36964 |
||
| 837 | * @see wp-admin/edit-tags.php L389 |
||
| 838 | */ |
||
| 839 | if ( true != (boolean) pods_var( 'show_tagcloud_in_edit', $options, (boolean) pods_var( 'show_tagcloud', $options, true ) ) ) { |
||
| 840 | $options['labels']['popular_items'] = null; |
||
| 841 | } |
||
| 842 | |||
| 843 | // Max length for taxonomies are 32 characters |
||
| 844 | $taxonomy = substr( $taxonomy, 0, 32 ); |
||
| 845 | |||
| 846 | // i18n compatibility for plugins that override it |
||
| 847 | View Code Duplication | if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) { |
|
| 848 | $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' ); |
||
| 849 | } |
||
| 850 | |||
| 851 | View Code Duplication | if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) { |
|
| 852 | pods_debug( array( $taxonomy, $ct_post_types, $options ) ); |
||
| 853 | } |
||
| 854 | |||
| 855 | register_taxonomy( $taxonomy, $ct_post_types, $options ); |
||
| 856 | |||
| 857 | if ( ! isset( self::$content_types_registered['taxonomies'] ) ) { |
||
| 858 | self::$content_types_registered['taxonomies'] = array(); |
||
| 859 | } |
||
| 860 | |||
| 861 | self::$content_types_registered['taxonomies'][] = $taxonomy; |
||
| 862 | } |
||
| 863 | |||
| 864 | foreach ( $pods_cpt_ct['post_types'] as $post_type => $options ) { |
||
| 865 | if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type, self::$content_types_registered['post_types'] ) ) { |
||
| 866 | continue; |
||
| 867 | } |
||
| 868 | |||
| 869 | $options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type ); |
||
| 870 | $options = apply_filters( 'pods_register_post_type', $options, $post_type ); |
||
| 871 | |||
| 872 | $options = self::object_label_fix( $options, 'post_type' ); |
||
| 873 | |||
| 874 | // Max length for post types are 20 characters |
||
| 875 | $post_type = substr( $post_type, 0, 20 ); |
||
| 876 | |||
| 877 | // i18n compatibility for plugins that override it |
||
| 878 | View Code Duplication | if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) { |
|
| 879 | $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' ); |
||
| 880 | } |
||
| 881 | |||
| 882 | View Code Duplication | if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) { |
|
| 883 | pods_debug( array( $post_type, $options ) ); |
||
| 884 | } |
||
| 885 | |||
| 886 | register_post_type( $post_type, $options ); |
||
| 887 | |||
| 888 | if ( ! isset( self::$content_types_registered['post_types'] ) ) { |
||
| 889 | self::$content_types_registered['post_types'] = array(); |
||
| 890 | } |
||
| 891 | |||
| 892 | self::$content_types_registered['post_types'][] = $post_type; |
||
| 893 | } |
||
| 894 | |||
| 895 | } |
||
| 896 | |||
| 897 | /** |
||
| 898 | * Check if we need to flush WordPress rewrite rules |
||
| 899 | * This gets run during 'init' action late in the game to give other plugins time to register their rewrite rules |
||
| 900 | */ |
||
| 901 | public function flush_rewrite_rules() { |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Update Post Type messages |
||
| 919 | * |
||
| 920 | * @param array $messages |
||
| 921 | * |
||
| 922 | * @return array |
||
| 923 | * @since 2.0.2 |
||
| 924 | */ |
||
| 925 | public function setup_updated_messages( $messages ) { |
||
| 973 | |||
| 974 | /** |
||
| 975 | * @param $args |
||
| 976 | * @param string $type |
||
| 977 | * |
||
| 978 | * @return array |
||
| 979 | */ |
||
| 980 | public static function object_label_fix( $args, $type = 'post_type' ) { |
||
| 981 | |||
| 982 | if ( empty( $args ) || ! is_array( $args ) ) { |
||
| 983 | $args = array(); |
||
| 984 | } |
||
| 985 | |||
| 986 | if ( ! isset( $args['labels'] ) || ! is_array( $args['labels'] ) ) { |
||
| 987 | $args['labels'] = array(); |
||
| 988 | } |
||
| 989 | |||
| 990 | $label = pods_v( 'name', $args['labels'], pods_v( 'label', $args, __( 'Items', 'pods' ), true ), true ); |
||
| 991 | $singular_label = pods_v( 'singular_name', $args['labels'], pods_v( 'label_singular', $args, __( 'Item', 'pods' ), true ), true ); |
||
| 992 | |||
| 993 | $labels = $args['labels']; |
||
| 994 | |||
| 995 | $labels['name'] = $label; |
||
| 996 | $labels['singular_name'] = $singular_label; |
||
| 997 | |||
| 998 | if ( 'post_type' == $type ) { |
||
| 999 | $labels['menu_name'] = pods_v( 'menu_name', $labels, $label, true ); |
||
| 1000 | $labels['name_admin_bar'] = pods_v( 'name_admin_bar', $labels, $singular_label, true ); |
||
| 1001 | $labels['add_new'] = pods_v( 'add_new', $labels, __( 'Add New', 'pods' ), true ); |
||
| 1002 | $labels['add_new_item'] = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true ); |
||
| 1003 | $labels['new_item'] = pods_v( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), true ); |
||
| 1004 | $labels['edit'] = pods_v( 'edit', $labels, __( 'Edit', 'pods' ), true ); |
||
| 1005 | $labels['edit_item'] = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true ); |
||
| 1006 | $labels['view'] = pods_v( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true ); |
||
| 1007 | $labels['view_item'] = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true ); |
||
| 1008 | $labels['all_items'] = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true ); |
||
| 1009 | $labels['search_items'] = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true ); |
||
| 1010 | $labels['not_found'] = pods_v( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), true ); |
||
| 1011 | $labels['not_found_in_trash'] = pods_v( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), true ); |
||
| 1012 | $labels['parent'] = pods_v( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true ); |
||
| 1013 | $labels['parent_item_colon'] = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), true ); |
||
| 1014 | $labels['featured_image'] = pods_v( 'featured_image', $labels, __( 'Featured Image', 'pods' ), true ); |
||
| 1015 | $labels['set_featured_image'] = pods_v( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), true ); |
||
| 1016 | $labels['remove_featured_image'] = pods_v( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), true ); |
||
| 1017 | $labels['use_featured_image'] = pods_v( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), true ); |
||
| 1018 | $labels['archives'] = pods_v( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), true ); |
||
| 1019 | $labels['insert_into_item'] = pods_v( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), true ); |
||
| 1020 | $labels['uploaded_to_this_item'] = pods_v( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), true ); |
||
| 1021 | $labels['filter_items_list'] = pods_v( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), true ); |
||
| 1022 | $labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true ); |
||
| 1023 | $labels['items_list'] = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true ); |
||
| 1024 | } elseif ( 'taxonomy' == $type ) { |
||
| 1025 | $labels['menu_name'] = pods_v( 'menu_name', $labels, $label, true ); |
||
| 1026 | $labels['search_items'] = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true ); |
||
| 1027 | $labels['popular_items'] = pods_v( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), true ); |
||
| 1028 | $labels['all_items'] = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true ); |
||
| 1029 | $labels['parent_item'] = pods_v( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true ); |
||
| 1030 | $labels['parent_item_colon'] = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), true ); |
||
| 1031 | $labels['edit_item'] = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true ); |
||
| 1032 | $labels['view_item'] = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true ); |
||
| 1033 | $labels['update_item'] = pods_v( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), true ); |
||
| 1034 | $labels['add_new_item'] = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true ); |
||
| 1035 | $labels['new_item_name'] = pods_v( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), true ); |
||
| 1036 | $labels['separate_items_with_commas'] = pods_v( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), true ); |
||
| 1037 | $labels['add_or_remove_items'] = pods_v( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), true ); |
||
| 1038 | $labels['choose_from_most_used'] = pods_v( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), true ); |
||
| 1039 | $labels['not_found'] = pods_v( 'not_found', $labels, sprintf( __( 'No %s found.', 'pods' ), $label ), true ); |
||
| 1040 | $labels['no_terms'] = pods_v( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), true ); |
||
| 1041 | $labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true ); |
||
| 1042 | $labels['items_list'] = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true ); |
||
| 1043 | } |
||
| 1044 | |||
| 1045 | $args['labels'] = $labels; |
||
| 1046 | |||
| 1047 | return $args; |
||
| 1048 | } |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Activate and Install |
||
| 1052 | */ |
||
| 1053 | public function activate_install() { |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * |
||
| 1075 | */ |
||
| 1076 | public function activate() { |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * |
||
| 1093 | */ |
||
| 1094 | public function deactivate() { |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * |
||
| 1102 | */ |
||
| 1103 | public function needs_upgrade( $current = null, $last = null ) { |
||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * @param $_blog_id |
||
| 1133 | * @param $user_id |
||
| 1134 | * @param $domain |
||
| 1135 | * @param $path |
||
| 1136 | * @param $site_id |
||
| 1137 | * @param $meta |
||
| 1138 | */ |
||
| 1139 | public function new_blog( $_blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * @param null $_blog_id |
||
| 1148 | */ |
||
| 1149 | public function setup( $_blog_id = null ) { |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * @param null $_blog_id |
||
| 1227 | */ |
||
| 1228 | public function reset( $_blog_id = null ) { |
||
| 1308 | |||
| 1309 | public function run() { |
||
| 1310 | |||
| 1311 | static $ran; |
||
| 1312 | |||
| 1313 | if ( ! empty( $ran ) ) { |
||
| 1314 | return; |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | $ran = true; |
||
| 1318 | |||
| 1319 | $this->load_i18n(); |
||
| 1320 | |||
| 1321 | if ( ! did_action( 'plugins_loaded' ) ) { |
||
| 1322 | add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 ); |
||
| 1323 | } else { |
||
| 1324 | $this->load_components(); |
||
| 1325 | } |
||
| 1326 | |||
| 1327 | if ( ! did_action( 'setup_theme' ) ) { |
||
| 1328 | add_action( 'setup_theme', array( $this, 'load_meta' ), 14 ); |
||
| 1329 | } else { |
||
| 1330 | $this->load_meta(); |
||
| 1331 | } |
||
| 1332 | |||
| 1333 | if ( ! did_action( 'init' ) ) { |
||
| 1334 | add_action( 'init', array( $this, 'core' ), 11 ); |
||
| 1335 | add_action( 'init', array( $this, 'add_rest_support' ), 12 ); |
||
| 1336 | add_action( 'init', array( $this, 'setup_content_types' ), 11 ); |
||
| 1337 | |||
| 1338 | if ( is_admin() ) { |
||
| 1339 | add_action( 'init', array( $this, 'admin_init' ), 12 ); |
||
| 1340 | } |
||
| 1341 | } else { |
||
| 1342 | $this->core(); |
||
| 1343 | $this->add_rest_support(); |
||
| 1344 | $this->setup_content_types(); |
||
| 1345 | |||
| 1346 | if ( is_admin() ) { |
||
| 1347 | $this->admin_init(); |
||
| 1348 | } |
||
| 1349 | } |
||
| 1350 | |||
| 1351 | add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ), 15 ); |
||
| 1352 | add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ), 15 ); |
||
| 1353 | add_action( 'login_enqueue_scripts', array( $this, 'register_assets' ), 15 ); |
||
| 1354 | |||
| 1355 | add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 ); |
||
| 1356 | add_action( 'delete_attachment', array( $this, 'delete_attachment' ) ); |
||
| 1357 | |||
| 1358 | // Register widgets |
||
| 1359 | add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
||
| 1360 | |||
| 1361 | // Show admin bar links |
||
| 1362 | add_action( 'admin_bar_menu', array( $this, 'admin_bar_links' ), 81 ); |
||
| 1363 | |||
| 1364 | } |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Delete Attachments from relationships |
||
| 1368 | * |
||
| 1369 | * @param int $_ID |
||
| 1370 | */ |
||
| 1371 | public function delete_attachment( $_ID ) { |
||
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Register widgets for Pods |
||
| 1471 | */ |
||
| 1472 | public function register_widgets() { |
||
| 1492 | |||
| 1493 | /** |
||
| 1494 | * Add Admin Bar links |
||
| 1495 | */ |
||
| 1496 | public function admin_bar_links() { |
||
| 1542 | |||
| 1543 | /** |
||
| 1544 | * Add REST API support to post type and taxonomy objects. |
||
| 1545 | * |
||
| 1546 | * @uses "init" |
||
| 1547 | * |
||
| 1548 | * @since 2.5.6 |
||
| 1549 | */ |
||
| 1550 | public function add_rest_support() { |
||
| 1612 | } |
||
| 1613 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.