Plugin Directory

Changeset 2331815


Ignore:
Timestamp:
06/28/2020 02:43:28 AM (6 years ago)
Author:
oscarssanchez
Message:

1.1 Release

Location:
simple-reading-progress-bar
Files:
15 added
7 edited

Legend:

Unmodified
Added
Removed
  • simple-reading-progress-bar/trunk/css/admin-simple-progress-reading-bar.css

    r2331002 r2331815  
    33    margin-top: 1em;
    44}
     5
     6.srpb-post-type-list {
     7    margin-left: 18px;
     8}
     9
     10.form-table td p.srpb-input {
     11    margin-top: 10px;
     12}
  • simple-reading-progress-bar/trunk/php/class-admin.php

    r2331002 r2331815  
    7474            'bar_color'    => '#eeee22',
    7575            'bar_height'   => '10',
    76             'bar_position' => 'top'
     76            'bar_position' => 'top',
     77            'post_types'   => array(
     78                'post' => true
     79        )
    7780    );
    7881
     
    8184        return array(
    8285            'bar_color' => array(
    83                 'label' => __( 'Bar Color', 'simple-reading-progress-bar' ),
     86                'label' => __( 'Bar Color: ', 'simple-reading-progress-bar' ),
    8487                'value' => $value['bar_color']
    8588            ),
    8689            'bar_height' => array(
    87                 'label' => __( 'Bar Height', 'simple-reading-progress-bar' ),
     90                'label' => __( 'Bar Height: ', 'simple-reading-progress-bar' ),
    8891                'value' => $value['bar_height']
    8992            ),
    9093            'bar_position' => array(
    91                 'label' => __( 'Bar Position', 'simple-reading-progress-bar' ),
     94                'label' => __( 'Bar Position: ', 'simple-reading-progress-bar' ),
    9295                'value' => $value['bar_position']
     96            ),
     97            'post_types' => array(
     98                'label' => __( 'Display on these post types: ', 'simple-reading-progress-bar' ),
     99                'value' => $value['post_types']
    93100            ),
    94101        );
     
    102109     */
    103110    public function sanitize_settings( $settings ) {
     111        /**
     112         * Make this setting actual booleans.
     113         */
     114        foreach ( $settings['post_types'] as $post_type => $enabled ) {
     115            if( 'on' === $enabled ) {
     116                $settings['post_types'][ $post_type ] = true;
     117            }
     118        }
     119
    104120        $settings['bar_color']    = ! empty( $settings['bar_color'] ) ? sanitize_hex_color( $settings['bar_color'] ) : '#eeee22';
    105121        $settings['bar_height']   = ( ! empty( $settings['bar_height'] ) || 0 === $settings['bar_height'] ) ? intval( $settings['bar_height'] ) : '10';
     
    115131        register_setting(
    116132            'reading',
    117             self::OPTION,
     133            self::OPTION,
    118134            array( $this, 'sanitize_settings' )
    119135        );
     
    121137        add_settings_field(
    122138            'simple_reading_progress_bar_settings',
    123             'Progress Bar Settings:',
     139            'Progress Bar Settings',
    124140            array( $this, 'render_settings' ),
    125141            'reading',
  • simple-reading-progress-bar/trunk/php/class-bar.php

    r2331002 r2331815  
    4646     */
    4747    public function bar_styles() {
    48         $settings = $this->plugin->components->admin->settings;
    49         ?>
    50         <style>
    51             progress {
    52                 position: fixed;
    53                 left: 0;
     48        if ( $this->is_bar_active() ) {
     49            $settings = $this->plugin->components->admin->settings;
     50            ?>
     51            <style>
     52                progress {
     53                    position: fixed;
     54                    left: 0;
    5455                <?php echo esc_attr( $settings['bar_position']['value'] ); ?>: 0;
    55                 z-index: 9999999;
    56                 width: 100%;
    57                 height: <?php echo esc_attr( $settings['bar_height']['value'] . 'px' ); ?>;
    58                 border: none;
    59                 background-color: transparent;
    60                 -webkit-appearance: none;
    61                 -moz-appearance: none;
    62             }
     56                    z-index: 9999999;
     57                    width: 100%;
     58                    height: <?php echo esc_attr( $settings['bar_height']['value'] . 'px' ); ?>;
     59                    border: none;
     60                    background-color: transparent;
     61                    -webkit-appearance: none;
     62                    -moz-appearance: none;
     63                }
    6364
    64             progress::-webkit-progress-bar {
    65                 background-color: transparent;
    66             }
     65                progress::-webkit-progress-bar {
     66                    background-color: transparent;
     67                }
    6768
    68             progress::-webkit-progress-value {
    69                 background-color: <?php echo esc_attr( $settings['bar_color']['value'] ); ?>;
    70             }
     69                progress::-webkit-progress-value {
     70                    background-color: <?php echo esc_attr( $settings['bar_color']['value'] ); ?>;
     71                }
    7172
    72             progress::-moz-progress-bar {
    73                 background-color: <?php echo esc_attr( $settings['bar_color']['value'] ); ?>;
    74             }
    75         </style>
    76         <?php
     73                progress::-moz-progress-bar {
     74                    background-color: <?php echo esc_attr( $settings['bar_color']['value'] ); ?>;
     75                }
     76            </style>
     77            <?php
     78        }
    7779    }
    7880
     
    8183     */
    8284    public function render_bar() {
    83         if ( is_single() ) {
     85        if ( $this->is_bar_active() ) {
    8486            ?>
    8587            <progress value="100" id="progressBar">
     
    9698     */
    9799    public function load_bar_styles() {
    98         if ( is_single() ) {
     100        if ( $this->is_bar_active() ) {
    99101            wp_enqueue_style( 'srpb', plugins_url( '../css/srpb.css', __FILE__ ), array(), Plugin::VERSION );
    100102        }
     
    105107     */
    106108    public function load_bar_scripts() {
    107         if ( is_single() ) {
     109        if ( $this->is_bar_active() ) {
    108110            wp_enqueue_script( 'srpb_scripts', plugins_url( '../js/srpb_scripts.js', __FILE__ ), array( 'jquery' ), Plugin::VERSION, true );
    109111        }
    110112    }
     113
     114    /**
     115     * Return whether the bar has been activated for the current post type.
     116     *
     117     * @return bool
     118     */
     119    public function is_bar_active() {
     120        $settings  = $this->plugin->components->admin->settings;
     121        $post_type = get_post_type();
     122
     123        if ( ! empty( $settings['post_types']['value'][ $post_type ] ) && true === $settings['post_types']['value'][ $post_type ] ) {
     124            return true;
     125        } else {
     126            return false;
     127        }
     128    }
    111129}
  • simple-reading-progress-bar/trunk/php/class-plugin.php

    r2331002 r2331815  
    2020     * @var string
    2121     */
    22     const VERSION = '1.0';
     22    const VERSION = '1.1';
    2323
    2424    /**
  • simple-reading-progress-bar/trunk/readme.txt

    r2331704 r2331815  
    55Requires at least: 4.6
    66Tested up to: 5.4.2
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 (or later)
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Enhance your readers experience by adding a simple, yet professional progress bar to your post content.
     11A simple and easy to custom progress bar at the top of your posts!
    1212
    1313== Description ==
    1414
    15 Make a better impression to your readers by adding a Progress Bar displaying on all of your posts.
    16 
    17 Ever wanted to display a progress bar like the big news sites do? Now it is possible with one click!
    18 
    19 Have questions, suggestions or want to contribute? I am happy to hear from you!
     15Display a simple progress bar at the top of your posts. With customization options.
    2016
    2117== Installation ==
    2218
    23 * Upload the folder to your /wp-content/plugins/ directory.
    24 * Activate the plugin through the ‘Plugins’ menu in WordPress.
    25 * Go to Settings -> Reading (wp-admin/options-reading.php) and adjust the bar display settings.
     19* Upload the folder to your /wp-content/plugins/ directory
     20* Activate the plugin through the ‘Plugins’ menu in WordPress
    2621
    2722== Changelog ==
     23
     24= 1.1 =
     25
     26* Adds per post type support for public post types.
     27* Improves form markup
    2828
    2929= 1.0 =
  • simple-reading-progress-bar/trunk/simple-reading-progress-bar.php

    r2331002 r2331815  
    55 * Text Domain: simple-reading-progress-bar
    66 * Plugin URI: https://github.com/oscarssanchez/simple-reading-progress-bar
    7  * Version: 1.0
     7 * Version: 1.1
    88 * Author: Oscar Sańchez
    99 * Author URI: http://oscarssanchez.com
  • simple-reading-progress-bar/trunk/templates/admin-page.php

    r2331002 r2331815  
    88defined( 'WPINC' ) or die;
    99?>
    10 <div class="wrap">
    11         <table class="form-table">
    12             <tr valign="top">
    13                 <th scope="row"><label><?php echo esc_html( $this->settings['bar_color']['label'] ); ?></label></th>
    14                 <td><input name="<?php echo esc_attr( self::OPTION ); ?>[bar_color]" type="text" id="color-<?php echo esc_attr( $this->settings['bar_color']['value'] ); ?>" value="<?php echo esc_attr( $this->settings['bar_color']['value'] ); ?>" class="colorpicker" autocomplete="off" /></td>
    15             </tr>
    16             <tr valign="top">
    17                 <th scope="row"><label><?php echo esc_html( $this->settings['bar_height']['label'] ); ?></label></th>
    18                 <td><input name="<?php echo esc_attr( self::OPTION ); ?>[bar_height]" type="number" class="barheight" value="<?php echo esc_attr( $this->settings['bar_height']['value'] ); ?>"> px</td>
    19             </tr>
    20             <tr valign="top">
    21                 <th scope="row"><label><?php echo esc_html( $this->settings['bar_position']['label'] ); ?></label></th>
    22                 <td><select name="<?php echo esc_attr( self::OPTION ); ?>[bar_position]">
    23                         <option value="top" <?php selected( $this->settings['bar_position']['value'], 'top' ); ?>><?php esc_html_e( 'Top', 'simple-reading-progress-bar' ); ?></option>
    24                         <option value="bottom" <?php selected( $this->settings['bar_position']['value'], 'bottom' ); ?>><?php esc_html_e( 'Bottom', 'simple-reading-progress-bar' ); ?></option>
    25                     </select>
    26                 </td>
    27             </tr>
    28         </table>
    29 </div>
     10<fieldset>
     11    <p class="srpb-input">
     12        <label><?php echo esc_html( $this->settings['bar_color']['label'] ); ?></label>
     13        <input name="<?php echo esc_attr( self::OPTION ); ?>[bar_color]" type="text" id="color-<?php echo esc_attr( $this->settings['bar_color']['value'] ); ?>" value="<?php echo esc_attr( $this->settings['bar_color']['value'] ); ?>" class="colorpicker" autocomplete="off" />
     14    </p>
     15    <p class="srpb-input">
     16        <label><?php echo esc_html( $this->settings['bar_height']['label'] ); ?></label>
     17        <input name="<?php echo esc_attr( self::OPTION ); ?>[bar_height]" type="number" class="barheight" value="<?php echo esc_attr( $this->settings['bar_height']['value'] ); ?>"> px
     18    </p>
     19    <p class="srpb-input">
     20        <label><?php echo esc_html( $this->settings['bar_position']['label'] ); ?></label>
     21        <select name="<?php echo esc_attr( self::OPTION ); ?>[bar_position]">
     22            <option value="top" <?php selected( $this->settings['bar_position']['value'], 'top' ); ?>><?php esc_html_e( 'Top', 'simple-reading-progress-bar' ); ?></option>
     23            <option value="bottom" <?php selected( $this->settings['bar_position']['value'], 'bottom' ); ?>><?php esc_html_e( 'Bottom', 'simple-reading-progress-bar' ); ?></option>
     24        </select>
     25    </p>
     26    <p class="srpb-input"><label><?php echo esc_html( $this->settings['post_types']['label'] ); ?></label></p>
     27    <ul class="srpb-post-type-list srpb-input">
     28        <?php
     29        foreach ( get_post_types( array( 'public' => true ) ) as $post_type ) :
     30            $enabled = $this->settings['post_types']['value'][ $post_type ];
     31            ?>
     32            <li><?php echo esc_html( ucwords( $post_type ) ); ?>
     33                <input type="checkbox" value="on" <?php checked( $enabled ); ?> name="<?php echo esc_attr( self::OPTION ); ?>[post_types][<?php echo esc_attr( $post_type ); ?>]">
     34            </li>
     35        <?php
     36        endforeach;
     37        ?>
     38    </ul>
     39</fieldset>
Note: See TracChangeset for help on using the changeset viewer.