Plugin Directory

Changeset 992286


Ignore:
Timestamp:
09/18/2014 12:10:21 AM (12 years ago)
Author:
leocaseiro
Message:

Version 1.5 Released

Location:
custom-options-plus
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • custom-options-plus/tags/1.5/custom-options-plus.php

    r983371 r992286  
    66You can for example, register the address and phone numbers of your company to leave in the header of your site. So, if someday relocate, you do not need to change your theme. Just change administratively.
    77You can also enter the login of your social networks. How to login twitter, Facebook, Youtube, contact email and more.
    8 Version: 1.4.1
     8Version: 1.5
    99Author: Leo Caseiro
    1010Author URI: http://leocaseiro.com.br/
    11 */
    12 
    13 /*  Copyright 2011-2014 Leo Caseiro (http://leocaseiro.com.br/)
    14 
    15     This program is free software; you can redistribute it and/or modify
    16     it under the terms of the GNU General Public License, version 2, as
    17     published by the Free Software Foundation.
    18 
    19     This program is distributed in the hope that it will be useful,
    20     but WITHOUT ANY WARRANTY; without even the implied warranty of
    21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22     GNU General Public License for more details.
    23 
    24     You should have received a copy of the GNU General Public License
    25     along with this program; if not, write to the Free Software
    26     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2711*/
    2812
     
    3317}
    3418
     19
    3520define( 'COP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    3621define( 'COP_PLUGIN_NAME', trim( dirname( COP_PLUGIN_BASENAME ), '/' ) );
     
    3823define( 'COP_PLUGIN_URL', WP_PLUGIN_URL . '/' . COP_PLUGIN_NAME );
    3924
    40 global $wpdb;
     25//Added on 1.5
     26define( 'COP_OPTIONS_PREFIX', 'cop_' );
     27define( 'COP_PLUGIN_VERSION', '1.5' );
     28
     29global $wpdb, $COP_TABLE;
    4130define( 'COP_TABLE',  $wpdb->prefix . 'custom_options_plus' );
     31
     32//Added on 1.5 as GLOBAL
     33$COP_TABLE = COP_TABLE;
    4234
    4335//Create a table in MySQL database when activate plugin
    4436function cop_setup() {
    45     global $wpdb;
    46     $wpdb->query('
    47         CREATE TABLE IF NOT EXISTS ' . COP_TABLE . ' (
     37    global $wpdb, $COP_TABLE;
     38
     39    $sql = "CREATE TABLE IF NOT EXISTS $COP_TABLE (
    4840          `id` int(5) NOT NULL AUTO_INCREMENT,
    4941          `label` varchar(100) NOT NULL,
     
    5244          PRIMARY KEY (`id`)
    5345        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    54     ' );
    55 }
     46    ";
     47
     48    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     49
     50    dbDelta($sql);
     51
     52
     53    update_option(COP_OPTIONS_PREFIX . 'version', COP_PLUGIN_VERSION);
     54}
     55
    5656register_activation_hook( __FILE__, 'cop_setup' );
    5757
     
    6767
    6868function cop_load_js_and_css() {
    69     wp_register_script( 'functions.js', COP_PLUGIN_DIR . 'functions.js', array('jquery'), '2.5.9' );
    70     wp_register_script( 'jquery.stringToSlug.min.js', COP_PLUGIN_DIR . 'jquery.stringToSlug.min.js', array('jquery'), '2.5.9' );
    71 
    72 }
    73 
    74 
     69    wp_register_script( 'functions.js', COP_PLUGIN_DIR . 'functions.js', array('jquery'), COP_PLUGIN_VERSION );
     70    wp_register_script( 'jquery.stringToSlug.min.js', COP_PLUGIN_DIR . 'jquery.stringToSlug.min.js', array('jquery'), COP_PLUGIN_VERSION );
     71}
    7572
    7673
    7774function cop_insert() {
    7875    global $wpdb;
    79    
    80     $_POST['label'] = filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS);
    81     $_POST['name']  = filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS);
    82     $_POST['value'] = filter_var($_POST['value'], FILTER_UNSAFE_RAW);   
    83    
    84     return $wpdb->insert( 
    85         COP_TABLE, 
    86         array( 
    87             'label' => $_POST['label'], 
     76
     77    $_POST['label'] = stripslashes_deep(filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS));
     78    $_POST['name']  = stripslashes_deep(filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS));
     79    $_POST['value'] = stripslashes_deep(filter_var($_POST['value'], FILTER_UNSAFE_RAW));
     80
     81    return $wpdb->insert(
     82        COP_TABLE,
     83        array(
     84            'label' => $_POST['label'],
    8885            'name' => $_POST['name'],
    8986            'value' => stripslashes($_POST['value'])
    90         )
     87        ),
     88        array('%s','%s','%s')
    9189    );
    9290}
     
    9492function cop_update() {
    9593    global $wpdb;
    96    
     94
    9795    $_POST['id']    = filter_var($_POST['id'], FILTER_VALIDATE_INT);
    98     $_POST['label'] = filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS);
    99     $_POST['name']  = filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS);
    100     $_POST['value'] = filter_var($_POST['value'], FILTER_UNSAFE_RAW);
    101    
    102    
     96    $_POST['label'] = stripslashes_deep(filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS));
     97    $_POST['name']  = stripslashes_deep(filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS));
     98    $_POST['value'] = stripslashes_deep(filter_var($_POST['value'], FILTER_UNSAFE_RAW));
     99
     100
    103101    return $wpdb->update(
    104         COP_TABLE, 
    105         array( 
    106             'label' => $_POST['label'], 
     102        COP_TABLE,
     103        array(
     104            'label' => $_POST['label'],
    107105            'name'  => $_POST['name'],
    108106            'value' => stripslashes($_POST['value'])
    109107        ),
    110         array ('id' => $_POST['id'])
     108        array ('id' => $_POST['id']),
     109        array('%s','%s','%s'),
     110        array('%d')
    111111    );
    112112
     
    114114
    115115function cop_delete( $id ) {
    116     global $wpdb;
    117    
    118     return $wpdb->query($wpdb->prepare('DELETE FROM ' . COP_TABLE . ' WHERE id = \'%d\' ', $id) );
     116    global $wpdb, $COP_TABLE;
     117    return $wpdb->query($wpdb->prepare("DELETE FROM $COP_TABLE WHERE id = %d ", $id) );
    119118}
    120119
    121120function cop_get_options() {
    122     global $wpdb;
    123    
    124     return $wpdb->get_results('SELECT * FROM ' . COP_TABLE . ' ORDER BY label ASC');
     121    global $wpdb, $COP_TABLE;
     122    return $wpdb->get_results("SELECT id, label, name, value FROM $COP_TABLE ORDER BY label ASC");
    125123}
    126124
    127125function cop_get_option( $id ) {
    128     global $wpdb;
    129    
    130     return $wpdb->get_row('SELECT * FROM ' . COP_TABLE . ' WHERE id = ' . $id );
     126    global $wpdb, $COP_TABLE;
     127    return $wpdb->get_row($wpdb->prepare("SELECT id, label, name, value FROM $COP_TABLE WHERE id = %d",  $id ));
    131128}
    132129
     
    141138    wp_enqueue_script( 'stringToSlug', COP_PLUGIN_URL . '/js/jquery.stringToSlug.min.js', array('jquery'), '2.5.9' );
    142139    wp_enqueue_script( 'copFunctions', COP_PLUGIN_URL . '/js/functions.js', array('stringToSlug') );
    143    
    144    
     140
     141
    145142    $id     = '';
    146143    $label  = '';
    147144    $name   = '';
    148145    $value  = '';
    149    
     146
    150147    $message = '';
    151    
     148
    152149    if ( isset($_GET['del']) && $_GET['del'] > 0 ) :
    153150        if ( cop_delete( $_GET['del'] ) ) :
    154151            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
    155152        endif;
    156        
    157        
     153
     154
    158155    elseif ( isset($_POST['id']) ) :
    159        
     156
    160157        if ($_POST['id'] == '') :
    161158            cop_insert();
    162             $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';         
    163            
    164         elseif ($_POST['id'] > 0) :     
     159            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
     160
     161        elseif ($_POST['id'] > 0) :
    165162            cop_update();
    166             $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';         
    167            
     163            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
     164
    168165        endif;
    169        
    170        
     166
     167
    171168    elseif ( isset($_GET['id']) && $_GET['id'] > 0 ) :
    172        
     169
    173170        $option = cop_get_option( $_GET['id'] );
    174        
     171
    175172        $id     = $option->id;
    176173        $label  = $option->label;
    177174        $name   = $option->name;
    178175        $value  = $option->value;
    179        
     176
    180177    endif;
    181    
     178
    182179    $options = cop_get_options();
    183180?>
    184    
     181
    185182    <div class="wrap">
    186183        <div id="icon-tools" class="icon32"></div><h2>Custom Options Plus <a href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>#new-custom-option" class="add-new-h2">Add New</a></h2>
    187        
     184
    188185        <?php echo $message; ?>
    189186        <br />
     
    207204                    <tbody id="the-list">
    208205                        <?php $trclass = 'class="alternate"';
    209                         foreach ($options as $option ) : 
     206                        foreach ($options as $option ) :
    210207                        ?>
    211208                        <tr <?php echo $trclass; ?> rowspan="2">
     
    213210                                <?php echo $option->label; ?>
    214211                                <div class="row-actions">
    215                                     <span class="edit"><a href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>&id=<?php echo $option->id; ?>#new-custom-option">Edit</a> | </span>
     212                                    <span class="edit"><a href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>&amp;id=<?php echo $option->id; ?>#new-custom-option">Edit</a> | </span>
    216213                                    <span class="delete"><a onclick="return confirm('Are you sure want to delete item?')" class="submitdelete" title="Delete <?php echo $option->label; ?>" href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>&del=<?php echo $option->id; ?>">Delete</a></span>
    217214                                </div>
    218215                            </td>
    219216                            <td>
    220                                 <input style="font-size:12px;" type="text" onfocus="this.select();" readonly="readonly" value="<?php echo $option->name; ?>" class="shortcode-in-list-table wp-ui-text-highlight code">
     217                                <textarea style="font-size:12px;" type="text" onclick="this.select();" onfocus="this.select();" readonly="readonly" class="shortcode-in-list-table wp-ui-text-highlight code"><?php echo $option->name; ?></textarea>
    221218                            </td>
    222                             <td><?php echo htmlentities(utf8_decode($option->value)); ?></td>
     219                            <td><div style="overflow:auto; min-height:99%; width:99%; margin:2px; padding:2px; background-color:#eee; clear:both;"><?php echo $option->value; ?></div></td>
    223220                        </tr>
    224221                        <?php
     
    230227        <br />
    231228        <?php endif; ?>
    232        
     229
    233230        <form method="post" action="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>">
    234231            <input type="hidden" name="id" value="<?php echo $id; ?>" />
    235232            <h3 id="new-custom-option">Add new Custom Option</h3>
    236             <table class="form-table">             
     233            <table class="form-table">
    237234                <tbody>
    238235                    <tr valign="top">
    239                         <td scope="row">
     236                        <th scope="row">
    240237                            <label for="label">Label:</label>
    241238                        </td>
     
    245242                    </tr>
    246243                    <tr>
    247                         <td scope="row">
     244                        <th scope="row">
    248245                            <label for="name">*Name:</label>
    249246                        </td>
    250247                        <td>
    251248                            <input name="name" type="text" id="name" value="<?php echo $name; ?>" class="regular-text">
    252                         </td>                       
     249                        </td>
    253250                    </tr>
    254251                    <tr>
    255                         <td scope="row">
     252                        <th scope="row">
    256253                            <label for="value">Value:</label>
    257254                        </td>
    258255                        <td>
    259256                            <textarea name="value" rows="7" cols="40" type="text" id="value" class="regular-text code"><?php echo $value; ?></textarea>
    260                         </td>                       
     257                        </td>
    261258                    </tr>
    262259                </tbody>
     
    264261            <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"></p>
    265262        </form>
    266        
     263
    267264    </div>
    268265<?php
     
    273270//get your single option
    274271function get_custom( $name ) {
    275     global $wpdb;
     272    global $wpdb, $COP_TABLE;
     273
    276274    if ( '' != $name ) :
    277         return $wpdb->get_var( $wpdb->prepare( 'SELECT value FROM ' . COP_TABLE . ' WHERE name = \'%s\' LIMIT 1', $name ) );   
     275        return $wpdb->get_var( $wpdb->prepare( "SELECT value FROM $COP_TABLE WHERE name = %s LIMIT 1", $name ) );
    278276    else :
    279277        return false;
    280278    endif;
    281 } 
     279}
    282280
    283281//get your array options
    284282function get_customs( $name ) {
    285     global $wpdb;
     283    global $wpdb, $COP_TABLE;
    286284    if ( '' != $name ) :
    287         $list = $wpdb->get_results( $wpdb->prepare( 'SELECT value FROM ' . COP_TABLE . ' WHERE name = \'%s\' ', $name ) , ARRAY_A);
     285        $list = $wpdb->get_results( $wpdb->prepare( "SELECT value FROM $COP_TABLE WHERE name = %s ", $name ) , ARRAY_A);
    288286        $array = array();
    289287        foreach ( $list as $key => $name ) :
     
    297295
    298296
    299 //Tutorial em Help Button
     297//Tutorial on Help Button
    300298function cop_plugin_help($contextual_help, $screen_id, $screen) {
    301299
  • custom-options-plus/tags/1.5/js/functions.js

    r867617 r992286  
    1 
    2 jQuery(document).ready( function() {
    3     jQuery("#label").stringToSlug({
    4         setEvents: 'keyup keydown blur',
    5         getPut: '#name',
    6         space: '_'
    7     });
     1jQuery(document).ready( function($) {
     2    if ($("#name").val() === '') {
     3            $("#label").stringToSlug({
     4            setEvents: 'keyup keydown blur',
     5            getPut: '#name',
     6            space: '_'
     7        });
     8    }
    89});
  • custom-options-plus/tags/1.5/readme.txt

    r983371 r992286  
    1 === Custom Options Plus === 
     1=== Custom Options Plus ===
    22Contributors: leocaseiro
    33Donate link: http://leocaseiro.com.br/contato/
     
    55Requires at least: 2.7
    66Tested up to: 4.0
    7 Stable tag: 1.4.1
     7Stable tag: 1.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    1111
    12 == Description == 
     12== Description ==
    1313Custom Options Plus is the easiest way to add your custom variables as a Settings Page for your Theme.
    1414
     
    2323[Support on GitHub](https://github.com/leocaseiro/Wordpress-Plugin-Custom-Options-Plus/issues "GitHub Issues for Support"), please!
    2424
    25 == Installation == 
     25== Installation ==
    26261. Download the plugin.
    27272. Activate the plugin.
     
    4646== Changelog ==
    4747
     48= 1.5 =
     49
     50* Lot of best practices improvements on code
     51* ESCAPE bug fix following suggestion from @pierre-r on github Issue #4
     52* SQL Injection improvement using correctly $wpdp->prepare
     53* Plugin Version added
     54* Admin Layout improvements
     55* Automatic name generated only on Add New mode
     56
     57= 1.4.1 =
     58
     59* README improvements
     60
    4861= 1.4 =
    4962
     
    5467= 1.1 =
    5568* Value field from varchar(255) to text
    56 * SQL Injection fix following suggestion by Andy Stratton in http://wordpress.org/support/topic/plugin-custom-options-plus-stripslashes-needed-on-submission-of-content?replies=1
     69* SQL Injection fix following suggestion from Andy Stratton in http://wordpress.org/support/topic/plugin-custom-options-plus-stripslashes-needed-on-submission-of-content?replies=1
    5770* New Layout using WP List Table
    5871
  • custom-options-plus/trunk/custom-options-plus.php

    r983371 r992286  
    66You can for example, register the address and phone numbers of your company to leave in the header of your site. So, if someday relocate, you do not need to change your theme. Just change administratively.
    77You can also enter the login of your social networks. How to login twitter, Facebook, Youtube, contact email and more.
    8 Version: 1.4.1
     8Version: 1.5
    99Author: Leo Caseiro
    1010Author URI: http://leocaseiro.com.br/
    11 */
    12 
    13 /*  Copyright 2011-2014 Leo Caseiro (http://leocaseiro.com.br/)
    14 
    15     This program is free software; you can redistribute it and/or modify
    16     it under the terms of the GNU General Public License, version 2, as
    17     published by the Free Software Foundation.
    18 
    19     This program is distributed in the hope that it will be useful,
    20     but WITHOUT ANY WARRANTY; without even the implied warranty of
    21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22     GNU General Public License for more details.
    23 
    24     You should have received a copy of the GNU General Public License
    25     along with this program; if not, write to the Free Software
    26     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2711*/
    2812
     
    3317}
    3418
     19
    3520define( 'COP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    3621define( 'COP_PLUGIN_NAME', trim( dirname( COP_PLUGIN_BASENAME ), '/' ) );
     
    3823define( 'COP_PLUGIN_URL', WP_PLUGIN_URL . '/' . COP_PLUGIN_NAME );
    3924
    40 global $wpdb;
     25//Added on 1.5
     26define( 'COP_OPTIONS_PREFIX', 'cop_' );
     27define( 'COP_PLUGIN_VERSION', '1.5' );
     28
     29global $wpdb, $COP_TABLE;
    4130define( 'COP_TABLE',  $wpdb->prefix . 'custom_options_plus' );
     31
     32//Added on 1.5 as GLOBAL
     33$COP_TABLE = COP_TABLE;
    4234
    4335//Create a table in MySQL database when activate plugin
    4436function cop_setup() {
    45     global $wpdb;
    46     $wpdb->query('
    47         CREATE TABLE IF NOT EXISTS ' . COP_TABLE . ' (
     37    global $wpdb, $COP_TABLE;
     38
     39    $sql = "CREATE TABLE IF NOT EXISTS $COP_TABLE (
    4840          `id` int(5) NOT NULL AUTO_INCREMENT,
    4941          `label` varchar(100) NOT NULL,
     
    5244          PRIMARY KEY (`id`)
    5345        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    54     ' );
    55 }
     46    ";
     47
     48    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     49
     50    dbDelta($sql);
     51
     52
     53    update_option(COP_OPTIONS_PREFIX . 'version', COP_PLUGIN_VERSION);
     54}
     55
    5656register_activation_hook( __FILE__, 'cop_setup' );
    5757
     
    6767
    6868function cop_load_js_and_css() {
    69     wp_register_script( 'functions.js', COP_PLUGIN_DIR . 'functions.js', array('jquery'), '2.5.9' );
    70     wp_register_script( 'jquery.stringToSlug.min.js', COP_PLUGIN_DIR . 'jquery.stringToSlug.min.js', array('jquery'), '2.5.9' );
    71 
    72 }
    73 
    74 
     69    wp_register_script( 'functions.js', COP_PLUGIN_DIR . 'functions.js', array('jquery'), COP_PLUGIN_VERSION );
     70    wp_register_script( 'jquery.stringToSlug.min.js', COP_PLUGIN_DIR . 'jquery.stringToSlug.min.js', array('jquery'), COP_PLUGIN_VERSION );
     71}
    7572
    7673
    7774function cop_insert() {
    7875    global $wpdb;
    79    
    80     $_POST['label'] = filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS);
    81     $_POST['name']  = filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS);
    82     $_POST['value'] = filter_var($_POST['value'], FILTER_UNSAFE_RAW);   
    83    
    84     return $wpdb->insert( 
    85         COP_TABLE, 
    86         array( 
    87             'label' => $_POST['label'], 
     76
     77    $_POST['label'] = stripslashes_deep(filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS));
     78    $_POST['name']  = stripslashes_deep(filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS));
     79    $_POST['value'] = stripslashes_deep(filter_var($_POST['value'], FILTER_UNSAFE_RAW));
     80
     81    return $wpdb->insert(
     82        COP_TABLE,
     83        array(
     84            'label' => $_POST['label'],
    8885            'name' => $_POST['name'],
    8986            'value' => stripslashes($_POST['value'])
    90         )
     87        ),
     88        array('%s','%s','%s')
    9189    );
    9290}
     
    9492function cop_update() {
    9593    global $wpdb;
    96    
     94
    9795    $_POST['id']    = filter_var($_POST['id'], FILTER_VALIDATE_INT);
    98     $_POST['label'] = filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS);
    99     $_POST['name']  = filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS);
    100     $_POST['value'] = filter_var($_POST['value'], FILTER_UNSAFE_RAW);
    101    
    102    
     96    $_POST['label'] = stripslashes_deep(filter_var($_POST['label'], FILTER_SANITIZE_SPECIAL_CHARS));
     97    $_POST['name']  = stripslashes_deep(filter_var($_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS));
     98    $_POST['value'] = stripslashes_deep(filter_var($_POST['value'], FILTER_UNSAFE_RAW));
     99
     100
    103101    return $wpdb->update(
    104         COP_TABLE, 
    105         array( 
    106             'label' => $_POST['label'], 
     102        COP_TABLE,
     103        array(
     104            'label' => $_POST['label'],
    107105            'name'  => $_POST['name'],
    108106            'value' => stripslashes($_POST['value'])
    109107        ),
    110         array ('id' => $_POST['id'])
     108        array ('id' => $_POST['id']),
     109        array('%s','%s','%s'),
     110        array('%d')
    111111    );
    112112
     
    114114
    115115function cop_delete( $id ) {
    116     global $wpdb;
    117    
    118     return $wpdb->query($wpdb->prepare('DELETE FROM ' . COP_TABLE . ' WHERE id = \'%d\' ', $id) );
     116    global $wpdb, $COP_TABLE;
     117    return $wpdb->query($wpdb->prepare("DELETE FROM $COP_TABLE WHERE id = %d ", $id) );
    119118}
    120119
    121120function cop_get_options() {
    122     global $wpdb;
    123    
    124     return $wpdb->get_results('SELECT * FROM ' . COP_TABLE . ' ORDER BY label ASC');
     121    global $wpdb, $COP_TABLE;
     122    return $wpdb->get_results("SELECT id, label, name, value FROM $COP_TABLE ORDER BY label ASC");
    125123}
    126124
    127125function cop_get_option( $id ) {
    128     global $wpdb;
    129    
    130     return $wpdb->get_row('SELECT * FROM ' . COP_TABLE . ' WHERE id = ' . $id );
     126    global $wpdb, $COP_TABLE;
     127    return $wpdb->get_row($wpdb->prepare("SELECT id, label, name, value FROM $COP_TABLE WHERE id = %d",  $id ));
    131128}
    132129
     
    141138    wp_enqueue_script( 'stringToSlug', COP_PLUGIN_URL . '/js/jquery.stringToSlug.min.js', array('jquery'), '2.5.9' );
    142139    wp_enqueue_script( 'copFunctions', COP_PLUGIN_URL . '/js/functions.js', array('stringToSlug') );
    143    
    144    
     140
     141
    145142    $id     = '';
    146143    $label  = '';
    147144    $name   = '';
    148145    $value  = '';
    149    
     146
    150147    $message = '';
    151    
     148
    152149    if ( isset($_GET['del']) && $_GET['del'] > 0 ) :
    153150        if ( cop_delete( $_GET['del'] ) ) :
    154151            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
    155152        endif;
    156        
    157        
     153
     154
    158155    elseif ( isset($_POST['id']) ) :
    159        
     156
    160157        if ($_POST['id'] == '') :
    161158            cop_insert();
    162             $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';         
    163            
    164         elseif ($_POST['id'] > 0) :     
     159            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
     160
     161        elseif ($_POST['id'] > 0) :
    165162            cop_update();
    166             $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';         
    167            
     163            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
     164
    168165        endif;
    169        
    170        
     166
     167
    171168    elseif ( isset($_GET['id']) && $_GET['id'] > 0 ) :
    172        
     169
    173170        $option = cop_get_option( $_GET['id'] );
    174        
     171
    175172        $id     = $option->id;
    176173        $label  = $option->label;
    177174        $name   = $option->name;
    178175        $value  = $option->value;
    179        
     176
    180177    endif;
    181    
     178
    182179    $options = cop_get_options();
    183180?>
    184    
     181
    185182    <div class="wrap">
    186183        <div id="icon-tools" class="icon32"></div><h2>Custom Options Plus <a href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>#new-custom-option" class="add-new-h2">Add New</a></h2>
    187        
     184
    188185        <?php echo $message; ?>
    189186        <br />
     
    207204                    <tbody id="the-list">
    208205                        <?php $trclass = 'class="alternate"';
    209                         foreach ($options as $option ) : 
     206                        foreach ($options as $option ) :
    210207                        ?>
    211208                        <tr <?php echo $trclass; ?> rowspan="2">
     
    213210                                <?php echo $option->label; ?>
    214211                                <div class="row-actions">
    215                                     <span class="edit"><a href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>&id=<?php echo $option->id; ?>#new-custom-option">Edit</a> | </span>
     212                                    <span class="edit"><a href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>&amp;id=<?php echo $option->id; ?>#new-custom-option">Edit</a> | </span>
    216213                                    <span class="delete"><a onclick="return confirm('Are you sure want to delete item?')" class="submitdelete" title="Delete <?php echo $option->label; ?>" href="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>&del=<?php echo $option->id; ?>">Delete</a></span>
    217214                                </div>
    218215                            </td>
    219216                            <td>
    220                                 <input style="font-size:12px;" type="text" onfocus="this.select();" readonly="readonly" value="<?php echo $option->name; ?>" class="shortcode-in-list-table wp-ui-text-highlight code">
     217                                <textarea style="font-size:12px;" type="text" onclick="this.select();" onfocus="this.select();" readonly="readonly" class="shortcode-in-list-table wp-ui-text-highlight code"><?php echo $option->name; ?></textarea>
    221218                            </td>
    222                             <td><?php echo htmlentities(utf8_decode($option->value)); ?></td>
     219                            <td><div style="overflow:auto; min-height:99%; width:99%; margin:2px; padding:2px; background-color:#eee; clear:both;"><?php echo $option->value; ?></div></td>
    223220                        </tr>
    224221                        <?php
     
    230227        <br />
    231228        <?php endif; ?>
    232        
     229
    233230        <form method="post" action="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>">
    234231            <input type="hidden" name="id" value="<?php echo $id; ?>" />
    235232            <h3 id="new-custom-option">Add new Custom Option</h3>
    236             <table class="form-table">             
     233            <table class="form-table">
    237234                <tbody>
    238235                    <tr valign="top">
    239                         <td scope="row">
     236                        <th scope="row">
    240237                            <label for="label">Label:</label>
    241238                        </td>
     
    245242                    </tr>
    246243                    <tr>
    247                         <td scope="row">
     244                        <th scope="row">
    248245                            <label for="name">*Name:</label>
    249246                        </td>
    250247                        <td>
    251248                            <input name="name" type="text" id="name" value="<?php echo $name; ?>" class="regular-text">
    252                         </td>                       
     249                        </td>
    253250                    </tr>
    254251                    <tr>
    255                         <td scope="row">
     252                        <th scope="row">
    256253                            <label for="value">Value:</label>
    257254                        </td>
    258255                        <td>
    259256                            <textarea name="value" rows="7" cols="40" type="text" id="value" class="regular-text code"><?php echo $value; ?></textarea>
    260                         </td>                       
     257                        </td>
    261258                    </tr>
    262259                </tbody>
     
    264261            <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"></p>
    265262        </form>
    266        
     263
    267264    </div>
    268265<?php
     
    273270//get your single option
    274271function get_custom( $name ) {
    275     global $wpdb;
     272    global $wpdb, $COP_TABLE;
     273
    276274    if ( '' != $name ) :
    277         return $wpdb->get_var( $wpdb->prepare( 'SELECT value FROM ' . COP_TABLE . ' WHERE name = \'%s\' LIMIT 1', $name ) );   
     275        return $wpdb->get_var( $wpdb->prepare( "SELECT value FROM $COP_TABLE WHERE name = %s LIMIT 1", $name ) );
    278276    else :
    279277        return false;
    280278    endif;
    281 } 
     279}
    282280
    283281//get your array options
    284282function get_customs( $name ) {
    285     global $wpdb;
     283    global $wpdb, $COP_TABLE;
    286284    if ( '' != $name ) :
    287         $list = $wpdb->get_results( $wpdb->prepare( 'SELECT value FROM ' . COP_TABLE . ' WHERE name = \'%s\' ', $name ) , ARRAY_A);
     285        $list = $wpdb->get_results( $wpdb->prepare( "SELECT value FROM $COP_TABLE WHERE name = %s ", $name ) , ARRAY_A);
    288286        $array = array();
    289287        foreach ( $list as $key => $name ) :
     
    297295
    298296
    299 //Tutorial em Help Button
     297//Tutorial on Help Button
    300298function cop_plugin_help($contextual_help, $screen_id, $screen) {
    301299
  • custom-options-plus/trunk/js/functions.js

    r867617 r992286  
    1 
    2 jQuery(document).ready( function() {
    3     jQuery("#label").stringToSlug({
    4         setEvents: 'keyup keydown blur',
    5         getPut: '#name',
    6         space: '_'
    7     });
     1jQuery(document).ready( function($) {
     2    if ($("#name").val() === '') {
     3            $("#label").stringToSlug({
     4            setEvents: 'keyup keydown blur',
     5            getPut: '#name',
     6            space: '_'
     7        });
     8    }
    89});
  • custom-options-plus/trunk/readme.txt

    r983371 r992286  
    1 === Custom Options Plus === 
     1=== Custom Options Plus ===
    22Contributors: leocaseiro
    33Donate link: http://leocaseiro.com.br/contato/
     
    55Requires at least: 2.7
    66Tested up to: 4.0
    7 Stable tag: 1.4.1
     7Stable tag: 1.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    1111
    12 == Description == 
     12== Description ==
    1313Custom Options Plus is the easiest way to add your custom variables as a Settings Page for your Theme.
    1414
     
    2323[Support on GitHub](https://github.com/leocaseiro/Wordpress-Plugin-Custom-Options-Plus/issues "GitHub Issues for Support"), please!
    2424
    25 == Installation == 
     25== Installation ==
    26261. Download the plugin.
    27272. Activate the plugin.
     
    4646== Changelog ==
    4747
     48= 1.5 =
     49
     50* Lot of best practices improvements on code
     51* ESCAPE bug fix following suggestion from @pierre-r on github Issue #4
     52* SQL Injection improvement using correctly $wpdp->prepare
     53* Plugin Version added
     54* Admin Layout improvements
     55* Automatic name generated only on Add New mode
     56
     57= 1.4.1 =
     58
     59* README improvements
     60
    4861= 1.4 =
    4962
     
    5467= 1.1 =
    5568* Value field from varchar(255) to text
    56 * SQL Injection fix following suggestion by Andy Stratton in http://wordpress.org/support/topic/plugin-custom-options-plus-stripslashes-needed-on-submission-of-content?replies=1
     69* SQL Injection fix following suggestion from Andy Stratton in http://wordpress.org/support/topic/plugin-custom-options-plus-stripslashes-needed-on-submission-of-content?replies=1
    5770* New Layout using WP List Table
    5871
Note: See TracChangeset for help on using the changeset viewer.