Plugin Directory

Changeset 1550765


Ignore:
Timestamp:
12/09/2016 04:29:20 PM (9 years ago)
Author:
elusivelight
Message:

1.4.0

Location:
widget-css-classes
Files:
34 added
6 edited

Legend:

Unmodified
Added
Removed
  • widget-css-classes/trunk/css/widget-css-classes.css

    r1332286 r1550765  
    1 .wcssc_copy span, .wcssc_remove span {
    2     vertical-align: middle;
     1.wcssc_copy span, .wcssc_remove span, .wcssc_sort span {
     2    vertical-align: text-bottom;
    33    margin: 0;
    44    padding: 0;
    55}
    6 .wcssc_copy, .wcssc_remove {
     6.wcssc_copy, .wcssc_remove, .wcssc_sort {
    77    text-decoration: none;
    88}
     9.wcssc_sort {
     10    display: none;
     11    cursor: move;
     12}
     13.wcssc_sort_fixed .wcssc_sort {
     14    visibility: hidden;
     15}
     16
     17.wcssc_sortable .wcssc_drop_placeholder {
     18    background: #e5e5e5;
     19    height: 30px;
     20}
  • widget-css-classes/trunk/includes/widget-css-classes-settings.class.php

    r1332286 r1550765  
    2222    private $general_settings = array();
    2323
    24     function __construct() {
     24    public function __construct() {
    2525        add_action( 'admin_init', array( $this, 'load_settings' ) );
    2626        add_action( 'admin_init', array( $this, 'register_general_settings' ) );
     
    2929    }
    3030
    31     function load_settings() {
     31    public function load_settings() {
    3232        $this->general_settings = get_option( $this->general_key );
    3333    }
    3434
    35     function section_general_desc() {
    36     }
    37 
    38     function register_general_settings() {
     35    public function section_general_desc() {
     36    }
     37
     38    public function register_general_settings() {
    3939        $this->plugin_tabs[$this->general_key] = esc_attr__( 'Widget CSS Classes Settings', 'widget-css-classes' );
    4040
     
    5050    }
    5151
    52     function show_number_option() { ?>
     52    public function show_number_option() { ?>
    5353    <input type="radio" name="<?php echo esc_attr( $this->general_key ).'[show_number]'; ?>" value="1" <?php checked( $this->general_settings['show_number'], 1 ); ?> /> <?php esc_attr_e( 'Yes', 'widget-css-classes' ); ?>&nbsp;&nbsp;
    5454    <input type="radio" name="<?php echo esc_attr( $this->general_key ).'[show_number]'; ?>" value="0" <?php checked( $this->general_settings['show_number'], 0 ); ?> /> <?php esc_attr_e( 'No', 'widget-css-classes' ); ?>
     
    5656    }
    5757
    58     function show_location_option() {
     58    public function show_location_option() {
    5959        ?>
    6060    <input type="radio" name="<?php echo esc_attr( $this->general_key ).'[show_location]'; ?>" value="1" <?php checked( $this->general_settings['show_location'], 1 ); ?> /> <?php esc_attr_e( 'Yes', 'widget-css-classes' ); ?>&nbsp;&nbsp;
     
    6363    }
    6464
    65     function show_evenodd_option() {
     65    public function show_evenodd_option() {
    6666        ?>
    6767    <input type="radio" name="<?php echo esc_attr( $this->general_key ).'[show_evenodd]'; ?>" value="1" <?php checked( $this->general_settings['show_evenodd'], 1 ); ?> /> <?php esc_attr_e( 'Yes', 'widget-css-classes' ); ?>&nbsp;&nbsp;
     
    7070    }
    7171
    72     function show_id_option() {
     72    public function show_id_option() {
    7373        ?>
    7474        <input type="radio" name="<?php echo esc_attr( $this->general_key ).'[show_id]'; ?>" value="1" <?php checked( $this->general_settings['show_id'], 1 ); ?> /> <?php esc_attr_e( 'Yes', 'widget-css-classes' ); ?>&nbsp;&nbsp;
     
    7777    }
    7878
    79     function type_option() {
     79    public function type_option() {
    8080        ?>
    8181        <input type="radio" name="<?php echo esc_attr( $this->general_key ).'[type]'; ?>" value="1" <?php checked( $this->general_settings['type'], 1 ); ?> /> <?php esc_attr_e( 'Text', 'widget-css-classes' ); ?>&nbsp;&nbsp;
     
    8686    }
    8787
    88     function defined_classes_option() {
     88    public function defined_classes_option() {
     89        wp_enqueue_script( 'jquery-ui-sortable' );
    8990        $presets = explode( ';', $this->general_settings['defined_classes'] );
     91        ?>
     92        <div class="wcssc_sortable">
     93        <?php
    9094        if ( count( $presets ) > 1 ) {
    9195            foreach ( $presets as $key => $preset ) {
    9296                if ( $preset != '' ) {
    9397                ?>
    94                     <p><input type="text" name="<?php echo esc_attr( $this->general_key ).'[defined_classes]['.esc_attr( $key ).']'; ?>" value="<?php echo esc_attr( $preset ); ?>" />
    95                     <a class="wcssc_remove" href="#"><span class="dashicons dashicons-dismiss"></span></a></p>
     98                    <p class="wcssc_defined_classes">
     99                        <a class="wcssc_sort" href="#"><span class="dashicons dashicons-sort"></span></a>
     100                        <input type="text" name="<?php echo esc_attr( $this->general_key ).'[defined_classes]['.esc_attr( $key ).']'; ?>" value="<?php echo esc_attr( $preset ); ?>" />
     101                        <a class="wcssc_remove" href="#"><span class="dashicons dashicons-dismiss"></span></a>
     102                    </p>
    96103                <?php
    97104                }
    98105            }
    99106            ?>
    100             <p class="wcssc_defined_classes">
     107            <p class="wcssc_defined_classes wcssc_sort_fixed">
     108                <a class="wcssc_sort" href="#"><span class="dashicons dashicons-sort"></span></a>
    101109                <input type="text" name="<?php echo esc_attr( $this->general_key ).'[defined_classes][]'; ?>" value="" />
    102110                <a href="#" class="wcssc_copy" rel=".wcssc_defined_classes"><span class="dashicons dashicons-plus-alt"></span></a>
     
    106114        } else {
    107115            ?>
    108             <p class="wcssc_defined_classes"><input type="text" name="<?php echo esc_attr( $this->general_key ).'[defined_classes][]'; ?>" value="<?php echo esc_attr( $this->general_settings['defined_classes'] ); ?>" />
    109             <a href="#" class="wcssc_copy" rel=".wcssc_defined_classes"><span class="dashicons dashicons-plus-alt"></span></a>
    110             <a class="wcssc_remove" href="#"><span class="dashicons dashicons-dismiss"></span></a></p>
    111         <?php
    112         }
    113     }
    114 
    115     function register_importexport_settings() {
    116         $this->plugin_tabs['importexport'] = esc_attr__( 'Import/Export', 'widget-css-classes' );
    117 
    118         if ( isset( $_GET['wcssc_message'] ) ) {
    119             switch ( $_GET['wcssc_message'] ) {
    120                 case 1:
    121                     $wcssc_message = esc_attr__( 'Settings Imported', 'widget-css-classes' );
    122                     break;
    123                 case 2:
    124                     $wcssc_message = esc_attr__( 'Invalid Settings File', 'widget-css-classes' );
    125                     break;
    126                 case 3:
    127                     $wcssc_message = esc_attr__( 'No Settings File Selected', 'widget-css-classes' );
    128                     break;
    129                 default:
    130                     $wcssc_message = '';
    131                     break;
    132             }
    133         }
    134 
    135         if ( isset( $wcssc_message ) && $wcssc_message != '' ) {
    136             echo '<div class="updated"><p>'.esc_html( $wcssc_message ).'</p></div>';
    137         }
    138 
    139         // export settings
    140         if ( isset( $_GET['widget-css-classes-settings-export'] ) ) {
    141             header( "Content-Disposition: attachment; filename=widget-css-classes-settings.txt" );
    142             header( 'Content-Type: text/plain; charset=utf-8' );
    143             $general = get_option( 'WCSSC_options' );
    144 
    145             echo "[START=WCSSC SETTINGS]\n";
    146             foreach ( $general as $id => $text )
    147                 echo "$id\t".json_encode( $text )."\n";
    148             echo "[STOP=WCSSC SETTINGS]";
    149             exit;
    150         }
    151 
    152         // import settings
    153         if ( isset( $_POST['widget-css-classes-settings-import'] ) ) {
    154             $wcssc_message = '';
    155             if ( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) {
    156                 $import = explode( "\n", file_get_contents( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) );
    157                 if ( array_shift( $import ) == "[START=WCSSC SETTINGS]" && array_pop( $import ) == "[STOP=WCSSC SETTINGS]" ) {
    158                     foreach ( $import as $import_option ) {
    159                         list( $key, $value ) = explode( "\t", $import_option );
    160                         $options[$key] = json_decode( sanitize_text_field( $value ) );
    161                         if ( $options['dropdown'] ) { // Update for 1.3.0
    162                             $options['defined_classes'] = $options['dropdown'];
    163                             unset( $options['dropdown'] );
     116            <p class="wcssc_defined_classes wcssc_sort_fixed">
     117                <a class="wcssc_sort" href="#"><span class="dashicons dashicons-sort"></span></a>
     118                <input type="text" name="<?php echo esc_attr( $this->general_key ).'[defined_classes][]'; ?>" value="<?php echo esc_attr( $this->general_settings['defined_classes'] ); ?>" />
     119                <a href="#" class="wcssc_copy" rel=".wcssc_defined_classes"><span class="dashicons dashicons-plus-alt"></span></a>
     120                <a class="wcssc_remove" href="#"><span class="dashicons dashicons-dismiss"></span></a>
     121            </p>
     122        <?php
     123        }
     124        ?>
     125        </div>
     126        <?php
     127    }
     128
     129    public function register_importexport_settings() {
     130
     131        if ( current_user_can('manage_options' ) ) {
     132
     133            $this->plugin_tabs['importexport'] = esc_attr__( 'Import/Export', 'widget-css-classes' );
     134
     135            if ( isset( $_GET['wcssc_message'] ) ) {
     136                switch ( $_GET['wcssc_message'] ) {
     137                    case 1:
     138                        $wcssc_message_class = 'updated';
     139                        $wcssc_message       = esc_attr__( 'Settings Imported', 'widget-css-classes' );
     140                        break;
     141                    case 2:
     142                        $wcssc_message_class = 'error';
     143                        $wcssc_message       = esc_attr__( 'Invalid Settings File', 'widget-css-classes' );
     144                        break;
     145                    case 3:
     146                        $wcssc_message_class = 'error';
     147                        $wcssc_message       = esc_attr__( 'No Settings File Selected', 'widget-css-classes' );
     148                        break;
     149                    default:
     150                        $wcssc_message_class = '';
     151                        $wcssc_message       = '';
     152                        break;
     153                }
     154            }
     155
     156            if ( isset( $wcssc_message ) && $wcssc_message != '' ) {
     157                echo '<div class=" ' . $wcssc_message_class . ' "><p>' . esc_html( $wcssc_message ) . '</p></div>';
     158            }
     159
     160            // export settings
     161            if ( isset( $_GET['widget-css-classes-settings-export'] ) ) {
     162                header( "Content-Disposition: attachment; filename=widget-css-classes-settings.txt" );
     163                header( 'Content-Type: text/plain; charset=utf-8' );
     164                $general = get_option( 'WCSSC_options' );
     165
     166                echo "[START=WCSSC SETTINGS]\n";
     167                foreach ( $general as $id => $text ) {
     168                    echo "$id\t" . json_encode( $text ) . "\n";
     169                }
     170                echo "[STOP=WCSSC SETTINGS]";
     171                exit;
     172            }
     173
     174            // import settings
     175            if ( isset( $_POST['widget-css-classes-settings-import'] ) ) {
     176                $wcssc_message = '';
     177                if ( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) {
     178                    $import = explode( "\n",
     179                        file_get_contents( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) );
     180                    if ( array_shift( $import ) == "[START=WCSSC SETTINGS]" && array_pop( $import ) == "[STOP=WCSSC SETTINGS]" ) {
     181                        foreach ( $import as $import_option ) {
     182                            list( $key, $value ) = explode( "\t", $import_option );
     183                            $options[ $key ] = json_decode( sanitize_text_field( $value ) );
     184                            if ( $options['dropdown'] ) { // Update for 1.3.0
     185                                $options['defined_classes'] = $options['dropdown'];
     186                                unset( $options['dropdown'] );
     187                            }
    164188                        }
     189                        update_option( 'WCSSC_options', $options );
     190                        $wcssc_message = 1;
     191                    } else {
     192                        $wcssc_message = 2;
    165193                    }
    166                     update_option( 'WCSSC_options', $options );
    167                     $wcssc_message = 1;
    168194                } else {
    169                     $wcssc_message = 2;
    170                 }
    171             } else {
    172                 $wcssc_message = 3;
    173             }
    174 
    175             wp_redirect( admin_url( '/options-general.php?page=widget-css-classes-settings&tab=importexport&wcssc_message='.esc_attr( $wcssc_message ) ) );
    176             exit;
    177         }
    178     }
    179 
    180     function validate_input( $input ) {
     195                    $wcssc_message = 3;
     196                }
     197
     198                wp_redirect( admin_url( '/options-general.php?page=widget-css-classes-settings&tab=importexport&wcssc_message=' . esc_attr( $wcssc_message ) ) );
     199                exit;
     200            }
     201
     202        }
     203    }
     204
     205    public function validate_input( $input ) {
    181206        $output = array();
    182207
     
    199224    }
    200225
    201     function add_admin_menus() {
     226    public function add_admin_menus() {
    202227        add_options_page( esc_attr__( 'Widget CSS Classes', 'widget-css-classes' ), esc_attr__( 'Widget CSS Classes', 'widget-css-classes' ), 'manage_options', 'widget-css-classes-settings', array( $this, 'plugin_options_page' ) );
    203228    }
     
    209234     * to render the tabs.
    210235     */
    211     function plugin_options_page() {
     236    public function plugin_options_page() {
    212237        $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $this->general_key;
    213238        ?>
     
    232257     * plugin_options_page method.
    233258     */
    234     function plugin_options_tabs() {
     259    public function plugin_options_tabs() {
    235260        $current_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $this->general_key;
    236261
     
    243268    }
    244269
    245     function importexport_fields() {
     270    public function importexport_fields() {
    246271        ?>
    247272    <h3><?php esc_html_e( 'Import/Export Settings', 'widget-css-classes' ); ?></h3>
  • widget-css-classes/trunk/includes/widget-css-classes.class.php

    r1332286 r1550765  
    3232        if ( WCSSC_Loader::$settings['show_id'] == 1 || WCSSC_Loader::$settings['type'] > 0 ) {
    3333            //$fields .= "<div class='wcssc' style='border: 1px solid #ddd; padding: 5px; background: #fafafa; margin: 1em 0; line-height: 1.5;'>\n";
    34             //$fields .= "<div class='wcssc'>\n";
     34            $fields .= "<div class='wcssc'>\n";
    3535
    3636            // show id field
     
    8484            }
    8585
    86             //$fields .= "</div>\n";
     86            $fields .= "</div>\n";
    8787        }
    8888
     
    102102     */
    103103    public static function update_widget( $instance, $new_instance ) {
     104        if ( !isset( $new_instance['classes'] ) ) $new_instance['classes'] = null;
     105        if ( !isset( $new_instance['classes-defined'] ) ) $new_instance['classes-defined'] = array();
    104106        $instance['classes'] = $new_instance['classes'];
    105107        $instance['classes-defined'] = $new_instance['classes-defined'];
     
    107109            $instance['ids']     = $new_instance['ids'];
    108110        }
    109         if ( is_array( $instance['classes-defined'] ) ) {
     111        if ( ! empty( $instance['classes-defined'] ) && is_array( $instance['classes-defined'] ) ) {
    110112            // Merge predefined classes with input classes
    111113            $text_classes = explode( ' ', $instance['classes'] );
     
    134136
    135137        global $wp_registered_widgets, $widget_number;
    136 
     138       
     139        if ( ! isset( $params[0] ) ) {
     140            return $params;
     141        }
     142       
    137143        $arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets
    138144        $this_id                = $params[0]['id']; // Get the id for the current sidebar we're processing
  • widget-css-classes/trunk/js/widget-css-classes.js

    r1332286 r1550765  
    1010    } );
    1111
     12    if ( $.isFunction( $.fn.sortable ) ) {
     13        $('.wcssc_sortable .wcssc_sort').show();
     14        $('.wcssc_sortable').sortable({
     15            items: 'p:not(.wcssc_sort_fixed)',
     16            placeholder: 'wcssc_drop_placeholder'
     17        }).disableSelection();
     18    }
     19
    1220} );
  • widget-css-classes/trunk/readme.txt

    r1535315 r1550765  
    99Requires at least: 3.3
    1010Tested up to: 4.7
    11 Stable tag: 1.3.0
     11Stable tag: 1.4.0
    1212
    1313Add custom classes and ids plus first, last, even, odd, and numbered classes to your widgets.
     
    9595== Changelog ==
    9696
     97= 1.4.0 =
     98* Feature: Sort Pre-defined classes (thanks Jory Hogeveen)
     99* Security: Prevent unauthenticated import of settings
     100* Fix: Notice message when classes is empty (thanks Jory Hogeveen)
     101
    97102= 1.3.0 =
    98103* Feature: Change dropdown to checkboxes for multiple class selection
     
    159164== Upgrade Notice ==
    160165
     166= 1.4 =
     167New feature, bug fix, security fix
     168
    161169= 1.2.7 =
    162170Bug fix
  • widget-css-classes/trunk/widget-css-classes.php

    r1332280 r1550765  
    22/*
    33Plugin Name: Widget CSS Classes
    4 Version: 1.3.0
     4Version: 1.4.0
    55Description: Add custom, first, last, even, odd, and numbered classes to your widgets.
    66Author: C.M. Kendrick
Note: See TracChangeset for help on using the changeset viewer.