Custom Field Template - Version 2.3

Version Description

  • Post preview after publishing a post.
  • Code cleaning.
Download this release

Release Info

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

Code changes from version 2.2.1 to 2.3

Files changed (2) hide show
  1. custom-field-template.php +59 -41
  2. readme.txt +6 -2
custom-field-template.php CHANGED
@@ -5,7 +5,7 @@ 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
  Author URI: http://wpgogo.com/
8
- Version: 2.2.1
9
  Text Domain: custom-field-template
10
  Domain Path: /
11
  */
@@ -15,7 +15,7 @@ This program is based on the rc:custom_field_gui plugin written by Joshua Sigar.
15
  I appreciate your efforts, Joshua.
16
  */
17
 
18
- /* Copyright 2008 -2014 Hiroaki Miyashita
19
 
20
  This program is free software; you can redistribute it and/or modify
21
  it under the terms of the GNU General Public License as published by
@@ -56,6 +56,8 @@ class custom_field_template {
56
  add_filter( 'the_content_rss', array(&$this, 'custom_field_template_the_content') );
57
 
58
  add_filter( 'attachment_fields_to_edit', array(&$this, 'custom_field_template_attachment_fields_to_edit'), 10, 2 );
 
 
59
 
60
  if ( isset($_REQUEST['cftsearch_submit']) ) :
61
  if ( !empty($_REQUEST['limit']) )
@@ -747,6 +749,7 @@ class custom_field_template {
747
  function custom_field_template_admin_scripts() {
748
  global $post;
749
  $options = $this->get_custom_field_template_data();
 
750
 
751
  if ( !defined('WP_PLUGIN_DIR') )
752
  $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
@@ -767,8 +770,8 @@ class custom_field_template {
767
  if ( !empty($options['custom_field_template_use_validation']) ) :
768
  wp_enqueue_script( 'jquery-validate', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.validate.js', array('jquery') );
769
  wp_enqueue_script( 'additional-methods', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/additional-methods.js', array('jquery') );
770
- if ( file_exists(ABSPATH . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG . '.js') )
771
- wp_enqueue_script( 'messages_' . WPLANG, '/' . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG .'.js', array('jquery') );
772
  endif;
773
  endif;
774
 
@@ -856,6 +859,7 @@ type = file';
856
 
857
  function get_custom_field_template_data() {
858
  $options = get_option('custom_field_template_data');
 
859
  return $options;
860
  }
861
 
@@ -985,6 +989,7 @@ type = file';
985
 
986
  function custom_field_template_admin() {
987
  global $wp_version;
 
988
 
989
  $options = $this->get_custom_field_template_data();
990
 
@@ -1747,7 +1752,7 @@ hideKey = true<br />
1747
  </div>
1748
 
1749
  <?php
1750
- if ( WPLANG == 'ja' ) :
1751
  ?>
1752
  <div class="postbox" style="min-width:200px;">
1753
  <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
@@ -1806,7 +1811,7 @@ jQuery(this).addClass("closed");
1806
  return $custom_fields;
1807
  }
1808
 
1809
- function make_textfield( $name, $sid, $data ) {
1810
  $cftnum = $size = $default = $hideKey = $label = $code = $class = $style = $before = $after = $maxlength = $multipleButton = $date = $dateFirstDayOfWeek = $dateFormat = $startDate = $endDate = $readOnly = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
1811
  $hide = $addfield = $out = $out_key = $out_value = '';
1812
  extract($data);
@@ -1824,8 +1829,8 @@ jQuery(this).addClass("closed");
1824
 
1825
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
1826
 
1827
- if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
1828
- $value = $this->get_post_meta( $_REQUEST[ 'post' ], $title, false );
1829
  if ( !empty($value) && is_array($value) ) {
1830
  $ct_value = count($value);
1831
  $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
@@ -1895,7 +1900,7 @@ jQuery(this).addClass("closed");
1895
  return array($out, $out_key, $out_value);
1896
  }
1897
 
1898
- function make_checkbox( $name, $sid, $data ) {
1899
  $cftnum = $value = $valueLabel = $checked = $hideKey = $label = $code = $class = $style = $before = $after = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
1900
  $hide = $addfield = $out = $out_key = $out_value = '';
1901
  extract($data);
@@ -1911,8 +1916,8 @@ jQuery(this).addClass("closed");
1911
 
1912
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
1913
 
1914
- if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
1915
- $selected = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
1916
  if ( $selected ) {
1917
  if ( in_array(stripcslashes($value), $selected) ) $checked = 'checked="checked"';
1918
  }
@@ -1957,7 +1962,7 @@ jQuery(this).addClass("closed");
1957
  return array($out, $out_key, $out_value);
1958
  }
1959
 
1960
- function make_radio( $name, $sid, $data ) {
1961
  $cftnum = $values = $valueLabels = $clearButton = $default = $hideKey = $label = $code = $class = $style = $before = $after = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
1962
  $hide = $addfield = $out = $out_key = $out_value = '';
1963
  extract($data);
@@ -1976,8 +1981,8 @@ jQuery(this).addClass("closed");
1976
 
1977
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
1978
 
1979
- if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
1980
- $selected = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
1981
  $ct_value = count($selected);
1982
  $selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : '';
1983
  } else {
@@ -2050,7 +2055,7 @@ jQuery(this).addClass("closed");
2050
  return array($out, $out_key, $out_value);
2051
  }
2052
 
2053
- function make_select( $name, $sid, $data ) {
2054
  $cftnum = $values = $valueLabels = $default = $hideKey = $label = $code = $class = $style = $before = $after = $selectLabel = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
2055
  $hide = $addfield = $out = $out_key = $out_value = '';
2056
  extract($data);
@@ -2069,8 +2074,8 @@ jQuery(this).addClass("closed");
2069
 
2070
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
2071
 
2072
- if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
2073
- $selected = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
2074
  $ct_value = count($selected);
2075
  $selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : '';
2076
  } else {
@@ -2136,7 +2141,7 @@ jQuery(this).addClass("closed");
2136
  return array($out, $out_key, $out_value);
2137
  }
2138
 
2139
- function make_textarea( $name, $sid, $data ) {
2140
  $cftnum = $rows = $cols = $tinyMCE = $htmlEditor = $mediaButton = $default = $hideKey = $label = $code = $class = $style = $wrap = $before = $after = $multipleButton = $mediaOffMedia = $mediaOffImage = $mediaOffVideo = $mediaOffAudio = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
2141
  $hide = $addfield = $out = $out_key = $out_value = $media = $editorcontainer_class = '';
2142
  extract($data);
@@ -2156,8 +2161,8 @@ jQuery(this).addClass("closed");
2156
 
2157
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
2158
 
2159
- if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
2160
- $value = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
2161
  if ( !empty($value) && is_array($value) ) {
2162
  $ct_value = count($value);
2163
  $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
@@ -2330,7 +2335,7 @@ jQuery(this).addClass("closed");
2330
  return array($out, $out_key, $out_value);
2331
  }
2332
 
2333
- function make_file( $name, $sid, $data ) {
2334
  $cftnum = $size = $hideKey = $label = $class = $style = $before = $after = $multipleButton = $relation = $mediaLibrary = $mediaPicker = '';
2335
  $hide = $addfield = $out = $out_key = $out_value = $picker = $inside_fieldset = '';
2336
  extract($data);
@@ -2344,8 +2349,8 @@ jQuery(this).addClass("closed");
2344
 
2345
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
2346
 
2347
- if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
2348
- $value = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
2349
  $ct_value = count($value);
2350
  $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
2351
  }
@@ -2374,7 +2379,7 @@ jQuery(this).addClass("closed");
2374
 
2375
  if ( $mediaPicker == true ) :
2376
  $picker = __(' OR ', 'custom-field-template');
2377
- $picker .= '<a href="'.$image_upload_iframe_src.'&post_id='.$_REQUEST[ 'post' ].'&TB_iframe=1&tab='.$tab.'" class="thickbox" onclick="jQuery('."'#cft_current_template'".').val(jQuery(this).parent().parent().parent().';
2378
  if ( $inside_fieldset ) $picker .= 'parent().';
2379
  $picker .= 'parent().attr(\'id\').replace(\'cft_\',\'\'));jQuery('."'#cft_clicked_id'".').val(jQuery(this).parent().find(\'input\').attr(\'id\'));">'.__('Select by Media Picker', 'custom-field-template').'</a>';
2380
  endif;
@@ -2398,7 +2403,7 @@ jQuery(this).addClass("closed");
2398
  $title = esc_attr(trim($post->post_title));
2399
 
2400
  if ( !empty($mediaLibrary) ) :
2401
- $title = '<a href="'.$image_upload_iframe_src.'&post_id='.$_REQUEST[ 'post' ].'&TB_iframe=1&tab='.$tab.'" class="thickbox">'.$title.'</a>';
2402
  endif;
2403
 
2404
  $out_value .= '<p><label for="'.$name . $sid . '_' . $cftnum . '_delete"><input type="checkbox" name="'.$name . '_delete[' . $sid . '][' . $cftnum . ']" id="'.$name_id . $sid . '_' . $cftnum . '_delete" value="1" class="delete_file_checkbox" /> ' . __('Delete', 'custom-field-template') . '</label> <img src="'.$thumb_url.'" width="32" height="32" style="vertical-align:middle;" /> ' . $title . ' </p>';
@@ -2419,7 +2424,11 @@ jQuery(this).addClass("closed");
2419
 
2420
  $options = $this->get_custom_field_template_data();
2421
 
2422
- if ( isset($_REQUEST['post']) ) $post = get_post($_REQUEST['post']);
 
 
 
 
2423
 
2424
  if ( !empty($options['custom_fields'][$id]['disable']) )
2425
  return;
@@ -2473,10 +2482,10 @@ jQuery(this).addClass("closed");
2473
  endif;
2474
  endif;
2475
 
2476
- if ( (!isset($_REQUEST['post']) || $_REQUEST['post']<0) && !empty($options['custom_fields'][$id]['category']) && $_REQUEST['cft_mode'] != 'ajaxload' )
2477
  return;
2478
 
2479
- if ( isset($_REQUEST['post']) && !empty($options['custom_fields'][$id]['category']) && !isset($options['posts'][$_REQUEST['post']]) && $options['posts'][$_REQUEST['post']] !== $id && $_REQUEST['cft_mode'] != 'ajaxload' )
2480
  return;
2481
 
2482
  if ( !isset($_REQUEST['id']) && !empty($options['custom_fields'][$id]['category']) && $_REQUEST['cft_mode'] == 'ajaxload' ) :
@@ -2504,7 +2513,7 @@ jQuery(this).addClass("closed");
2504
  $post_ids = explode(',', $options['custom_fields'][$id]['post']);
2505
  $post_ids = array_filter( $post_ids );
2506
  $post_ids = array_unique(array_filter(array_map('trim', $post_ids)));
2507
- if ( !in_array($_REQUEST['post'], $post_ids) )
2508
  return;
2509
  endif;
2510
 
@@ -2567,7 +2576,7 @@ jQuery(this).addClass("closed");
2567
 
2568
  if ( isset($data['multipleButton']) && $data['multipleButton'] == true ) :
2569
  $addfield .= ' <span>';
2570
- if ( isset($_REQUEST['post']) ) $addbutton = $this->get_post_meta( $_REQUEST['post'], $title, true )-1;
2571
  if ( !isset($addbutton) || $addbutton<=0 ) $addbutton = 0;
2572
  if ( $data['cftnum']/2 == $addbutton ) :
2573
  if ( substr($wp_version, 0, 3) < '3.3' ) :
@@ -2602,26 +2611,26 @@ jQuery(this).addClass("closed");
2602
  $tmpout .= '</fieldset>';
2603
  }
2604
  else if( $data['type'] == 'textfield' || $data['type'] == 'text' ) {
2605
- list($out_all,$out_key,$out_value) = $this->make_textfield( $title, $parentSN, $data );
2606
  }
2607
  else if( $data['type'] == 'checkbox' ) {
2608
- list($out_all,$out_key,$out_value) = $this->make_checkbox( $title, $parentSN, $data );
2609
  }
2610
  else if( $data['type'] == 'radio' ) {
2611
  $data['values'] = explode( '#', $data['value'] );
2612
  if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] );
2613
- list($out_all,$out_key,$out_value) = $this->make_radio( $title, $parentSN, $data );
2614
  }
2615
  else if( $data['type'] == 'select' ) {
2616
  if ( isset($data['value']) ) $data['values'] = explode( '#', $data['value'] );
2617
  if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] );
2618
- list($out_all,$out_key,$out_value) = $this->make_select( $title, $parentSN, $data );
2619
  }
2620
  else if( $data['type'] == 'textarea' ) {
2621
- list($out_all,$out_key,$out_value) = $this->make_textarea( $title, $parentSN, $data );
2622
  }
2623
  else if( $data['type'] == 'file' ) {
2624
- list($out_all,$out_key,$out_value) = $this->make_file( $title, $parentSN, $data );
2625
  }
2626
  if ( isset($options['custom_fields'][$id]['format']) && is_numeric($options['custom_fields'][$id]['format']) ) :
2627
  $duplicator = '['.$title.']';
@@ -3006,7 +3015,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3006
  return $id;
3007
 
3008
  if ( !empty($_POST['wp-preview']) && $id != $post->ID ) :
3009
- $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $id ) );
3010
  $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN (" . implode( ',', $revision_ids ) . ")" );
3011
 
3012
  wp_cache_flush();
@@ -3022,13 +3031,13 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
3022
  add_metadata( 'post', $post->ID, $key, $val );
3023
  endif;
3024
  endforeach;
3025
- endif;
3026
-
3027
  $id = $post->ID;
3028
  endif;
3029
 
3030
- if ( $post->post_type == 'revision' )
3031
- return $id;
3032
 
3033
  if ( !isset($_REQUEST['custom-field-template-id']) ) :
3034
  if ( isset($options['posts'][$id]) ) unset($options['posts'][$id]);
@@ -4149,6 +4158,15 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
4149
  endif;
4150
  update_option('custom_field_template_data', $options);
4151
  }
 
 
 
 
 
 
 
 
 
4152
  }
4153
 
4154
  if ( !function_exists('esc_html') ) :
5
  Description: This plugin adds the default custom fields on the Write Post/Page.
6
  Author: Hiroaki Miyashita
7
  Author URI: http://wpgogo.com/
8
+ Version: 2.3
9
  Text Domain: custom-field-template
10
  Domain Path: /
11
  */
