Custom Field Template - Version 0.7

Version Description

Download this release

Release Info

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

Code changes from version 0.6.5 to 0.7

Files changed (2) hide show
  1. custom-field-template.php +57 -8
  2. readme.txt +5 -3
custom-field-template.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Field Template
4
  Plugin URI: http://wordpressgogo.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: 0.6.5
8
  Author URI: http://wordpressgogo.com/
9
  */
10
 
@@ -26,6 +26,8 @@ class custom_field_template {
26
 
27
  add_filter( 'media_send_to_editor', array(&$this, 'media_send_to_custom_field'), 15 );
28
  add_filter( 'plugin_action_links', array(&$this, 'wpaq_filter_plugin_actions',), 10, 2);
 
 
29
  }
30
 
31
  function media_send_to_custom_field($html) {
@@ -215,6 +217,7 @@ mediaButton = true';
215
  for ( $i = 0; $i < count($options['custom_fields'])+1; $i++ ) {
216
  ?>
217
  <tr><td>
 
218
  <p><label for="custom_field_template_title[<?= $i ?>]"><?php echo sprintf(__('Template Title %d', 'custom-field-template'), $i+1); ?></label>:<br />
219
  <input type="text" name="custom_field_template_title[<?= $i ?>]" id="custom_field_template_title[<?= $i ?>]" value="<?= stripcslashes($options['custom_fields'][$i]['title']) ?>" size="60" /></p>
220
  <p><label for="custom_field_template_content[<?= $i ?>]"><?php echo sprintf(__('Template Content %d', 'custom-field-template'), $i+1); ?></label>:<br />
@@ -278,7 +281,7 @@ mediaButton = true';
278
  <?php
279
  for ($i=0;$i<count($options['php'])+1;$i++) :
280
  ?>
281
- <tr><th>CODE# <?= $i ?></th></tr>
282
  <tr><td>
283
  <p><textarea name="custom_field_template_php[]" rows="10" cols="60"><?= stripcslashes($options['php'][$i]) ?></textarea></p>
284
  </td></tr>
@@ -349,6 +352,12 @@ hideKey = true<br />
349
  <tr>
350
  <th>level</th><td>level = 1</td><td>level = 3</td><td>level = 5</td><td>level = 7</td><td>level = 9</td>
351
  </tr>
 
 
 
 
 
 
352
  </tbody>
353
  </table>
354
  </div>
@@ -435,7 +444,7 @@ jQuery(this).addClass("closed");
435
  }
436
  }
437
 
438
- if ( $hideKey == true ) $hide = ' class="hideKey""';
439
 
440
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
441
  $title = stripcslashes($label);
@@ -470,7 +479,7 @@ jQuery(this).addClass("closed");
470
  if( $checked == true ) $checked = 'checked="checked"';
471
  }
472
 
473
- if ( $hideKey == true ) $hide = ' class="hideKey""';
474
 
475
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
476
  $title = stripcslashes($label);
@@ -507,7 +516,7 @@ jQuery(this).addClass("closed");
507
  $selected = $default;
508
  }
509
 
510
- if ( $hideKey == true ) $hide = ' class="hideKey""';
511
 
512
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
513
  $title = stripcslashes($label);
@@ -561,7 +570,7 @@ jQuery(this).addClass("closed");
561
  $selected = $default;
562
  }
563
 
564
- if ( $hideKey == true ) $hide = ' class="hideKey""';
565
 
566
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
567
  $title = stripcslashes($label);
@@ -642,7 +651,7 @@ EOF;
642
 
643
  }
644
 
645
- if ( $hideKey == true ) $hide = ' class="hideKey""';
646
 
647
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
648
  $title = stripcslashes($label);
@@ -875,6 +884,8 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
875
  $title = $wpdb->escape(stripcslashes(trim($title)));
876
  delete_post_meta($id, $title);
877
  }
 
 
878
 
