Changeset 992286
- Timestamp:
- 09/18/2014 12:10:21 AM (12 years ago)
- Location:
- custom-options-plus
- Files:
-
- 6 edited
- 1 copied
-
tags/1.5 (copied) (copied from custom-options-plus/trunk)
-
tags/1.5/custom-options-plus.php (modified) (15 diffs)
-
tags/1.5/js/functions.js (modified) (1 diff)
-
tags/1.5/readme.txt (modified) (5 diffs)
-
trunk/custom-options-plus.php (modified) (15 diffs)
-
trunk/js/functions.js (modified) (1 diff)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-options-plus/tags/1.5/custom-options-plus.php
r983371 r992286 6 6 You 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. 7 7 You can also enter the login of your social networks. How to login twitter, Facebook, Youtube, contact email and more. 8 Version: 1. 4.18 Version: 1.5 9 9 Author: Leo Caseiro 10 10 Author 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 modify16 it under the terms of the GNU General Public License, version 2, as17 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 of21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the22 GNU General Public License for more details.23 24 You should have received a copy of the GNU General Public License25 along with this program; if not, write to the Free Software26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA27 11 */ 28 12 … … 33 17 } 34 18 19 35 20 define( 'COP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 36 21 define( 'COP_PLUGIN_NAME', trim( dirname( COP_PLUGIN_BASENAME ), '/' ) ); … … 38 23 define( 'COP_PLUGIN_URL', WP_PLUGIN_URL . '/' . COP_PLUGIN_NAME ); 39 24 40 global $wpdb; 25 //Added on 1.5 26 define( 'COP_OPTIONS_PREFIX', 'cop_' ); 27 define( 'COP_PLUGIN_VERSION', '1.5' ); 28 29 global $wpdb, $COP_TABLE; 41 30 define( 'COP_TABLE', $wpdb->prefix . 'custom_options_plus' ); 31 32 //Added on 1.5 as GLOBAL 33 $COP_TABLE = COP_TABLE; 42 34 43 35 //Create a table in MySQL database when activate plugin 44 36 function 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 ( 48 40 `id` int(5) NOT NULL AUTO_INCREMENT, 49 41 `label` varchar(100) NOT NULL, … … 52 44 PRIMARY KEY (`id`) 53 45 ) 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 56 56 register_activation_hook( __FILE__, 'cop_setup' ); 57 57 … … 67 67 68 68 function 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 } 75 72 76 73 77 74 function cop_insert() { 78 75 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'], 88 85 'name' => $_POST['name'], 89 86 'value' => stripslashes($_POST['value']) 90 ) 87 ), 88 array('%s','%s','%s') 91 89 ); 92 90 } … … 94 92 function cop_update() { 95 93 global $wpdb; 96 94 97 95 $_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 103 101 return $wpdb->update( 104 COP_TABLE, 105 array( 106 'label' => $_POST['label'], 102 COP_TABLE, 103 array( 104 'label' => $_POST['label'], 107 105 'name' => $_POST['name'], 108 106 'value' => stripslashes($_POST['value']) 109 107 ), 110 array ('id' => $_POST['id']) 108 array ('id' => $_POST['id']), 109 array('%s','%s','%s'), 110 array('%d') 111 111 ); 112 112 … … 114 114 115 115 function 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) ); 119 118 } 120 119 121 120 function 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"); 125 123 } 126 124 127 125 function 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 )); 131 128 } 132 129 … … 141 138 wp_enqueue_script( 'stringToSlug', COP_PLUGIN_URL . '/js/jquery.stringToSlug.min.js', array('jquery'), '2.5.9' ); 142 139 wp_enqueue_script( 'copFunctions', COP_PLUGIN_URL . '/js/functions.js', array('stringToSlug') ); 143 144 140 141 145 142 $id = ''; 146 143 $label = ''; 147 144 $name = ''; 148 145 $value = ''; 149 146 150 147 $message = ''; 151 148 152 149 if ( isset($_GET['del']) && $_GET['del'] > 0 ) : 153 150 if ( cop_delete( $_GET['del'] ) ) : 154 151 $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>'; 155 152 endif; 156 157 153 154 158 155 elseif ( isset($_POST['id']) ) : 159 156 160 157 if ($_POST['id'] == '') : 161 158 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) : 165 162 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 168 165 endif; 169 170 166 167 171 168 elseif ( isset($_GET['id']) && $_GET['id'] > 0 ) : 172 169 173 170 $option = cop_get_option( $_GET['id'] ); 174 171 175 172 $id = $option->id; 176 173 $label = $option->label; 177 174 $name = $option->name; 178 175 $value = $option->value; 179 176 180 177 endif; 181 178 182 179 $options = cop_get_options(); 183 180 ?> 184 181 185 182 <div class="wrap"> 186 183 <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 188 185 <?php echo $message; ?> 189 186 <br /> … … 207 204 <tbody id="the-list"> 208 205 <?php $trclass = 'class="alternate"'; 209 foreach ($options as $option ) : 206 foreach ($options as $option ) : 210 207 ?> 211 208 <tr <?php echo $trclass; ?> rowspan="2"> … … 213 210 <?php echo $option->label; ?> 214 211 <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']); ?>&id=<?php echo $option->id; ?>#new-custom-option">Edit</a> | </span> 216 213 <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> 217 214 </div> 218 215 </td> 219 216 <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> 221 218 </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> 223 220 </tr> 224 221 <?php … … 230 227 <br /> 231 228 <?php endif; ?> 232 229 233 230 <form method="post" action="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>"> 234 231 <input type="hidden" name="id" value="<?php echo $id; ?>" /> 235 232 <h3 id="new-custom-option">Add new Custom Option</h3> 236 <table class="form-table"> 233 <table class="form-table"> 237 234 <tbody> 238 235 <tr valign="top"> 239 <t dscope="row">236 <th scope="row"> 240 237 <label for="label">Label:</label> 241 238 </td> … … 245 242 </tr> 246 243 <tr> 247 <t dscope="row">244 <th scope="row"> 248 245 <label for="name">*Name:</label> 249 246 </td> 250 247 <td> 251 248 <input name="name" type="text" id="name" value="<?php echo $name; ?>" class="regular-text"> 252 </td> 249 </td> 253 250 </tr> 254 251 <tr> 255 <t dscope="row">252 <th scope="row"> 256 253 <label for="value">Value:</label> 257 254 </td> 258 255 <td> 259 256 <textarea name="value" rows="7" cols="40" type="text" id="value" class="regular-text code"><?php echo $value; ?></textarea> 260 </td> 257 </td> 261 258 </tr> 262 259 </tbody> … … 264 261 <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"></p> 265 262 </form> 266 263 267 264 </div> 268 265 <?php … … 273 270 //get your single option 274 271 function get_custom( $name ) { 275 global $wpdb; 272 global $wpdb, $COP_TABLE; 273 276 274 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 ) ); 278 276 else : 279 277 return false; 280 278 endif; 281 } 279 } 282 280 283 281 //get your array options 284 282 function get_customs( $name ) { 285 global $wpdb ;283 global $wpdb, $COP_TABLE; 286 284 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); 288 286 $array = array(); 289 287 foreach ( $list as $key => $name ) : … … 297 295 298 296 299 //Tutorial emHelp Button297 //Tutorial on Help Button 300 298 function cop_plugin_help($contextual_help, $screen_id, $screen) { 301 299 -
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 }); 1 jQuery(document).ready( function($) { 2 if ($("#name").val() === '') { 3 $("#label").stringToSlug({ 4 setEvents: 'keyup keydown blur', 5 getPut: '#name', 6 space: '_' 7 }); 8 } 8 9 }); -
custom-options-plus/tags/1.5/readme.txt
r983371 r992286 1 === Custom Options Plus === 1 === Custom Options Plus === 2 2 Contributors: leocaseiro 3 3 Donate link: http://leocaseiro.com.br/contato/ … … 5 5 Requires at least: 2.7 6 6 Tested up to: 4.0 7 Stable tag: 1. 4.17 Stable tag: 1.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 11 12 == Description == 12 == Description == 13 13 Custom Options Plus is the easiest way to add your custom variables as a Settings Page for your Theme. 14 14 … … 23 23 [Support on GitHub](https://github.com/leocaseiro/Wordpress-Plugin-Custom-Options-Plus/issues "GitHub Issues for Support"), please! 24 24 25 == Installation == 25 == Installation == 26 26 1. Download the plugin. 27 27 2. Activate the plugin. … … 46 46 == Changelog == 47 47 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 48 61 = 1.4 = 49 62 … … 54 67 = 1.1 = 55 68 * Value field from varchar(255) to text 56 * SQL Injection fix following suggestion byAndy Stratton in http://wordpress.org/support/topic/plugin-custom-options-plus-stripslashes-needed-on-submission-of-content?replies=169 * 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 57 70 * New Layout using WP List Table 58 71 -
custom-options-plus/trunk/custom-options-plus.php
r983371 r992286 6 6 You 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. 7 7 You can also enter the login of your social networks. How to login twitter, Facebook, Youtube, contact email and more. 8 Version: 1. 4.18 Version: 1.5 9 9 Author: Leo Caseiro 10 10 Author 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 modify16 it under the terms of the GNU General Public License, version 2, as17 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 of21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the22 GNU General Public License for more details.23 24 You should have received a copy of the GNU General Public License25 along with this program; if not, write to the Free Software26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA27 11 */ 28 12 … … 33 17 } 34 18 19 35 20 define( 'COP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 36 21 define( 'COP_PLUGIN_NAME', trim( dirname( COP_PLUGIN_BASENAME ), '/' ) ); … … 38 23 define( 'COP_PLUGIN_URL', WP_PLUGIN_URL . '/' . COP_PLUGIN_NAME ); 39 24 40 global $wpdb; 25 //Added on 1.5 26 define( 'COP_OPTIONS_PREFIX', 'cop_' ); 27 define( 'COP_PLUGIN_VERSION', '1.5' ); 28 29 global $wpdb, $COP_TABLE; 41 30 define( 'COP_TABLE', $wpdb->prefix . 'custom_options_plus' ); 31 32 //Added on 1.5 as GLOBAL 33 $COP_TABLE = COP_TABLE; 42 34 43 35 //Create a table in MySQL database when activate plugin 44 36 function 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 ( 48 40 `id` int(5) NOT NULL AUTO_INCREMENT, 49 41 `label` varchar(100) NOT NULL, … … 52 44 PRIMARY KEY (`id`) 53 45 ) 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 56 56 register_activation_hook( __FILE__, 'cop_setup' ); 57 57 … … 67 67 68 68 function 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 } 75 72 76 73 77 74 function cop_insert() { 78 75 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'], 88 85 'name' => $_POST['name'], 89 86 'value' => stripslashes($_POST['value']) 90 ) 87 ), 88 array('%s','%s','%s') 91 89 ); 92 90 } … … 94 92 function cop_update() { 95 93 global $wpdb; 96 94 97 95 $_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 103 101 return $wpdb->update( 104 COP_TABLE, 105 array( 106 'label' => $_POST['label'], 102 COP_TABLE, 103 array( 104 'label' => $_POST['label'], 107 105 'name' => $_POST['name'], 108 106 'value' => stripslashes($_POST['value']) 109 107 ), 110 array ('id' => $_POST['id']) 108 array ('id' => $_POST['id']), 109 array('%s','%s','%s'), 110 array('%d') 111 111 ); 112 112 … … 114 114 115 115 function 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) ); 119 118 } 120 119 121 120 function 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"); 125 123 } 126 124 127 125 function 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 )); 131 128 } 132 129 … … 141 138 wp_enqueue_script( 'stringToSlug', COP_PLUGIN_URL . '/js/jquery.stringToSlug.min.js', array('jquery'), '2.5.9' ); 142 139 wp_enqueue_script( 'copFunctions', COP_PLUGIN_URL . '/js/functions.js', array('stringToSlug') ); 143 144 140 141 145 142 $id = ''; 146 143 $label = ''; 147 144 $name = ''; 148 145 $value = ''; 149 146 150 147 $message = ''; 151 148 152 149 if ( isset($_GET['del']) && $_GET['del'] > 0 ) : 153 150 if ( cop_delete( $_GET['del'] ) ) : 154 151 $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>'; 155 152 endif; 156 157 153 154 158 155 elseif ( isset($_POST['id']) ) : 159 156 160 157 if ($_POST['id'] == '') : 161 158 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) : 165 162 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 168 165 endif; 169 170 166 167 171 168 elseif ( isset($_GET['id']) && $_GET['id'] > 0 ) : 172 169 173 170 $option = cop_get_option( $_GET['id'] ); 174 171 175 172 $id = $option->id; 176 173 $label = $option->label; 177 174 $name = $option->name; 178 175 $value = $option->value; 179 176 180 177 endif; 181 178 182 179 $options = cop_get_options(); 183 180 ?> 184 181 185 182 <div class="wrap"> 186 183 <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 188 185 <?php echo $message; ?> 189 186 <br /> … … 207 204 <tbody id="the-list"> 208 205 <?php $trclass = 'class="alternate"'; 209 foreach ($options as $option ) : 206 foreach ($options as $option ) : 210 207 ?> 211 208 <tr <?php echo $trclass; ?> rowspan="2"> … … 213 210 <?php echo $option->label; ?> 214 211 <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']); ?>&id=<?php echo $option->id; ?>#new-custom-option">Edit</a> | </span> 216 213 <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> 217 214 </div> 218 215 </td> 219 216 <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> 221 218 </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> 223 220 </tr> 224 221 <?php … … 230 227 <br /> 231 228 <?php endif; ?> 232 229 233 230 <form method="post" action="<?php echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']); ?>"> 234 231 <input type="hidden" name="id" value="<?php echo $id; ?>" /> 235 232 <h3 id="new-custom-option">Add new Custom Option</h3> 236 <table class="form-table"> 233 <table class="form-table"> 237 234 <tbody> 238 235 <tr valign="top"> 239 <t dscope="row">236 <th scope="row"> 240 237 <label for="label">Label:</label> 241 238 </td> … … 245 242 </tr> 246 243 <tr> 247 <t dscope="row">244 <th scope="row"> 248 245 <label for="name">*Name:</label> 249 246 </td> 250 247 <td> 251 248 <input name="name" type="text" id="name" value="<?php echo $name; ?>" class="regular-text"> 252 </td> 249 </td> 253 250 </tr> 254 251 <tr> 255 <t dscope="row">252 <th scope="row"> 256 253 <label for="value">Value:</label> 257 254 </td> 258 255 <td> 259 256 <textarea name="value" rows="7" cols="40" type="text" id="value" class="regular-text code"><?php echo $value; ?></textarea> 260 </td> 257 </td> 261 258 </tr> 262 259 </tbody> … … 264 261 <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"></p> 265 262 </form> 266 263 267 264 </div> 268 265 <?php … … 273 270 //get your single option 274 271 function get_custom( $name ) { 275 global $wpdb; 272 global $wpdb, $COP_TABLE; 273 276 274 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 ) ); 278 276 else : 279 277 return false; 280 278 endif; 281 } 279 } 282 280 283 281 //get your array options 284 282 function get_customs( $name ) { 285 global $wpdb ;283 global $wpdb, $COP_TABLE; 286 284 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); 288 286 $array = array(); 289 287 foreach ( $list as $key => $name ) : … … 297 295 298 296 299 //Tutorial emHelp Button297 //Tutorial on Help Button 300 298 function cop_plugin_help($contextual_help, $screen_id, $screen) { 301 299 -
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 }); 1 jQuery(document).ready( function($) { 2 if ($("#name").val() === '') { 3 $("#label").stringToSlug({ 4 setEvents: 'keyup keydown blur', 5 getPut: '#name', 6 space: '_' 7 }); 8 } 8 9 }); -
custom-options-plus/trunk/readme.txt
r983371 r992286 1 === Custom Options Plus === 1 === Custom Options Plus === 2 2 Contributors: leocaseiro 3 3 Donate link: http://leocaseiro.com.br/contato/ … … 5 5 Requires at least: 2.7 6 6 Tested up to: 4.0 7 Stable tag: 1. 4.17 Stable tag: 1.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 11 12 == Description == 12 == Description == 13 13 Custom Options Plus is the easiest way to add your custom variables as a Settings Page for your Theme. 14 14 … … 23 23 [Support on GitHub](https://github.com/leocaseiro/Wordpress-Plugin-Custom-Options-Plus/issues "GitHub Issues for Support"), please! 24 24 25 == Installation == 25 == Installation == 26 26 1. Download the plugin. 27 27 2. Activate the plugin. … … 46 46 == Changelog == 47 47 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 48 61 = 1.4 = 49 62 … … 54 67 = 1.1 = 55 68 * Value field from varchar(255) to text 56 * SQL Injection fix following suggestion byAndy Stratton in http://wordpress.org/support/topic/plugin-custom-options-plus-stripslashes-needed-on-submission-of-content?replies=169 * 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 57 70 * New Layout using WP List Table 58 71
Note: See TracChangeset
for help on using the changeset viewer.