15
  I appreciate your efforts, Joshua.
16
  */
17
 
18
+ /* Copyright 2008 -2015 Hiroaki Miyashita
19
 
20
  This program is free software; you can redistribute it and/or modify
21
  it under the terms of the GNU General Public License as published by
56
  add_filter( 'the_content_rss', array(&$this, 'custom_field_template_the_content') );
57
 
58
  add_filter( 'attachment_fields_to_edit', array(&$this, 'custom_field_template_attachment_fields_to_edit'), 10, 2 );
59
+ add_filter( '_wp_post_revision_fields', array(&$this, 'custom_field_template_wp_post_revision_fields'), 1 );
60
+ add_filter( 'edit_form_after_title', array(&$this, 'custom_field_template_edit_form_after_title') );
61
 
62
  if ( isset($_REQUEST['cftsearch_submit']) ) :
63
  if ( !empty($_REQUEST['limit']) )
749
  function custom_field_template_admin_scripts() {
750
  global $post;
751
  $options = $this->get_custom_field_template_data();
752
+ $locale = get_locale();
753
 
754
  if ( !defined('WP_PLUGIN_DIR') )
755
  $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
770
  if ( !empty($options['custom_field_template_use_validation']) ) :
771
  wp_enqueue_script( 'jquery-validate', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.validate.js', array('jquery') );
772
  wp_enqueue_script( 'additional-methods', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/additional-methods.js', array('jquery') );
773
+ if ( file_exists(ABSPATH . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . $locale . '.js') )
774
+ wp_enqueue_script( 'messages_' . $locale, '/' . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . $locale .'.js', array('jquery') );
775
  endif;
776
  endif;
777
 
859
 
860
  function get_custom_field_template_data() {
861
  $options = get_option('custom_field_template_data');
862
+ if ( !empty($options) && !is_array($options) ) $options = array();
863
  return $options;
864
  }
865
 
989
 
990
  function custom_field_template_admin() {
991
  global $wp_version;
992
+ $locale = get_locale();
993
 
994
  $options = $this->get_custom_field_template_data();
995
 
1752
  </div>
1753
 
1754
  <?php
1755
+ if ( $locale == 'ja' ) :
1756
  ?>
1757
  <div class="postbox" style="min-width:200px;">
1758
  <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
1811
  return $custom_fields;
1812
  }
1813
 
1814
+ function make_textfield( $name, $sid, $data, $post_id ) {
1815
  $cftnum = $size = $default = $hideKey = $label = $code = $class = $style = $before = $after = $maxlength = $multipleButton = $date = $dateFirstDayOfWeek = $dateFormat = $startDate = $endDate = $readOnly = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
1816
  $hide = $addfield = $out = $out_key = $out_value = '';
1817
  extract($data);
1829
 
1830
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
1831
 
1832
+ if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) {
1833
+ $value = $this->get_post_meta( $post_id, $title, false );
1834
  if ( !empty($value) && is_array($value) ) {
1835
  $ct_value = count($value);
1836
  $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
1900
  return array($out, $out_key, $out_value);
1901
  }
1902
 
1903
+ function make_checkbox( $name, $sid, $data, $post_id ) {
1904
  $cftnum = $value = $valueLabel = $checked = $hideKey = $label = $code = $class = $style = $before = $after = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
1905
  $hide = $addfield = $out = $out_key = $out_value = '';
1906
  extract($data);
1916
 
1917
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
1918
 
1919
+ if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) {
1920
+ $selected = $this->get_post_meta( $post_id, $title );
1921
  if ( $selected ) {
1922
  if ( in_array(stripcslashes($value), $selected) ) $checked = 'checked="checked"';
1923
  }
1962
  return array($out, $out_key, $out_value);
1963
  }
1964
 
1965
+ function make_radio( $name, $sid, $data, $post_id ) {
1966
  $cftnum = $values = $valueLabels = $clearButton = $default = $hideKey = $label = $code = $class = $style = $before = $after = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
1967
  $hide = $addfield = $out = $out_key = $out_value = '';
1968
  extract($data);
1981
 
1982
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
1983
 
1984
+ if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) {
1985
+ $selected = $this->get_post_meta( $post_id, $title );
1986
  $ct_value = count($selected);
1987
  $selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : '';
1988
  } else {
2055
  return array($out, $out_key, $out_value);
2056
  }
2057
 
2058
+ function make_select( $name, $sid, $data, $post_id ) {
2059
  $cftnum = $values = $valueLabels = $default = $hideKey = $label = $code = $class = $style = $before = $after = $selectLabel = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
2060
  $hide = $addfield = $out = $out_key = $out_value = '';
2061
  extract($data);
2074
 
2075
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
2076
 
2077
+ if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) {
2078
+ $selected = $this->get_post_meta( $post_id, $title );
2079
  $ct_value = count($selected);
2080
  $selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : '';
2081
  } else {
2141
  return array($out, $out_key, $out_value);
2142
  }
2143
 
2144
+ function make_textarea( $name, $sid, $data, $post_id ) {
2145
  $cftnum = $rows = $cols = $tinyMCE = $htmlEditor = $mediaButton = $default = $hideKey = $label = $code = $class = $style = $wrap = $before = $after = $multipleButton = $mediaOffMedia = $mediaOffImage = $mediaOffVideo = $mediaOffAudio = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
2146
  $hide = $addfield = $out = $out_key = $out_value = $media = $editorcontainer_class = '';
2147
  extract($data);
2161
 
2162
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
2163
 
2164
+ if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) {
2165
+ $value = $this->get_post_meta( $post_id, $title );
2166
  if ( !empty($value) && is_array($value) ) {
2167
  $ct_value = count($value);
2168
  $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
2335
  return array($out, $out_key, $out_value);
2336
  }
2337
 
2338
+ function make_file( $name, $sid, $data, $post_id ) {
2339
  $cftnum = $size = $hideKey = $label = $class = $style = $before = $after = $multipleButton = $relation = $mediaLibrary = $mediaPicker = '';
2340
  $hide = $addfield = $out = $out_key = $out_value = $picker = $inside_fieldset = '';
2341
  extract($data);
2349
 
2350
  if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
2351
 
2352
+ if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) {
2353
+ $value = $this->get_post_meta( $post_id, $title );
2354
  $ct_value = count($value);
2355
  $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
2356
  }
2379
 
2380
  if ( $mediaPicker == true ) :
2381
  $picker = __(' OR ', 'custom-field-template');
2382
+ $picker .= '<a href="'.$image_upload_iframe_src.'&post_id='.$post_id.'&TB_iframe=1&tab='.$tab.'" class="thickbox" onclick="jQuery('."'#cft_current_template'".').val(jQuery(this).parent().parent().parent().';
2383
  if ( $inside_fieldset ) $picker .= 'parent().';
2384
  $picker .= 'parent().attr(\'id\').replace(\'cft_\',\'\'));jQuery('."'#cft_clicked_id'".').val(jQuery(this).parent().find(\'input\').attr(\'id\'));">'.__('Select by Media Picker', 'custom-field-template').'</a>';
2385
  endif;
2403
  $title = esc_attr(trim($post->post_title));
2404
 
2405
  if ( !empty($mediaLibrary) ) :
2406
+ $title = '<a href="'.$image_upload_iframe_src.'&post_id='.$post_id.'&TB_iframe=1&tab='.$tab.'" class="thickbox">'.$title.'</a>';
2407
  endif;
2408
 
2409
  $out_value .= '<p><label for="'.$name . $sid . '_' . $cftnum . '_delete"><input type="checkbox" name="'.$name . '_delete[' . $sid . '][' . $cftnum . ']" id="'.$name_id . $sid . '_' . $cftnum . '_delete" value="1" class="delete_file_checkbox" /> ' . __('Delete', 'custom-field-template') . '</label> <img src="'.$thumb_url.'" width="32" height="32" style="vertical-align:middle;" /> ' . $title . ' </p>';
2424
 
2425
  $options = $this->get_custom_field_template_data();
2426
 
2427
+ $post_id = isset($_REQUEST['post']) ? $_REQUEST['post'] : '';
2428
+
2429
+ if ( isset($post_id) ) $post = get_post($post_id);
2430
+
2431
+ if ( isset($_REQUEST['revision']) ) $post_id = $_REQUEST['revision'];
2432
 
2433
  if ( !empty($options['custom_fields'][$id]['disable']) )
2434
  return;
2482
  endif;
2483
  endif;
2484
 
2485
+ if ( (!isset($post_id) || $post_id<0) && !empty($options['custom_fields'][$id]['category']) && $_REQUEST['cft_mode'] != 'ajaxload' )
2486
  return;
2487
 
2488
+ if ( isset($post_id) && !empty($options['custom_fields'][$id]['category']) && !isset($options['posts'][$post_id]) && $options['posts'][$post_id] !== $id && $_REQUEST['cft_mode'] != 'ajaxload' )
2489
  return;
2490
 
2491
  if ( !isset($_REQUEST['id']) && !empty($options['custom_fields'][$id]['category']) && $_REQUEST['cft_mode'] == 'ajaxload' ) :
2513
  $post_ids = explode(',', $options['custom_fields'][$id]['post']);
2514
  $post_ids = array_filter( $post_ids );
2515
  $post_ids = array_unique(array_filter(array_map('trim', $post_ids)));
2516
+ if ( !in_array($post_id, $post_ids) )
2517
  return;
2518
  endif;
2519
 
2576
 
2577
  if ( isset($data['multipleButton']) && $data['multipleButton'] == true ) :
2578
  $addfield .= ' <span>';
2579
+ if ( isset($post_id) ) $addbutton = $this->get_post_meta( $post_id, $title, true )-1;
2580
  if ( !isset($addbutton) || $addbutton<=0 ) $addbutton = 0;
2581
  if ( $data['cftnum']/2 == $addbutton ) :
2582
  if ( substr($wp_version, 0, 3) < '3.3' ) :
2611
  $tmpout .= '</fieldset>';
2612
  }
2613
  else if( $data['type'] == 'textfield' || $data['type'] == 'text' ) {
2614
+ list($out_all,$out_key,$out_value) = $this->make_textfield( $title, $parentSN, $data, $post_id );
2615
  }
2616
  else if( $data['type'] == 'checkbox' ) {
2617
+ list($out_all,$out_key,$out_value) = $this->make_checkbox( $title, $parentSN, $data, $post_id );
2618
  }
2619
  else if( $data['type'] == 'radio' ) {
2620
  $data['values'] = explode( '#', $data['value'] );
2621
  if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] );
2622
+ list($out_all,$out_key,$out_value) = $this->make_radio( $title, $parentSN, $data, $post_id );
2623
  }
2624
  else if( $data['type'] == 'select' ) {
2625
  if ( isset($data['value']) ) $data['values'] = explode( '#', $data['value'] );
2626
  if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] );
2627
+ list($out_all,$out_key,$out_value) = $this->make_select( $title, $parentSN, $data, $post_id );
2628
  }
2629
  else if( $data['type'] == 'textarea' ) {
2630
+ list($out_all,$out_key,$out_value) = $this->make_textarea( $title, $parentSN, $data, $post_id );
2631
  }
2632
  else if( $data['type'] == 'file' ) {
2633
+ list($out_all,$out_key,$out_value) = $this->make_file( $title, $parentSN, $data, $post_id );
2634
  }
2635
  if ( isset($options['custom_fields'][$id]['format']) && is_numeric($options['custom_fields'][$id]['format']) ) :
2636
  $duplicator = '['.$title.']';
3015
  return $id;
3016
 
3017
  if ( !empty($_POST['wp-preview']) && $id != $post->ID ) :
3018
+ /*$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $id ) );
3019
  $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN (" . implode( ',', $revision_ids ) . ")" );
3020
 
3021
  wp_cache_flush();
3031
  add_metadata( 'post', $post->ID, $key, $val );
3032
  endif;
3033
  endforeach;
3034
+ endif;*/
3035
+
3036
  $id = $post->ID;
