Custom Field Template - Version 2.1.7

Version Description

  • Code cleaning.
Download this release

Release Info

Developer Hiroaki Miyashita
Plugin Icon 128x128 Custom Field Template
Version 2.1.7
Comparing to
See all releases

Code changes from version 2.1.6 to 2.1.7

Files changed (2) hide show
  1. custom-field-template.php +19 -15
  2. readme.txt +4 -1
custom-field-template.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Field Template
4
  Plugin URI: http://wpgogo.com/development/custom-field-template.html
5
  Description: This plugin adds the default custom fields on the Write Post/Page.
6
  Author: Hiroaki Miyashita
7
- Version: 2.1.6
8
  Author URI: http://wpgogo.com/
9
  */
10
 
@@ -299,8 +299,10 @@ class custom_field_template {
299
  endif;
300
  endif;
301
  endif;
302
- else :
303
- return array_map('maybe_unserialize', $meta_cache);
 
 
304
  endif;
305
 
306
  return '';
@@ -318,7 +320,8 @@ class custom_field_template {
318
  $this->install_custom_field_template_css();
319
  $options = $this->get_custom_field_template_data();
320
  }
321
-
 
322
  $out .= '<fieldset style="clear:both;">' . "\n";
323
  $out .= '<div class="inline-edit-group">';
324
  $out .= '<style type="text/css">' . "\n" .
@@ -330,7 +333,7 @@ class custom_field_template {
330
  if ( count($options['custom_fields'])>1 ) {
331
  $out .= '<select id="custom_field_template_select">';
332
  for ( $i=0; $i < count($options['custom_fields']); $i++ ) {
333
- if ( $i == $options['posts'][$_REQUEST['post']] ) {
334
  $out .= '<option value="' . $i . '" selected="selected">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
335
  } else
336
  $out .= '<option value="' . $i . '">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
@@ -1159,7 +1162,7 @@ margin-bottom:0pt;
1159
  <p><label for="custom_field_template_title[<?php echo $i; ?>]"><?php echo sprintf(__('Template Title', 'custom-field-template'), $i); ?></label>:<br />
1160
  <input type="text" name="custom_field_template_title[<?php echo $i; ?>]" id="custom_field_template_title[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['title']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['title'])); ?>" size="80" /></p>
1161
  <p><label for="custom_field_template_instruction[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Template Instruction', 'custom-field-template'), $i); ?></a></label>:<br />
1162
- <textarea class="large-text" name="custom_field_template_instruction[<?php echo $i; ?>]" id="custom_field_template_instruction[<?php echo $i; ?>]" rows="5" cols="80"<?php if ( empty($options['custom_fields'][$i]['instruction']) ) : echo ' style="display:none;"'; endif; ?>><?php if ( isset($options['custom_fields'][$i]['instruction']) ) echo stripcslashes($options['custom_fields'][$i]['instruction']); ?></textarea></p>
1163
  <p><label for="custom_field_template_post_type[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Post Type', 'custom-field-template'), $i); ?></a></label>:<br />
1164
  <span<?php if ( empty($options['custom_fields'][$i]['post_type']) ) : echo ' style="display:none;"'; endif; ?>>
1165
  <input type="radio" name="custom_field_template_post_type[<?php echo $i; ?>]" id="custom_field_template_post_type[<?php echo $i; ?>]" value=""<?php if ( !isset($options['custom_fields'][$i]['post_type']) ) : echo ' checked="checked"'; endif; ?> /> <?php _e('Both', 'custom-field-template'); ?>
@@ -1187,7 +1190,7 @@ margin-bottom:0pt;
1187
  ?>
1188
  </select></p>
1189
  <p><label for="custom_field_template_content[<?php echo $i; ?>]"><?php echo sprintf(__('Template Content', 'custom-field-template'), $i); ?></label>:<br />
1190
- <textarea name="custom_field_template_content[<?php echo $i; ?>]" class="resizable large-text" id="custom_field_template_content[<?php echo $i; ?>]" rows="10" cols="80"><?php if ( isset($options['custom_fields'][$i]['content']) ) echo stripcslashes($options['custom_fields'][$i]['content']); ?></textarea></p>
1191
  </td></tr>
1192
  <?php
1193
  }
@@ -1325,7 +1328,7 @@ margin-bottom:0pt;
1325
  <table class="form-table" style="margin-bottom:5px;">
1326
  <tbody>
1327
  <tr><td>
1328
- <p><textarea name="custom_field_template_css" class="large-text resizable" id="custom_field_template_css" rows="10" cols="80"><?php if ( isset($options['css']) ) echo stripcslashes($options['css']); ?></textarea></p>
1329
  </td></tr>
1330
  <tr><td>
1331
  <p><input type="submit" name="custom_field_template_css_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
@@ -1352,7 +1355,7 @@ margin-bottom:0pt;
1352
  ?>
1353
  <tr><th><strong>FORMAT #<?php echo $i; ?></strong></th></tr>
1354
  <tr><td>
1355
- <p><textarea name="custom_field_template_shortcode_format[<?php echo $i; ?>]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['shortcode_format'][$i]) ) echo stripcslashes($options['shortcode_format'][$i]); ?></textarea></p>
1356
  <p><label><input type="checkbox" name="custom_field_template_shortcode_format_use_php[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['shortcode_format_use_php'][$i]) ) { echo ' checked="checked"'; } ?> /> <?php _e('Use PHP', 'custom-field-template'); ?></label></p>
1357
  </td></tr>
1358
  <?php
@@ -1386,7 +1389,7 @@ ex. `radio` and `select`:</dt><dd>$values = array('dog', 'cat', 'monkey'); $defa
1386
  ?>
1387
  <tr><th><strong>CODE #<?php echo $i; ?></strong></th></tr>
1388
  <tr><td>
1389
- <p><textarea name="custom_field_template_php[]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['php'][$i]) ) echo stripcslashes($options['php'][$i]); ?></textarea></p>
1390
  </td></tr>
1391
  <?php
1392
  endfor;
@@ -1427,7 +1430,7 @@ ex. `radio` and `select`:</dt><dd>$values = array('dog', 'cat', 'monkey'); $defa
1427
  <input type="text" name="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]" id="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]" value="<?php if ( isset($options['hook'][$i]['custom_post_type']) ) echo esc_attr(stripcslashes($options['hook'][$i]['custom_post_type'])); ?>" size="80" /></p>
1428
  <p><label for="custom_field_template_hook_category[<?php echo $i; ?>]"><?php echo sprintf(__('Category ID (comma-deliminated)', 'custom-field-template'), $i); ?></label>:<br />
1429
  <input type="text" name="custom_field_template_hook_category[<?php echo $i; ?>]" id="custom_field_template_hook_category[<?php echo $i; ?>]" value="<?php if ( isset($options['hook'][$i]['category']) ) echo esc_attr(stripcslashes($options['hook'][$i]['category'])); ?>" size="80" /></p>
1430
- <p><label for="custom_field_template_hook_content[<?php echo $i; ?>]"><?php echo sprintf(__('Content', 'custom-field-template'), $i); ?></label>:<br /><textarea name="custom_field_template_hook_content[<?php echo $i; ?>]" class="large-text resizable" rows="5" cols="80"><?php if ( isset($options['hook'][$i]['content']) ) echo stripcslashes($options['hook'][$i]['content']); ?></textarea></p>
1431
  <p><label><input type="checkbox" name="custom_field_template_hook_use_php[<?php echo $i; ?>]" id="custom_field_template_hook_use_php[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['use_php']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Use PHP', 'custom-field-template'); ?></label></p>
1432
  <p><label><input type="checkbox" name="custom_field_template_hook_feed[<?php echo $i; ?>]" id="custom_field_template_hook_feed[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['feed']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Apply to feeds', 'custom-field-template'); ?></label></p>
1433
  </td></tr>
@@ -2163,6 +2166,7 @@ jQuery(this).addClass("closed");
2163
  endif;
2164
 
2165
  $rand = rand();
 
2166
 
2167
  if( $tinyMCE == true ) {
2168
  $out_value = '<script type="text/javascript">' . "\n" .
@@ -2307,7 +2311,7 @@ jQuery(this).addClass("closed");
2307
  endif;
2308
  endif;
2309
 
2310
- $out_value .= '<div' . $editorcontainer_class . ' id="editorcontainer_' . sha1($name . $rand) . '"><textarea id="' . sha1($name . $rand) . '" name="' . $name . '[' . $sid . '][]" rows="' .$rows. '" cols="' . $cols . '"' . $content_class . $style . $event_output . $wrap . '>' . esc_attr(trim($value)) . '</textarea><input type="hidden" name="'.$name.'_rand['.$sid.']" value="'.$rand.'" /></div>';
2311
  if ( ($htmlEditor == true || $tinyMCE == true) && substr($wp_version, 0, 3) < '3.3' ) $out_value .= '</div>';
2312
  $out_value .= trim($after);
2313
  $out .= $out_value.'</dd></dl>'."\n";
@@ -3061,7 +3065,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3061
  foreach( $field_val as $title => $data) :
3062
  //if ( is_numeric($data['parentSN']) ) $field_key = $data['parentSN'];
3063
  $name = $this->sanitize_name( $title );
3064
- $title = $wpdb->escape(stripcslashes(trim($title)));
3065
 
3066
  if ( isset($data['level']) && is_numeric($data['level']) && $current_user->user_level < $data['level'] ) :
3067
  $save_value[$title] = $this->get_post_meta($id, $title, false);
@@ -4064,7 +4068,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
4064
  foreach( $fields as $field_key => $field_val) :
4065
  foreach( $field_val as $title => $data) :
4066
  $name = $this->sanitize_name( $title );
4067
- $title = $wpdb->escape(stripcslashes(trim($title)));
4068
  $value = $this->get_post_meta($post_id, $title);
4069
  if ( is_array($value) ) :
4070
  foreach ( $value as $val ) :
@@ -4108,7 +4112,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
4108
  foreach( $fields as $field_key => $field_val) :
4109
  foreach( $field_val as $title => $data) :
4110
  $name = $this->sanitize_name( $title );
4111
- $title = $wpdb->escape(stripcslashes(trim($title)));
4112
  if ( $data['valueCount'] == true ) :
4113
  $query = $wpdb->prepare("SELECT COUNT(meta_id) as meta_count, `". $wpdb->postmeta."`.meta_value FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s GROUP BY `". $wpdb->postmeta."`.meta_value;", $title);
4114
  $result = $wpdb->get_results($query, ARRAY_A);
4
  Plugin URI: http://wpgogo.com/development/custom-field-template.html
5
  Description: This plugin adds the default custom fields on the Write Post/Page.
6
  Author: Hiroaki Miyashita
7
+ Version: 2.1.7
8
  Author URI: http://wpgogo.com/
9
  */
10
 
299
  endif;
300
  endif;
301
  endif;
302
+ else :
303
+ if ( is_array($meta_cache) ) :
304
+ return array_map('maybe_unserialize', $meta_cache);
305
+ endif;
306
  endif;
307
 
308
  return '';
320
  $this->install_custom_field_template_css();
321
  $options = $this->get_custom_field_template_data();
322
  }
323
+
324
+ $out = '';
325
  $out .= '<fieldset style="clear:both;">' . "\n";
326
  $out .= '<div class="inline-edit-group">';
327
  $out .= '<style type="text/css">' . "\n" .
333
  if ( count($options['custom_fields'])>1 ) {
334
  $out .= '<select id="custom_field_template_select">';
335
  for ( $i=0; $i < count($options['custom_fields']); $i++ ) {
336
+ if ( isset($_REQUEST['post']) && isset($options['posts'][$_REQUEST['post']]) && $i == $options['posts'][$_REQUEST['post']] ) {
337
  $out .= '<option value="' . $i . '" selected="selected">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
338
  } else
339
  $out .= '<option value="' . $i . '">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
1162
  <p><label for="custom_field_template_title[<?php echo $i; ?>]"><?php echo sprintf(__('Template Title', 'custom-field-template'), $i); ?></label>:<br />
1163
  <input type="text" name="custom_field_template_title[<?php echo $i; ?>]" id="custom_field_template_title[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['title']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['title'])); ?>" size="80" /></p>
1164
  <p><label for="custom_field_template_instruction[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Template Instruction', 'custom-field-template'), $i); ?></a></label>:<br />
1165
+ <textarea class="large-text" name="custom_field_template_instruction[<?php echo $i; ?>]" id="custom_field_template_instruction[<?php echo $i; ?>]" rows="5" cols="80"<?php if ( empty($options['custom_fields'][$i]['instruction']) ) : echo ' style="display:none;"'; endif; ?>><?php if ( isset($options['custom_fields'][$i]['instruction']) ) echo htmlspecialchars(stripcslashes($options['custom_fields'][$i]['instruction'])); ?></textarea></p>
1166
  <p><label for="custom_field_template_post_type[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Post Type', 'custom-field-template'), $i); ?></a></label>:<br />
1167
  <span<?php if ( empty($options['custom_fields'][$i]['post_type']) ) : echo ' style="display:none;"'; endif; ?>>
1168
  <input type="radio" name="custom_field_template_post_type[<?php echo $i; ?>]" id="custom_field_template_post_type[<?php echo $i; ?>]" value=""<?php if ( !isset($options['custom_fields'][$i]['post_type']) ) : echo ' checked="checked"'; endif; ?> /> <?php _e('Both', 'custom-field-template'); ?>
1190
  ?>
1191
  </select></p>
1192
  <p><label for="custom_field_template_content[<?php echo $i; ?>]"><?php echo sprintf(__('Template Content', 'custom-field-template'), $i); ?></label>:<br />
1193
+ <textarea name="custom_field_template_content[<?php echo $i; ?>]" class="resizable large-text" id="custom_field_template_content[<?php echo $i; ?>]" rows="10" cols="80"><?php if ( isset($options['custom_fields'][$i]['content']) ) echo htmlspecialchars(stripcslashes($options['custom_fields'][$i]['content'])); ?></textarea></p>
1194
  </td></tr>
1195
  <?php
1196
  }
1328
  <table class="form-table" style="margin-bottom:5px;">
1329
  <tbody>
1330
  <tr><td>
1331
+ <p><textarea name="custom_field_template_css" class="large-text resizable" id="custom_field_template_css" rows="10" cols="80"><?php if ( isset($options['css']) ) echo htmlspecialchars(stripcslashes($options['css'])); ?></textarea></p>
1332
  </td></tr>
1333
  <tr><td>
1334
  <p><input type="submit" name="custom_field_template_css_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
1355
  ?>
1356
  <tr><th><strong>FORMAT #<?php echo $i; ?></strong></th></tr>
1357
  <tr><td>
1358
+ <p><textarea name="custom_field_template_shortcode_format[<?php echo $i; ?>]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['shortcode_format'][$i]) ) echo htmlspecialchars(stripcslashes($options['shortcode_format'][$i])); ?></textarea></p>
1359
  <p><label><input type="checkbox" name="custom_field_template_shortcode_format_use_php[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['shortcode_format_use_php'][$i]) ) { echo ' checked="checked"'; } ?> /> <?php _e('Use PHP', 'custom-field-template'); ?></label></p>
1360
  </td></tr>
1361
  <?php
1389
  ?>
1390
  <tr><th><strong>CODE #<?php echo $i; ?></strong></th></tr>
1391
  <tr><td>
1392
+ <p><textarea name="custom_field_template_php[]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['php'][$i]) ) echo htmlspecialchars(stripcslashes($options['php'][$i])); ?></textarea></p>
1393
  </td></tr>
1394
  <?php
1395
  endfor;
1430
  <input type="text" name="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]" id="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]" value="<?php if ( isset($options['hook'][$i]['custom_post_type']) ) echo esc_attr(stripcslashes($options['hook'][$i]['custom_post_type'])); ?>" size="80" /></p>
1431
  <p><label for="custom_field_template_hook_category[<?php echo $i; ?>]"><?php echo sprintf(__('Category ID (comma-deliminated)', 'custom-field-template'), $i); ?></label>:<br />
1432
  <input type="text" name="custom_field_template_hook_category[<?php echo $i; ?>]" id="custom_field_template_hook_category[<?php echo $i; ?>]" value="<?php if ( isset($options['hook'][$i]['category']) ) echo esc_attr(stripcslashes($options['hook'][$i]['category'])); ?>" size="80" /></p>
1433
+ <p><label for="custom_field_template_hook_content[<?php echo $i; ?>]"><?php echo sprintf(__('Content', 'custom-field-template'), $i); ?></label>:<br /><textarea name="custom_field_template_hook_content[<?php echo $i; ?>]" class="large-text resizable" rows="5" cols="80"><?php if ( isset($options['hook'][$i]['content']) ) echo htmlspecialchars(stripcslashes($options['hook'][$i]['content'])); ?></textarea></p>
1434
  <p><label><input type="checkbox" name="custom_field_template_hook_use_php[<?php echo $i; ?>]" id="custom_field_template_hook_use_php[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['use_php']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Use PHP', 'custom-field-template'); ?></label></p>
1435
  <p><label><input type="checkbox" name="custom_field_template_hook_feed[<?php echo $i; ?>]" id="custom_field_template_hook_feed[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['feed']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Apply to feeds', 'custom-field-template'); ?></label></p>
1436
  </td></tr>
2166
  endif;
2167
 
2168
  $rand = rand();
2169
+ $switch = '';
2170
 
2171
  if( $tinyMCE == true ) {
2172
  $out_value = '<script type="text/javascript">' . "\n" .
2311
  endif;
2312
  endif;
2313
 
2314
+ $out_value .= '<div' . $editorcontainer_class . ' id="editorcontainer_' . sha1($name . $rand) . '"><textarea id="' . sha1($name . $rand) . '" name="' . $name . '[' . $sid . '][]" rows="' .$rows. '" cols="' . $cols . '"' . $content_class . $style . $event_output . $wrap . '>' . htmlspecialchars(trim($value)) . '</textarea><input type="hidden" name="'.$name.'_rand['.$sid.']" value="'.$rand.'" /></div>';
2315
  if ( ($htmlEditor == true || $tinyMCE == true) && substr($wp_version, 0, 3) < '3.3' ) $out_value .= '</div>';
2316
  $out_value .= trim($after);
2317
  $out .= $out_value.'</dd></dl>'."\n";
3065
  foreach( $field_val as $title => $data) :
3066
  //if ( is_numeric($data['parentSN']) ) $field_key = $data['parentSN'];
3067
  $name = $this->sanitize_name( $title );
3068
+ $title = esc_sql(stripcslashes(trim($title)));
3069
 
3070
  if ( isset($data['level']) && is_numeric($data['level']) && $current_user->user_level < $data['level'] ) :
3071
  $save_value[$title] = $this->get_post_meta($id, $title, false);
4068
  foreach( $fields as $field_key => $field_val) :
4069
  foreach( $field_val as $title => $data) :
4070
  $name = $this->sanitize_name( $title );
4071
+ $title = esc_sql(stripcslashes(trim($title)));
4072
  $value = $this->get_post_meta($post_id, $title);
4073
  if ( is_array($value) ) :
4074
  foreach ( $value as $val ) :
4112
  foreach( $fields as $field_key => $field_val) :
4113
  foreach( $field_val as $title => $data) :
4114
  $name = $this->sanitize_name( $title );
4115
+ $title = esc_sql(stripcslashes(trim($title)));
4116
  if ( $data['valueCount'] == true ) :
4117
  $query = $wpdb->prepare("SELECT COUNT(meta_id) as meta_count, `". $wpdb->postmeta."`.meta_value FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s GROUP BY `". $wpdb->postmeta."`.meta_value;", $title);
4118
  $result = $wpdb->get_results($query, ARRAY_A);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wpgogo.com/development/custom-field-template.html
4
  Tags: custom field, custom fields, custom, fields, field, template, meta, custom field template, custom post type
5
  Requires at least: 2.1
6
  Tested up to: 3.6
7
- Stable tag: 2.1.6
8
  License: GPLv2 or later
9
 
10
  The Custom Field Template plugin extends the functionality of custom fields.
@@ -112,6 +112,9 @@ See the default template and modify it.
112
 
113
  == Changelog ==
114
 
 
 
 
115
  = 2.1.6 =
116
  * Bugfix: file type with the multipleButton attribute.
117
  * Bugfix: save_post duplicate execution.
4
  Tags: custom field, custom fields, custom, fields, field, template, meta, custom field template, custom post type
5
  Requires at least: 2.1
6
  Tested up to: 3.6
7
+ Stable tag: 2.1.7
8
  License: GPLv2 or later
9
 
10
  The Custom Field Template plugin extends the functionality of custom fields.
112
 
113
  == Changelog ==
114
 
115
+ = 2.1.7 =
116
+ * Code cleaning.
117
+
118
  = 2.1.6 =
119
  * Bugfix: file type with the multipleButton attribute.
120
  * Bugfix: save_post duplicate execution.