Making WordPress.org


Ignore:
Timestamp:
09/22/2017 06:23:00 PM (7 years ago)
Author:
coreymckrill
Message:

WordCamp: Warn organizers when their site is in Coming Soon mode

  • Show a flag in the admin bar when Coming Soon mode is enabled.
  • Link the flag to the relevant section of the Customizer if the current user has the capability to change the mode.
  • Show admin notice on Post screens warning that subscribers will not be notified while in Coming Soon mode.
  • Prevent Jetpack post notification emails from being sent whil in Coming Soon mode.

Fixes #859
Props JayantiC, grapplerulrich

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wordcamp-coming-soon-page.php

    r5801 r5956  
    1414        add_filter( 'template_include',   array( $this, 'override_theme_template' ) );
    1515        add_action( 'template_redirect',  array( $this, 'disable_jetpacks_open_graph' ) );
     16        add_action( 'admin_bar_menu',     array( $this, 'admin_bar_menu_item' ), 1000 );
     17        add_action( 'admin_head',         array( $this, 'admin_bar_styling' ) );
     18        add_action( 'wp_head',            array( $this, 'admin_bar_styling' ) );
     19        add_action( 'admin_notices',      array( $this, 'block_new_post_admin_notice' ) );
     20        add_filter( 'get_post_metadata',  array( $this, 'jetpack_dont_email_post_to_subs' ), 10, 4 );
    1621
    1722        add_image_size( 'wccsp_image_medium_rectangle', 500, 300 );
     
    294299        return $settings['introduction'];
    295300    }
     301
     302    /**
     303     * Display notice in admin bar when Coming Soon mode is on.
     304     *
     305     * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
     306     */
     307    function admin_bar_menu_item( $wp_admin_bar ) {
     308        $settings = $GLOBALS['WCCSP_Settings']->get_settings();
     309        if ( $settings['enabled'] !== 'on' ) {
     310            return;
     311        }
     312
     313        $menu_slug   = add_query_arg(
     314            array(
     315                'autofocus[section]' => 'wccsp_live_preview',
     316                'url'                => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ),
     317            ),
     318            '/customize.php'
     319        );
     320        $setting_url = admin_url( $menu_slug );
     321
     322        if ( ! current_user_can( 'manage_options' ) ) {
     323            $setting_url = '';
     324        }
     325
     326        $wp_admin_bar->add_node( array(
     327            'id'     => 'wordcamp-coming-soon-info',
     328            'href'   => $setting_url,
     329            'parent' => 'root-default',
     330            'title'  => __( 'Coming Soon Mode ON', 'wordcamporg' ),
     331            'meta'   => array( 'class' => 'wc-coming-soon-info' ),
     332        ) );
     333    }
     334
     335    /**
     336     * Styles for the Coming Soon flag in the Admin bar.
     337     */
     338    public function admin_bar_styling() {
     339        $settings = $GLOBALS['WCCSP_Settings']->get_settings();
     340        if ( $settings['enabled'] !== 'on' ) {
     341            return;
     342        }
     343
     344        echo '<style type="text/css">#wpadminbar .wc-coming-soon-info, #wpadminbar .wc-coming-soon-info a { background: #FFE399; color: #23282d }</style>';
     345    }
     346
     347    /*
     348     * Show a notice if Coming Soon is enabled.
     349     *
     350     * Explain to users why publishing is disabled when Coming Soon is enabled.
     351     */
     352    public function block_new_post_admin_notice() {
     353        $settings = $GLOBALS['WCCSP_Settings']->get_settings();
     354        if ( $settings['enabled'] !== 'on' ) {
     355            return;
     356        }
     357
     358        $menu_slug   = add_query_arg(
     359            array(
     360                'autofocus[section]' => 'wccsp_live_preview',
     361                'url'                => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ),
     362            ),
     363            '/customize.php'
     364        );
     365        $setting_url = admin_url( $menu_slug );
     366
     367        $screen = get_current_screen();
     368        if ( trim( $screen->id ) == 'post' ) {
     369            $class = 'notice notice-warning';
     370            $message = sprintf(
     371                __( '<a href="%s">Coming Soon mode</a> is enabled. Site subscribers will not receive email notifications about published posts.', 'wordcamporg' ),
     372                esc_url( $setting_url )
     373            );
     374
     375            if ( ! current_user_can( 'manage_options' ) ) {
     376                $message = wp_strip_all_tags( $message );
     377            }
     378
     379            printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
     380        }
     381    }
     382
     383    /**
     384     * Disable sending of Jetpack emails when Coming Soon mode is on.
     385     *
     386     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     387     *                                     or an array of values.
     388     * @param int               $object_id Object ID.
     389     * @param string            $meta_key  Meta key.
     390     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     391     */
     392    function jetpack_dont_email_post_to_subs( $value, $object_id, $meta_key, $single ) {
     393        if ( '_jetpack_dont_email_post_to_subs' === $meta_key ) {
     394            $settings = $GLOBALS['WCCSP_Settings']->get_settings();
     395
     396            if ( $settings['enabled'] === 'on' ) {
     397                return true;
     398            }
     399        }
     400
     401        return $value;
     402    }
     403
    296404} // end WordCamp_Coming_Soon_Page
Note: See TracChangeset for help on using the changeset viewer.