3037
  endif;
3038
 
3039
+ /*if ( $post->post_type == 'revision' )
3040
+ return $id;*/
3041
 
3042
  if ( !isset($_REQUEST['custom-field-template-id']) ) :
3043
  if ( isset($options['posts'][$id]) ) unset($options['posts'][$id]);
4158
  endif;
4159
  update_option('custom_field_template_data', $options);
4160
  }
4161
+
4162
+ function custom_field_template_wp_post_revision_fields($fields) {
4163
+ $fields['cft_debug_preview'] = 'cft_debug_preview';
4164
+ return $fields;
4165
+ }
4166
+
4167
+ function custom_field_template_edit_form_after_title() {
4168
+ echo '<input type="hidden" name="cft_debug_preview" value="cft_debug_preview" />';
4169
+ }
4170
  }
4171
 
4172
  if ( !function_exists('esc_html') ) :
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Hiroaki Miyashita
3
  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.9
7
- Stable tag: 2.2.1
8
  License: GPLv2 or later
9
 
10
  The Custom Field Template plugin extends the functionality of custom fields.
@@ -112,6 +112,10 @@ See the default template and modify it.
112
 
113
  == Changelog ==
114
 
 
 
 
 
115
  = 2.2.1 =
116
  * Bugfix: fieldset type.
117
 
3
  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: 4.1.1
7
+ Stable tag: 2.3
8
  License: GPLv2 or later
9
 
10
  The Custom Field Template plugin extends the functionality of custom fields.
112
 
113
  == Changelog ==
114
 
115
+ = 2.3 =
116
+ * Post preview after publishing a post.
117
+ * Code cleaning.
118
+
119
  = 2.2.1 =
120
  * Bugfix: fieldset type.
121