879
  foreach( $fields as $title => $data) {
880
  for($i = 0; $i<count($data); $i++) {
@@ -886,7 +897,8 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
886
  if ( $options['custom_field_template_use_wpautop'] && $data[$i]['type'] == 'textarea' )
887
  $meta_value = wpautop($meta_value);
888
  if( isset( $meta_value ) && strlen( $meta_value ) ) {
889
- add_post_meta( $id, $title, $meta_value );
 
890
 
891
  if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) {
892
  preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'], $matched);
@@ -895,6 +907,11 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
895
  }
896
  }
897
  }
 
 
 
 
 
898
 
899
  $options['posts'][$id] = $_REQUEST['custom-field-template-id'];
900
  update_option('custom_field_template_data', $options);
@@ -970,6 +987,38 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
970
  return $Data;
971
  }
972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  }
974
 
975
  $custom_field_template = new custom_field_template();
4
  Plugin URI: http://wordpressgogo.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: 0.7
8
  Author URI: http://wordpressgogo.com/
9
  */
10
 
26
 
27
  add_filter( 'media_send_to_editor', array(&$this, 'media_send_to_custom_field'), 15 );
28
  add_filter( 'plugin_action_links', array(&$this, 'wpaq_filter_plugin_actions',), 10, 2);
29
+
30
+ add_shortcode( 'cft', array(&$this, 'output_custom_field_values') );
31
  }
32
 
33
  function media_send_to_custom_field($html) {
217
  for ( $i = 0; $i < count($options['custom_fields'])+1; $i++ ) {
218
  ?>
219
  <tr><td>
220
+ <p><strong>TEMPLATE #<?= $i ?></strong></p>
221
  <p><label for="custom_field_template_title[<?= $i ?>]"><?php echo sprintf(__('Template Title %d', 'custom-field-template'), $i+1); ?></label>:<br />
222
  <input type="text" name="custom_field_template_title[<?= $i ?>]" id="custom_field_template_title[<?= $i ?>]" value="<?= stripcslashes($options['custom_fields'][$i]['title']) ?>" size="60" /></p>
223
  <p><label for="custom_field_template_content[<?= $i ?>]"><?php echo sprintf(__('Template Content %d', 'custom-field-template'), $i+1); ?></label>:<br />
281
  <?php
282
  for ($i=0;$i<count($options['php'])+1;$i++) :
283
  ?>
284
+ <tr><th><strong>CODE #<?= $i ?></strong></th></tr>
285
  <tr><td>
286
  <p><textarea name="custom_field_template_php[]" rows="10" cols="60"><?= stripcslashes($options['php'][$i]) ?></textarea></p>
287
  </td></tr>
352
  <tr>
353
  <th>level</th><td>level = 1</td><td>level = 3</td><td>level = 5</td><td>level = 7</td><td>level = 9</td>
354
  </tr>
355
+ <tr>
356
+ <th>insertTag</th><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td>
357
+ </tr>
358
+ <tr>
359
+ <th>output</th><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td>
360
+ </tr>
361
  </tbody>
362
  </table>
363
  </div>
444
  }
445
  }
446
 
447
+ if ( $hideKey == true ) $hide = ' class="hideKey"';
448
 
449
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
450
  $title = stripcslashes($label);
479
  if( $checked == true ) $checked = 'checked="checked"';
480
  }
481
 
482
+ if ( $hideKey == true ) $hide = ' class="hideKey"';
483
 
484
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
485
  $title = stripcslashes($label);
516
  $selected = $default;
517
  }
518
 
519
+ if ( $hideKey == true ) $hide = ' class="hideKey"';
520
 
521
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
522
  $title = stripcslashes($label);
570
  $selected = $default;
571
  }
572
 
573
+ if ( $hideKey == true ) $hide = ' class="hideKey"';
574
 
575
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
576
  $title = stripcslashes($label);
651
 
652
  }
653
 
654
+ if ( $hideKey == true ) $hide = ' class="hideKey"';
655
 
656
  if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
657
  $title = stripcslashes($label);
884
  $title = $wpdb->escape(stripcslashes(trim($title)));
885
  delete_post_meta($id, $title);
886
  }
