Changeset 7637 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/class-event-admin.php
- Timestamp:
- 08/29/2018 11:19:29 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/class-event-admin.php
r7629 r7637 16 16 abstract class Event_Admin { 17 17 18 public $active_admin_notices; 19 18 20 /** 19 21 * Event_Admin constructor. 20 22 */ 21 23 public function __construct() { 24 25 $this->active_admin_notices = array(); 22 26 23 27 add_action( 'add_meta_boxes', array( $this, 'metabox' ) ); … … 51 55 52 56 add_action( 'transition_post_status', array( $this, 'log_status_changes' ), 10, 3 ); 57 58 add_filter( 'redirect_post_location', array( $this, 'add_admin_notices_to_redirect_url' ), 10, 2 ); 59 60 // Admin notices 61 add_action( 'admin_notices', array( $this, 'print_admin_notices' ) ); 53 62 } 54 63 … … 411 420 412 421 $this->validate_and_add_note( $post_id ); 422 423 } 424 425 /** 426 * Add our custom admin notice keys to the redirect URL. 427 * 428 * Any member can add a key to $this->active_admin_notices to signify that the corresponding message should 429 * be shown when the redirect finished. When it does, print_admin_notices() will examine the URL and create 430 * a notice with the message that corresponds to the key. 431 * 432 * @param string $location 433 * @param int $post_id 434 * 435 * @return string 436 */ 437 public function add_admin_notices_to_redirect_url( $location, $post_id ) { 438 if ( $this->active_admin_notices ) { 439 $location = add_query_arg( 'wcpt_messages', implode( ',', $this->active_admin_notices ), $location ); 440 } 441 442 // Don't show conflicting messages like 'Post submitted.' 443 if ( in_array( 1, $this->active_admin_notices ) && false !== strpos( $location, 'message=8' ) ) { 444 $location = remove_query_arg( 'message', $location ); 445 } 446 447 return $location; 448 } 449 450 /** 451 * Return admin notices for messages that were passed in the URL. 452 */ 453 abstract public function get_admin_notices(); 454 455 /** 456 * Create admin notices for messages that were passed in the URL. 457 * 458 * Any member can add a key to $this->active_admin_notices to signify that the corresponding message should 459 * be shown when the redirect finished. add_admin_notices_to_redirect_url() adds those keys to the redirect 460 * url, and this function examines the URL and create a notice with the message that corresponds to the key. 461 * 462 * $notices[key]['type'] should equal 'error' or 'updated'. 463 */ 464 public function print_admin_notices() { 465 466 global $post; 467 $screen = get_current_screen(); 468 469 470 if ( empty( $post->post_type ) || $this->get_event_type() != $post->post_type || 'post' !== $screen->base ) { 471 return; 472 } 473 474 $notices = $this->get_admin_notices(); 475 476 if ( ! empty( $_REQUEST['wcpt_messages'] ) ) { 477 $active_notices = explode( ',', $_REQUEST['wcpt_messages'] ); 478 479 foreach ( $active_notices as $notice_key ) { 480 if ( isset( $notices[ $notice_key ] ) ) { 481 ?> 482 483 <div class="<?php echo esc_attr( $notices[ $notice_key ]['type'] ); ?>"> 484 <p><?php echo wp_kses( $notices[ $notice_key ]['notice'], wp_kses_allowed_html( 'post' ) ); ?></p> 485 </div> 486 487 <?php 488 } 489 } 490 } 413 491 414 492 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)