Making WordPress.org


Ignore:
Timestamp:
08/29/2018 11:19:29 AM (8 years ago)
Author:
vedjain
Message:

WordCamp: Added meetup.com API sync to meetup posts.

This is part 1 of adding meetup API sync with meetup admin page. This commit syncs some of the group details like members count, location etc. Currently, information sync for list of co-organizers etc is yet to be implemented.

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  
    1616abstract class Event_Admin {
    1717
     18        public $active_admin_notices;
     19
    1820        /**
    1921         * Event_Admin constructor.
    2022         */
    2123        public function __construct() {
     24
     25                $this->active_admin_notices = array();
    2226
    2327                add_action( 'add_meta_boxes', array( $this, 'metabox' ) );
     
    5155
    5256                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' ) );
    5362        }
    5463
     
    411420
    412421                $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                }
    413491
    414492        }
Note: See TracChangeset for help on using the changeset viewer.