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 PodsAdmin |
||
| 34 | */ |
||
| 35 | static $admin; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var mixed|void |
||
| 39 | */ |
||
| 40 | static $version; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var mixed|void |
||
| 44 | */ |
||
| 45 | static $version_last; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var mixed|void |
||
| 49 | */ |
||
| 50 | static $db_version; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Upgrades to trigger (last installed version => upgrade version) |
||
| 54 | * |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | static $upgrades = array( |
||
| 58 | '1.0.0' => '2.0.0' |
||
| 59 | //'2.0.0' => '2.1.0' |
||
| 60 | ); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Whether an Upgrade for 1.x has happened |
||
| 64 | * |
||
| 65 | * @var bool |
||
| 66 | */ |
||
| 67 | static $upgraded; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Whether an Upgrade is needed |
||
| 71 | * |
||
| 72 | * @var bool |
||
| 73 | */ |
||
| 74 | static $upgrade_needed = false; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Singleton handling for a basic pods_init() request |
||
| 78 | * |
||
| 79 | * @return \PodsInit |
||
| 80 | * |
||
| 81 | * @since 2.3.5 |
||
| 82 | */ |
||
| 83 | public static function init() { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Setup and Initiate Pods |
||
| 94 | * |
||
| 95 | * @return \PodsInit |
||
| 96 | * |
||
| 97 | * @license http://www.gnu.org/licenses/gpl-2.0.html |
||
| 98 | * @since 1.8.9 |
||
| 99 | */ |
||
| 100 | function __construct() { |
||
| 101 | |||
| 102 | self::$version = get_option( 'pods_framework_version' ); |
||
| 103 | self::$version_last = get_option( 'pods_framework_version_last' ); |
||
| 104 | self::$db_version = get_option( 'pods_framework_db_version' ); |
||
| 105 | self::$upgraded = (int) get_option( 'pods_framework_upgraded_1_x' ); |
||
| 106 | |||
| 107 | if ( empty( self::$version_last ) && 0 < strlen( get_option( 'pods_version' ) ) ) { |
||
| 108 | $old_version = get_option( 'pods_version' ); |
||
| 109 | |||
| 110 | if ( ! empty( $old_version ) ) { |
||
| 111 | if ( false === strpos( $old_version, '.' ) ) { |
||
| 112 | $old_version = pods_version_to_point( $old_version ); |
||
| 113 | } |
||
| 114 | |||
| 115 | update_option( 'pods_framework_version_last', $old_version ); |
||
| 116 | |||
| 117 | self::$version_last = $old_version; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | self::$upgrade_needed = $this->needs_upgrade(); |
||
| 122 | |||
| 123 | add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); |
||
| 124 | add_action( 'plugins_loaded', array( $this, 'activate_install' ), 9 ); |
||
| 125 | |||
| 126 | add_action( 'wp_loaded', array( $this, 'flush_rewrite_rules' ) ); |
||
| 127 | |||
| 128 | $this->run(); |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Load the plugin textdomain and set default constants |
||
| 134 | */ |
||
| 135 | public function plugins_loaded() { |
||
| 136 | |||
| 137 | if ( ! defined( 'PODS_LIGHT' ) ) { |
||
| 138 | define( 'PODS_LIGHT', false ); |
||
| 139 | } |
||
| 140 | |||
| 141 | if ( ! defined( 'PODS_TABLELESS' ) ) { |
||
| 142 | define( 'PODS_TABLELESS', false ); |
||
| 143 | } |
||
| 144 | |||
| 145 | load_plugin_textdomain( 'pods' ); |
||
| 146 | |||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Load Pods Components |
||
| 151 | */ |
||
| 152 | public function load_components() { |
||
| 153 | |||
| 154 | if ( empty( self::$version ) ) { |
||
| 155 | return; |
||
| 156 | } |
||
| 157 | |||
| 158 | if ( ! defined( 'PODS_LIGHT' ) || ! PODS_LIGHT ) { |
||
| 159 | self::$components = pods_components(); |
||
| 160 | } |
||
| 161 | |||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Load Pods Meta |
||
| 166 | */ |
||
| 167 | public function load_meta() { |
||
| 168 | |||
| 169 | self::$meta = pods_meta()->core(); |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Set up the Pods core |
||
| 174 | */ |
||
| 175 | public function core() { |
||
| 176 | |||
| 177 | if ( empty( self::$version ) ) { |
||
| 178 | return; |
||
| 179 | } |
||
| 180 | |||
| 181 | // Session start |
||
| 182 | pods_session_start(); |
||
| 183 | |||
| 184 | add_shortcode( 'pods', 'pods_shortcode' ); |
||
| 185 | add_shortcode( 'pods-form', 'pods_shortcode_form' ); |
||
| 186 | |||
| 187 | $security_settings = array( |
||
| 188 | 'pods_disable_file_browser' => 0, |
||
| 189 | 'pods_files_require_login' => 1, |
||
| 190 | 'pods_files_require_login_cap' => '', |
||
| 191 | 'pods_disable_file_upload' => 0, |
||
| 192 | 'pods_upload_require_login' => 1, |
||
| 193 | 'pods_upload_require_login_cap' => '' |
||
| 194 | ); |
||
| 195 | |||
| 196 | foreach ( $security_settings as $security_setting => $setting ) { |
||
| 197 | $setting = get_option( $security_setting ); |
||
| 198 | if ( ! empty( $setting ) ) { |
||
| 199 | $security_settings[ $security_setting ] = $setting; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | foreach ( $security_settings as $security_setting => $setting ) { |
||
| 204 | if ( 0 == $setting ) { |
||
| 205 | $setting = false; |
||
| 206 | } elseif ( 1 == $setting ) { |
||
| 207 | $setting = true; |
||
| 208 | } |
||
| 209 | |||
| 210 | if ( in_array( $security_setting, array( 'pods_files_require_login', 'pods_upload_require_login' ) ) ) { |
||
| 211 | if ( 0 < strlen( $security_settings[ $security_setting . '_cap' ] ) ) { |
||
| 212 | $setting = $security_settings[ $security_setting . '_cap' ]; |
||
| 213 | } |
||
| 214 | } elseif ( in_array( $security_setting, array( |
||
| 215 | 'pods_files_require_login_cap', |
||
| 216 | 'pods_upload_require_login_cap' |
||
| 217 | ) ) ) { |
||
| 218 | continue; |
||
| 219 | } |
||
| 220 | |||
| 221 | if ( ! defined( strtoupper( $security_setting ) ) ) { |
||
| 222 | define( strtoupper( $security_setting ), $setting ); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | $this->register_pods(); |
||
| 227 | |||
| 228 | $avatar = PodsForm::field_loader( 'avatar' ); |
||
| 229 | |||
| 230 | if ( method_exists( $avatar, 'get_avatar' ) ) { |
||
| 231 | add_filter( 'get_avatar', array( $avatar, 'get_avatar' ), 10, 4 ); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Register Scripts and Styles |
||
| 237 | */ |
||
| 238 | public function register_assets() { |
||
| 239 | |||
| 240 | if ( ! wp_style_is( 'jquery-ui', 'registered' ) ) { |
||
| 241 | wp_register_style( 'jquery-ui', PODS_URL . 'ui/css/smoothness/jquery-ui.custom.css', array(), '1.8.16' ); |
||
| 242 | } |
||
| 243 | |||
| 244 | wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' ); |
||
| 245 | |||
| 246 | if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) { |
||
| 247 | wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' ); |
||
| 248 | } |
||
| 249 | |||
| 250 | if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) { |
||
| 251 | wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' ); |
||
| 252 | } |
||
| 253 | |||
| 254 | wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array( |
||
| 255 | 'jquery', |
||
| 256 | 'pods-json', |
||
| 257 | 'jquery-qtip2' |
||
| 258 | ), PODS_VERSION ); |
||
| 259 | |||
| 260 | wp_register_style( 'pods-form', PODS_URL . 'ui/css/pods-form.css', array(), PODS_VERSION ); |
||
| 261 | |||
| 262 | wp_register_style( 'pods-cleditor', PODS_URL . 'ui/css/jquery.cleditor.css', array(), '1.3.0' ); |
||
| 263 | wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' ); |
||
| 264 | |||
| 265 | wp_register_style( 'pods-codemirror', PODS_URL . 'ui/css/codemirror.css', array(), '4.8' ); |
||
| 266 | wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '4.8', true ); |
||
| 267 | wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/addon/mode/loadmode.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 268 | wp_register_script( 'pods-codemirror-overlay', PODS_URL . 'ui/js/codemirror/addon/mode/overlay.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 269 | wp_register_script( 'pods-codemirror-hints', PODS_URL . 'ui/js/codemirror/addon/mode/show-hint.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 270 | wp_register_script( 'pods-codemirror-mode-xml', PODS_URL . 'ui/js/codemirror/mode/xml/xml.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 271 | wp_register_script( 'pods-codemirror-mode-html', PODS_URL . 'ui/js/codemirror/mode/htmlmixed/htmlmixed.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 272 | wp_register_script( 'pods-codemirror-mode-css', PODS_URL . 'ui/js/codemirror/mode/css/css.js', array( 'pods-codemirror' ), '4.8', true ); |
||
| 273 | |||
| 274 | if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) { |
||
| 275 | wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/css/jquery.ui.timepicker.css', array(), '1.1.1' ); |
||
| 276 | } |
||
| 277 | |||
| 278 | if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) { |
||
| 279 | wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/jquery.ui.timepicker.min.js', array( |
||
| 280 | 'jquery', |
||
| 281 | 'jquery-ui-core', |
||
| 282 | 'jquery-ui-datepicker', |
||
| 283 | 'jquery-ui-slider' |
||
| 284 | ), '1.1.1' ); |
||
| 285 | } |
||
| 286 | |||
| 287 | wp_register_style( 'pods-attach', PODS_URL . 'ui/css/jquery.pods.attach.css', array(), PODS_VERSION ); |
||
| 288 | wp_register_script( 'pods-attach', PODS_URL . 'ui/js/jquery.pods.attach.js', array(), PODS_VERSION ); |
||
| 289 | |||
| 290 | wp_register_style( 'pods-select2', PODS_URL . 'ui/js/select2/select2.css', array(), '3.3.1' ); |
||
| 291 | wp_register_script( 'pods-select2', PODS_URL . 'ui/js/select2/select2.min.js', array( 'jquery' ), '3.3.1' ); |
||
| 292 | |||
| 293 | wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' ); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Register internal Post Types |
||
| 298 | */ |
||
| 299 | public function register_pods() { |
||
| 300 | |||
| 301 | $args = array( |
||
| 302 | 'label' => 'Pods', |
||
| 303 | 'labels' => array( 'singular_name' => 'Pod' ), |
||
| 304 | 'public' => false, |
||
| 305 | 'can_export' => false, |
||
| 306 | 'query_var' => false, |
||
| 307 | 'rewrite' => false, |
||
| 308 | 'capability_type' => 'pods_pod', |
||
| 309 | 'has_archive' => false, |
||
| 310 | 'hierarchical' => false, |
||
| 311 | 'supports' => array( 'title', 'author' ), |
||
| 312 | 'menu_icon' => 'dashicons-pods' |
||
| 313 | ); |
||
| 314 | |||
| 315 | $args = self::object_label_fix( $args, 'post_type' ); |
||
| 316 | |||
| 317 | register_post_type( '_pods_pod', apply_filters( 'pods_internal_register_post_type_pod', $args ) ); |
||
| 318 | |||
| 319 | $args = array( |
||
| 320 | 'label' => 'Pod Fields', |
||
| 321 | 'labels' => array( 'singular_name' => 'Pod Field' ), |
||
| 322 | 'public' => false, |
||
| 323 | 'can_export' => false, |
||
| 324 | 'query_var' => false, |
||
| 325 | 'rewrite' => false, |
||
| 326 | 'capability_type' => 'pods_pod', |
||
| 327 | 'has_archive' => false, |
||
| 328 | 'hierarchical' => true, |
||
| 329 | 'supports' => array( 'title', 'editor', 'author' ), |
||
| 330 | 'menu_icon' => 'dashicons-pods' |
||
| 331 | ); |
||
| 332 | |||
| 333 | $args = self::object_label_fix( $args, 'post_type' ); |
||
| 334 | |||
| 335 | register_post_type( '_pods_field', apply_filters( 'pods_internal_register_post_type_field', $args ) ); |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Include Admin |
||
| 340 | */ |
||
| 341 | public function admin_init() { |
||
| 342 | |||
| 343 | self::$admin = pods_admin(); |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Register Post Types and Taxonomies |
||
| 348 | */ |
||
| 349 | public function setup_content_types( $force = false ) { |
||
| 350 | |||
| 351 | if ( empty( self::$version ) ) { |
||
| 352 | return; |
||
| 353 | } |
||
| 354 | |||
| 355 | $post_types = PodsMeta::$post_types; |
||
| 356 | $taxonomies = PodsMeta::$taxonomies; |
||
| 357 | |||
| 358 | $existing_post_types = get_post_types(); |
||
| 359 | $existing_taxonomies = get_taxonomies(); |
||
| 360 | |||
| 361 | $pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' ); |
||
| 362 | |||
| 363 | $cpt_positions = array(); |
||
| 364 | |||
| 365 | if ( empty( $pods_cpt_ct ) && ( ! empty( $post_types ) || ! empty( $taxonomies ) ) ) { |
||
| 366 | $force = true; |
||
| 367 | } elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['post_types'] ) && ! empty( $post_types ) ) { |
||
| 368 | $force = true; |
||
| 369 | } elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['taxonomies'] ) && ! empty( $taxonomies ) ) { |
||
| 370 | $force = true; |
||
| 371 | } |
||
| 372 | |||
| 373 | if ( false === $pods_cpt_ct || $force ) { |
||
| 374 | /** |
||
| 375 | * @var WP_Query |
||
| 376 | */ |
||
| 377 | global $wp_query; |
||
| 378 | |||
| 379 | $reserved_query_vars = array( |
||
| 380 | 'post_type', |
||
| 381 | 'taxonomy', |
||
| 382 | 'output' |
||
| 383 | ); |
||
| 384 | |||
| 385 | if ( is_object( $wp_query ) ) { |
||
| 386 | $reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) ); |
||
| 387 | } |
||
| 388 | |||
| 389 | $pods_cpt_ct = array( |
||
| 390 | 'post_types' => array(), |
||
| 391 | 'taxonomies' => array() |
||
| 392 | ); |
||
| 393 | |||
| 394 | $pods_post_types = $pods_taxonomies = array(); |
||
| 395 | $supported_post_types = $supported_taxonomies = array(); |
||
| 396 | |||
| 397 | $post_format_post_types = array(); |
||
| 398 | |||
| 399 | foreach ( $post_types as $post_type ) { |
||
| 400 | // Post Type exists already |
||
| 401 | View Code Duplication | if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) { |
|
| 402 | continue; |
||
| 403 | } elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) { |
||
| 404 | continue; |
||
| 405 | } elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) { |
||
| 406 | continue; |
||
| 407 | } |
||
| 408 | |||
| 409 | $post_type['options']['name'] = $post_type['name']; |
||
| 410 | $post_type = array_merge( $post_type, (array) $post_type['options'] ); |
||
| 411 | |||
| 412 | $post_type_name = pods_var( 'name', $post_type ); |
||
| 413 | |||
| 414 | // Labels |
||
| 415 | $cpt_label = esc_html( pods_var_raw( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $post_type ) ) ), null, true ) ); |
||
| 416 | $cpt_singular = esc_html( pods_var_raw( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_var_raw( 'label', $post_type, $post_type_name, null, true ) ) ), null, true ) ); |
||
| 417 | |||
| 418 | $cpt_labels = array(); |
||
| 419 | $cpt_labels['name'] = $cpt_label; |
||
| 420 | $cpt_labels['singular_name'] = $cpt_singular; |
||
| 421 | $cpt_labels['menu_name'] = pods_var_raw( 'menu_name', $post_type, '', null, true ); |
||
| 422 | $cpt_labels['add_new'] = pods_var_raw( 'label_add_new', $post_type, '', null, true ); |
||
| 423 | $cpt_labels['add_new_item'] = pods_var_raw( 'label_add_new_item', $post_type, '', null, true ); |
||
| 424 | $cpt_labels['new_item'] = pods_var_raw( 'label_new_item', $post_type, '', null, true ); |
||
| 425 | $cpt_labels['edit'] = pods_var_raw( 'label_edit', $post_type, '', null, true ); |
||
| 426 | $cpt_labels['edit_item'] = pods_var_raw( 'label_edit_item', $post_type, '', null, true ); |
||
| 427 | $cpt_labels['view'] = pods_var_raw( 'label_view', $post_type, '', null, true ); |
||
| 428 | $cpt_labels['view_item'] = pods_var_raw( 'label_view_item', $post_type, '', null, true ); |
||
| 429 | $cpt_labels['all_items'] = pods_var_raw( 'label_all_items', $post_type, '', null, true ); |
||
| 430 | $cpt_labels['search_items'] = pods_var_raw( 'label_search_items', $post_type, '', null, true ); |
||
| 431 | $cpt_labels['not_found'] = pods_var_raw( 'label_not_found', $post_type, '', null, true ); |
||
| 432 | $cpt_labels['not_found_in_trash'] = pods_var_raw( 'label_not_found_in_trash', $post_type, '', null, true ); |
||
| 433 | $cpt_labels['parent'] = pods_var_raw( 'label_parent', $post_type, '', null, true ); |
||
| 434 | $cpt_labels['parent_item_colon'] = pods_var_raw( 'label_parent_item_colon', $post_type, '', null, true ); |
||
| 435 | |||
| 436 | // Supported |
||
| 437 | $cpt_supported = array( |
||
| 438 | 'title' => (boolean) pods_var( 'supports_title', $post_type, false ), |
||
| 439 | 'editor' => (boolean) pods_var( 'supports_editor', $post_type, false ), |
||
| 440 | 'author' => (boolean) pods_var( 'supports_author', $post_type, false ), |
||
| 441 | 'thumbnail' => (boolean) pods_var( 'supports_thumbnail', $post_type, false ), |
||
| 442 | 'excerpt' => (boolean) pods_var( 'supports_excerpt', $post_type, false ), |
||
| 443 | 'trackbacks' => (boolean) pods_var( 'supports_trackbacks', $post_type, false ), |
||
| 444 | 'custom-fields' => (boolean) pods_var( 'supports_custom_fields', $post_type, false ), |
||
| 445 | 'comments' => (boolean) pods_var( 'supports_comments', $post_type, false ), |
||
| 446 | 'revisions' => (boolean) pods_var( 'supports_revisions', $post_type, false ), |
||
| 447 | 'page-attributes' => (boolean) pods_var( 'supports_page_attributes', $post_type, false ), |
||
| 448 | 'post-formats' => (boolean) pods_var( 'supports_post_formats', $post_type, false ) |
||
| 449 | ); |
||
| 450 | |||
| 451 | // Custom Supported |
||
| 452 | $cpt_supported_custom = pods_var( 'supports_custom', $post_type, '' ); |
||
| 453 | |||
| 454 | if ( ! empty( $cpt_supported_custom ) ) { |
||
| 455 | $cpt_supported_custom = explode( ',', $cpt_supported_custom ); |
||
| 456 | $cpt_supported_custom = array_filter( array_unique( $cpt_supported_custom ) ); |
||
| 457 | |||
| 458 | foreach ( $cpt_supported_custom as $cpt_support ) { |
||
| 459 | $cpt_supported[ $cpt_support ] = true; |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | // Genesis Support |
||
| 464 | if ( function_exists( 'genesis' ) ) { |
||
| 465 | $cpt_supported['genesis-seo'] = (boolean) pods_var( 'supports_genesis_seo', $post_type, false ); |
||
| 466 | $cpt_supported['genesis-layouts'] = (boolean) pods_var( 'supports_genesis_layouts', $post_type, false ); |
||
| 467 | $cpt_supported['genesis-simple-sidebars'] = (boolean) pods_var( 'supports_genesis_simple_sidebars', $post_type, false ); |
||
| 468 | } |
||
| 469 | |||
| 470 | // YARPP Support |
||
| 471 | if ( defined( 'YARPP_VERSION' ) ) { |
||
| 472 | $cpt_supported['yarpp_support'] = (boolean) pods_var( 'supports_yarpp_support', $post_type, false ); |
||
| 473 | } |
||
| 474 | |||
| 475 | // Jetpack Support |
||
| 476 | if ( class_exists( 'Jetpack' ) ) { |
||
| 477 | $cpt_supported['supports_jetpack_publicize'] = (boolean) pods_var( 'supports_jetpack_publicize', $post_type, false ); |
||
| 478 | $cpt_supported['supports_jetpack_markdown'] = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false ); |
||
| 479 | } |
||
| 480 | |||
| 481 | // WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :( |
||
| 482 | $cpt_supports = array(); |
||
| 483 | |||
| 484 | if ( ! pods_version_check( 'wp', '3.5' ) ) { |
||
| 485 | $cpt_supports = array( '_bug_fix_pre_35' ); |
||
| 486 | } |
||
| 487 | |||
| 488 | foreach ( $cpt_supported as $cpt_support => $supported ) { |
||
| 489 | if ( true === $supported ) { |
||
| 490 | $cpt_supports[] = $cpt_support; |
||
| 491 | |||
| 492 | if ( 'post-formats' === $cpt_support ) { |
||
| 493 | $post_format_post_types[] = $post_type_name; |
||
| 494 | } |
||
| 495 | } |
||
| 496 | } |
||
| 497 | |||
| 498 | if ( empty( $cpt_supports ) && pods_version_check( 'wp', '3.5' ) ) { |
||
| 499 | $cpt_supports = false; |
||
| 500 | } |
||
| 501 | |||
| 502 | // Rewrite |
||
| 503 | $cpt_rewrite = (boolean) pods_var( 'rewrite', $post_type, true ); |
||
| 504 | $cpt_rewrite_array = array( |
||
| 505 | 'slug' => pods_var( 'rewrite_custom_slug', $post_type, str_replace( '_', '-', $post_type_name ), null, true ), |
||
| 506 | 'with_front' => (boolean) pods_var( 'rewrite_with_front', $post_type, true ), |
||
| 507 | 'feeds' => (boolean) pods_var( 'rewrite_feeds', $post_type, (boolean) pods_var( 'has_archive', $post_type, false ) ), |
||
| 508 | 'pages' => (boolean) pods_var( 'rewrite_pages', $post_type, true ) |
||
| 509 | ); |
||
| 510 | |||
| 511 | if ( false !== $cpt_rewrite ) { |
||
| 512 | $cpt_rewrite = $cpt_rewrite_array; |
||
| 513 | } |
||
| 514 | |||
| 515 | $capability_type = pods_var( 'capability_type', $post_type, 'post' ); |
||
| 516 | |||
| 517 | if ( 'custom' == $capability_type ) { |
||
| 518 | $capability_type = pods_var( 'capability_type_custom', $post_type, 'post' ); |
||
| 519 | } |
||
| 520 | |||
| 521 | $show_in_menu = (boolean) pods_var( 'show_in_menu', $post_type, true ); |
||
| 522 | |||
| 523 | if ( $show_in_menu && 0 < strlen( pods_var_raw( 'menu_location_custom', $post_type ) ) ) { |
||
| 524 | $show_in_menu = pods_var_raw( 'menu_location_custom', $post_type ); |
||
| 525 | } |
||
| 526 | |||
| 527 | $menu_icon = pods_var( 'menu_icon', $post_type, null, null, true ); |
||
| 528 | |||
| 529 | if ( ! empty( $menu_icon ) ) { |
||
| 530 | $menu_icon = pods_evaluate_tags( $menu_icon ); |
||
| 531 | } |
||
| 532 | |||
| 533 | // Register Post Type |
||
| 534 | $pods_post_types[ $post_type_name ] = array( |
||
| 535 | 'label' => $cpt_label, |
||
| 536 | 'labels' => $cpt_labels, |
||
| 537 | 'description' => esc_html( pods_var_raw( 'description', $post_type ) ), |
||
| 538 | 'public' => (boolean) pods_var( 'public', $post_type, true ), |
||
| 539 | 'publicly_queryable' => (boolean) pods_var( 'publicly_queryable', $post_type, (boolean) pods_var( 'public', $post_type, true ) ), |
||
| 540 | 'exclude_from_search' => (boolean) pods_var( 'exclude_from_search', $post_type, ( (boolean) pods_var( 'public', $post_type, true ) ? false : true ) ), |
||
| 541 | 'show_ui' => (boolean) pods_var( 'show_ui', $post_type, (boolean) pods_var( 'public', $post_type, true ) ), |
||
| 542 | 'show_in_menu' => $show_in_menu, |
||
| 543 | 'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $post_type, (boolean) pods_var( 'public', $post_type, true ) ), |
||
| 544 | 'show_in_admin_bar' => (boolean) pods_var( 'show_in_admin_bar', $post_type, (boolean) pods_var( 'show_in_menu', $post_type, true ) ), |
||
| 545 | 'menu_position' => (int) pods_var( 'menu_position', $post_type, 0, null, true ), |
||
| 546 | 'menu_icon' => $menu_icon, |
||
| 547 | 'capability_type' => $capability_type, |
||
| 548 | //'capabilities' => $cpt_capabilities, |
||
| 549 | 'map_meta_cap' => (boolean) pods_var( 'capability_type_extra', $post_type, true ), |
||
| 550 | 'hierarchical' => (boolean) pods_var( 'hierarchical', $post_type, false ), |
||
| 551 | 'supports' => $cpt_supports, |
||
| 552 | //'register_meta_box_cb' => array($this, 'manage_meta_box'), |
||
| 553 | //'permalink_epmask' => EP_PERMALINK, |
||
| 554 | 'has_archive' => pods_v( 'has_archive_slug', $post_type, (boolean) pods_v( 'has_archive', $post_type, false ), true ), |
||
| 555 | 'rewrite' => $cpt_rewrite, |
||
| 556 | 'query_var' => ( false !== (boolean) pods_var( 'query_var', $post_type, true ) ? pods_var( 'query_var_string', $post_type, $post_type_name, null, true ) : false ), |
||
| 557 | 'can_export' => (boolean) pods_var( 'can_export', $post_type, true ) |
||
| 558 | ); |
||
| 559 | |||
| 560 | // YARPP doesn't use 'supports' array option (yet) |
||
| 561 | if ( ! empty( $cpt_supports['yarpp_support'] ) ) { |
||
| 562 | $pods_post_types[ $post_type_name ]['yarpp_support'] = true; |
||
| 563 | } |
||
| 564 | |||
| 565 | // Prevent reserved query_var issues |
||
| 566 | if ( in_array( $pods_post_types[ $post_type_name ]['query_var'], $reserved_query_vars ) ) { |
||
| 567 | $pods_post_types[ $post_type_name ]['query_var'] = 'post_type_' . $pods_post_types[ $post_type_name ]['query_var']; |
||
| 568 | } |
||
| 569 | |||
| 570 | if ( 25 == $pods_post_types[ $post_type_name ]['menu_position'] ) { |
||
| 571 | $pods_post_types[ $post_type_name ]['menu_position'] ++; |
||
| 572 | } |
||
| 573 | |||
| 574 | if ( $pods_post_types[ $post_type_name ]['menu_position'] < 1 || in_array( $pods_post_types[ $post_type_name ]['menu_position'], $cpt_positions ) ) { |
||
| 575 | unset( $pods_post_types[ $post_type_name ]['menu_position'] ); |
||
| 576 | } else { |
||
| 577 | $cpt_positions[] = $pods_post_types[ $post_type_name ]['menu_position']; |
||
| 578 | |||
| 579 | // This would be nice if WP supported floats in menu_position |
||
| 580 | // $pods_post_types[ $post_type_name ][ 'menu_position' ] = $pods_post_types[ $post_type_name ][ 'menu_position' ] . '.1'; |
||
| 581 | } |
||
| 582 | |||
| 583 | // Taxonomies |
||
| 584 | $cpt_taxonomies = array(); |
||
| 585 | $_taxonomies = get_taxonomies(); |
||
| 586 | $_taxonomies = array_merge_recursive( $_taxonomies, $pods_taxonomies ); |
||
| 587 | $ignore = array( 'nav_menu', 'link_category', 'post_format' ); |
||
| 588 | |||
| 589 | View Code Duplication | foreach ( $_taxonomies as $taxonomy => $label ) { |
|
| 590 | if ( in_array( $taxonomy, $ignore ) ) { |
||
| 591 | continue; |
||
| 592 | } |
||
| 593 | |||
| 594 | if ( false !== (boolean) pods_var( 'built_in_taxonomies_' . $taxonomy, $post_type, false ) ) { |
||
| 595 | $cpt_taxonomies[] = $taxonomy; |
||
| 596 | |||
| 597 | if ( isset( $supported_post_types[ $taxonomy ] ) && ! in_array( $post_type_name, $supported_post_types[ $taxonomy ] ) ) { |
||
| 598 | $supported_post_types[ $taxonomy ][] = $post_type_name; |
||
| 599 | } |
||
| 600 | } |
||
| 601 | } |
||
| 602 | |||
| 603 | if ( isset( $supported_taxonomies[ $post_type_name ] ) ) { |
||
| 604 | $supported_taxonomies[ $post_type_name ] = array_merge( (array) $supported_taxonomies[ $post_type_name ], $cpt_taxonomies ); |
||
| 605 | } else { |
||
| 606 | $supported_taxonomies[ $post_type_name ] = $cpt_taxonomies; |
||
| 607 | } |
||
| 608 | } |
||
| 609 | |||
| 610 | foreach ( $taxonomies as $taxonomy ) { |
||
| 611 | // Taxonomy Type exists already |
||
| 612 | View Code Duplication | if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) { |
|
| 613 | continue; |
||
| 614 | } elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) { |
||
| 615 | continue; |
||
| 616 | } elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) { |
||
| 617 | continue; |
||
| 618 | } |
||
| 619 | |||
| 620 | $taxonomy['options']['name'] = $taxonomy['name']; |
||
| 621 | $taxonomy = array_merge( $taxonomy, (array) $taxonomy['options'] ); |
||
| 622 | |||
| 623 | $taxonomy_name = pods_var( 'name', $taxonomy ); |
||
| 624 | |||
| 625 | // Labels |
||
| 626 | $ct_label = esc_html( pods_var_raw( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $taxonomy ) ) ), null, true ) ); |
||
| 627 | $ct_singular = esc_html( pods_var_raw( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_var_raw( 'label', $taxonomy, pods_var_raw( 'name', $taxonomy ), null, true ) ) ), null, true ) ); |
||
| 628 | |||
| 629 | $ct_labels = array(); |
||
| 630 | $ct_labels['name'] = $ct_label; |
||
| 631 | $ct_labels['singular_name'] = $ct_singular; |
||
| 632 | $ct_labels['menu_name'] = pods_var_raw( 'menu_name', $taxonomy, '', null, true ); |
||
| 633 | $ct_labels['search_items'] = pods_var_raw( 'label_search_items', $taxonomy, '', null, true ); |
||
| 634 | $ct_labels['popular_items'] = pods_var_raw( 'label_popular_items', $taxonomy, '', null, true ); |
||
| 635 | $ct_labels['all_items'] = pods_var_raw( 'label_all_items', $taxonomy, '', null, true ); |
||
| 636 | $ct_labels['parent_item'] = pods_var_raw( 'label_parent_item', $taxonomy, '', null, true ); |
||
| 637 | $ct_labels['parent_item_colon'] = pods_var_raw( 'label_parent_item_colon', $taxonomy, '', null, true ); |
||
| 638 | $ct_labels['edit_item'] = pods_var_raw( 'label_edit_item', $taxonomy, '', null, true ); |
||
| 639 | $ct_labels['update_item'] = pods_var_raw( 'label_update_item', $taxonomy, '', null, true ); |
||
| 640 | $ct_labels['add_new_item'] = pods_var_raw( 'label_add_new_item', $taxonomy, '', null, true ); |
||
| 641 | $ct_labels['new_item_name'] = pods_var_raw( 'label_new_item_name', $taxonomy, '', null, true ); |
||
| 642 | $ct_labels['separate_items_with_commas'] = pods_var_raw( 'label_separate_items_with_commas', $taxonomy, '', null, true ); |
||
| 643 | $ct_labels['add_or_remove_items'] = pods_var_raw( 'label_add_or_remove_items', $taxonomy, '', null, true ); |
||
| 644 | $ct_labels['choose_from_most_used'] = pods_var_raw( 'label_choose_from_the_most_used', $taxonomy, '', null, true ); |
||
| 645 | |||
| 646 | // Rewrite |
||
| 647 | $ct_rewrite = (boolean) pods_var( 'rewrite', $taxonomy, true ); |
||
| 648 | $ct_rewrite_array = array( |
||
| 649 | 'slug' => pods_var( 'rewrite_custom_slug', $taxonomy, str_replace( '_', '-', $taxonomy_name ), null, true ), |
||
| 650 | 'with_front' => (boolean) pods_var( 'rewrite_with_front', $taxonomy, true ), |
||
| 651 | 'hierarchical' => (boolean) pods_var( 'rewrite_hierarchical', $taxonomy, (boolean) pods_var( 'hierarchical', $taxonomy, false ) ) |
||
| 652 | ); |
||
| 653 | |||
| 654 | if ( false !== $ct_rewrite ) { |
||
| 655 | $ct_rewrite = $ct_rewrite_array; |
||
| 656 | } |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Default tax capabilities |
||
| 660 | * @see https://codex.wordpress.org/Function_Reference/register_taxonomy |
||
| 661 | */ |
||
| 662 | $capability_type = pods_var( 'capability_type', $taxonomy, 'default' ); |
||
| 663 | $tax_capabilities = array(); |
||
| 664 | |||
| 665 | if ( 'custom' == $capability_type ) { |
||
| 666 | $capability_type = pods_var( 'capability_type_custom', $taxonomy, 'default' ); |
||
| 667 | if ( ! empty( $capability_type ) && 'default' != $capability_type ) { |
||
| 668 | $capability_type .= '_term'; |
||
| 669 | $capability_type_plural = $capability_type . 's'; |
||
| 670 | $tax_capabilities = array( |
||
| 671 | // Singular |
||
| 672 | 'edit_term' => 'edit_' . $capability_type, |
||
| 673 | 'delete_term' => 'delete_' . $capability_type, |
||
| 674 | 'assign_term' => 'assign_' . $capability_type, |
||
| 675 | // Plural |
||
| 676 | 'manage_terms' => 'manage_' . $capability_type_plural, |
||
| 677 | 'edit_terms' => 'edit_' . $capability_type_plural, |
||
| 678 | 'delete_terms' => 'delete_' . $capability_type_plural, |
||
| 679 | 'assign_terms' => 'assign_' . $capability_type_plural, |
||
| 680 | ); |
||
| 681 | } |
||
| 682 | } |
||
| 683 | |||
| 684 | // Register Taxonomy |
||
| 685 | $pods_taxonomies[ $taxonomy_name ] = array( |
||
| 686 | 'label' => $ct_label, |
||
| 687 | 'labels' => $ct_labels, |
||
| 688 | 'public' => (boolean) pods_var( 'public', $taxonomy, true ), |
||
| 689 | 'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ), |
||
| 690 | 'show_ui' => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ), |
||
| 691 | 'show_in_menu' => (boolean) pods_var( 'show_in_menu', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ), |
||
| 692 | 'show_tagcloud' => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ), |
||
| 693 | 'hierarchical' => (boolean) pods_var( 'hierarchical', $taxonomy, false ), |
||
| 694 | //'capability_type' => $capability_type, |
||
| 695 | 'capabilities' => $tax_capabilities, |
||
| 696 | //'map_meta_cap' => (boolean) pods_var( 'capability_type_extra', $taxonomy, true ), |
||
| 697 | 'update_count_callback' => pods_var( 'update_count_callback', $taxonomy, null, null, true ), |
||
| 698 | 'query_var' => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ), |
||
| 699 | 'rewrite' => $ct_rewrite, |
||
| 700 | 'show_admin_column' => (boolean) pods_var( 'show_admin_column', $taxonomy, false ), |
||
| 701 | 'sort' => (boolean) pods_var( 'sort', $taxonomy, false ) |
||
| 702 | ); |
||
| 703 | |||
| 704 | if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) { |
||
| 705 | $pods_taxonomies[ $taxonomy_name ]['query_var'] = pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ); |
||
| 706 | }; |
||
| 707 | |||
| 708 | // Prevent reserved query_var issues |
||
| 709 | if ( in_array( $pods_taxonomies[ $taxonomy_name ]['query_var'], $reserved_query_vars ) ) { |
||
| 710 | $pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var']; |
||
| 711 | } |
||
| 712 | |||
| 713 | // Integration for Single Value Taxonomy UI |
||
| 714 | if ( function_exists( 'tax_single_value_meta_box' ) ) { |
||
| 715 | $pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false ); |
||
| 716 | $pods_taxonomies[ $taxonomy_name ]['required'] = (boolean) pods_var( 'single_value_required', $taxonomy, false ); |
||
| 717 | } |
||
| 718 | |||
| 719 | // Post Types |
||
| 720 | $ct_post_types = array(); |
||
| 721 | $_post_types = get_post_types(); |
||
| 722 | $_post_types = array_merge_recursive( $_post_types, $pods_post_types ); |
||
| 723 | $ignore = array( 'revision' ); |
||
| 724 | |||
| 725 | View Code Duplication | foreach ( $_post_types as $post_type => $options ) { |
|
| 726 | if ( in_array( $post_type, $ignore ) ) { |
||
| 727 | continue; |
||
| 728 | } |
||
| 729 | |||
| 730 | if ( false !== (boolean) pods_var( 'built_in_post_types_' . $post_type, $taxonomy, false ) ) { |
||
| 731 | $ct_post_types[] = $post_type; |
||
| 732 | |||
| 733 | if ( isset( $supported_taxonomies[ $post_type ] ) && ! in_array( $taxonomy_name, $supported_taxonomies[ $post_type ] ) ) { |
||
| 734 | $supported_taxonomies[ $post_type ][] = $taxonomy_name; |
||
| 735 | } |
||
| 736 | } |
||
| 737 | } |
||
| 738 | |||
| 739 | if ( isset( $supported_post_types[ $taxonomy_name ] ) ) { |
||
| 740 | $supported_post_types[ $taxonomy_name ] = array_merge( $supported_post_types[ $taxonomy_name ], $ct_post_types ); |
||
| 741 | } else { |
||
| 742 | $supported_post_types[ $taxonomy_name ] = $ct_post_types; |
||
| 743 | } |
||
| 744 | } |
||
| 745 | |||
| 746 | $pods_post_types = apply_filters( 'pods_wp_post_types', $pods_post_types ); |
||
| 747 | $pods_taxonomies = apply_filters( 'pods_wp_taxonomies', $pods_taxonomies ); |
||
| 748 | |||
| 749 | $supported_post_types = apply_filters( 'pods_wp_supported_post_types', $supported_post_types ); |
||
| 750 | $supported_taxonomies = apply_filters( 'pods_wp_supported_taxonomies', $supported_taxonomies ); |
||
| 751 | |||
| 752 | foreach ( $pods_taxonomies as $taxonomy => $options ) { |
||
| 753 | $ct_post_types = null; |
||
| 754 | |||
| 755 | if ( isset( $supported_post_types[ $taxonomy ] ) && ! empty( $supported_post_types[ $taxonomy ] ) ) { |
||
| 756 | $ct_post_types = $supported_post_types[ $taxonomy ]; |
||
| 757 | } |
||
| 758 | |||
| 759 | $pods_cpt_ct['taxonomies'][ $taxonomy ] = array( |
||
| 760 | 'post_types' => $ct_post_types, |
||
| 761 | 'options' => $options |
||
| 762 | ); |
||
| 763 | } |
||
| 764 | |||
| 765 | foreach ( $pods_post_types as $post_type => $options ) { |
||
| 766 | if ( isset( $supported_taxonomies[ $post_type ] ) && ! empty( $supported_taxonomies[ $post_type ] ) ) { |
||
| 767 | $options['taxonomies'] = $supported_taxonomies[ $post_type ]; |
||
| 768 | } |
||
| 769 | |||
| 770 | $pods_cpt_ct['post_types'][ $post_type ] = $options; |
||
| 771 | } |
||
| 772 | |||
| 773 | $pods_cpt_ct['post_format_post_types'] = $post_format_post_types; |
||
| 774 | |||
| 775 | pods_transient_set( 'pods_wp_cpt_ct', $pods_cpt_ct ); |
||
| 776 | } |
||
| 777 | |||
| 778 | foreach ( $pods_cpt_ct['taxonomies'] as $taxonomy => $options ) { |
||
| 779 | if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy, self::$content_types_registered['taxonomies'] ) ) { |
||
| 780 | continue; |
||
| 781 | } |
||
| 782 | |||
| 783 | $ct_post_types = $options['post_types']; |
||
| 784 | $options = $options['options']; |
||
| 785 | |||
| 786 | $options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy ); |
||
| 787 | $options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy ); |
||
| 788 | |||
| 789 | $options = self::object_label_fix( $options, 'taxonomy' ); |
||
| 790 | |||
| 791 | // Max length for taxonomies are 32 characters |
||
| 792 | $taxonomy = substr( $taxonomy, 0, 32 ); |
||
| 793 | |||
| 794 | // i18n compatibility for plugins that override it |
||
| 795 | View Code Duplication | if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) { |
|
| 796 | $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' ); |
||
| 797 | } |
||
| 798 | |||
| 799 | View Code Duplication | if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) { |
|
| 800 | pods_debug( array( $taxonomy, $ct_post_types, $options ) ); |
||
| 801 | } |
||
| 802 | |||
| 803 | register_taxonomy( $taxonomy, $ct_post_types, $options ); |
||
| 804 | |||
| 805 | if ( ! isset( self::$content_types_registered['taxonomies'] ) ) { |
||
| 806 | self::$content_types_registered['taxonomies'] = array(); |
||
| 807 | } |
||
| 808 | |||
| 809 | self::$content_types_registered['taxonomies'][] = $taxonomy; |
||
| 810 | } |
||
| 811 | |||
| 812 | foreach ( $pods_cpt_ct['post_types'] as $post_type => $options ) { |
||
| 813 | if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type, self::$content_types_registered['post_types'] ) ) { |
||
| 814 | continue; |
||
| 815 | } |
||
| 816 | |||
| 817 | $options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type ); |
||
| 818 | $options = apply_filters( 'pods_register_post_type', $options, $post_type ); |
||
| 819 | |||
| 820 | $options = self::object_label_fix( $options, 'post_type' ); |
||
| 821 | |||
| 822 | // Max length for post types are 20 characters |
||
| 823 | $post_type = substr( $post_type, 0, 20 ); |
||
| 824 | |||
| 825 | // i18n compatibility for plugins that override it |
||
| 826 | View Code Duplication | if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) { |
|
| 827 | $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' ); |
||
| 828 | } |
||
| 829 | |||
| 830 | View Code Duplication | if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) { |
|
| 831 | pods_debug( array( $post_type, $options ) ); |
||
| 832 | } |
||
| 833 | |||
| 834 | register_post_type( $post_type, $options ); |
||
| 835 | |||
| 836 | // Register post format taxonomy for this post type |
||
| 837 | if ( isset( $pods_cpt_ct['post_format_post_types'] ) && in_array( $post_type, $pods_cpt_ct['post_format_post_types'], true ) ) { |
||
| 838 | register_taxonomy_for_object_type( 'post_format', $post_type ); |
||
| 839 | } |
||
| 840 | |||
| 841 | if ( ! isset( self::$content_types_registered['post_types'] ) ) { |
||
| 842 | self::$content_types_registered['post_types'] = array(); |
||
| 843 | } |
||
| 844 | |||
| 845 | self::$content_types_registered['post_types'][] = $post_type; |
||
| 846 | } |
||
| 847 | |||
| 848 | } |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Check if we need to flush WordPress rewrite rules |
||
| 852 | * This gets run during 'init' action late in the game to give other plugins time to register their rewrite rules |
||
| 853 | */ |
||
| 854 | public function flush_rewrite_rules() { |
||
| 855 | |||
| 856 | $flush = (int) pods_transient_get( 'pods_flush_rewrites' ); |
||
| 857 | |||
| 858 | if ( 1 === $flush ) { |
||
| 859 | /** |
||
| 860 | * @var $wp_rewrite WP_Rewrite |
||
| 861 | */ |
||
| 862 | global $wp_rewrite; |
||
| 863 | $wp_rewrite->flush_rules(); |
||
| 864 | $wp_rewrite->init(); |
||
| 865 | |||
| 866 | pods_transient_set( 'pods_flush_rewrites', 0 ); |
||
| 867 | } |
||
| 868 | } |
||
| 869 | |||
| 870 | /** |
||
| 871 | * Update Post Type messages |
||
| 872 | * |
||
| 873 | * @param array $messages |
||
| 874 | * |
||
| 875 | * @return array |
||
| 876 | * @since 2.0.2 |
||
| 877 | */ |
||
| 878 | public function setup_updated_messages( $messages ) { |
||
| 879 | |||
| 880 | global $post, $post_ID; |
||
| 881 | |||
| 882 | $post_types = PodsMeta::$post_types; |
||
| 883 | $existing_post_types = get_post_types(); |
||
| 884 | |||
| 885 | $pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' ); |
||
| 886 | |||
| 887 | if ( empty( $pods_cpt_ct ) || empty( $post_types ) ) { |
||
| 888 | return $messages; |
||
| 889 | } |
||
| 890 | |||
| 891 | /* Use new function added in 4.4, which eventually applies preview_post_link filter |
||
| 892 | * Before 4.4, this filter is defined in wp-admin/includes/meta-boxes.php, $post parameter added in 4.0 |
||
| 893 | * there wasn't post parameter back in 3.8 |
||
| 894 | * Let's add $post in the filter as it won't hurt anyway. |
||
| 895 | */ |
||
| 896 | $preview_post_link = version_compare( $wp_version, "4.4", ">=" ) |
||
| 897 | ? get_preview_post_link( $post ) |
||
| 898 | : apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ), $post ); |
||
| 899 | |||
| 900 | foreach ( $post_types as $post_type ) { |
||
| 901 | if ( ! isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) { |
||
| 902 | continue; |
||
| 903 | } |
||
| 904 | |||
| 905 | $labels = self::object_label_fix( $pods_cpt_ct['post_types'][ $post_type['name'] ], 'post_type' ); |
||
| 906 | $labels = $labels['labels']; |
||
| 907 | |||
| 908 | $messages[ $post_type['name'] ] = array( |
||
| 909 | 1 => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ), |
||
| 910 | 2 => __( 'Custom field updated.', 'pods' ), |
||
| 911 | 3 => __( 'Custom field deleted.', 'pods' ), |
||
| 912 | 4 => sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] ), |
||
| 913 | /* translators: %s: date and time of the revision */ |
||
| 914 | 5 => isset( $_GET['revision'] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels['singular_name'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
||
| 915 | 6 => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ), |
||
| 916 | 7 => sprintf( __( '%s saved.', 'pods' ), $labels['singular_name'] ), |
||
| 917 | 8 => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( $preview_post_link ), $labels['singular_name'] ), |
||
| 918 | 9 => sprintf( __( '%s scheduled for: <strong>%s</strong>. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], // translators: Publish box date format, see http://php.net/date |
||
| 919 | date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $labels['singular_name'] ), |
||
| 920 | 10 => sprintf( __( '%s draft updated. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( $preview_post_link ), $labels['singular_name'] ) |
||
| 921 | ); |
||
| 922 | |||
| 923 | if ( false === (boolean) $pods_cpt_ct['post_types'][ $post_type['name'] ]['public'] ) { |
||
| 924 | $messages[ $post_type['name'] ][1] = sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] ); |
||
| 925 | $messages[ $post_type['name'] ][6] = sprintf( __( '%s published.', 'pods' ), $labels['singular_name'] ); |
||
| 926 | $messages[ $post_type['name'] ][8] = sprintf( __( '%s submitted.', 'pods' ), $labels['singular_name'] ); |
||
| 927 | $messages[ $post_type['name'] ][9] = sprintf( __( '%s scheduled for: <strong>%1$s</strong>.', 'pods' ), $labels['singular_name'], // translators: Publish box date format, see http://php.net/date |
||
| 928 | date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ); |
||
| 929 | $messages[ $post_type['name'] ][10] = sprintf( __( '%s draft updated.', 'pods' ), $labels['singular_name'] ); |
||
| 930 | } |
||
| 931 | } |
||
| 932 | |||
| 933 | return $messages; |
||
| 934 | } |
||
| 935 | |||
| 936 | /** |
||
| 937 | * @param $args |
||
| 938 | * @param string $type |
||
| 939 | * |
||
| 940 | * @return array |
||
| 941 | */ |
||
| 942 | public static function object_label_fix( $args, $type = 'post_type' ) { |
||
| 943 | |||
| 944 | if ( empty( $args ) || ! is_array( $args ) ) { |
||
| 945 | $args = array(); |
||
| 946 | } |
||
| 947 | |||
| 948 | if ( ! isset( $args['labels'] ) || ! is_array( $args['labels'] ) ) { |
||
| 949 | $args['labels'] = array(); |
||
| 950 | } |
||
| 951 | |||
| 952 | $label = pods_var_raw( 'name', $args['labels'], pods_var_raw( 'label', $args, __( 'Items', 'pods' ), null, true ), null, true ); |
||
| 953 | $singular_label = pods_var_raw( 'singular_name', $args['labels'], pods_var_raw( 'label_singular', $args, __( 'Item', 'pods' ), null, true ), null, true ); |
||
| 954 | |||
| 955 | $labels = $args['labels']; |
||
| 956 | |||
| 957 | $labels['name'] = $label; |
||
| 958 | $labels['singular_name'] = $singular_label; |
||
| 959 | |||
| 960 | if ( 'post_type' == $type ) { |
||
| 961 | $labels['menu_name'] = pods_var_raw( 'menu_name', $labels, $label, null, true ); |
||
| 962 | $labels['add_new'] = pods_var_raw( 'add_new', $labels, __( 'Add New', 'pods' ), null, true ); |
||
| 963 | $labels['add_new_item'] = pods_var_raw( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), null, true ); |
||
| 964 | $labels['new_item'] = pods_var_raw( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), null, true ); |
||
| 965 | $labels['edit'] = pods_var_raw( 'edit', $labels, __( 'Edit', 'pods' ), null, true ); |
||
| 966 | $labels['edit_item'] = pods_var_raw( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), null, true ); |
||
| 967 | $labels['view'] = pods_var_raw( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), null, true ); |
||
| 968 | $labels['view_item'] = pods_var_raw( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), null, true ); |
||
| 969 | $labels['all_items'] = pods_var_raw( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), null, true ); |
||
| 970 | $labels['search_items'] = pods_var_raw( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), null, true ); |
||
| 971 | $labels['not_found'] = pods_var_raw( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), null, true ); |
||
| 972 | $labels['not_found_in_trash'] = pods_var_raw( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), null, true ); |
||
| 973 | $labels['parent'] = pods_var_raw( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), null, true ); |
||
| 974 | $labels['parent_item_colon'] = pods_var_raw( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), null, true ); |
||
| 975 | $labels['feature_image'] = pods_var_raw( 'feature_image', $labels, __( 'Featured Image', 'pods' ), null, true ); |
||
| 976 | $labels['set_featured_image'] = pods_var_raw( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), null, true ); |
||
| 977 | $labels['remove_featured_image'] = pods_var_raw( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), null, true ); |
||
| 978 | $labels['use_featured_image'] = pods_var_raw( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), null, true ); |
||
| 979 | $labels['archives'] = pods_var_raw( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), null, true ); |
||
| 980 | $labels['insert_into_item'] = pods_var_raw( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), null, true ); |
||
| 981 | $labels['uploaded_to_this_item'] = pods_var_raw( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), null, true ); |
||
| 982 | $labels['filter_items_list'] = pods_var_raw( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), null, true ); |
||
| 983 | $labels['items_list_navigation'] = pods_var_raw( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), null, true ); |
||
| 984 | $labels['items_list'] = pods_var_raw( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), null, true ); |
||
| 985 | } elseif ( 'taxonomy' == $type ) { |
||
| 986 | $labels['menu_name'] = pods_var_raw( 'menu_name', $labels, $label, null, true ); |
||
| 987 | $labels['search_items'] = pods_var_raw( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), null, true ); |
||
| 988 | $labels['popular_items'] = pods_var_raw( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), null, true ); |
||
| 989 | $labels['all_items'] = pods_var_raw( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), null, true ); |
||
| 990 | $labels['parent_item'] = pods_var_raw( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), null, true ); |
||
| 991 | $labels['parent_item_colon'] = pods_var_raw( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), null, true ); |
||
| 992 | $labels['edit_item'] = pods_var_raw( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), null, true ); |
||
| 993 | $labels['update_item'] = pods_var_raw( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), null, true ); |
||
| 994 | $labels['add_new_item'] = pods_var_raw( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), null, true ); |
||
| 995 | $labels['new_item_name'] = pods_var_raw( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), null, true ); |
||
| 996 | $labels['separate_items_with_commas'] = pods_var_raw( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), null, true ); |
||
| 997 | $labels['add_or_remove_items'] = pods_var_raw( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), null, true ); |
||
| 998 | $labels['choose_from_most_used'] = pods_var_raw( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), null, true ); |
||
| 999 | $labels['no_terms'] = pods_var_raw( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), null, true ); |
||
| 1000 | $labels['items_list_navigation'] = pods_var_raw( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), null, true ); |
||
| 1001 | $labels['items_list'] = pods_var_raw( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), null, true ); |
||
| 1002 | } |
||
| 1003 | |||
| 1004 | $args['labels'] = $labels; |
||
| 1005 | |||
| 1006 | return $args; |
||
| 1007 | } |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Activate and Install |
||
| 1011 | */ |
||
| 1012 | public function activate_install() { |
||
| 1013 | |||
| 1014 | register_activation_hook( PODS_DIR . 'init.php', array( $this, 'activate' ) ); |
||
| 1015 | register_deactivation_hook( PODS_DIR . 'init.php', array( $this, 'deactivate' ) ); |
||
| 1016 | |||
| 1017 | add_action( 'wpmu_new_blog', array( $this, 'new_blog' ), 10, 6 ); |
||
| 1018 | |||
| 1019 | if ( empty( self::$version ) || version_compare( self::$version, PODS_VERSION, '<' ) || version_compare( self::$version, PODS_DB_VERSION, '<=' ) || self::$upgrade_needed ) { |
||
| 1020 | $this->setup(); |
||
| 1021 | } elseif ( self::$version !== PODS_VERSION ) { |
||
| 1022 | delete_option( 'pods_framework_version' ); |
||
| 1023 | add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' ); |
||
| 1024 | |||
| 1025 | self::$version = PODS_VERSION; |
||
| 1026 | |||
| 1027 | pods_api()->cache_flush_pods(); |
||
| 1028 | } |
||
| 1029 | |||
| 1030 | } |
||
| 1031 | |||
| 1032 | /** |
||
| 1033 | * |
||
| 1034 | */ |
||
| 1035 | public function activate() { |
||
| 1036 | |||
| 1037 | global $wpdb; |
||
| 1038 | |||
| 1039 | if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && 1 == $_GET['networkwide'] ) { |
||
| 1040 | $_blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `{$wpdb->blogs}`" ); |
||
| 1041 | |||
| 1042 | foreach ( $_blog_ids as $_blog_id ) { |
||
| 1043 | $this->setup( $_blog_id ); |
||
| 1044 | } |
||
| 1045 | } else { |
||
| 1046 | $this->setup(); |
||
| 1047 | } |
||
| 1048 | } |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * |
||
| 1052 | */ |
||
| 1053 | public function deactivate() { |
||
| 1054 | |||
| 1055 | pods_api()->cache_flush_pods(); |
||
| 1056 | |||
| 1057 | } |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * |
||
| 1061 | */ |
||
| 1062 | public function needs_upgrade( $current = null, $last = null ) { |
||
| 1063 | |||
| 1064 | if ( null === $current ) { |
||
| 1065 | $current = self::$version; |
||
| 1066 | } |
||
| 1067 | |||
| 1068 | if ( null === $last ) { |
||
| 1069 | $last = self::$version_last; |
||
| 1070 | } |
||
| 1071 | |||
| 1072 | $upgrade_needed = false; |
||
| 1073 | |||
| 1074 | if ( ! empty( $current ) ) { |
||
| 1075 | foreach ( self::$upgrades as $old_version => $new_version ) { |
||
| 1076 | /*if ( '2.1.0' == $new_version && ( is_developer() ) ) |
||
| 1077 | continue;*/ |
||
| 1078 | |||
| 1079 | if ( version_compare( $last, $old_version, '>=' ) && version_compare( $last, $new_version, '<' ) && version_compare( $current, $new_version, '>=' ) && 1 != self::$upgraded ) { |
||
| 1080 | $upgrade_needed = true; |
||
| 1081 | |||
| 1082 | break; |
||
| 1083 | } |
||
| 1084 | } |
||
| 1085 | } |
||
| 1086 | |||
| 1087 | return $upgrade_needed; |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | /** |
||
| 1091 | * @param $_blog_id |
||
| 1092 | * @param $user_id |
||
| 1093 | * @param $domain |
||
| 1094 | * @param $path |
||
| 1095 | * @param $site_id |
||
| 1096 | * @param $meta |
||
| 1097 | */ |
||
| 1098 | public function new_blog( $_blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
||
| 1099 | |||
| 1100 | if ( function_exists( 'is_multisite' ) && is_multisite() && is_plugin_active_for_network( basename( PODS_DIR ) . '/init.php' ) ) { |
||
| 1101 | $this->setup( $_blog_id ); |
||
| 1102 | } |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * @param null $_blog_id |
||
| 1107 | */ |
||
| 1108 | public function setup( $_blog_id = null ) { |
||
| 1109 | |||
| 1110 | global $wpdb; |
||
| 1111 | |||
| 1112 | // Switch DB table prefixes |
||
| 1113 | View Code Duplication | if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) { |
|
| 1114 | switch_to_blog( pods_absint( $_blog_id ) ); |
||
| 1115 | } else { |
||
| 1116 | $_blog_id = null; |
||
| 1117 | } |
||
| 1118 | |||
| 1119 | // Setup DB tables |
||
| 1120 | $pods_version = get_option( 'pods_framework_version' ); |
||
| 1121 | $pods_version_last = get_option( 'pods_framework_version_last' ); |
||
| 1122 | |||
| 1123 | // Install Pods |
||
| 1124 | if ( empty( $pods_version ) ) { |
||
| 1125 | pods_upgrade()->install( $_blog_id ); |
||
| 1126 | |||
| 1127 | $old_version = get_option( 'pods_version' ); |
||
| 1128 | |||
| 1129 | if ( ! empty( $old_version ) ) { |
||
| 1130 | if ( false === strpos( $old_version, '.' ) ) { |
||
| 1131 | $old_version = pods_version_to_point( $old_version ); |
||
| 1132 | } |
||
| 1133 | |||
| 1134 | delete_option( 'pods_framework_version_last' ); |
||
| 1135 | add_option( 'pods_framework_version_last', $pods_version, '', 'yes' ); |
||
| 1136 | |||
| 1137 | self::$version_last = $old_version; |
||
| 1138 | } |
||
| 1139 | } // Upgrade Wizard needed |
||
| 1140 | elseif ( $this->needs_upgrade( $pods_version, $pods_version_last ) ) { |
||
| 1141 | // Do not do anything |
||
| 1142 | return; |
||
| 1143 | } // Update Pods and run any required DB updates |
||
| 1144 | elseif ( version_compare( $pods_version, PODS_VERSION, '<=' ) ) { |
||
| 1145 | if ( false !== apply_filters( 'pods_update_run', null, PODS_VERSION, $pods_version, $_blog_id ) && ! isset( $_GET['pods_bypass_update'] ) ) { |
||
| 1146 | do_action( 'pods_update', PODS_VERSION, $pods_version, $_blog_id ); |
||
| 1147 | |||
| 1148 | // Update 2.0 alpha / beta sites |
||
| 1149 | if ( version_compare( '2.0.0-a-1', $pods_version, '<=' ) && version_compare( $pods_version, '2.0.0-b-15', '<=' ) ) { |
||
| 1150 | include( PODS_DIR . 'sql/update-2.0-beta.php' ); |
||
| 1151 | } |
||
| 1152 | |||
| 1153 | if ( version_compare( $pods_version, PODS_DB_VERSION, '<=' ) ) { |
||
| 1154 | include( PODS_DIR . 'sql/update.php' ); |
||
| 1155 | } |
||
| 1156 | |||
| 1157 | do_action( 'pods_update_post', PODS_VERSION, $pods_version, $_blog_id ); |
||
| 1158 | } |
||
| 1159 | |||
| 1160 | delete_option( 'pods_framework_version_last' ); |
||
| 1161 | add_option( 'pods_framework_version_last', $pods_version, '', 'yes' ); |
||
| 1162 | |||
| 1163 | self::$version_last = $pods_version; |
||
| 1164 | } |
||
| 1165 | |||
| 1166 | delete_option( 'pods_framework_version' ); |
||
| 1167 | add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' ); |
||
| 1168 | |||
| 1169 | delete_option( 'pods_framework_db_version' ); |
||
| 1170 | add_option( 'pods_framework_db_version', PODS_DB_VERSION, '', 'yes' ); |
||
| 1171 | |||
| 1172 | self::$version = PODS_VERSION; |
||
| 1173 | self::$db_version = PODS_DB_VERSION; |
||
| 1174 | |||
| 1175 | pods_api()->cache_flush_pods(); |
||
| 1176 | |||
| 1177 | // Restore DB table prefix (if switched) |
||
| 1178 | if ( null !== $_blog_id ) { |
||
| 1179 | restore_current_blog(); |
||
| 1180 | } |
||
| 1181 | |||
| 1182 | } |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * @param null $_blog_id |
||
| 1186 | */ |
||
| 1187 | public function reset( $_blog_id = null ) { |
||
| 1188 | |||
| 1189 | global $wpdb; |
||
| 1190 | |||
| 1191 | // Switch DB table prefixes |
||
| 1192 | View Code Duplication | if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) { |
|
| 1193 | switch_to_blog( pods_absint( $_blog_id ) ); |
||
| 1194 | } else { |
||
| 1195 | $_blog_id = null; |
||
| 1196 | } |
||
| 1197 | |||
| 1198 | $api = pods_api(); |
||
| 1199 | |||
| 1200 | $pods = $api->load_pods( array( 'names_ids' => true, 'table_info' => false ) ); |
||
| 1201 | |||
| 1202 | foreach ( $pods as $pod_id => $pod_label ) { |
||
| 1203 | $api->delete_pod( array( 'id' => $pod_id ) ); |
||
| 1204 | } |
||
| 1205 | |||
| 1206 | $templates = $api->load_templates(); |
||
| 1207 | |||
| 1208 | foreach ( $templates as $template ) { |
||
| 1209 | $api->delete_template( array( 'id' => $template['id'] ) ); |
||
| 1210 | } |
||
| 1211 | |||
| 1212 | $pages = $api->load_pages(); |
||
| 1213 | |||
| 1214 | foreach ( $pages as $page ) { |
||
| 1215 | $api->delete_page( array( 'id' => $page['id'] ) ); |
||
| 1216 | } |
||
| 1217 | |||
| 1218 | $helpers = $api->load_helpers(); |
||
| 1219 | |||
| 1220 | foreach ( $helpers as $helper ) { |
||
| 1221 | $api->delete_helper( array( 'id' => $helper['id'] ) ); |
||
| 1222 | } |
||
| 1223 | |||
| 1224 | $tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pods%'", ARRAY_N ); |
||
| 1225 | |||
| 1226 | if ( ! empty( $tables ) ) { |
||
| 1227 | foreach ( $tables as $table ) { |
||
| 1228 | $table = $table[0]; |
||
| 1229 | |||
| 1230 | pods_query( "DROP TABLE `{$table}`", false ); |
||
| 1231 | } |
||
| 1232 | } |
||
| 1233 | |||
| 1234 | // Remove any orphans |
||
| 1235 | $wpdb->query( " |
||
| 1236 | DELETE `p`, `pm` |
||
| 1237 | FROM `{$wpdb->posts}` AS `p` |
||
| 1238 | LEFT JOIN `{$wpdb->postmeta}` AS `pm` |
||
| 1239 | ON `pm`.`post_id` = `p`.`ID` |
||
| 1240 | WHERE |
||
| 1241 | `p`.`post_type` LIKE '_pods_%' |
||
| 1242 | " ); |
||
| 1243 | |||
| 1244 | delete_option( 'pods_framework_version' ); |
||
| 1245 | delete_option( 'pods_framework_db_version' ); |
||
| 1246 | delete_option( 'pods_framework_upgrade_2_0' ); |
||
| 1247 | delete_option( 'pods_framework_upgraded_1_x' ); |
||
| 1248 | |||
| 1249 | // @todo Make sure all entries are being cleaned and do something about the pods_framework_upgrade_{version} dynamic entries created by PodsUpgrade |
||
| 1250 | delete_option( 'pods_framework_upgrade_2_0_0' ); |
||
| 1251 | delete_option( 'pods_framework_upgrade_2_0_sister_ids' ); |
||
| 1252 | delete_option( 'pods_framework_version_last' ); |
||
| 1253 | |||
| 1254 | delete_option( 'pods_component_settings' ); |
||
| 1255 | |||
| 1256 | $api->cache_flush_pods(); |
||
| 1257 | |||
| 1258 | pods_transient_clear( 'pods_flush_rewrites' ); |
||
| 1259 | |||
| 1260 | self::$version = ''; |
||
| 1261 | |||
| 1262 | // Restore DB table prefix (if switched) |
||
| 1263 | if ( null !== $_blog_id ) { |
||
| 1264 | restore_current_blog(); |
||
| 1265 | } |
||
| 1266 | } |
||
| 1267 | |||
| 1268 | public function run() { |
||
| 1269 | |||
| 1270 | static $ran; |
||
| 1271 | |||
| 1272 | if ( ! empty( $ran ) ) { |
||
| 1273 | return; |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | $ran = true; |
||
| 1277 | |||
| 1278 | if ( ! did_action( 'plugins_loaded' ) ) { |
||
| 1279 | add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 ); |
||
| 1280 | } else { |
||
| 1281 | $this->load_components(); |
||
| 1282 | } |
||
| 1283 | |||
| 1284 | if ( ! did_action( 'setup_theme' ) ) { |
||
| 1285 | add_action( 'setup_theme', array( $this, 'load_meta' ), 14 ); |
||
| 1286 | } else { |
||
| 1287 | $this->load_meta(); |
||
| 1288 | } |
||
| 1289 | |||
| 1290 | if ( ! did_action( 'init' ) ) { |
||
| 1291 | add_action( 'init', array( $this, 'core' ), 11 ); |
||
| 1292 | add_action( 'init', array( $this, 'add_rest_support' ), 12 ); |
||
| 1293 | add_action( 'init', array( $this, 'setup_content_types' ), 11 ); |
||
| 1294 | |||
| 1295 | if ( is_admin() ) { |
||
| 1296 | add_action( 'init', array( $this, 'admin_init' ), 12 ); |
||
| 1297 | } |
||
| 1298 | } else { |
||
| 1299 | $this->core(); |
||
| 1300 | $this->add_rest_support(); |
||
| 1301 | $this->setup_content_types(); |
||
| 1302 | |||
| 1303 | if ( is_admin() ) { |
||
| 1304 | $this->admin_init(); |
||
| 1305 | } |
||
| 1306 | } |
||
| 1307 | |||
| 1308 | add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ), 15 ); |
||
| 1309 | add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ), 15 ); |
||
| 1310 | add_action( 'login_enqueue_scripts', array( $this, 'register_assets' ), 15 ); |
||
| 1311 | |||
| 1312 | add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 ); |
||
| 1313 | add_action( 'delete_attachment', array( $this, 'delete_attachment' ) ); |
||
| 1314 | |||
| 1315 | // Register widgets |
||
| 1316 | add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
||
| 1317 | |||
| 1318 | // Show admin bar links |
||
| 1319 | add_action( 'admin_bar_menu', array( $this, 'admin_bar_links' ), 81 ); |
||
| 1320 | |||
| 1321 | } |
||
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Delete Attachments from relationships |
||
| 1325 | * |
||
| 1326 | * @param int $_ID |
||
| 1327 | */ |
||
| 1328 | public function delete_attachment( $_ID ) { |
||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * Register widgets for Pods |
||
| 1428 | */ |
||
| 1429 | public function register_widgets() { |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Add Admin Bar links |
||
| 1452 | */ |
||
| 1453 | public function admin_bar_links() { |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Add REST API support to post type and taxonomy objects. |
||
| 1502 | * |
||
| 1503 | * @uses "init" |
||
| 1504 | * |
||
| 1505 | * @since 2.5.6 |
||
| 1506 | */ |
||
| 1507 | public function add_rest_support() { |
||
| 1569 | } |
||
| 1570 |
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.