Making WordPress.org

Ticket #334: coming-soon.2.diff

File coming-soon.2.diff, 38.9 KB (added by ryelle, 9 years ago)
  • bootstrap.php

     
    1313
    1414require_once( __DIR__ . '/classes/wordcamp-coming-soon-page.php' );
    1515require_once( __DIR__ . '/classes/wccsp-settings.php' );
     16require_once( __DIR__ . '/classes/wccsp-customizer.php' );
    1617
    1718$GLOBALS['WordCamp_Coming_Soon_Page'] = new WordCamp_Coming_Soon_Page();
    18 $GLOBALS['WCCSP_Settings']            = new WCCSP_Settings();
    19  No newline at end of file
     19$GLOBALS['WCCSP_Customizer']          = new WCCSP_Customizer();
     20$GLOBALS['WCCSP_Settings']            = new WCCSP_Settings();
  • classes/wccsp-customizer.php

     
     1<?php
     2
     3class WCCSP_Customizer {
     4        protected $settings;
     5
     6        /**
     7         * Constructor
     8         */
     9        public function __construct() {
     10                add_action( 'init', array( $this, 'init' ), 11 ); // after WCCSP_Settings::init()
     11                add_action( 'customize_register', array( $this, 'register_customizer_components' ) );
     12                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_customizer_scripts' ) );
     13        }
     14
     15        /**
     16         * Initializes variables
     17         */
     18        public function init() {
     19                $this->settings = $GLOBALS['WCCSP_Settings']->get_settings();
     20        }
     21
     22        /**
     23         * Register our Customizer settings, panels, sections, and controls
     24         *
     25         * @param \WP_Customize_Manager $wp_customize
     26         */
     27        public function register_customizer_components( $wp_customize ) {
     28                $wp_customize->add_section(
     29                        'wccsp_live_preview',
     30                        array(
     31                                'capability'  => $GLOBALS['WCCSP_Settings']::REQUIRED_CAPABILITY,
     32                                'title'       => __( 'Coming Soon Page', 'wordcamporg' ),
     33                                'description' => __( 'When enabled, the Coming Soon page will be displayed to logged-out users, giving you a chance to setup all of your content before your site is visible to the world.', 'wordcamporg' ) . $GLOBALS['WCCSP_Settings']->render_admin_notices(),
     34                        )
     35                );
     36
     37                $wp_customize->add_setting(
     38                        'wccsp_settings[enabled]',
     39                        array(
     40                                'default'           => 'off',
     41                                'type'              => 'option',
     42                                'capability'        => $GLOBALS['WCCSP_Settings']::REQUIRED_CAPABILITY,
     43                                'sanitize_callback' => 'sanitize_text_field',
     44                        )
     45                );
     46
     47                $wp_customize->add_control(
     48                        'wccsp_settings[enabled]',
     49                        array(
     50                                'section'     => 'wccsp_live_preview',
     51                                'type'        => 'radio',
     52                                'choices'     => array( 'on' => 'On', 'off' => 'Off' ),
     53                                'priority'    => 1,
     54                                'capability'  => $GLOBALS['WCCSP_Settings']::REQUIRED_CAPABILITY,
     55                        )
     56                );
     57
     58                $wp_customize->add_setting(
     59                        'wccsp_settings[body_background_color]',
     60                        array(
     61                                'default'           => '#0073aa',
     62                                'type'              => 'option',
     63                                'capability'        => $GLOBALS['WCCSP_Settings']::REQUIRED_CAPABILITY,
     64                                'sanitize_callback' => 'sanitize_hex_color',
     65                        )
     66                );
     67
     68                $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wccsp_settings[body_background_color]', array(
     69                        'section'     => 'wccsp_live_preview',
     70                        'label'       => __( 'Accent Color', 'wordcamporg' ),
     71                        'description' => __( 'This color is used to generate the header background, and the button colors.', 'wordcamporg' ),
     72                ) ) );
     73
     74                $wp_customize->add_setting(
     75                        'wccsp_settings[image_id]',
     76                        array(
     77                                'default'           => 0,
     78                                'type'              => 'option',
     79                                'capability'        => $GLOBALS['WCCSP_Settings']::REQUIRED_CAPABILITY,
     80                                'sanitize_callback' => 'absint',
     81                        )
     82                );
     83
     84                $wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'wccsp_settings[image_id]', array(
     85                        'label'       => __( 'Logo', 'wordcamporg' ),
     86                        'description' => __( 'A smaller image displayed above your WordCamp name.<br />Best size is less than 500px wide.', 'wordcamporg' ),
     87                        'section'     => 'wccsp_live_preview',
     88                        'mime_type'   => 'image',
     89                ) ) );
     90
     91                $wp_customize->add_setting(
     92                        'wccsp_settings[background_id]',
     93                        array(
     94                                'default'           => 0,
     95                                'type'              => 'option',
     96                                'capability'        => $GLOBALS['WCCSP_Settings']::REQUIRED_CAPABILITY,
     97                                'sanitize_callback' => 'absint',
     98                        )
     99                );
     100
     101                $wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'wccsp_settings[background_id]', array(
     102                        'label'       => __( 'Background Image', 'wordcamporg' ),
     103                        'description' => __( 'A larger image displayed behind the header text.<br />Best size is larger than 1000px wide.', 'wordcamporg' ),
     104                        'section'     => 'wccsp_live_preview',
     105                        'mime_type'   => 'image',
     106                ) ) );
     107        }
     108
     109        /**
     110         * Enqueue scripts and styles for the Customizer
     111         */
     112        public function enqueue_customizer_scripts() {
     113                if ( ! isset( $GLOBALS['wp_customize'] ) ) {
     114                        return;
     115                }
     116
     117                $GLOBALS['WordCamp_Coming_Soon_Page']->manage_plugin_theme_stylesheets();
     118
     119                // Enqueue our scripts
     120                wp_enqueue_script(
     121                        'wccsp-customizer',
     122                        plugins_url( 'javascript/wccsp-customizer.js', __DIR__ ),
     123                        array(),
     124                        1,
     125                        true
     126                );
     127        }
     128}
  • classes/wccsp-settings.php

     
    1010        public function __construct() {
    1111                add_action( 'admin_menu',                   array( $this, 'register_settings_pages' ) );
    1212                add_action( 'init',                         array( $this, 'init' ) );
    13                 add_action( 'admin_init',                   array( $this, 'register_settings' ) );
    14                 add_action( 'admin_enqueue_scripts',        array( $this, 'enqueue_scripts' ) );
    15                 add_action( 'admin_notices',                array( $this, 'render_admin_notices' ) );
    1613                add_action( 'update_option_wccsp_settings', array( $this, 'clear_static_page_cache' ) );
    1714        }
    1815
     
    2421        }
    2522
    2623        /**
    27          * Retrieves all of the settings from the database 
    28          * 
     24         * Retrieves all of the settings from the database
     25         *
    2926         * @return array
    3027         */
    3128        public function get_settings() {
    3229                $defaults = array(
    33                         'enabled'                    => 'off',        // so that sites created before the plugin was deployed won't display the home page when the plugin is activated
    34                         'body_background_color'      => '#666666',
    35                         'container_background_color' => '#FFFFFF',
    36                         'text_color'                 => '#000000',
     30                        // so that sites created before the plugin was deployed won't display the home page when the plugin is activated
     31                        'enabled'                    => 'off',
     32                        'body_background_color'      => '#0073aa',
    3733                        'image_id'                   => 0,
     34                        'background_id'              => 0,
     35                        'container_background_color' => '#FFFFFF', // deprecated
     36                        'text_color'                 => '#000000', // deprecated
    3837                );
    39                        
     38
    4039                $settings = shortcode_atts(
    4140                        $defaults,
    4241                        get_option( 'wccsp_settings', array() )
     
    4645        }
    4746
    4847        /**
    49          * Register and enqueue the JavaScript we need for the Settings screen
    50          * 
    51          * @param string $screen
     48         * Get the URL for the Coming Soon section in the Customizer
     49         *
     50         * @return string
    5251         */
    53         public function enqueue_scripts( $hook_suffix ) {
    54                 if ( 'settings_page_wccsp_settings' != $hook_suffix ) {
    55                         return;
    56                 }
    57                
    58                 wp_register_script(
    59                         'wccsp-settings',
    60                         plugins_url( '/javascript/wccsp-settings.js', __DIR__ ),
    61                         array( 'jquery', 'media-upload', 'media-views' ),
    62                         WordCamp_Coming_Soon_Page::VERSION
     52        public function get_customizer_section_url() {
     53                $url = add_query_arg(
     54                        array(
     55                                'autofocus[section]' => 'wccsp_live_preview',
     56                                'url'                => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ),
     57                        ),
     58                        '/customize.php'
    6359                );
    6460
    65                 wp_enqueue_media();
    66                 wp_enqueue_script( 'wccsp-settings' );
     61                return $url;
    6762        }
    6863
    6964        /**
    70          * Adds pages to the Admin Panel menu
     65         * Adds link to the Admin Panel menu (links off to customizer).
    7166         */
    7267        public function register_settings_pages() {
    7368                add_submenu_page(
     
    7570                        __( 'Coming Soon', 'wordcamporg' ),
    7671                        __( 'Coming Soon', 'wordcamporg' ),
    7772                        self::REQUIRED_CAPABILITY,
    78                         'wccsp_settings',
    79                         array( $this, 'markup_settings_page' )
     73                        $this->get_customizer_section_url()
    8074                );
    8175        }
    8276
    8377        /**
    84          * Creates the markup for the Settings page
    85          */
    86         public function markup_settings_page() {
    87                 if ( current_user_can( self::REQUIRED_CAPABILITY ) ) {
    88                         require_once( dirname( __DIR__ ) . '/views/settings-screen.php' );
    89                 } else {
    90                         wp_die( __( 'Access denied.', 'wordcamporg' ) );
    91                 }
    92         }
    93 
    94         /**
    95          * Registers settings sections, fields and settings
    96          */
    97         public function register_settings() {
    98                 add_settings_section(
    99                         'wccsp_default',
    100                         '',
    101                         array( $this, 'markup_section_headers' ),
    102                         'wccsp_settings'
    103                 );
    104                
    105 
    106                 add_settings_field(
    107                         'wccsp_enabled',
    108                         __( 'Enabled', 'wordcamporg' ),
    109                         array( $this, 'markup_fields' ),
    110                         'wccsp_settings',
    111                         'wccsp_default',
    112                         array( 'label_for' => 'wccsp_enabled_true' )
    113                 );
    114 
    115                 add_settings_field(
    116                         'wccsp_body_background_color',
    117                         __( 'Body Background Color', 'wordcamporg' ),
    118                         array( $this, 'markup_fields' ),
    119                         'wccsp_settings',
    120                         'wccsp_default',
    121                         array( 'label_for' => 'wccsp_body_background_color' )
    122                 );
    123 
    124                 add_settings_field(
    125                         'wccsp_container_background_color',
    126                         __( 'Container Background Color', 'wordcamporg' ),
    127                         array( $this, 'markup_fields' ),
    128                         'wccsp_settings',
    129                         'wccsp_default',
    130                         array( 'label_for' => 'wccsp_container_background_color' )
    131                 );
    132 
    133                 add_settings_field(
    134                         'wccsp_text_color',
    135                         __( 'Text Color', 'wordcamporg' ),
    136                         array( $this, 'markup_fields' ),
    137                         'wccsp_settings',
    138                         'wccsp_default',
    139                         array( 'label_for' => 'wccsp_text_color' )
    140                 );
    141 
    142                 add_settings_field(
    143                         'wccsp_image_id',
    144                         __( 'Image', 'wordcamporg' ),
    145                         array( $this, 'markup_fields' ),
    146                         'wccsp_settings',
    147                         'wccsp_default',
    148                         array( 'label_for' => 'wccsp_image_id' )
    149                 );
    150                
    151 
    152                 register_setting(
    153                         'wccsp_settings',
    154                         'wccsp_settings',
    155                         array( $this, 'validate_settings' )
    156                 );
    157         }
    158 
    159         /**
    160          * Adds the section introduction text to the Settings page
    161          *
    162          * @param array $section
    163          */
    164         public function markup_section_headers( $section ) {
    165                 require( dirname( __DIR__ ) . '/views/settings-section-headers.php' );
    166         }
    167 
    168         /**
    169          * Delivers the markup for settings fields
    170          *
    171          * @param array $field
    172          */
    173         public function markup_fields( $field ) {
    174                 switch ( $field['label_for'] ) {
    175                         case 'wccsp_image_id':
    176                                 $image = wp_get_attachment_image_src( $this->settings['image_id'], 'medium' );
    177                         break;
    178                 }
    179 
    180                 require( dirname( __DIR__ ) . '/views/settings-fields.php' );
    181         }
    182 
    183         /**
    184          * Validates submitted setting values before they get saved to the database.
    185          *
    186          * @param array $new_settings
    187          * @return array
    188          */
    189         public function validate_settings( $new_settings ) {
    190                 $new_settings = shortcode_atts( $this->settings, $new_settings );
    191 
    192                 if ( 'on' != $new_settings['enabled'] ) {
    193                         $new_settings['enabled'] = 'off';
    194                 }
    195                
    196                 $new_settings['body_background_color']      = sanitize_text_field( $new_settings['body_background_color'] );
    197                 $new_settings['container_background_color'] = sanitize_text_field( $new_settings['container_background_color'] );
    198                 $new_settings['text_color']                 = sanitize_text_field( $new_settings['text_color'] );
    199                
    200                 $new_settings['image_id'] = absint( $new_settings['image_id'] );
    201                
    202                 return $new_settings;
    203         }
    204 
    205         /**
    20678         * Clear the static page cache
    20779         * Changing the settings will change the how the page looks, so the cache needs to be refreshed.
    20880         */
     
    21688         * Renders notices for the administrator when problems are detected
    21789         */
    21890        public function render_admin_notices() {
    219                 $current_screen = get_current_screen();
    220                
    221                 if ( 'settings_page_wccsp_settings' != $current_screen->id ) {
    222                         return;
    223                 }
    224 
    22591                $active_modules            = Jetpack::$instance->get_active_modules();
    22692                $inactive_required_modules = array();
    22793                $required_modules          = array(
     
    22894                        'subscriptions' => __( 'Subscriptions', 'wordcamporg' ),
    22995                        'contact-form'  => __( 'Contact Form',  'wordcamporg' ),
    23096                );
    231                
     97
    23298                foreach ( $required_modules as $module_id => $module_name ) {
    23399                        if ( ! in_array( $module_id, $active_modules ) ) {
    234100                                $inactive_required_modules[] = $module_name;
     
    235101                        }
    236102                }
    237103
     104                ob_start();
    238105                if ( $inactive_required_modules ) {
    239106                        require_once( dirname( __DIR__ ) . '/views/settings-admin-notices.php' );
    240107                }
     108
     109                return ob_get_clean();
    241110        }
    242111} // end WCCSP_Settings
  • classes/wordcamp-coming-soon-page.php

     
    22
    33class WordCamp_Coming_Soon_Page {
    44        protected $override_theme_template;
    5         const VERSION = '0.1';
    6        
     5        const VERSION = '0.2';
     6
    77        /**
    88         * Constructor
    99         */
     
    1010        public function __construct() {
    1111                add_action( 'init',               array( $this, 'init' ), 11 );                               // after WCCSP_Settings::init()
    1212                add_action( 'wp_enqueue_scripts', array( $this, 'manage_plugin_theme_stylesheets' ), 99 );    // (hopefully) after all plugins/themes have enqueued their styles
    13                 add_action( 'wp_head',            array( $this, 'render_dynamic_styles' ) );
    1413                add_filter( 'template_include',   array( $this, 'override_theme_template' ) );
    1514
    1615                add_image_size( 'wccsp_image_medium_rectangle', 500, 300 );
     
    2120         */
    2221        public function init() {
    2322                $settings                      = $GLOBALS['WCCSP_Settings']->get_settings();
    24                 $this->override_theme_template = 'on' == $settings['enabled'] && ! current_user_can( 'edit_posts' );
     23                $this->override_theme_template = $this->is_coming_soon_preview() ||
     24                        ( 'on' == $settings['enabled'] &&  ! current_user_can( 'edit_posts' ) );
    2525        }
    2626
    2727        /**
     28         * Check if the current page is our section of the Previewer
     29         *
     30         * @return bool
     31         */
     32        public function is_coming_soon_preview() {
     33                global $wp_customize;
     34
     35                return isset( $_GET['wccsp-preview'] ) && $wp_customize->is_preview();
     36        }
     37
     38        /**
    2839         * Ensure the template has a consistent base of CSS rules, regardless of the current theme or Custom CSS
    29          * Dequeue irrelevant stylesheets and use TwentyThirteen as the base style
     40         * Dequeue irrelevant stylesheets
    3041         */
    3142        public function manage_plugin_theme_stylesheets() {
    3243                if ( ! $this->override_theme_template ) {
    3344                        return;
    3445                }
    35                
    3646                $this->dequeue_all_stylesheets();
    37                 $this->register_twentythirteen_styles();
    3847
     48                wp_register_style( 'open-sans', 'https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600', array(), null );
    3949                wp_enqueue_style(
    4050                        'wccsp-template',
    4151                        plugins_url( '/css/template-coming-soon.css', __DIR__ ),
    42                         array( 'twentythirteen-fonts', 'genericons', 'twentythirteen-style', 'admin-bar' ),
     52                        array( 'open-sans' ),
    4353                        self::VERSION
    4454                );
    4555        }
     
    4858         * Dequeue all enqueued stylesheets and Custom CSS
    4959         */
    5060        protected function dequeue_all_stylesheets() {
    51                 foreach( $GLOBALS['wp_styles']->queue as $stylesheet ) { 
     61                foreach( $GLOBALS['wp_styles']->queue as $stylesheet ) {
    5262                        wp_dequeue_style( $stylesheet );
    5363                }
    5464
     
    5666        }
    5767
    5868        /**
    59          * Register TwentyThirteen's base styles
    60          */
    61         protected function register_twentythirteen_styles() {
    62                 $twentythirteen_uri = get_theme_root_uri( 'twentythirteen' ) . '/twentythirteen';
    63                
    64                 if ( ! wp_style_is( 'twentythirteen-fonts', 'registered' ) ) {
    65                         wp_register_style( 'twentythirteen-fonts', '//fonts.googleapis.com/css?family=Source+Sans+Pro%3A300%2C400%2C700%2C300italic%2C400italic%2C700italic%7CBitter%3A400%2C700&#038;subset=latin%2Clatin-ext', array(), null );
    66                 }
    67 
    68                 if ( ! wp_style_is( 'genericons', 'registered' ) ) {
    69                         wp_register_style( 'genericons', $twentythirteen_uri . '/fonts/genericons.css' );
    70                 }
    71 
    72                 if ( ! wp_style_is( 'twentythirteen-style', 'registered' ) ) {
    73                         wp_register_style( 'twentythirteen-style', $twentythirteen_uri . '/style.css' );
    74                 }
    75         }
    76 
    77         /**
    78          * Render dynamic CSS styles
    79          */
    80         public function render_dynamic_styles() {
    81                 if ( ! $this->override_theme_template ) {
    82                         return;
    83                 }
    84                
    85                 $settings = $GLOBALS['WCCSP_Settings']->get_settings();
    86                 ?>
    87                
    88                 <!-- BEGIN wordcamp-coming-soon-page -->
    89                 <style type="text/css">
    90                         html, body {
    91                                 color: <?php echo esc_html( $settings['text_color'] ); ?>;
    92                         }
    93                        
    94                         #wccsp-container,
    95                         .widget  {
    96                                 background-color: <?php echo esc_html( $settings['container_background_color'] ); ?>;
    97                         }
    98 
    99                         @media all and ( min-width: 800px ) {
    100                                 html, body {
    101                                         background-color: <?php echo esc_html( $settings['body_background_color'] ); ?>;
    102                                 }
    103                         }
    104                 </style>
    105                 <!-- END wordcamp-coming-soon-page -->
    106 
    107                 <?php
    108         }
    109 
    110         /**
    11169         * Load the Coming Soon template instead of a theme template
    112          * 
     70         *
    11371         * @param string $template
    11472         * @return string
    11573         */
     
    11775                if ( $this->override_theme_template ) {
    11876                        $template = dirname( __DIR__ ) . '/views/template-coming-soon.php';
    11977                }
    120                
     78
    12179                return $template;
    12280        }
    12381
     
    12482        /**
    12583         * Collect all of the variables the Coming Soon template will need
    12684         * Doing this here keeps the template less cluttered and more of a pure view
    127          * 
     85         *
    12886         * @return array
    12987         */
    13088        function get_template_variables() {
    13189                $variables = array(
    13290                        'image_url'              => $this->get_image_url(),
     91                        'background_url'         => $this->get_bg_image_url(),
    13392                        'dates'                  => $this->get_dates(),
    13493                        'active_modules'         => Jetpack::$instance->get_active_modules(),
    13594                        'contact_form_shortcode' => $this->get_contact_form_shortcode(),
     95                        'colors'                 => $this->get_colors(),
    13696                );
    13797
    13898                return $variables;
     
    13999        }
    140100
    141101        /**
    142          * Retrieve the URL of the image displayed in the template
    143          *
     102         * Retrieve the colors for the template
     103         *
     104         * @return array
     105         */
     106        public function get_colors() {
     107                $settings = $GLOBALS['WCCSP_Settings']->get_settings();
     108
     109                if ( ! class_exists( 'Jetpack_Color' ) && function_exists( 'jetpack_require_lib' ) ) {
     110                        jetpack_require_lib( 'class.color' );
     111                }
     112
     113                $background = $settings['body_background_color'];
     114                // If it's still #666666, assume it was never changed, and use the new default.
     115                if ( '#666666' === $background ) {
     116                        $background = '#0073aa';
     117                }
     118
     119                // Just in case we can't find Jetpack_Color
     120                if ( class_exists( 'Jetpack_Color' ) ) {
     121                        $color = new Jetpack_Color( $background, 'hex' );
     122                        $color_hsl = $color->toHsl();
     123
     124                        $lighter_color = new Jetpack_Color( array(
     125                                $color_hsl['h'],
     126                                $color_hsl['s'],
     127                                ( $color_hsl['l'] >= 85 ) ? 100 : $color_hsl['l'] + 15
     128                        ), 'hsl' );
     129                        $darker_color = new Jetpack_Color( array(
     130                                $color_hsl['h'],
     131                                $color_hsl['s'],
     132                                ( $color_hsl['l'] < 10 ) ? 0 : $color_hsl['l'] - 10
     133                        ), 'hsl' );
     134
     135                        $background_lighter = '#' . $lighter_color->toHex();
     136                        $background_darker = '#' . $darker_color->toHex();
     137                } else {
     138                        $background_lighter = $background;
     139                        $background_darker = $background;
     140                }
     141
     142                $colors['main'] = $background;
     143                $colors['lighter'] = $background_lighter;
     144                $colors['darker'] = $background_darker;
     145
     146                // Not currently customizable
     147                $colors['text'] = '#32373c';
     148                $colors['light-text'] = '#b4b9be';
     149                $colors['border'] = '#00669b';
     150
     151                return $colors;
     152        }
     153
     154        /**
     155         * Retrieve the URL of the logo image displayed in the template
     156         *
    144157         * @return string|false
    145158         */
    146159        public function get_image_url() {
    147160                $settings   = $GLOBALS['WCCSP_Settings']->get_settings();
    148161                $image_meta = wp_get_attachment_metadata( $settings['image_id'] );
    149                 $size       = isset( $image_meta['sizes']['wccsp_image_medium_rectangle'] ) ? 'wccsp_image_medium_rectangle' : 'full'; 
     162                $size       = isset( $image_meta['sizes']['wccsp_image_medium_rectangle'] ) ? 'wccsp_image_medium_rectangle' : 'full';
    150163                $image      = wp_get_attachment_image_src( $settings['image_id'], $size );
    151                
     164
    152165                return $image ? $image[0] : false;
    153166        }
    154167
    155168        /**
     169         * Retrieve the URL of the background image displayed in the template
     170         *
     171         * @return string|false
     172         */
     173        public function get_bg_image_url() {
     174                $settings   = $GLOBALS['WCCSP_Settings']->get_settings();
     175                $image_meta = wp_get_attachment_metadata( $settings['background_id'] );
     176                $image      = wp_get_attachment_image_src( $settings['background_id'], 'full' );
     177
     178                return $image ? $image[0] : false;
     179        }
     180
     181        /**
    156182         * Retrieve the dates of the WordCamp
    157          * 
     183         *
    158184         * @return string|false
    159185         */
    160186        public function get_dates() {
     
    164190                if ( isset( $wordcamp_post->ID ) ) {
    165191                        if ( ! empty( $wordcamp_post->meta['Start Date (YYYY-mm-dd)'][0] ) ) {
    166192                                // translators: date format, see https://php.net/date
    167                                 $dates = date_i18n( __( 'l, F jS Y' , 'wordcamporg' ), $wordcamp_post->meta['Start Date (YYYY-mm-dd)'][0] );
     193                                $dates = date_i18n( __( 'F jS Y' , 'wordcamporg' ), $wordcamp_post->meta['Start Date (YYYY-mm-dd)'][0] );
    168194
    169195                                if ( ! empty( $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0] ) ) {
    170196                                        if ( $wordcamp_post->meta['Start Date (YYYY-mm-dd)'][0] !== $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0] ) {
    171197                                                // translators: date format, see https://php.net/date
    172                                                 $dates .= ' - ' . date_i18n( __( 'l, F jS Y' , 'wordcamporg' ), $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0] );
     198                                                $dates .= ' - ' . date_i18n( __( 'F jS Y' , 'wordcamporg' ), $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0] );
    173199                                        }
    174200                                }
    175201                        }
    176202                }
    177                
     203
    178204                return $dates;
    179205        }
    180206
     
    184210         * We can't just create an arbitrary shortcode because of https://github.com/Automattic/jetpack/issues/102. Instead we have to use a form that's tied to a page.
    185211         * This is somewhat fragile, though. It should work in most cases because the first $page that contains [contact-form] will be the one we automatically create
    186212         * when the site is created, but if the organizers delete that and then add multiple forms, the wrong form could be displayed. The alternative approaches also
    187          * have problems, though, and #102 should be fixed relatively soon, so hopefully this will be good enough until it can be refactored. 
     213         * have problems, though, and #102 should be fixed relatively soon, so hopefully this will be good enough until it can be refactored.
    188214         * todo Refactor this once #102-jetpack is fixed.
    189          *       
     215         *
    190216         * @return string|false
    191217         */
    192218        public function get_contact_form_shortcode() {
    193219                $contact_form_shortcode = false;
    194220                $shortcode_regex        = get_shortcode_regex();
    195                
     221
    196222                $all_pages = get_posts( array(
    197223                        'post_type'      => 'page',
    198224                        'posts_per_page' => -1,
    199225                ) );
    200                
     226
    201227                foreach ( $all_pages as $page ) {
    202228                        preg_match_all( '/' . $shortcode_regex . '/s', $page->post_content, $matches, PREG_SET_ORDER );
    203229
     
    206232                                        global $post;
    207233                                        $post = $page;
    208234                                        setup_postdata( $post );
    209                                        
     235
    210236                                        ob_start();
    211237                                        echo do_shortcode( $shortcode[0] );
    212238                                        $contact_form_shortcode = ob_get_clean();
    213                                        
     239
    214240                                        wp_reset_postdata();
    215241                                        break;
    216242                                }
    217243                        }
    218244                }
    219                
     245
    220246                return $contact_form_shortcode;
    221247        }
    222248} // end WordCamp_Coming_Soon_Page
  • css/template-coming-soon.css

     
    1 h1, h2 {
    2         margin-top: 0;
    3         margin-bottom: 1em;
     1body {
     2        margin: 0;
     3        font-family: "Open Sans", sans-serif;
     4        font-size: 24px;
     5        -webkit-font-smoothing: antialiased;
     6        -moz-osx-font-smoothing: grayscale;
     7        background-color: white;
     8}
     9
     10.wccsp-background {
     11        position: absolute;
     12        top: 0;
     13        left: 0;
     14        right: 0;
     15        z-index: -1;
     16}
     17
     18.wccsp-container {
     19        margin: 0 auto;
     20        padding: 0 20px;
     21        max-width: 730px;
     22}
     23
     24.wccsp-header {
     25        padding: 120px 0;
     26}
     27
     28.wccsp-image {
    429        text-align: center;
    530}
    631
    7 #wccsp-container {
    8         max-width: 700px;
    9         margin-left: auto;
    10         margin-right: auto;
    11         padding: 40px;
    12         overflow: auto;
    13 }
    14        
    15         #wccsp-image {
    16                 display: block;
     32        .wccsp-image img {
    1733                max-width: 100%;
    18                 margin: 0 auto 40px auto;
    1934        }
    20        
    21         #wccsp-introduction {
    22                 margin-bottom: 0;
     35
     36h1 {
     37        margin: 0;
     38        margin-bottom: 10px;
     39        font-size: 62px;
     40        font-weight: 300;
     41        text-align: center;
     42}
     43
     44@media screen and (max-width: 400px) {
     45        h1 {
     46                font-size: 48px;
    2347        }
    24        
    25         .wccsp-box {
    26                 width: 100%;
    27                 min-height: 150px;
    28                 overflow: auto;
    29                 margin: 40px 40px 0 0;
    30                 padding: 15px;
    31        
    32                 border: 1px solid black;        /* todo box shadow */
     48}
     49
     50h2 {
     51        font-size: 28px;
     52        font-weight: 600;
     53}
     54
     55h2.wccsp-dates {
     56        margin: 0;
     57        margin-bottom: 50px;
     58        font-size: 30px;
     59        font-weight: 300;
     60        text-align: center;
     61}
     62
     63button,
     64input,
     65optgroup,
     66select,
     67textarea {
     68        color: inherit;
     69        font: inherit;
     70        margin: 0;
     71}
     72
     73button,
     74input[type="text"],
     75input[type="email"],
     76input[type="submit"],
     77textarea {
     78        box-sizing: border-box;
     79        padding: 5px;
     80        width: 100%;
     81        border: none;
     82        font-size: 18px;
     83        line-height: normal;
     84}
     85
     86input[type="text"],
     87input[type="email"] {
     88        height: 40px;
     89}
     90
     91textarea {
     92        height: 200px;
     93        resize: vertical;
     94}
     95
     96button,
     97input[type="submit"] {
     98        -webkit-appearance: button;
     99        cursor: pointer;
     100        height: 40px;
     101        font-size: 14px;
     102        border-width: 1px 1px 2px;
     103        border-style: solid;
     104        border-radius: 3px;
     105}
     106
     107label {
     108        display: block;
     109}
     110
     111        label span {
     112                margin-left: 8px;
     113                text-transform: uppercase;
     114                font-size: 16px;
    33115        }
    34        
    35                 #wccsp-container .wccsp-box:last-child {
    36                         margin-right: 0;
     116
     117.jetpack_subscription_widget {
     118}
     119
     120        .jetpack_subscription_widget form {
     121                display: flex;
     122                padding: 5px;
     123                background: white;
     124        }
     125
     126        .jetpack_subscription_widget p {
     127                margin: 0;
     128        }
     129
     130                .jetpack_subscription_widget p.error {
     131                        margin-bottom: 5px;
     132                        font-size: 16px;
    37133                }
    38                
    39                 .wccsp-box .widget {
    40                         margin: 0;
    41                         padding: 0;
    42                 }
    43        
    44                 .wccsp-box h2 {
    45                         margin-top: 0;
    46                 }
    47                
    48                 .wccsp-box p:last-child {
    49                         margin-bottom: 0;
    50                 }
    51                
    52                 .wccsp-box input[type="text"],
    53                 .wccsp-box input[type="email"],
    54                 .wccsp-box textarea {
    55                         width: 100%;
    56                         margin-bottom: 1em;
    57                         padding: 2px 3px;
    58                        
    59                         /* todo not working */
    60                 }
    61                
    62                 .wccsp-box input[type="text"]:last-child {
    63                         margin-bottom: 0;
    64                 }
    65                
    66                 .wccsp-box input[type="submit"] {
    67                         margin: 0 auto;                         /*todo not working */
    68                         text-align: center;
    69                 }
    70                
    71                 .wccsp-box textarea {
    72                         height: 8em;
    73                 }
    74134
    75                 .grunion-field-label span {
    76                         padding-left: 5px;
     135        #subscribe-email {
     136                flex: 3;
     137        }
     138
     139                #subscribe-email input[type="submit"] {
     140                        padding: 5px 30px;
    77141                }
    78142
    79 @media all and ( min-width: 800px ) {
    80         #wccsp-container {
    81                 margin-top: 50px;
    82                 margin-bottom: 50px;
    83                 border: 1px solid black; /* todo box shadow */
     143        #subscribe-submit  {
     144                flex: 1;
    84145        }
    85146
    86                 .wccsp-box {
    87                         float: left;
    88                         width: 46%;             /* todo temp workaround */
    89                 }
    90 }
    91  No newline at end of file
     147.wccsp-introduction {
     148        margin-bottom: 75px;
     149        padding: 75px 0;
     150        border-bottom: 2px solid #f0f2f3;
     151}
     152
     153        .wccsp-introduction p {
     154                margin: 0;
     155        }
     156
     157.wccsp-contact {
     158        margin-bottom: 75px;
     159}
     160
     161        .wccsp-contact h2 {
     162                margin: 0 0 50px;
     163        }
     164
     165        .wccsp-contact input[type="text"],
     166        .wccsp-contact input[type="email"],
     167        .wccsp-contact textarea {
     168                border: 1px solid #cbcdce;
     169        }
     170
     171        .wccsp-contact form > div {
     172                margin-bottom: 40px;
     173        }
     174
     175        .wccsp-contact label {
     176                margin-bottom: 10px;
     177        }
     178
     179        .wccsp-contact input[type="submit"] {
     180                padding: 5px 30px;
     181                width: auto;
     182        }
     183
     184.wccsp-footer {
     185        background: #32373c;
     186        text-align: center;
     187        padding: 20px 0;
     188        font-size: 16px;
     189        font-weight: 400;
     190}
     191
     192        .wccsp-footer a:link,
     193        .wccsp-footer a:visited,
     194        .wccsp-footer a:hover,
     195        .wccsp-footer a:active {
     196                color: white;
     197                text-decoration: none;
     198        }
     199
     200        .wccsp-footer a:hover,
     201        .wccsp-footer a:focus {
     202                text-decoration: underline;
     203        }
  • javascript/wccsp-customizer.js

     
     1wp.customize.ComingSoonPageCustomizer = ( function( $, api ) {
     2        'use strict';
     3
     4        var self = {
     5                sectionID    : 'wccsp_live_preview',
     6                siteURL      : window.location.protocol + '//' + window.location.hostname,
     7        };
     8
     9        self.previewPageURL = self.siteURL + '?wccsp-preview';
     10
     11        /**
     12         * Initialize
     13         */
     14        self.initialize = function() {
     15                api.section( self.sectionID ).container.bind( 'expanded',  self.loadPreviewPage     );
     16                api.section( self.sectionID ).container.bind( 'collapsed', self.unloadPreviewPage   );
     17        };
     18
     19        /**
     20         * Load the Coming Soon page when navigating to our section
     21         *
     22         * @param {object} event
     23         */
     24        self.loadPreviewPage = function( event ) {
     25                if ( self.previewPageURL !== api.previewer.previewUrl.get() ) {
     26                        api.previewer.previewUrl.set( self.previewPageURL );
     27                }
     28        };
     29
     30        /**
     31         * Unload the Coming Soon page when navigating away from our section
     32         *
     33         * @param {object} event
     34         */
     35        self.unloadPreviewPage = function( event ) {
     36                if ( self.previewPageURL === api.previewer.previewUrl.get() ) {
     37                        api.previewer.previewUrl.set( self.siteURL );
     38                }
     39        };
     40
     41        api.bind( 'ready', self.initialize );
     42        return self;
     43
     44} ( jQuery, wp.customize ) );
  • javascript/wccsp-settings.js

     
    1 jQuery( document ).ready( function( $ ) {
    2        
    3         var WCCSP_Settings = {
    4                
    5                 /**
    6                  * Constructor
    7                  */
    8                 __construct: function () {
    9                         $( '#wccsp-select-image' ).click( WCCSP_Settings.uploader );
    10                 },
    11 
    12                 /**
    13                  * Injects the media modal and assigns the chosen attachment ID to corresponding input field
    14                  *
    15                  * @param object event
    16                  * @returns {boolean}
    17                  */
    18                 uploader : function( event ) {
    19                         var frame = wp.media( {
    20                                 title           : 'Select Image',
    21                                 multiple        : false,
    22                                 library         : { type : 'image' },
    23                                 button          : { text : 'Select Image' }
    24                         } );
    25 
    26                         frame.on( 'close', function() {
    27                                 var attachments = frame.state().get( 'selection' ).toJSON();
    28                                 $( '#wccsp_image_id' ).val( parseInt( attachments[0].id ) );
    29                                 $( '#wccsp_image_preview' ).text( 'You have chosen a new image. The preview will be updated after you click on the Save Changes button.' );
    30                         } );
    31 
    32                         frame.open();
    33                         return false;
    34                 }
    35         }; // end WCCSP_Settings
    36 
    37         WCCSP_Settings.__construct();
    38 } );
    39  No newline at end of file
  • views/settings-admin-notices.php

     
    1 <div class="error">
    2         <ul>
    3                 <?php foreach ( $inactive_required_modules as $module ) : ?>
    4                         <li>
    5                                 <?php // translators: %s is the name of the jetpack module ?>
    6                                 <?php printf( __( "Please activate Jetpack's %s module.", 'wordcamporg' ), esc_html( $module ) ); ?>
    7                         </li>
    8                 <?php endforeach; ?>
    9         </ul>
    10 </div>
     1<?php foreach ( $inactive_required_modules as $module ) : ?>
     2        <div class="error" style="margin-top:15px;">
     3                <?php // translators: %s is the name of the jetpack module ?>
     4                <?php printf( __( "Please activate Jetpack's %s module.", 'wordcamporg' ), esc_html( $module ) ); ?>
     5        </div>
     6<?php endforeach; ?>
  • views/settings-fields.php

     
    1 <?php if ( 'wccsp_enabled_true' == $field['label_for'] ) : ?>
    2         <input id="wccsp_enabled_true" name="wccsp_settings[enabled]" type="radio" value="on" <?php checked( $this->settings['enabled'], 'on' ); ?> />
    3         <span class="example">
    4                 <?php // translators: If Coming Soon plugin is enabled ?>
    5                 <?php _e( 'On', 'wordcamporg' ); ?>
    6         </span><br />
    7        
    8         <input id="wccsp_enabled_false" name="wccsp_settings[enabled]" type="radio" value="off" <?php checked( $this->settings['enabled'], 'off' ); ?> />
    9         <span class="example">
    10                 <?php // translators: If Coming Soon plugin is disabled ?>
    11                 <?php _e( 'Off', 'wordcamporg' ); ?>
    12         </span>
    13 <?php endif; ?>
    14 
    15 
    16 <?php if ( 'wccsp_body_background_color' == $field['label_for'] ) : ?>
    17         <input id="wccsp_body_background_color" name="wccsp_settings[body_background_color]" type="text" class="short-text" value="<?php echo esc_attr( $this->settings['body_background_color'] ); ?>" />
    18 <?php endif; ?>
    19 
    20 
    21 <?php if ( 'wccsp_container_background_color' == $field['label_for'] ) : ?>
    22         <input id="wccsp_container_background_color" name="wccsp_settings[container_background_color]" type="text" class="short-text" value="<?php echo esc_attr( $this->settings['container_background_color'] ); ?>" />
    23 <?php endif; ?>
    24 
    25 
    26 <?php if ( 'wccsp_text_color' == $field['label_for'] ) : ?>
    27         <input id="wccsp_text_color" name="wccsp_settings[text_color]" type="text" class="short-text" value="<?php echo esc_attr( $this->settings['text_color'] ); ?>" />
    28 <?php endif; ?>
    29 
    30 
    31 <?php if ( 'wccsp_image_id' == $field['label_for'] ) : ?>
    32         <p>
    33                 <input type="hidden" id="wccsp_image_id" name="wccsp_settings[image_id]" value="<?php echo esc_attr( $this->settings['image_id'] ); ?>" />
    34                 <a href="javascript:;" id="wccsp-select-image" class="button insert-media add_media" title="<?php _e( 'Select Image', 'wordcamporg' ); ?>">
    35                         <?php _e( 'Select Image', 'wordcamporg' ); ?>
    36                 </a>
    37         </p>
    38        
    39         <?php if( $image ) : ?>
    40                 <p id="wccsp_image_preview">
    41                         <?php _e( 'Current image preview:', 'wordcamporg' ); ?><br />
    42                         <img src="<?php echo esc_attr( $image[0] ); ?>" alt="<?php _e( 'Image Preview', 'wordcamporg' ); ?>" />
    43                 </p>
    44         <?php endif; ?>
    45 <?php endif; ?>
  • views/settings-section-headers.php

     
    1 <p>
    2         <?php _e(
    3                 'When enabled, the Coming Soon page will be displayed to logged-out users, giving you a chance to setup
    4                  all of your content before your site is visible to the world. To preview the page, just open your site in
    5                  an Incognito/Private tab, or log out of your account.',
    6                 'wordcamporg'
    7         ); ?>
    8 </p>
  • views/template-coming-soon.php

     
    44        <meta charset="<?php bloginfo( 'charset' ); ?>">
    55        <meta name="viewport" content="width=device-width">
    66        <title><?php echo esc_html( get_bloginfo( 'name' ) ); ?></title>
    7        
     7
    88        <?php wp_head(); ?>
    99        <?php extract( $GLOBALS['WordCamp_Coming_Soon_Page']->get_template_variables() ); ?>
     10        <!-- BEGIN wordcamp-coming-soon-page -->
     11        <style type="text/css">
     12        body,
     13        button,
     14        input[type="text"],
     15        input[type="email"],
     16        input[type="submit"],
     17        textarea {
     18                color: <?php echo esc_attr( $colors['text'] ); ?>;
     19        }
     20
     21        label span {
     22                color: <?php echo esc_attr( $colors['light-text'] ); ?>;
     23        }
     24
     25        .wccsp-header {
     26                position: relative;
     27                color: white;
     28                overflow: hidden;
     29                <?php if ( $background_url ) : ?>
     30                background: url( '<?php echo esc_url( $background_url ); ?>') no-repeat center;
     31                background-size: cover;
     32                <?php else: ?>
     33                background: <?php echo esc_attr( $colors['main'] ); ?>;
     34                background: linear-gradient( 45deg, <?php echo esc_attr( $colors['main'] ); ?>, <?php echo esc_attr( $colors['lighter'] ); ?> );
     35                <?php endif; ?>
     36        }
     37
     38        <?php if ( $background_url ) : ?>
     39        .wccsp-header::after {
     40                content: ' ';
     41                position: absolute;
     42                z-index: 0;
     43                background: rgba( 0, 0, 0, 0.3 );
     44                top: 0;
     45                left: 0;
     46                right: 0;
     47                bottom: 0;
     48        }
     49        .wccsp-header * {
     50                position: relative;
     51                z-index: 1;
     52        }
     53        <?php endif; ?>
     54
     55        h2.wccsp-dates {
     56                color: rgba( 255, 255, 255, 0.8 );
     57        }
     58
     59        button,
     60        input[type="submit"] {
     61                background: <?php echo esc_attr( $colors['main'] ); ?>;
     62                color: white;
     63                text-shadow: 0 0 5px rgba( 0, 0, 0, 0.5 );
     64                border-color: <?php echo esc_attr( $colors['darker'] ); ?>;
     65        }
     66        </style>
     67        <!-- END wordcamp-coming-soon-page -->
    1068</head>
    1169
    1270<body <?php body_class(); ?>>
    1371        <div id="wccsp-container">
    14                
    15                 <h1><?php echo esc_attr( get_bloginfo( 'name' ) ); ?></h1>
    16                
    17                 <?php if ( $image_url ) : ?>
    18                         <img id="wccsp-image" src="<?php echo esc_attr( $image_url ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" />
    19                 <?php endif; ?>
     72                <div class="wccsp-header">
     73                        <div class="wccsp-container">
     74                                <?php if ( $image_url ) : ?>
     75                                        <div class="wccsp-image">
     76                                                <img id="wccsp-image" src="<?php echo esc_attr( $image_url ); ?>" />
     77                                        </div>
     78                                <?php endif; ?>
    2079
    21                 <?php if ( $dates ) : ?>
    22                         <h2><?php echo esc_html( $dates ); ?></h2>
    23                 <?php endif; ?>
    24                
    25                 <p id="wccsp-introduction">
    26                         <?php printf(
    27                                 // translators: %s is the name of the blog
    28                                 __( '%s is in the early planning stages. In the meantime, you can subscribe to be notified when the site goes live, or contact the organizers to get involved.', 'wordcamporg' ),
    29                                 esc_html( get_bloginfo( 'name' ) )
    30                         ); ?>
    31                 </p>
     80                                <h1><?php echo esc_attr( get_bloginfo( 'name' ) ); ?></h1>
    3281
    33                 <?php if ( in_array( 'subscriptions', $active_modules ) ) : ?>
    34                         <div class="wccsp-box">
    35                                 <?php echo do_shortcode( sprintf(
    36                                         '[jetpack_subscription_form title="%s"]',
    37                                         __( 'Subscribe for Updates', 'wordcamporg' )
    38                                 ) ); ?>
    39                         </div>
    40                 <?php endif; ?>
     82                                <?php if ( $dates ) : ?>
     83                                        <h2 class="wccsp-dates"><?php echo esc_html( $dates ); ?></h2>
     84                                <?php endif; ?>
    4185
    42                 <?php if ( in_array( 'contact-form', $active_modules ) && $contact_form_shortcode ) : ?>
    43                         <div class="wccsp-box">
    44                                 <h2><?php _e( 'Contact the Organizers' , 'wordcamporg' ); ?></h2>
    45                                
    46                                 <?php echo $contact_form_shortcode; // intentionally not escaping because it's the output of do_shortcode() ?>
    47                         </div>
    48                 <?php endif; ?>
    49                
     86                                <?php if ( in_array( 'subscriptions', $active_modules ) ) : ?>
     87                                        <div class="wccsp-subscription">
     88                                                <?php echo do_shortcode( sprintf(
     89                                                        '[jetpack_subscription_form subscribe_text="" title="" subscribe_button="%s"]',
     90                                                        __( 'Send me updates!', 'wordcamporg' )
     91                                                ) ); ?>
     92                                        </div>
     93                                <?php endif; ?>
     94                        </div><!-- .wccsp-container -->
     95                </div><!-- .wccsp-header -->
     96
     97                <div class="wccsp-container">
     98                        <div class="wccsp-introduction">
     99                                <p id="wccsp-introduction">
     100                                        <?php printf(
     101                                                // translators: %s is the name of the blog
     102                                                __( '%s is in the early planning stages. In the meantime, you can subscribe to be notified when the site goes live, or contact the organizers to get involved.', 'wordcamporg' ),
     103                                                esc_html( get_bloginfo( 'name' ) )
     104                                        ); ?>
     105                                </p>
     106                        </div><!-- .wccsp-introduction -->
     107
     108                        <?php if ( in_array( 'contact-form', $active_modules ) && $contact_form_shortcode ) : ?>
     109                                <div class="wccsp-contact">
     110                                        <h2><?php _e( 'Contact the Organizers' , 'wordcamporg' ); ?></h2>
     111
     112                                        <?php echo $contact_form_shortcode; // intentionally not escaping because it's the output of do_shortcode() ?>
     113                                </div>
     114                        <?php endif; ?>
     115                </div><!-- .wccsp-container -->
     116
    50117        </div><!-- #wccsp_container -->
    51        
     118
     119        <div class="wccsp-footer">
     120                <p><a href="https://central.wordcamp.org/schedule/"><?php _e( 'See all upcoming events at WordCamp Central', 'wordcamporg' ); ?></a></p>
     121        </div>
     122
    52123        <?php wp_footer(); ?>
    53124</body>
    54125</html>