Plugin Directory

Changeset 2834451


Ignore:
Timestamp:
12/15/2022 01:18:42 PM (3 years ago)
Author:
mukulwp
Message:

Update Option Page and made it more user friendly

Location:
font-resizer-with-post-reading-time/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • font-resizer-with-post-reading-time/trunk/index.php

    r2832099 r2834451  
    44Plugin URI: https://getwebexperts.com/font-resizer-with-post-reading-time
    55Description: With this plugin, you can easily display post reading time and a font resizing option on every single blog page.
    6 Version: 1.0.2
     6Version: 1.0.3
    77Author: Get Web Experts
    88Author URI: https://getwebexperts.com/
     
    1212define("fsc_ASSETS_DIR", plugin_dir_url(__FILE__) . "assets/");
    1313define("fsc_ASSETS_PUBLIC_DIR", plugin_dir_url(__FILE__) . "assets/public");
    14 define( "fsc_ASSETS_ADMIN_DIR", plugin_dir_url( __FILE__ ) . "assets/admin" );
     14define("fsc_ASSETS_ADMIN_DIR", plugin_dir_url(__FILE__) . "assets/admin");
    1515define('fsc_VERSION', time());
    1616
     17$fsc_disable_options = array(
     18    __('Font Size Resizer', 'font-size-change'),
     19    __('Post Reading Time', 'font-size-change'),
     20);
    1721
    1822class fontSizeChange
     
    2731        add_action('plugins_loaded', array($this, 'load_textdomain'));
    2832        add_action('wp_enqueue_scripts', array($this, 'load_front_assets'));
    29         add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_assets' ) );
    30     }
    31 
    32     function load_admin_assets() {
    33             wp_enqueue_style( 'fsc-admin-css', fsc_ASSETS_ADMIN_DIR . "/css/admin.css", null, $this->version );
    34 }
     33        add_action('admin_enqueue_scripts', array($this, 'load_admin_assets'));
     34    }
     35
     36    function load_admin_assets()
     37    {
     38        wp_enqueue_style('fsc-admin-css', fsc_ASSETS_ADMIN_DIR . "/css/admin.css", null, $this->version);
     39        wp_enqueue_style('wp-color-picker');
     40        wp_enqueue_script('fsc-color-picker-js', plugins_url('fsc-color-picker-script.js', __FILE__), array('wp-color-picker'), false, true);
     41    }
    3542
    3643    function load_front_assets()
     
    4047        wp_enqueue_style('fsc-min-fontawesome', fsc_ASSETS_PUBLIC_DIR . "/css/fontawesome.min.css", null, $this->version);
    4148
    42         wp_enqueue_script('fsc-main-js', fsc_ASSETS_PUBLIC_DIR . "/js/fscmain.js", null, $this->version, true );
     49        wp_enqueue_script('fsc-main-js', fsc_ASSETS_PUBLIC_DIR . "/js/fscmain.js", null, $this->version, true);
    4350    }
    4451
     
    5360
    5461//Display Font Resizer on Frontend
    55 function fsc_display_frontend($content){
    56     $fsc_font_size_resizer = esc_attr(get_option('fsc_font_size_resizer'));
    57     $fsc_reading_time = esc_attr(get_option('fsc_reading_time'));
     62function fsc_display_frontend($content)
     63{
     64    error_reporting(0);
     65    $fsc_disable = get_option('fsc_disable_option');
    5866    $fsc_reading_time_pre_text = esc_attr(get_option('fsc_reading_time_pre_text'));
    59     $fsc_reading_time_pre_text = $fsc_reading_time_pre_text ? $fsc_reading_time_pre_text: __("Read in", "change-font-size");
     67    $fsc_reading_time_pre_text = $fsc_reading_time_pre_text ? $fsc_reading_time_pre_text : __("Read in", "change-font-size");
    6068    $fsc_btn_bg = esc_attr(get_option('fsc_btn_bg'));
    6169    $fsc_btn_color = esc_attr(get_option('fsc_btn_color'));
     
    6775    $font_size_resizer_display = '';
    6876    $min = '';
    69     $stripped_content = strip_tags( $content );
    70     $wordn            = str_word_count( $stripped_content );
    71     $reading_minute   = floor( $wordn / 200 );
    72     $reading_seconds  = floor( $wordn % 200 / ( 200 / 60 ) );
    73    
    74     if(is_singular('post')){
    75         if($reading_minute > 1){
     77    $stripped_content = strip_tags($content);
     78    $wordn            = str_word_count($stripped_content);
     79    $reading_minute   = floor($wordn / 200);
     80    $reading_seconds  = floor($wordn % 200 / (200 / 60));
     81
     82    if (is_singular('post')) {
     83        if ($reading_minute > 1) {
    7684            $min = "mintues";
    77         }else{
     85        } else {
    7886            $min = "mintue";
    7987        }
    80         if($fsc_reading_time != "disable"){
    81             $reading_time_display =  "<div style='background-color: $fsc_reading_time_bg; color: $fsc_reading_time_color' class='fsc_reading_time'>".
    82             $fsc_reading_time_pre_text. ' '. $reading_minute.'.'.$reading_seconds . ' '. $min.
     88        if (!in_array('Post Reading Time', $fsc_disable)) {
     89            $reading_time_display =  "<div style='background-color: $fsc_reading_time_bg; color: $fsc_reading_time_color' class='fsc_reading_time'>" .
     90                $fsc_reading_time_pre_text . ' ' . $reading_minute . '.' . $reading_seconds . ' ' . $min .
     91                '</div>';
     92        }
     93        if (!in_array('Font Size Resizer', $fsc_disable)) {
     94            $font_size_resizer_display = "<div>
     95            <button style='background-color:$fsc_btn_bg; border: $fsc_btn_border;' class='fsc_btn' title='Increase Font Size' id='fsc_plus'><i style='color: $fsc_btn_color;' class='fa fa-plus'></i></button>
     96            <button style='background-color:$fsc_btn_bg; border: $fsc_btn_border;' class='fsc_btn' id='fsc_minus' title='Decrease Font Size'><i style='color: $fsc_btn_color;' class='fa fa-minus'></i></button>
     97            </div>";
     98        }
     99        $fsc_icon = '<div class="fsc_wrapper">' .
     100            $reading_time_display .
     101            $font_size_resizer_display .
     102
    83103            '</div>';
    84         }
    85         if($fsc_font_size_resizer != "disable"){
    86             $font_size_resizer_display = "<div>
    87             <button style='background-color:$fsc_btn_bg; color: $fsc_btn_color; border: $fsc_btn_border;' class='fsc_btn' title='Increase Font Size' id='fsc_plus'><i class='fa fa-plus'></i></button>
    88             <button style='background-color:$fsc_btn_bg; color: $fsc_btn_color; border: $fsc_btn_border;' class='fsc_btn' id='fsc_minus' title='Decrease Font Size'><i class='fa fa-minus'></i></button>
    89             </div>";
    90         }
    91         $fsc_icon = '<div class="fsc_wrapper">'.
    92         $reading_time_display.
    93         $font_size_resizer_display.
    94        
    95     '</div>';
    96    
    97 }
     104    }
    98105    $fsc_icon .= sprintf('%s', $content);
    99     return '<div class="fsc_text">'. $fsc_icon. '</div>';
    100    
     106    return '<div class="fsc_text">' . $fsc_icon . '</div>';
    101107}
    102108
     
    158164                $fields = array(
    159165                    array(
    160                         'label'       => __('Disable Font Size Resizer', 'font-size-change'),
    161                         'id'          => 'fsc_font_size_resizer',
    162                         'type'        => 'text',
    163                         'section'     => 'fsc_section',
    164                          'placeholder' => __('Type disable to disable font size resizer', 'font-size-change'),
    165                     ),
    166 
    167                     array(
    168                         'label'       => __('Disable Reading Time', 'font-size-change'),
    169                         'id'          => 'fsc_reading_time',
    170                         'type'        => 'text',
    171                         'section'     => 'fsc_section',
    172                          'placeholder' => __('Type disable to disable reading time', 'font-size-change'),
     166                        'label'       => __('Disable', 'font-size-change'),
     167                        'id'          => 'fsc_disable_option',
     168                        'type'        => 'checkbox',
     169                        'section'     => 'fsc_section',
     170                        'placeholder' => __('Type disable to disable font size resizer', 'font-size-change'),
    173171                    ),
    174172
     
    176174                        'label'       => __('Change Reading Time Prefix Text', 'font-size-change'),
    177175                        'id'          => 'fsc_reading_time_pre_text',
    178                         'type'        => 'text',
    179                         'section'     => 'fsc_section',
    180                          'placeholder' => __('Default Value: Read in', 'font-size-change'),
     176                        'type'        => 'textarea',
     177                        'section'     => 'fsc_section',
     178                        'placeholder' => __('Default Value: Read in', 'font-size-change'),
    181179                    ),
    182180
     
    186184                        'type'        => 'text',
    187185                        'section'     => 'fsc_section',
    188                          'placeholder' => __('Example: blueviolet or #8A2BE2'),
     186                        'desc'        => __('Default Plus Minus Button Background Color: transparent', 'font-size-change'),
    189187                    ),
    190188
     
    194192                        'type'        => 'text',
    195193                        'section'     => 'fsc_section',
    196                          'placeholder' => __('Example: blueviolet or #8A2BE2'),
     194                        'placeholder' => __('Example: blueviolet or #8A2BE2'),
     195                        'desc'        => __('Default Plus Minus Button Color: #8A2BE2', 'font-size-change'),
    197196                    ),
    198197
     
    200199                        'label'       => __('Change Plus Minus Button Border', 'font-size-change'),
    201200                        'id'          => 'fsc_btn_border',
    202                         'type'        => 'text',
    203                         'section'     => 'fsc_section',
    204                          'placeholder' => __('Example: 1px solid blueviolet or #8A2BE2'),
     201                        'type'        => 'textarea',
     202                        'section'     => 'fsc_section',
     203                        'placeholder' => __('Example: 1px solid blueviolet or #8A2BE2'),
     204                        'desc'        => __('Default Plus Minus Button Border: 1px solid #8A2BE2', 'font-size-change'),
    205205                    ),
    206206
     
    210210                        'type'        => 'text',
    211211                        'section'     => 'fsc_section',
    212                          'placeholder' => __('Example: blueviolet or #8A2BE2'),
     212                        'placeholder' => __('Example: blueviolet or #8A2BE2'),
     213                        'desc'        => __('Default Reading Time Background Color: #8A2BE2', 'font-size-change'),
    213214                    ),
    214215
     
    218219                        'type'        => 'text',
    219220                        'section'     => 'fsc_section',
    220                          'placeholder' => __('Example: blueviolet or #8A2BE2'),
     221                        'placeholder' => __('Example: blueviolet or #8A2BE2'),
     222                        'desc'        => __('Default Reading Time Color: #ffffff', 'font-size-change'),
    221223                    ),
    222224
     
    232234            public function fsc_field_callback($field)
    233235            {
     236                global $fsc_disable_options;
    234237                $value = get_option($field['id']);
     238                $option_d = get_option('fsc_disable_option');
    235239                switch ($field['type']) {
     240                    case 'text':
     241                        printf(
     242                            '<input class="my-color-field" name="%1$s" id="%1$s" type="%2$s" placeholder="%3$s" value="%4$s"/>',
     243                            $field['id'],
     244                            $field['type'],
     245                            isset($field['placeholder']) ? $field['placeholder'] : '',
     246                            $value
     247                        );
     248                        break;
     249                    case 'textarea':
     250                        printf(
     251                            '<textarea name="%1$s" id="%1$s" placeholder="%2$s" rows="1" cols="30">%3$s</textarea>',
     252                            $field['id'],
     253                            isset($field['placeholder']) ? $field['placeholder'] : '',
     254                            $value
     255                        );
     256                        break;
     257                        case 'checkbox':
     258                        foreach ($fsc_disable_options as $fsc_disable_option) {
     259                            $selected_d = '';
     260
     261                            if (is_array($option_d) && in_array($fsc_disable_option, $option_d)) {
     262                                $selected_d = 'checked';
     263                            }
     264                            printf('<input type="checkbox" name="fsc_disable_option[]" value="%s" %s /> %s <br/>', $fsc_disable_option, $selected_d, $fsc_disable_option);
     265                        }
     266                        break;
    236267                    default:
    237268                        printf(
    238                           '<input class="fsc_setting_form_field" name="%1$s" id="%1$s" type="%2$s" placeholder="%3$s" value="%4$s"/>',
     269                            '<input class="fsc_setting_form_field" name="%1$s" id="%1$s" type="%2$s" placeholder="%3$s" value="%4$s"/>',
    239270                            $field['id'],
    240271                            $field['type'],
     
    252283        new fsc_Settings_Page();
    253284        //Option Page End
    254 
    255 
    256 
    257 
  • font-resizer-with-post-reading-time/trunk/readme.txt

    r2832099 r2834451  
    55Requires at least: 4.7
    66Requires PHP: 7.0
    7 Tested up to: 6.0
    8 Stable tag: 1.0.2
     7Tested up to: 6.1.1
     8Stable tag: 1.0.3
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.