Custom Field Template - Version 1.8

Version Description

  • Added the tagName attribute for the insertTag of the custom taxonomy.
  • Bugfix: value count.
  • Bugfix: search.
Download this release

Release Info

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

Code changes from version 1.7.9 to 1.8

Files changed (2) hide show
  1. custom-field-template.php +42 -23
  2. readme.txt +7 -2
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: 1.7.9
8
  Author URI: http://wpgogo.com/
9
  */
10
 
@@ -13,7 +13,7 @@ This program is based on the rc:custom_field_gui plugin written by Joshua Sigar.
13
  I appreciate your efforts, Joshua.
14
  */
15
 
16
- /* Copyright 2008 -2010 Hiroaki Miyashita
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License as published by
@@ -58,7 +58,7 @@ class custom_field_template {
58
  if ( $_REQUEST['limit'] )
59
  add_action( 'post_limits', array(&$this, 'custom_field_template_post_limits'));
60
  add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join') );
61
- add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where') );
62
  add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby' ) );
63
  endif;
64
 
@@ -1297,6 +1297,9 @@ hideKey = true<br />
1297
  <th>insertTag</th><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td></td>
1298
  </tr>
1299
  <tr>
 
 
 
1300
  <th>output</th><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td></td>
1301
  </tr>
1302
  <tr>
@@ -2607,9 +2610,15 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
2607
  endif;
2608
  if ( $data['type'] != 'file' ) :
2609
  if( isset( $value ) && strlen( $value ) ) :
2610
- if ( $data['insertTag'] == true ) $tags_input[] = $value;
 
 
 
 
 
 
2611
  if ( $data['valueCount'] == true ) :
2612
- $options['value_count'][$title][$value] = $this->set_value_count($title, $value);
2613
  endif;
2614
 
2615
  if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) {
@@ -2692,15 +2701,20 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
2692
  endforeach;
2693
 
2694
  if ( is_array($tags_input) ) :
2695
- if ( class_exists('SimpleTags') ) :
2696
- wp_cache_flush();
2697
- $taxonomy = wp_get_object_terms($id, 'post_tag', array());
2698
- if ( $taxonomy ) foreach($taxonomy as $val) $tags[] = $val->name;
2699
- if ( is_array($tags) ) $tags_input = array_merge($tags, $tags_input);
2700
- endif;
2701
- $tags_input = array_unique($tags_input);
2702
- if ( substr($wp_version, 0, 3) >= '2.3' )
2703
- wp_set_post_tags( $id, $tags_input );
 
 
 
 
 
2704
  endif;
2705
 
2706
  $options['posts'][$id] = $_REQUEST['custom-field-template-id'];
@@ -2903,11 +2917,16 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
2903
  'image_size' => '',
2904
  'image_src' => false,
2905
  'image_width' => false,
2906
- 'image_height' => false
 
 
2907
  ), $attr));
2908
 
2909
  $metakey = $key;
2910
  if ( $metakey ) :
 
 
 
2911
  $metavalue = $this->get_post_meta($post_id, $key, $single);
2912
  if ( !is_array($metavalue) ) $metavalue = array($metavalue);
2913
  if ( $before_list ) : $output = $before_list . "\n"; endif;
@@ -2925,7 +2944,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
2925
  $output .= $before_value . $val . $after_value . "\n";
2926
  endforeach;
2927
  if ( $after_list ) : $output .= $after_list . "\n"; endif;
2928
- return $output;
2929
  endif;
2930
 
2931
  if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
@@ -3295,7 +3314,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3295
  $output .= '</form>' . "\n";
3296
  endif;
3297
 
3298
- return stripcslashes($output);
3299
  }
3300
 
3301
  function custom_field_template_posts_where($where) {
@@ -3405,7 +3424,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3405
  $in_posts = "'" . implode("', '", $ids) . "'";
3406
  $where .= " AND ID IN (" . $in_posts . ")";
3407
  endif;
3408
- $where .= " AND " . $wpdb->posts . ".post_type = 'post'";
3409
  endif;
3410
  if ( is_array($_REQUEST['cftcategory_not_in']) ) :
3411
  $ids = get_objects_in_term($_REQUEST['cftcategory_not_in'], 'category');
@@ -3487,12 +3506,12 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3487
  return $ret;
3488
  }
3489
 
3490
- function set_value_count($key, $value) {
3491
  global $wpdb;
3492
 
3493
- $query = $wpdb->prepare("SELECT COUNT(meta_id) FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s AND `". $wpdb->postmeta."`.meta_value = %s;", $key, $value);
 
3494
  $count = $wpdb->get_var($query);
3495
-
3496
  return (int)$count;
3497
  }
3498
 
@@ -3525,7 +3544,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3525
  if ( is_array($value) ) :
3526
  foreach ( $value as $val ) :
3527
  if ( $data['valueCount'] == true ) :
3528
- $count = $this->set_value_count($title, $val)-1;
3529
  if ( $count<=0 )
3530
  unset($options['value_count'][$title][$val]);
3531
  else
@@ -3534,7 +3553,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3534
  endforeach;
3535
  else :
3536
  if ( $data['valueCount'] == true ) :
3537
- $count = $this->set_value_count($title, $value)-1;
3538
  if ( $count<=0 )
3539
  unset($options['value_count'][$title][$value]);
3540
  else
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: 1.8
8
  Author URI: http://wpgogo.com/
9
  */
