Changeset 3784 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wccsp-settings.php
- Timestamp:
- 08/09/2016 02:53:51 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wccsp-settings.php
r3780 r3784 1 1 <?php 2 3 /* 4 * todo 5 * Now that using Customizer, this class isn't really needed and doesn't make sense. Its functions can be moved 6 * into wordcamp-coming-soon-page.php and wccsp-customizer.php 7 */ 2 8 3 9 class WCCSP_Settings { … … 11 17 add_action( 'admin_menu', array( $this, 'register_settings_pages' ) ); 12 18 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' ) );16 19 add_action( 'update_option_wccsp_settings', array( $this, 'clear_static_page_cache' ) ); 17 20 } … … 32 35 $defaults = array( 33 36 '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', 37 'body_background_color' => '#0073aa', 37 38 'image_id' => 0, 39 'background_id' => 0, 40 'container_background_color' => '#FFFFFF', // deprecated 41 'text_color' => '#000000', // deprecated 38 42 ); 39 43 … … 47 51 48 52 /** 49 * Register and enqueue the JavaScript we need for the Settings screen53 * Get the URL for the Coming Soon section in the Customizer 50 54 * 51 * @ param string $screen55 * @return string 52 56 */ 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 57 public function get_customizer_section_url() { 58 $url = add_query_arg( 59 array( 60 'autofocus[section]' => 'wccsp_live_preview', 61 'url' => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ), 62 ), 63 admin_url( 'customize.php' ) 63 64 ); 64 65 65 wp_enqueue_media(); 66 wp_enqueue_script( 'wccsp-settings' ); 66 return $url; 67 67 } 68 68 69 69 /** 70 * Adds pages to the Admin Panel menu 70 * Add a link to the Settings menu 71 * 72 * Even though this lives in the Customizer, having a link in the regular admin menus helps with 73 * discoverability. 71 74 */ 72 75 public function register_settings_pages() { … … 76 79 __( 'Coming Soon', 'wordcamporg' ), 77 80 self::REQUIRED_CAPABILITY, 78 'wccsp_settings', 79 array( $this, 'markup_settings_page' ) 81 $this->get_customizer_section_url() 80 82 ); 81 }82 83 /**84 * Creates the markup for the Settings page85 */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 settings96 */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 page161 *162 * @param array $section163 */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 fields170 *171 * @param array $field172 */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_settings187 * @return array188 */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 83 } 204 84 … … 217 97 */ 218 98 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 225 99 $active_modules = Jetpack::$instance->get_active_modules(); 226 100 $inactive_required_modules = array(); … … 236 110 } 237 111 112 ob_start(); 113 238 114 if ( $inactive_required_modules ) { 239 115 require_once( dirname( __DIR__ ) . '/views/settings-admin-notices.php' ); 240 116 } 117 118 return ob_get_clean(); 241 119 } 242 120 } // end WCCSP_Settings
Note: See TracChangeset
for help on using the changeset viewer.