WordPress.org

Plugin Directory

Changeset 1443547


Ignore:
Timestamp:
06/26/16 06:54:18 (11 months ago)
Author:
sdavis2702
Message:

add setting defaults and fix Customizer PHP notices

Location:
simple-course-creator-post-meta/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • simple-course-creator-post-meta/trunk/includes/admin/class-scc-post-meta-customizer.php

    r1055123 r1443547  
    3939 
    4040        // If Simple Course Creator Customizer is installed, hook into 
    41         // its <style> section of the head. If not, go for wp_head().  
     41        // its <style> section of the head. If not, go for wp_head(). 
    4242        $scc_styles_loc = $this->sccc_active ? 'scc_add_to_styles' : 'wp_head'; 
    4343        add_action( $scc_styles_loc, array( $this, 'head_styles' ) ); 
     
    4545 
    4646 
    47     /**  
     47    /** 
    4848     * create customizer settings 
    4949     * 
     
    6262 
    6363                $wp_customize->add_section( 'scc_post_meta_customizer', array( 
    64                     'title'         => 'SCC Post Meta ' . __( 'Design', 'scc_post_meta' ), 
    65                     'description'   => sprintf( __( 'Use this section to style the post meta output. For complete SCC output style options, you should install the %s plugin.', 'scc_post_meta' ), '<a href="http://buildwpyourself.com/downloads/scc-customizer/" target="_blank">SCC Customizer</a>' ), 
    66                     'priority'      => 100, 
     64                    'title'        => 'SCC Post Meta ' . __( 'Design', 'scc_post_meta' ), 
     65                    'description'  => sprintf( __( 'Use this section to style the post meta output. For complete SCC output style options, you should install the %s plugin.', 'scc_post_meta' ), '<a href="http://buildwpyourself.com/downloads/scc-customizer/" target="_blank">SCC Customizer</a>' ), 
     66                    'priority'     => 100, 
    6767                ) ); 
    6868 
     
    7171            // post meta text color 
    7272            $colors[] = array( 
    73                 'slug'      =>'scc_pm_text_color',  
    74                 'label'     => __( 'Post Meta Text Color', 'scc_post_meta' ), 
    75                 'priority'  => 101 
     73                'slug'      =>'scc_pm_text_color', 
     74                'label'     => __( 'Post Meta Text Color', 'scc_post_meta' ), 
     75                'priority'  => 101 
    7676            ); 
    7777 
     
    8181                // customizer settings 
    8282                $wp_customize->add_setting( $color['slug'], array( 
    83                     'default'       => $color['default'], 
    84                     'type'          => 'option',  
    85                     'capability'    =>  'edit_theme_options' 
     83                    'type'        => 'option', 
     84                    'capability'  =>  'edit_theme_options' 
    8685                ) ); 
    8786 
    8887                // customizer controls 
    8988                $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 
    90                     'label'     => $color['label'],  
    91                     'section'   => $sccpm_customizer, 
    92                     'settings'  => $color['slug'], 
    93                     'priority'  => $color['priority'] 
     89                    'label'     => $color['label'], 
     90                    'section'   => $sccpm_customizer, 
     91                    'settings'  => $color['slug'], 
     92                    'priority'  => $color['priority'] 
    9493                ) ) ); 
    9594            } 
     
    104103        if ( '' === $color ) : 
    105104            return ''; 
    106         endif; 
     105        endif; 
    107106 
    108107        // 3 or 6 hex digits, or the empty string. 
    109108        if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) : 
    110109            return $color; 
    111         endif; 
     110        endif; 
    112111 
    113112        return null; 
     
    131130                    // post meta text color 
    132131                    if ( $scc_pm_text_color ) { 
    133                         echo 'color:' . $this->scc_post_meta_sanitize_hex_color( $scc_pm_text_color ) . ';';         
     132                        echo 'color:' . $this->scc_post_meta_sanitize_hex_color( $scc_pm_text_color ) . ';'; 
    134133                    } 
    135134 
    136                 echo '}';            
     135                echo '}'; 
    137136            echo ! $this->sccc_active ? '</style>' : ''; 
    138137        } 
  • simple-course-creator-post-meta/trunk/includes/admin/class-scc-post-meta-settings.php

    r1055123 r1443547  
    77 * 
    88 * It does not use add_settings_section() from WordPress Settings API 
    9  * because it uses the settings section already created by SCC.  
     9 * because it uses the settings section already created by SCC. 
    1010 * 
    1111 * @since 1.0.0 
     
    3737        // add option for hiding the date 
    3838        add_settings_field( 'display_date', __( 'Post Meta Date', 'scc_post_meta'), array( $this, 'post_meta_date' ), 'simple_course_creator', 'course_display_settings' ); 
    39  
    40         if ( get_option( 'course_display_settings' ) == false ) { 
    41             update_option( 'display_author', '0' ); 
    42             update_option( 'display_date', '0' ); 
    43         } 
    4439    } 
    4540 
     
    5146     */ 
    5247    public function post_meta_author() { 
    53         $pm_author = get_option( 'course_display_settings' ); 
     48 
     49        // set default option value 
     50        $default = array( 'display_author' => '0' ); 
     51        $options = get_option( 'course_display_settings', $default ); 
     52        $options = wp_parse_args( $options, $default ); 
    5453        ?> 
    55         <input id="display_post_meta_author" type="checkbox" name="course_display_settings[display_author]" value="1" <?php echo checked( 1, isset( $pm_author['display_author'] ) ? $pm_author['display_author'] : 0, false ); ?>> 
     54        <input id="display_post_meta_author" type="checkbox" name="course_display_settings[display_author]" value="1" <?php echo checked( 1, isset( $options['display_author'] ) ? $options['display_author'] : '0', false ); ?>> 
    5655        <label for="display_post_meta_author"><?php _e( 'Check this box to hide the list item post meta author.', 'scc_post_meta' ); ?></label> 
    5756        <?php 
     
    6564     */ 
    6665    public function post_meta_date() { 
    67         $pm_date = get_option( 'course_display_settings' ); 
     66 
     67        // set default option value 
     68        $default = array( 'display_date' => '0' ); 
     69        $options = get_option( 'course_display_settings', $default ); 
     70        $options = wp_parse_args( $options, $default ); 
    6871        ?> 
    69         <input id="display_post_meta_date" type="checkbox" name="course_display_settings[display_date]" value="1" <?php echo checked( 1, isset( $pm_date['display_date'] ) ? $pm_date['display_date'] : 0, false ); ?>> 
     72        <input id="display_post_meta_date" type="checkbox" name="course_display_settings[display_date]" value="1" <?php echo checked( 1, isset( $options['display_date'] ) ? $options['display_date'] : '0', false ); ?>> 
    7073        <label for="display_post_meta_date"><?php _e( 'Check this box to hide the list item post meta date.', 'scc_post_meta' ); ?></label> 
    7174        <?php 
    7275    } 
    73  
    74  
    75     /** 
    76      * save options settings 
    77      * 
    78      * @used_by post_meta_author() & post_meta_date() 
    79      */ 
    80     public function save_settings( $input ) { 
    81         $post_meta_options = get_option( 'course_display_settings' ); 
    82  
    83         // hide post author 
    84         $post_meta_options['display_author'] = ( isset( $input['display_author'] ) && $input['display_author'] == true ? '1' : '0' ); 
    85  
    86         // hide post date 
    87         $post_meta_options['display_date'] = ( isset( $input['display_date'] ) && $input['display_date'] == true ? '1' : '0' ); 
    88  
    89         return $input; 
    90     } 
    9176} 
    9277new SCC_Post_Meta_Settings(); 
  • simple-course-creator-post-meta/trunk/includes/display/class-scc-post-meta-hook.php

    r1055123 r1443547  
    77 * 
    88 * It uses SCC's "scc_after_list_item" hook to place the information 
    9  * based on the plugin settings.  
     9 * based on the plugin settings. 
    1010 * 
    1111 * @since 1.0.0 
     
    3737     */ 
    3838    public function after_item_post_meta( $post_id ) { 
    39         $pm_options = get_option( 'course_display_settings' ); 
     39 
     40        // set option defaults 
     41        $defaults = array( 
     42            'display_author'  => '0', 
     43            'display_date'    => '0', 
     44        ); 
     45        $options = get_option( 'course_display_settings', $defaults ); 
     46        $options = wp_parse_args( $options, $defaults ); 
     47 
     48        // set filters 
    4049        $written_by = apply_filters( 'written_by', __( 'written by', 'scc_post_meta' ) ); 
    4150        $written_on = apply_filters( 'written_on', __( 'on', 'scc_post_meta' ) ); 
     
    4554 
    4655        // show post meta data based on settings 
    47         if ( ( ! isset( $pm_options['display_author'] ) || $pm_options['display_author'] == '0' ) || ( ! isset( $pm_options['display_date'] ) || $pm_options['display_date'] == '0' ) ) { 
     56        if ( ( ! isset( $options['display_author'] ) || '0' == $options['display_author'] ) || ( ! isset( $options['display_date'] ) || '0' == $options['display_date'] ) ) { 
    4857            $pm_open = '<p class="scc-post-meta">'; 
    4958            $pm_close = '</p>'; 
     
    5362        } 
    5463        echo $pm_open; 
    55         if ( ! isset( $pm_options['display_author'] ) || $pm_options['display_author'] == '0' ) { 
     64        if ( ! isset( $options['display_author'] ) || '0' == $options['display_author'] ) { 
    5665            echo '<span class="sccpm-author">' . $written_by . '</span> ' . get_the_author_meta( 'display_name', $author_name ); 
    5766        } 
    58         if ( ! isset( $pm_options['display_date'] ) || $pm_options['display_date'] == '0' ) { 
    59             if ( ! isset( $pm_options['display_author'] ) || $pm_options['display_author'] == '0' ) { 
     67        if ( ! isset( $options['display_date'] ) || '0' == $options['display_date'] ) { 
     68            if ( ! isset( $options['display_author'] ) || '0' == $options['display_author'] ) { 
    6069                echo ' <span class="sccpm-date">' . $written_on . '</span> '; 
    6170            } 
  • simple-course-creator-post-meta/trunk/readme.txt

    r1055123 r1443547  
    44Tags: customizer, series, course, lesson, taxonomy, sdavis2702 
    55Requires at least: 3.8 
    6 Tested up to: 4.1 
    7 Stable tag: 1.0.6 
     6Tested up to: 4.6 
     7Stable tag: 1.0.7 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    3838= Does this plugin add customizer options for the post meta output? = 
    3939 
    40 Yes.  
     40Yes. 
    4141 
    4242= What if I already have Simple Course Creator Customizer installed? = 
    4343 
    44 The post meta customizer options will be merged with SCC Customizer.  
     44The post meta customizer options will be merged with SCC Customizer. 
    4545 
    4646== Screenshots == 
     
    5151 
    5252== Changelog == 
     53 
     54= 1.0.7 = 
     55* improved: added default values for settings 
     56* fixed: PHP notices in Customizer 
    5357 
    5458= 1.0.6 = 
  • simple-course-creator-post-meta/trunk/simple-course-creator-post-meta.php

    r1055123 r1443547  
    44 * Plugin URI: http://buildwpyourself.com/downloads/scc-post-meta/ 
    55 * Description: Add post meta information to each post in the output listing 
    6  * Version: 1.0.6 
     6 * Version: 1.0.7 
    77 * Author: Sean Davis 
    88 * Author URI: http://seandavis.co 
    99 * License: GPL2 
    1010 * Requires at least: 3.8 
    11  * Tested up to: 4.1 
     11 * Tested up to: 4.6 
    1212 * Text Domain: scc_post_meta 
    1313 * Domain Path: /languages/ 
    14  *  
     14 * 
    1515 * This plugin is free software; you can redistribute it and/or modify 
    16  * it under the terms of the GNU General Public License, version 2, as  
     16 * it under the terms of the GNU General Public License, version 2, as 
    1717 * published by the Free Software Foundation. 
    18  *  
     18 * 
    1919 * This plugin is distributed in the hope that it will be useful, 
    2020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    2121 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    2222 * GNU General Public License for more details. 
    23  *  
     23 * 
    2424 * You should have received a copy of the GNU General Public License 
    2525 * along with this program; if not, see http://www.gnu.org/licenses/. 
     
    5353 
    5454        // define plugin version 
    55         define( 'SCCPM_VERSION', '1.0.6' ); 
     55        define( 'SCCPM_VERSION', '1.0.7' ); 
    5656 
    5757        // define plugin directory 
Note: See TracChangeset for help on using the changeset viewer.