887
+
888
+ $tags_input = explode(",", $_POST['tags_input']);
889
 
890
  foreach( $fields as $title => $data) {
891
  for($i = 0; $i<count($data); $i++) {
897
  if ( $options['custom_field_template_use_wpautop'] && $data[$i]['type'] == 'textarea' )
898
  $meta_value = wpautop($meta_value);
899
  if( isset( $meta_value ) && strlen( $meta_value ) ) {
900
+ add_post_meta( $id, $title, $meta_value );
901
+ if ( $data[$i]['insertTag'] == true ) $tags_input[] = $meta_value;
902
 
903
  if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) {
904
  preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'], $matched);
907
  }
908
  }
909
  }
910
+
911
+ if ( is_array($tags_input) ) :
912
+ $tags_input = array_unique($tags_input);
913
+ wp_set_post_tags( $id, $tags_input );
914
+ endif;
915
 
916
  $options['posts'][$id] = $_REQUEST['custom-field-template-id'];
917
  update_option('custom_field_template_data', $options);
987
  return $Data;
988
  }
989
 
990
+ function output_custom_field_values($attr) {
991
+ global $post;
992
+ $options = $this->get_custom_field_template_data();
993
+
994
+ extract(shortcode_atts(array(
995
+ 'post_id' => $post->ID,
996
+ 'template' => 0
997
+ ), $attr));
998
+
999
+ $fields = $this->get_custom_fields( $template );
1000
+
1001
+ if( $fields == null)
1002
+ return;
1003
+
1004
+ $output = '<dl class="cft">' . "\n";
1005
+ foreach ( $fields as $key => $val ) :
1006
+ $value = get_post_meta( $post_id, $key );
1007
+ foreach ( $val as $key2 => $val2 ) :
1008
+ $hide = '';
1009
+ if ( $val2['output'] == true ) :
1010
+ if ( $val2['hideKey'] == true ) $hide = ' class="hideKey"';
1011
+ if ( !empty($val2['label']) && $options['custom_field_template_replace_keys_by_labels'] )
1012
+ $key = stripcslashes($val2['label']);
1013
+ $output .= '<dt><span' . $hide . '>' . $key . '</span></dt>' . "\n";
1014
+ $output .= '<dd>' . $value[$key2] . '</dd>' . "\n";
1015
+ endif;
1016
+ endforeach;
1017
+ endforeach;
1018
+ $output .= '</dl>' . "\n";
1019
+
1020
+ return $output;
1021
+ }
1022
  }
1023
 
1024
  $custom_field_template = new custom_field_template();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wordpressgogo.com/development/custom-field-template.html
4
  Tags: custom, fields, field, template, meta, custom field, custom fields, custom field template
5
  Requires at least: 2.1
6
  Tested up to: 2.7
7
- Stable tag: 0.6.5
8
 
9
  This plugin adds the default custom fields on the Write Post/Page.
10
 
@@ -22,8 +22,10 @@ The Custom Field Template plugin adds the default custom fields on the Write Pos
22
  * You can customize the design of custom field template with css.
23
  * You can replace custom keys by labels.
24
  * You can use wpautop function.
25
- * You can use PHP codes in order to set values. (experimental)
26
- * You can set an access user level in each field.
 
 
27
 
28
  == Installation ==
29
 
4
  Tags: custom, fields, field, template, meta, custom field, custom fields, custom field template
5
  Requires at least: 2.1
6
  Tested up to: 2.7
7
+ Stable tag: 0.7
8
 
9
  This plugin adds the default custom fields on the Write Post/Page.
10
 
22
  * You can customize the design of custom field template with css.
23
  * You can replace custom keys by labels.
24
  * You can use wpautop function.
25
+ * You can use PHP codes in order to set values. (experimental, `code = 0`)
26
+ * You can set an access user level in each field. (`level = 1`)
27
+ * Supprt for inserting custom field values into tags automatically. (`insertTag = true`)
28
+ * Adds [cft] Shortcode to display the custom field template. (only shows the attributes which have `output = true`)
29
 
30
  == Installation ==
31