10
 
13
  I appreciate your efforts, Joshua.
14
  */
15
 
16
+ /* Copyright 2008 -2011 Hiroaki Miyashita
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License as published by
58
  if ( $_REQUEST['limit'] )
59
  add_action( 'post_limits', array(&$this, 'custom_field_template_post_limits'));
60
  add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join') );
61
+ add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where'), 100 );
62
  add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby' ) );
63
  endif;
64
 
1297
  <th>insertTag</th><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td></td>
1298
  </tr>
1299
  <tr>
1300
+ <th>tagName</th><td>tagName = movie_tag</td><td>tagName = book_tag</td><td>tagName = img_tag</td><td>tagName = dvd_tag</td><td>tagName = bd_tag</td><td></td>
1301
+ </tr>
1302
+ <tr>
1303
  <th>output</th><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td></td>
1304
  </tr>
1305
  <tr>
2610
  endif;
2611
  if ( $data['type'] != 'file' ) :
2612
  if( isset( $value ) && strlen( $value ) ) :
2613
+ if ( $data['insertTag'] == true ) :
2614
+ if ( !empty($data['tagName']) ) :
2615
+ $tags_input[trim($data['tagName'])][] = $value;
2616
+ else :
2617
+ $tags_input['post_tag'][] = $value;
2618
+ endif;
2619
+ endif;
2620
  if ( $data['valueCount'] == true ) :
2621
+ $options['value_count'][$title][$value] = $this->set_value_count($title, $value, $id)+1;
2622
  endif;
2623
 
2624
  if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) {
2701
  endforeach;
2702
 
2703
  if ( is_array($tags_input) ) :
2704
+ foreach ( $tags_input as $tags_key => $tags_value ) :
2705
+ if ( class_exists('SimpleTags') && $tags_key == 'post_tag' ) :
2706
+ wp_cache_flush();
2707
+ $taxonomy = wp_get_object_terms($id, 'post_tag', array());
2708
+ if ( $taxonomy ) foreach($taxonomy as $val) $tags[] = $val->name;
2709
+ if ( is_array($tags) ) $tags_value = array_merge($tags, $tags_value);
2710
+ endif;
2711
+
2712
+ $tags_input = array_unique($tags_value);
2713
+ if ( substr($wp_version, 0, 3) >= '2.8' )
2714
+ wp_set_post_terms( $id, $tags_value, $tags_key );
2715
+ else if ( substr($wp_version, 0, 3) >= '2.3' )
2716
+ wp_set_post_tags( $id, $tags_value );
2717
+ endforeach;
2718
  endif;
2719
 
2720
  $options['posts'][$id] = $_REQUEST['custom-field-template-id'];
2917
  'image_size' => '',
2918
  'image_src' => false,
2919
  'image_width' => false,
2920
+ 'image_height' => false,
2921
+ 'value_count' => false,
2922
+ 'value' => ''
2923
  ), $attr));
2924
 
2925
  $metakey = $key;
2926
  if ( $metakey ) :
2927
+ if ( $value_count && $value ) :
2928
+ return number_format($options['value_count'][$metakey][$value]);
2929
+ endif;
2930
  $metavalue = $this->get_post_meta($post_id, $key, $single);
2931
  if ( !is_array($metavalue) ) $metavalue = array($metavalue);
2932
  if ( $before_list ) : $output = $before_list . "\n"; endif;
2944
  $output .= $before_value . $val . $after_value . "\n";
2945
  endforeach;
2946
  if ( $after_list ) : $output .= $after_list . "\n"; endif;
2947
+ return do_shortcode($output);
2948
  endif;
2949
 
2950
  if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
3314
  $output .= '</form>' . "\n";
3315
  endif;
3316
 
3317
+ return do_shortcode(stripcslashes($output));
3318
  }
3319
 
3320
  function custom_field_template_posts_where($where) {
3424
  $in_posts = "'" . implode("', '", $ids) . "'";
3425
  $where .= " AND ID IN (" . $in_posts . ")";
3426
  endif;
3427
+ $where .= " AND `" . $wpdb->posts . "`.post_type = 'post'";
3428
  endif;
3429
  if ( is_array($_REQUEST['cftcategory_not_in']) ) :
3430
  $ids = get_objects_in_term($_REQUEST['cftcategory_not_in'], 'category');
3506
  return $ret;
3507
  }
3508
 
3509
+ function set_value_count($key, $value, $id) {
3510
  global $wpdb;
3511
 
3512
+ if ( $id ) $where = " AND `". $wpdb->postmeta."`.post_id<>".$id;
3513
+ $query = $wpdb->prepare("SELECT COUNT(meta_id) FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s AND `". $wpdb->postmeta."`.meta_value = %s $where;", $key, $value);
3514
  $count = $wpdb->get_var($query);
 
3515
  return (int)$count;
3516
  }
3517
 
3544
  if ( is_array($value) ) :
3545
  foreach ( $value as $val ) :
3546
  if ( $data['valueCount'] == true ) :
3547
+ $count = $this->set_value_count($title, $val, '')-1;
3548
  if ( $count<=0 )
3549
  unset($options['value_count'][$title][$val]);
3550
  else
3553
  endforeach;
3554
  else :
3555
  if ( $data['valueCount'] == true ) :
3556
+ $count = $this->set_value_count($title, $value, '')-1;
3557
  if ( $count<=0 )
3558
  unset($options['value_count'][$title][$value]);
3559
  else
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Hiroaki Miyashita
3
  Donate link: http://wpgogo.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: 3.0.1
7
- Stable tag: 1.7.9
8
 
9
  This plugin adds the default custom fields on the Write Post/Page.
10
 
@@ -103,6 +103,11 @@ See the default template and modify it.
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
106
  = 1.7.9 =
107
  * Bugfix: media blank issue of the custom post type.
108
 
3
  Donate link: http://wpgogo.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: 3.1
7
+ Stable tag: 1.8
8
 
9
  This plugin adds the default custom fields on the Write Post/Page.
10
 
103
 
104
  == Changelog ==
105
 
106
+ = 1.8 =
107
+ * Added the `tagName` attribute for the `insertTag` of the custom taxonomy.
108
+ * Bugfix: value count.
109
+ * Bugfix: search.
110
+
111
  = 1.7.9 =
112
  * Bugfix: media blank issue of the custom post type.
113