| @@ -96,11 +96,14 @@ | ||
| 96 | 96 | case 'term': |
| 97 | 97 | return $this->term_hooks(); |
| 98 | 98 | case 'options-page': |
| 99 | 99 | return $this->options_page_hooks(); |
| 100 | + | |
| 100 | 101 | } |
| 101 | 102 | } |
| 102 | 103 | |
| 104 | + do_action( 'cmb2_init_hooks', $this ); | |
| 105 | + | |
| 103 | 106 | return $this; |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | 109 | public function post_hooks() { |
| @@ -154,9 +157,9 @@ | ||
| 154 | 157 | |
| 155 | 158 | if ( $this->cmb->has_columns ) { |
| 156 | 159 | add_filter( 'manage_edit-comments_columns', array( $this, 'register_column_headers' ) ); |
| 157 | 160 | add_action( 'manage_comments_custom_column', array( $this, 'column_display' ), 10, 3 ); |
| 158 | - add_filter( "manage_edit-comments_sortable_columns", array( $this, 'columns_sortable' ) ); | |
| 161 | + add_filter( 'manage_edit-comments_sortable_columns', array( $this, 'columns_sortable' ) ); | |
| 159 | 162 | add_action( 'pre_get_posts', array( $this, 'columns_sortable_orderby' ) ); |
| 160 | 163 | } |
| 161 | 164 | |
| 162 | 165 | return $this; |
| @@ -175,9 +178,9 @@ | ||
| 175 | 178 | |
| 176 | 179 | if ( $this->cmb->has_columns ) { |
| 177 | 180 | add_filter( 'manage_users_columns', array( $this, 'register_column_headers' ) ); |
| 178 | 181 | add_filter( 'manage_users_custom_column', array( $this, 'return_column_display' ), 10, 3 ); |
| 179 | - add_filter( "manage_users_sortable_columns", array( $this, 'columns_sortable' ) ); | |
| 182 | + add_filter( 'manage_users_sortable_columns', array( $this, 'columns_sortable' ) ); | |
| 180 | 183 | add_action( 'pre_get_posts', array( $this, 'columns_sortable_orderby' ) ); |
| 181 | 184 | } |
| 182 | 185 | |
| 183 | 186 | return $this; |
| @@ -267,10 +270,10 @@ | ||
| 267 | 270 | * |
| 268 | 271 | * @param array $dependencies The registered style dependencies for the cmb2 stylesheet. |
| 269 | 272 | */ |
| 270 | 273 | $dependencies = apply_filters( 'cmb2_style_dependencies', array() ); |
| 271 | - wp_register_style( 'cmb2-styles', CMB2_Utils::url( "css/cmb2{$front}{$rtl}{$min}.css" ), $dependencies, CMB2_VERSION ); | |
| 272 | - wp_register_style( 'cmb2-display-styles', CMB2_Utils::url( "css/cmb2-display{$rtl}{$min}.css" ), $dependencies, CMB2_VERSION ); | |
| 274 | + wp_register_style( 'cmb2-styles', CMB2_Utils::url( "css/cmb2{$front}{$rtl}{$min}.css" ), $dependencies ); | |
| 275 | + wp_register_style( 'cmb2-display-styles', CMB2_Utils::url( "css/cmb2-display{$rtl}{$min}.css" ), $dependencies ); | |
| 273 | 276 | |
| 274 | 277 | self::$css_registration_done = true; |
| 275 | 278 | } |
| 276 | 279 | |
| @@ -307,9 +310,9 @@ | ||
| 307 | 310 | * |
| 308 | 311 | * @param string $hook Current hook for the admin page. |
| 309 | 312 | */ |
| 310 | 313 | public function do_scripts( $hook ) { |
| 311 | - $hooks = array( | |
| 314 | + $should_pre_enqueue = in_array( $hook, array( | |
| 312 | 315 | 'post.php', |
| 313 | 316 | 'post-new.php', |
| 314 | 317 | 'page-new.php', |
| 315 | 318 | 'page.php', |
| @@ -318,12 +321,25 @@ | ||
| 318 | 321 | 'term.php', |
| 319 | 322 | 'user-new.php', |
| 320 | 323 | 'profile.php', |
| 321 | 324 | 'user-edit.php', |
| 322 | - ); | |
| 325 | + ), true ); | |
| 326 | + | |
| 327 | + /** | |
| 328 | + * Filter to determine if CMB2 should be pre-enqueued on the current page. | |
| 329 | + * | |
| 330 | + * `show_form_for_type` will have us covered if we miss something here, but may be a | |
| 331 | + * flash of unstyled content. | |
| 332 | + * | |
| 333 | + * @param bool $should_pre_enqueue Whether CMB2 should be pre-enqueued on the current page. | |
| 334 | + * @param string $hook The current hook for the admin page. | |
| 335 | + * @param object $cmb The CMB2 object. | |
| 336 | + */ | |
| 337 | + $should_pre_enqueue = apply_filters( 'cmb2_should_pre_enqueue', $should_pre_enqueue, $hook, $this ); | |
| 338 | + | |
| 323 | 339 | // only pre-enqueue our scripts/styles on the proper pages |
| 324 | 340 | // show_form_for_type will have us covered if we miss something here. |
| 325 | - if ( in_array( $hook, $hooks, true ) ) { | |
| 341 | + if ( $should_pre_enqueue ) { | |
| 326 | 342 | if ( $this->cmb->prop( 'cmb_styles' ) ) { |
| 327 | 343 | self::enqueue_cmb_css(); |
| 328 | 344 | } |
| 329 | 345 | if ( $this->cmb->prop( 'enqueue_js' ) ) { |
| @@ -339,9 +355,9 @@ | ||
| 339 | 355 | * |
| 340 | 356 | * @param array $columns Array of columns available for the admin page. |
| 341 | 357 | */ |
| 342 | 358 | public function register_column_headers( $columns ) { |
| 343 | - foreach ( $this->cmb->prop( 'fields' ) as $key => $field ) { | |
| 359 | + foreach ( $this->cmb->prop( 'fields' ) as $field ) { | |
| 344 | 360 | if ( empty( $field['column'] ) ) { |
| 345 | 361 | continue; |
| 346 | 362 | } |
| 347 | 363 | |
| @@ -392,9 +408,9 @@ | ||
| 392 | 408 | * |
| 393 | 409 | * @return array $columns An array of sortable columns with CMB2 columns. |
| 394 | 410 | */ |
| 395 | 411 | public function columns_sortable( $columns ) { |
| 396 | - foreach ( $this->cmb->prop( 'fields' ) as $key => $field ) { | |
| 412 | + foreach ( $this->cmb->prop( 'fields' ) as $field ) { | |
| 397 | 413 | if ( ! empty( $field['column'] ) && empty( $field['column']['disable_sortable'] ) ) { |
| 398 | 414 | $columns[ $field['id'] ] = $field['id']; |
| 399 | 415 | } |
| 400 | 416 | } |
| @@ -417,9 +433,9 @@ | ||
| 417 | 433 | } |
| 418 | 434 | |
| 419 | 435 | $orderby = $query->get( 'orderby' ); |
| 420 | 436 | |
| 421 | - foreach ( $this->cmb->prop( 'fields' ) as $key => $field ) { | |
| 437 | + foreach ( $this->cmb->prop( 'fields' ) as $field ) { | |
| 422 | 438 | if ( |
| 423 | 439 | empty( $field['column'] ) |
| 424 | 440 | || ! empty( $field['column']['disable_sortable'] ) |
| 425 | 441 | || $field['id'] !== $orderby |
| @@ -556,9 +572,13 @@ | ||
| 556 | 572 | ? ' hide-if-js' |
| 557 | 573 | : ''; |
| 558 | 574 | } |
| 559 | 575 | |
| 560 | - $toggle_button = '<button type="button" class="handlediv button-link" aria-expanded="true"><span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $title ) . '</span><span class="toggle-indicator" aria-hidden="true"></span></button>'; | |
| 576 | + $toggle_button = sprintf( | |
| 577 | + '<button type="button" class="handlediv button-link" aria-expanded="true"><span class="screen-reader-text">%s</span><span class="toggle-indicator" aria-hidden="true"></span></button>', | |
| 578 | + /* translators: %s: name of CMB2 box (panel) */ | |
| 579 | + sprintf( __( 'Toggle panel: %s' ), $title ) | |
| 580 | + ); | |
| 561 | 581 | $title_tag = '<h2 class="hndle"><span>' . esc_attr( $title ) . '</span></h2>' . "\n"; |
| 562 | 582 | |
| 563 | 583 | echo '<div id="' . $cmb_id . '" class="' . postbox_classes( $cmb_id, $page ) . $hidden_class . '">' . "\n"; |
| 564 | 584 | |
| @@ -574,9 +594,9 @@ | ||
| 574 | 594 | |
| 575 | 595 | echo '</div>' . "\n"; |
| 576 | 596 | |
| 577 | 597 | } else { |
| 578 | - echo $toggle_button;; | |
| 598 | + echo $toggle_button; | |
| 579 | 599 | echo $title_tag; |
| 580 | 600 | } |
| 581 | 601 | |
| 582 | 602 | echo '<div class="inside">' . "\n"; |
| @@ -935,9 +955,9 @@ | ||
| 935 | 955 | $can_save = ( |
| 936 | 956 | $this->cmb->prop( 'save_fields' ) |
| 937 | 957 | // check nonce. |
| 938 | 958 | && isset( $_POST[ $this->cmb->nonce() ] ) |
| 939 | - && wp_verify_nonce( sanitize_text_field( wp_unslash ( $_POST[ $this->cmb->nonce() ] ) ), $this->cmb->nonce() ) | |
| 959 | + && wp_verify_nonce( $_POST[ $this->cmb->nonce() ], $this->cmb->nonce() ) | |
| 940 | 960 | // check if autosave. |
| 941 | 961 | && ! ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
| 942 | 962 | // get the metabox types & compare it to this type. |
| 943 | 963 | && ( $type && in_array( $type, $this->cmb->box_types() ) ) |