/htdocs/wp-content/plugins/custom-field-template/custom-field-template.php
PHP | 4139 lines | 3640 code | 431 blank | 68 comment | 1293 complexity | 60e8c3c8e03db0d6fad14c3fa3048630 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Plugin Name: Custom Field Template
- Plugin URI: http://wpgogo.com/development/custom-field-template.html
- Description: This plugin adds the default custom fields on the Write Post/Page.
- Author: Hiroaki Miyashita
- Version: 2.1.5
- Author URI: http://wpgogo.com/
- */
-
- /*
- This program is based on the rc:custom_field_gui plugin written by Joshua Sigar.
- I appreciate your efforts, Joshua.
- */
-
- /* Copyright 2008 -2013 Hiroaki Miyashita
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- class custom_field_template {
- var $is_excerpt;
-
- function custom_field_template() {
- add_action( 'init', array(&$this, 'custom_field_template_init'), 100 );
- add_action( 'admin_menu', array(&$this, 'custom_field_template_admin_menu') );
- add_action( 'admin_print_scripts', array(&$this, 'custom_field_template_admin_scripts') );
- add_action( 'admin_head', array(&$this, 'custom_field_template_admin_head'), 100 );
- add_action( 'dbx_post_sidebar', array(&$this, 'custom_field_template_dbx_post_sidebar') );
-
- //add_action( 'edit_post', array(&$this, 'edit_meta_value'), 100 );
- add_action( 'save_post', array(&$this, 'edit_meta_value'), 100, 2 );
- //add_action( 'publish_post', array(&$this, 'edit_meta_value'), 100 );
-
- add_action( 'delete_post', array(&$this, 'custom_field_template_delete_post'), 100 );
-
- add_filter( 'media_send_to_editor', array(&$this, 'media_send_to_custom_field'), 15 );
- add_filter( 'plugin_action_links', array(&$this, 'wpaq_filter_plugin_actions'), 100, 2 );
-
- add_filter( 'get_the_excerpt', array(&$this, 'custom_field_template_get_the_excerpt'), 1 );
- add_filter( 'the_content', array(&$this, 'custom_field_template_the_content') );
- add_filter( 'the_content_rss', array(&$this, 'custom_field_template_the_content') );
-
- add_filter( 'attachment_fields_to_edit', array(&$this, 'custom_field_template_attachment_fields_to_edit'), 10, 2 );
-
- if ( isset($_REQUEST['cftsearch_submit']) ) :
- if ( !empty($_REQUEST['limit']) )
- add_action( 'post_limits', array(&$this, 'custom_field_template_post_limits'), 100);
- add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join'), 100 );
- add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where'), 100 );
- add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby'), 100 );
- endif;
-
- if ( function_exists('add_shortcode') ) :
- add_shortcode( 'cft', array(&$this, 'output_custom_field_values') );
- add_shortcode( 'cftsearch', array(&$this, 'search_custom_field_values') );
- endif;
-
- add_filter( 'get_post_metadata', array(&$this, 'get_preview_postmeta'), 10, 4 );
- }
-
- function custom_field_template_init() {
- global $wp_version;
- $options = $this->get_custom_field_template_data();
-
- if ( function_exists('load_plugin_textdomain') ) {
- if ( !defined('WP_PLUGIN_DIR') ) {
- load_plugin_textdomain('custom-field-template', str_replace( ABSPATH, '', dirname(__FILE__) ) );
- } else {
- load_plugin_textdomain('custom-field-template', false, dirname( plugin_basename(__FILE__) ) );
- }
- }
-
- if ( is_user_logged_in() && isset($_REQUEST['post']) && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'selectbox' ) {
- echo $this->custom_field_template_selectbox();
- exit();
- }
-
- if ( is_user_logged_in() && isset($_REQUEST['post']) && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'ajaxsave' ) {
- if ( $_REQUEST['post'] > 0 )
- $this->edit_meta_value( $_REQUEST['post'], '' );
- exit();
- }
-
- if ( is_user_logged_in() && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'ajaxload') {
- if ( isset($_REQUEST['id']) ) :
- $id = $_REQUEST['id'];
- elseif ( isset($options['posts'][$_REQUEST['post']]) ) :
- $id = $options['posts'][$_REQUEST['post']];
- else :
- $filtered_cfts = $this->custom_field_template_filter();
- if ( count($filtered_cfts)>0 ) :
- $id = $filtered_cfts[0]['id'];
- else :
- $id = 0;
- endif;
- endif;
- list($body, $init_id) = $this->load_custom_field( $id );
- echo $body;
- exit();
- }
-
- if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/plugins.php') && ((isset($_GET['activate']) && $_GET['activate'] == 'true') || (isset($_GET['activate-multi']) && $_GET['activate-multi'] == 'true') ) ) {
- $options = $this->get_custom_field_template_data();
- if( !$options ) {
- $this->install_custom_field_template_data();
- $this->install_custom_field_template_css();
- }
- }
-
- if ( function_exists('current_user_can') && current_user_can('edit_plugins') ) :
- if ( isset($_POST['custom_field_template_export_options_submit']) ) :
- $filename = "cft".date('Ymd');
- header("Accept-Ranges: none");
- header("Content-Disposition: attachment; filename=$filename");
- header('Content-Type: application/octet-stream');
- echo maybe_serialize($options);
- exit();
- endif;
- endif;
-
- if ( !empty($options['custom_field_template_widget_shortcode']) )
- add_filter('widget_text', 'do_shortcode');
-
- if ( substr($wp_version, 0, 3) >= '2.7' ) {
- if ( empty($options['custom_field_template_disable_custom_field_column']) ) :
- add_action( 'manage_posts_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 );
- add_filter( 'manage_posts_columns', array(&$this, 'add_manage_posts_columns') );
- add_action( 'manage_pages_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 );
- add_filter( 'manage_pages_columns', array(&$this, 'add_manage_pages_columns') );
- endif;
- if ( empty($options['custom_field_template_disable_quick_edit']) )
- add_action( 'quick_edit_custom_box', array(&$this, 'add_quick_edit_custom_box'), 10, 2 );
- }
-
- if ( substr($wp_version, 0, 3) < '2.5' ) {
- add_action( 'simple_edit_form', array(&$this, 'insert_custom_field'), 1 );
- add_action( 'edit_form_advanced', array(&$this, 'insert_custom_field'), 1 );
- add_action( 'edit_page_form', array(&$this, 'insert_custom_field'), 1 );
- } else {
- if ( substr($wp_version, 0, 3) >= '3.3' && file_exists(ABSPATH . 'wp-admin/includes/screen.php') ) :
- require_once(ABSPATH . 'wp-admin/includes/screen.php');
- endif;
- require_once(ABSPATH . 'wp-admin/includes/template.php');
-
- if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) :
- remove_meta_box('postcustom', 'post', 'normal');
- remove_meta_box('postcustom', 'page', 'normal');
- remove_meta_box('pagecustomdiv', 'page', 'normal');
- endif;
-
- if ( !empty($options['custom_field_template_deploy_box']) ) :
- if ( !empty($options['custom_fields']) ) :
- $i = 0;
- foreach ( $options['custom_fields'] as $key => $val ) :
- if ( empty($options['custom_field_template_replace_the_title']) ) $title = __('Custom Field Template', 'custom-field-template');
- else $title = $options['custom_fields'][$key]['title'];
- if ( empty($options['custom_fields'][$key]['custom_post_type']) ) :
- if ( empty($options['custom_fields'][$key]['post_type']) ) :
- add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', $key);
- add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', $key);
- elseif ( $options['custom_fields'][$key]['post_type']=='post' ) :
- add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', $key);
- elseif ( $options['custom_fields'][$key]['post_type']=='page' ) :
- add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', $key);
- endif;
- else :
- $tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']);
- $tmp_custom_post_type = array_filter( $tmp_custom_post_type );
- $tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type)));
- foreach ( $tmp_custom_post_type as $type ) :
- add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), $type, 'normal', 'core', $key);
- endforeach;
- endif;
- $i++;
- endforeach;
- endif;
- else :
- add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'post', 'normal', 'core');
- add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'page', 'normal', 'core');
- endif;
-
- if ( empty($options['custom_field_template_deploy_box']) && is_array($options['custom_fields']) ) :
- $custom_post_type = array();
- foreach($options['custom_fields'] as $key => $val ) :
- if ( isset($options['custom_fields'][$key]['custom_post_type']) ) :
- $tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']);
- $tmp_custom_post_type = array_filter( $tmp_custom_post_type );
- $tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type)));
- $custom_post_type = array_merge($custom_post_type, $tmp_custom_post_type);
- endif;
- endforeach;
- if ( isset($custom_post_type) && is_array($custom_post_type) ) :
- foreach( $custom_post_type as $val ) :
- if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) :
- remove_meta_box('postcustom', $val, 'normal');
- endif;
- add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), $val, 'normal', 'core');
- if ( empty($options['custom_field_template_disable_custom_field_column']) ) :
- add_filter( 'manage_'.$val.'_posts_columns', array(&$this, 'add_manage_pages_columns') );
- endif;
- endforeach;
- endif;
- endif;
- }
-
- if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') ) :
- add_action('admin_head', array(&$this, 'custom_field_template_admin_head_buffer') );
- add_action('admin_footer', array(&$this, 'custom_field_template_admin_footer_buffer') );
- endif;
- }
-
- function custom_field_template_attachment_fields_to_edit($form_fields, $post) {
- $form_fields["custom_field_template"]["label"] = __('Media Picker', 'custom-field-template');
- $form_fields["custom_field_template"]["input"] = "html";
- $form_fields["custom_field_template"]["html"] = '<a href="javascript:void(0);" onclick="var win = window.dialogArguments || opener || parent || top;win.cft_use_this('.$post->ID.');return false;">'.__('Use this', 'custom-field-template').'</a>';
-
- return $form_fields;
- }
-
- function custom_field_template_add_enctype($buffer) {
- $buffer = preg_replace('/<form name="post"/', '<form enctype="multipart/form-data" name="post"', $buffer);
- return $buffer;
- }
-
- function custom_field_template_admin_head_buffer() {
- ob_start(array(&$this, 'custom_field_template_add_enctype'));
- }
-
- function custom_field_template_admin_footer_buffer() {
- ob_end_flush();
- }
-
- function has_meta( $postid ) {
- global $wpdb;
-
- return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id FROM $wpdb->postmeta WHERE post_id = %d ORDER BY meta_key,meta_id", $postid), ARRAY_A );
- }
-
- function get_post_meta($post_id, $key = '', $single = false) {
- if ( !$post_id ) return '';
-
- if ( $preview_id = $this->get_preview_id( $post_id ) ) $post_id = $preview_id;
-
- $post_id = (int) $post_id;
-
- $meta_cache = wp_cache_get($post_id, 'cft_post_meta');
-
- if ( !$meta_cache ) {
- if ( $meta_list = $this->has_meta( $post_id ) ) {
- foreach ( (array) $meta_list as $metarow) {
- $mpid = (int) $metarow['post_id'];
- $mkey = $metarow['meta_key'];
- $mval = $metarow['meta_value'];
-
- if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) )
- $cache[$mpid] = array();
- if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) )
- $cache[$mpid][$mkey] = array();
-
- $cache[$mpid][$mkey][] = $mval;
- }
- }
-
- /*foreach ( (array) $ids as $id ) {
- if ( ! isset($cache[$id]) )
- $cache[$id] = array();
- }*/
-
- if ( !empty($cache) && is_array($cache) ) :
- foreach ( (array) array_keys($cache) as $post)
- wp_cache_set($post, $cache[$post], 'cft_post_meta');
-
- $meta_cache = wp_cache_get($post_id, 'cft_post_meta');
- endif;
- }
-
- if ( $key ) :
- if ( $single && isset($meta_cache[$key][0]) ) :
- return maybe_unserialize( $meta_cache[$key][0] );
- else :
- if ( isset($meta_cache[$key]) ) :
- if ( is_array($meta_cache[$key]) ) :
- return array_map('maybe_unserialize', $meta_cache[$key]);
- else :
- return $meta_cache[$key];
- endif;
- endif;
- endif;
- else :
- return array_map('maybe_unserialize', $meta_cache);
- endif;
-
- return '';
- }
-
- function add_quick_edit_custom_box($column_name, $type) {
- if( $column_name == 'custom-fields' ) :
- global $wp_version;
- $options = $this->get_custom_field_template_data();
-
- if( $options == null)
- return;
-
- if ( !$options['css'] ) {
- $this->install_custom_field_template_css();
- $options = $this->get_custom_field_template_data();
- }
-
- $out .= '<fieldset style="clear:both;">' . "\n";
- $out .= '<div class="inline-edit-group">';
- $out .= '<style type="text/css">' . "\n" .
- '<!--' . "\n";
- $out .= $options['css'] . "\n";
- $out .= '-->' . "\n" .
- '</style>';
-
- if ( count($options['custom_fields'])>1 ) {
- $out .= '<select id="custom_field_template_select">';
- for ( $i=0; $i < count($options['custom_fields']); $i++ ) {
- if ( $i == $options['posts'][$_REQUEST['post']] ) {
- $out .= '<option value="' . $i . '" selected="selected">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
- } else
- $out .= '<option value="' . $i . '">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
- }
- $out .= '</select>';
- $out .= '<input type="button" class="button" value="' . __('Load', 'custom-field-template') . '" onclick="var post = jQuery(this).parent().parent().parent().parent().attr(\'id\').replace(\'edit-\',\'\'); var cftloading_select = function() {jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=\'+jQuery(\'#custom_field_template_select\').val()+\'&post=\'+post, success: function(html) {jQuery(\'#cft\').html(html);}});};cftloading_select(post);" />';
- }
-
- $out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />';
- $out .= '<div id="cft" class="cft">';
- $out .= '</div>';
-
- $out .= '</div>' . "\n";
- $out .= '</fieldset>' . "\n";
-
- echo $out;
- endif;
- }
-
- function custom_field_template_admin_head() {
- global $wp_version, $post;
- $options = $this->get_custom_field_template_data();
-
- if ( !defined('WP_PLUGIN_DIR') )
- $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
- else
- $plugin_dir = dirname( plugin_basename(__FILE__) );
-
- echo '<link rel="stylesheet" type="text/css" href="' . wp_guess_url() . '/' . PLUGINDIR . '/' . $plugin_dir . '/js/datePicker.css" />'."\n";
-
- if ( !empty($options['custom_field_template_use_validation']) ) :
- if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || (is_object($post) && $post->post_type=='page') ) :
- ?>
- <script type="text/javascript">
- // <![CDATA[
- jQuery(document).ready(function() {
- jQuery("#post").validate();
- });
- //-->
- </script>
- <style type="text/css">
- <!--
- label.error { color:#FF0000; }
- -->
- </style>
-
- <?php
- endif;
- endif;
-
- if ( substr($wp_version, 0, 3) >= '2.7' && is_user_logged_in() && ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) && !strstr($_SERVER['REQUEST_URI'], 'page=') ) {
- ?>
- <script type="text/javascript">
- // <![CDATA[
- jQuery(document).ready(function() {
- jQuery('.hide-if-no-js-cft').show();
- jQuery('.hide-if-js-cft').hide();
-
- inlineEditPost.addEvents = function(r) {
- r.each(function() {
- var row = jQuery(this);
- jQuery('a.editinline', row).click(function() {
- inlineEditPost.edit(this);
- post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-','');
- inlineEditPost.cft_load(post_id);
- return false;
- });
- });
- }
-
- inlineEditPost.save = function(id) {
- if( typeof(id) == 'object' )
- id = this.getId(id);
-
- jQuery('table.widefat .inline-edit-save .waiting').show();
-
- var params = {
- action: 'inline-save',
- post_type: <?php if ( substr($wp_version, 0, 3) >= '3.0' ) echo 'typenow'; else echo 'this.type'; ?>,
- post_ID: id,
- edit_date: 'true'
- };
-
- var fields = jQuery('#edit-'+id+' :input').fieldSerialize();
- params = fields + '&' + jQuery.param(params);
-
- // make ajax request
- jQuery.post('admin-ajax.php', params,
- function(r) {
- jQuery('table.widefat .inline-edit-save .waiting').hide();
-
- if (r) {
- if ( -1 != r.indexOf('<tr') ) {
- jQuery(inlineEditPost.what+id).remove();
- jQuery('#edit-'+id).before(r).remove();
-
- var row = jQuery(inlineEditPost.what+id);
- row.hide();
-
- if ( 'draft' == jQuery('input[name="post_status"]').val() )
- row.find('td.column-comments').hide();
-
- row.find('.hide-if-no-js').removeClass('hide-if-no-js');
- jQuery('.hide-if-no-js-cft').show();
- jQuery('.hide-if-js-cft').hide();
-
- inlineEditPost.addEvents(row);
- row.fadeIn();
- } else {
- r = r.replace( /<.[^<>]*?>/g, '' );
- jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
- }
- } else {
- jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
- }
- }
- , 'html');
- return false;
- }
-
- jQuery('.editinline').click(function () {post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-',''); inlineEditPost.cft_load(post_id);});
- inlineEditPost.cft_load = function (post_id) {
- jQuery.ajax({type: 'GET', url: '?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&post='+post_id, success: function(html) {jQuery('#cft').html(html);}});
- };
- });
- //-->
- </script>
- <style type="text/css">
- <!--
- div.cft_list p.key { font-weight:bold; margin: 0; }
- div.cft_list p.value { margin: 0 0 0 10px; }
- .cft-actions { visibility: hidden; padding: 2px 0 0; }
- tr:hover .cft-actions { visibility: visible; }
- .inline-edit-row fieldset label { display:inline; }
- label.error { color:#FF0000; }
- -->
- </style>
- <?php
- }
- }
-
- function custom_field_template_dbx_post_sidebar() {
- global $wp_version;
- $options = $this->get_custom_field_template_data();
-
- if ( !empty($options['custom_field_template_deploy_box']) ) :
- $suffix = '"+win.jQuery("#cft_current_template").val()+"';
- else :
- $suffix = '';
- endif;
-
- $out = '';
- $out .= '<script type="text/javascript">' . "\n" .
- '// <![CDATA[' . "\n";
- $out .= 'function cft_use_this(file_id) {
- var win = window.dialogArguments || opener || parent || top;
- win.jQuery("#"+win.jQuery("#cft_clicked_id").val()+"_hide").val(file_id);
- var fields = win.jQuery("#cft'.$suffix.' :input").fieldSerialize();
- win.jQuery.ajax({type: "POST", url: "?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post="+win.jQuery(\'#post_ID\').val()+"&custom-field-template-verify-key="+win.jQuery("#custom-field-template-verify-key").val(), data: fields, success: function() {win.jQuery.ajax({type: "GET", url: "?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id="+win.jQuery("#cft_current_template").val()+"&post="+win.jQuery(\'#post_ID\').val(), success: function(html) {win.jQuery("#cft'.$suffix.'").html(html);win.tb_remove();}});}});
- }';
-
- $out .= 'function qt_set(new_id) { eval("qt_"+new_id+" = new QTags(\'qt_"+new_id+"\', \'"+new_id+"\', \'editorcontainer_"+new_id+"\', \'more\');");}';
-
- $out .= 'function _edInsertContent(myField, myValue) {
- var sel, startPos, endPos, scrollTop;
-
- //IE support
- if (document.selection) {
- myField.focus();
- sel = document.selection.createRange();
- sel.text = myValue;
- myField.focus();
- }
- //MOZILLA/NETSCAPE support
- else if (myField.selectionStart || myField.selectionStart == "0") {
- startPos = myField.selectionStart;
- endPos = myField.selectionEnd;
- scrollTop = myField.scrollTop;
- myField.value = myField.value.substring(0, startPos)
- + myValue
- + myField.value.substring(endPos, myField.value.length);
- myField.focus();
- myField.selectionStart = startPos + myValue.length;
- myField.selectionEnd = startPos + myValue.length;
- myField.scrollTop = scrollTop;
- } else {
- myField.value += myValue;
- myField.focus();
- }
- }';
-
- $out .= 'function send_to_custom_field(h) {' . "\n" .
- ' if ( tmpFocus ) ed = tmpFocus;' . "\n" .
- ' else if ( typeof tinyMCE == "undefined" ) ed = document.getElementById("content");' . "\n" .
- ' else { ed = tinyMCE.get("content"); if(ed) {if(!ed.isHidden()) isTinyMCE = true;}}' . "\n" .
- ' if ( typeof tinyMCE != "undefined" && isTinyMCE && !ed.isHidden() ) {' . "\n" .
- ' ed.focus();' . "\n" .
- ' if ( tinymce.isIE && ed.windowManager.insertimagebookmark )' . "\n" .
- ' ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);' . "\n" .
- ' if ( h.indexOf("[caption") === 0 ) {' . "\n" .
- ' if ( ed.plugins.wpeditimage )' . "\n" .
- ' h = ed.plugins.wpeditimage._do_shcode(h);' . "\n" .
- ' } else if ( h.indexOf("[gallery") === 0 ) {' . "\n" .
- ' if ( ed.plugins.wpgallery )' . "\n" .
- ' h = ed.plugins.wpgallery._do_gallery(h);' . "\n" .
- ' } else if ( h.indexOf("[embed") === 0 ) {' . "\n" .
- ' if ( ed.plugins.wordpress )' . "\n" .
- ' h = ed.plugins.wordpress._setEmbed(h);' . "\n" .
- ' }' . "\n" .
- ' ed.execCommand("mceInsertContent", false, h);' . "\n" .
- ' } else {' . "\n" .
- ' if ( tmpFocus ) _edInsertContent(tmpFocus, h);' . "\n" .
- ' else edInsertContent(edCanvas, h);' . "\n" .
- ' }' . "\n";
-
- if ( empty($options['custom_field_template_use_multiple_insert']) ) {
- $out .= ' tb_remove();' . "\n" .
- ' tmpFocus = undefined;' . "\n" .
- ' isTinyMCE = false;' . "\n";
- }
-
- if ( substr($wp_version, 0, 3) < '3.3' ) :
- $qt_position = 'jQuery(\'#editorcontainer_\'+id).prev()';
- $load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, id);';
- else :
- $qt_position = 'jQuery(\'#qt_\'+id+\'_toolbar\')';
- $load_tinyMCE = 'var ed = new tinyMCE.Editor(id, tinyMCEPreInit.mceInit[\'content\']); ed.render();';
- endif;
-
- $out .= '}' . "\n" .
- 'jQuery(".thickbox").bind("click", function (e) {' . "\n" .
- ' tmpFocus = undefined;' . "\n" .
- ' isTinyMCE = false;' . "\n" .
- '});' . "\n" .
- 'var isTinyMCE;' . "\n" .
- 'var tmpFocus;' . "\n" .
- 'function focusTextArea(id) {' . "\n" .
- ' jQuery(document).ready(function() {' . "\n" .
- ' if ( typeof tinyMCE != "undefined" ) {' . "\n" .
- ' var elm = tinyMCE.get(id);' . "\n" .
- ' }' . "\n" .
- ' if ( ! elm || elm.isHidden() ) {' . "\n" .
- ' elm = document.getElementById(id);' . "\n" .
- ' isTinyMCE = false;' . "\n" .
- ' }else isTinyMCE = true;' . "\n" .
- ' tmpFocus = elm' . "\n" .
- ' elm.focus();' . "\n" .
- ' if (elm.createTextRange) {' . "\n" .
- ' var range = elm.createTextRange();' . "\n" .
- ' range.move("character", elm.value.length);' . "\n" .
- ' range.select();' . "\n" .
- ' } else if (elm.setSelectionRange) {' . "\n" .
- ' elm.setSelectionRange(elm.value.length, elm.value.length);' . "\n" .
- ' }' . "\n" .
- ' });' . "\n" .
- '}' . "\n" .
- 'function switchMode(id) {' . "\n" .
- ' var ed = tinyMCE.get(id);' . "\n" .
- ' if ( ! ed || ed.isHidden() ) {' . "\n" .
- ' document.getElementById(id).value = switchEditors.wpautop(document.getElementById(id).value);' . "\n" .
- ' if ( ed ) { '.$qt_position.'.hide(); ed.show(); }' . "\n" .
- ' else {'.$load_tinyMCE.'}' . "\n" .
- ' } else {' . "\n" .
- ' ed.hide(); '.$qt_position.'.show(); document.getElementById(id).style.color="#000000";' . "\n" .
- ' }' . "\n" .
- '}' . "\n";
-
- $out .= 'function thickbox(link) {' . "\n" .
- ' var t = link.title || link.name || null;' . "\n" .
- ' var a = link.href || link.alt;' . "\n" .
- ' var g = link.rel || false;' . "\n" .
- ' tb_show(t,a,g);' . "\n" .
- ' link.blur();' . "\n" .
- ' return false;' . "\n" .
- '}' . "\n";
- $out .= '//--></script>';
- $out .= '<input type="hidden" id="cft_current_template" value="" />';
- $out .= '<input type="hidden" id="cft_clicked_id" value="" />';
- $out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />';
-
- $out .= '<style type="text/css">' . "\n" .
- '<!--' . "\n";
- $out .= $options['css'] . "\n";
- $out .= '.editorcontainer { overflow:hidden; background:#FFFFFF; }
- .content { width:98%; }
- .editorcontainer .content { padding: 6px; line-height: 150%; border: 0 none; outline: none; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -khtml-box-sizing: border-box; box-sizing: border-box; }
- .quicktags { border:1px solid #DFDFDF; border-collapse: separate; -moz-border-radius: 6px 6px 0 0; -webkit-border-top-right-radius: 6px; -webkit-border-top-left-radius: 6px; -khtml-border-top-right-radius: 6px; -khtml-border-top-left-radius: 6px; border-top-right-radius: 6px; border-top-left-radius: 6px; }
- .quicktags { padding: 0; margin-bottom: -1px; border-bottom-width:1px; background-image: url("images/ed-bg.gif"); background-position: left top; background-repeat: repeat; }
- .quicktags div div { padding: 2px 4px 0; }
- .quicktags div div input { margin: 3px 1px 4px; line-height: 18px; display: inline-block; border-width: 1px; border-style: solid; min-width: 26px; padding: 2px 4px; font-size: 12px; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; background:#FFFFFF url(images/fade-butt.png) repeat-x scroll 0 -2px; overflow: visible; }' . "\n";
- $out .= '-->' . "\n" .
- '</style>';
- echo $out;
- }
-
- function add_manage_posts_custom_column($column_name, $post_id) {
- $data = $this->get_post_meta($post_id);
-
- if( is_array($data) && $column_name == 'custom-fields' ) :
- $flag = 0;
- $content = $output = '';
- foreach($data as $key => $val) :
- if ( substr($key, 0, 1) == '_' || !$val[0] ) continue;
- $content .= '<p class="key">' . $key . '</p>' . "\n";
- foreach($val as $val2) :
- $val2 = htmlspecialchars($val2, ENT_QUOTES);
- if ( $flag ) :
- $content .= '<p class="value">' . $val2 . '</p>' . "\n";
- else :
- if ( function_exists('mb_strlen') ) :
- if ( mb_strlen($val2) > 50 ) :
- $before_content = mb_substr($val2, 0, 50);
- $after_content = mb_substr($val2, 50);
- $content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n";
- $flag = 1;
- else :
- $content .= '<p class="value">' . $val2 . '</p>' . "\n";
- endif;
- else :
- if ( strlen($val2) > 50 ) :
- $before_content = substr($val2, 0, 50);
- $after_content = substr($val2, 50);
- $content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n";
- $flag = 1;
- else :
- $content .= '<p class="value">' . $val2 . '</p>' . "\n";
- endif;
- endif;
- endif;
- endforeach;
- endforeach;
- if ( $content ) :
- $content = preg_replace('/([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)\n([^$]+)/', '\1\2\3\4[[[break]]]\5', $content);
- @list($before, $after) = explode('[[[break]]]', $content, 2);
- $after = preg_replace('/\[\[\[break\]\]\]/', '', $after);
- $output .= '<div class="cft_list">';
- $output .= balanceTags($before, true);
- if ( $after ) :
- $output .= '<span class="hide-if-no-js-cft"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().show(); jQuery(this).parent().next().next().show(); jQuery(this).parent().hide();">... ' . __('read more', 'custom-field-template') . '</a></span>';
- $output .= '<span class="hide-if-js-cft">' . balanceTags($after, true) . '</span>';
- $output .= '<span style="display:none;"><a href="javascript:void(0);" onclick="jQuery(this).parent().prev().hide(); jQuery(this).parent().prev().prev().show(); jQuery(this).parent().hide();">[^]</a></span>';
- endif;
- $output .= '</div>';
- else :
- $output .= ' ';
- endif;
- endif;
-
- if ( isset($output) ) echo $output;
- }
-
- function add_manage_posts_columns($columns) {
- $new_columns = array();
- foreach($columns as $key => $val) :
- $new_columns[$key] = $val;
- if ( $key == 'tags' )
- $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template');
- endforeach;
- return $new_columns;
- }
-
- function add_manage_pages_columns($columns) {
- $new_columns = array();
- foreach($columns as $key => $val) :
- $new_columns[$key] = $val;
- if ( $key == 'author' )
- $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template');
- endforeach;
- return $new_columns;
- }
-
- function media_send_to_custom_field($html) {
- if ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/admin-ajax.php') ) return $html;
- $out = '<script type="text/javascript">' . "\n" .
- ' /* <![CDATA[ */' . "\n" .
- ' var win = window.dialogArguments || opener || parent || top;' . "\n" .
- ' if ( typeof win.send_to_custom_field == "function" ) ' . "\n" .
- ' win.send_to_custom_field("' . addslashes($html) . '");' . "\n" .
- ' else ' . "\n" .
- ' win.send_to_editor("' . addslashes($html) . '");' . "\n" .
- '/* ]]> */' . "\n" .
- '</script>' . "\n";
-
- echo $out;
- exit();
-
- /*if ($options['custom_field_template_use_multiple_insert']) {
- return;
- } else {
- exit();
- }*/
- }
-
- function wpaq_filter_plugin_actions($links, $file){
- static $this_plugin;
-
- if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
-
- if( $file == $this_plugin ){
- $settings_link = '<a href="options-general.php?page=custom-field-template.php">' . __('Settings') . '</a>';
- $links = array_merge( array($settings_link), $links);
- }
- return $links;
- }
-
- function custom_field_template_admin_scripts() {
- global $post;
- $options = $this->get_custom_field_template_data();
-
- if ( !defined('WP_PLUGIN_DIR') )
- $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
- else
- $plugin_dir = dirname( plugin_basename(__FILE__) );
-
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'jquery-form' );
- wp_enqueue_script( 'bgiframe', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.bgiframe.js', array('jquery') ) ;
- if (strpos($_SERVER['REQUEST_URI'], 'custom-field-template') !== false )
- wp_enqueue_script( 'textarearesizer', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.textarearesizer.js', array('jquery') );
- if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || (is_object($post) && $post->post_type=='page') ) :
- wp_enqueue_script('date', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/date.js', array('jquery') );
- wp_enqueue_script('datePicker', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.datePicker.js', array('jquery') );
- wp_enqueue_script('editor');
- wp_enqueue_script('quicktags');
-
- if ( !empty($options['custom_field_template_use_validation']) ) :
- wp_enqueue_script( 'jquery-validate', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.validate.js', array('jquery') );
- wp_enqueue_script( 'additional-methods', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/additional-methods.js', array('jquery') );
- if ( file_exists(ABSPATH . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG . '.js') )
- wp_enqueue_script( 'messages_' . WPLANG, '/' . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG .'.js', array('jquery') );
- endif;
- endif;
-
- }
-
- function install_custom_field_template_data() {
- $options['custom_field_template_before_list'] = '<ul>';
- $options['custom_field_template_after_list'] = '</ul>';
- $options['custom_field_template_before_value'] = '<li>';
- $options['custom_field_template_after_value'] = '</li>';
- $options['custom_fields'][0]['title'] = __('Default Template', 'custom-field-template');
- $options['custom_fields'][0]['content'] = '[Plan]
- type = text
- size = 35
- label = Where are you going to go?
-
- [Plan]
- type = textfield
- size = 35
- hideKey = true
-
- [Favorite Fruits]
- type = checkbox
- value = apple # orange # banana # grape
- default = orange # grape
-
- [Miles Walked]
- type = radio
- value = 0-9 # 10-19 # 20+
- default = 10-19
- clearButton = true
-
- [Temper Level]
- type = select
- value = High # Medium # Low
- default = Low
-
- [Hidden Thought]
- type = textarea
- rows = 4
- cols = 40
- tinyMCE = true
- htmlEditor = true
- mediaButton = true
-
- [File Upload]
- type = file';
- $options['shortcode_format'][0] = '<table class="cft">
- <tbody>
- <tr>
- <th>Plan</th><td colspan="3">[Plan]</td>
- </tr>
- <tr>
- <th>Favorite Fruits</th><td>[Favorite Fruits]</td>
- <th>Miles Walked</th><td>[Miles Walked]</td>
- </tr>
- <tr>
- <th>Temper Level</th><td colspan="3">[Temper Level]</td>
- </tr>
- <tr>
- <th>Hidden Thought</th><td colspan="3">[Hidden Thought]</td>
- </tr>
- </tbody>
- </table>';
- update_option('custom_field_template_data', $options);
- }
-
- function install_custom_field_template_css() {
- $options = get_option('custom_field_template_data');
- $options['css'] = '.cft { overflow:hidden; }
- .cft:after { content:" "; clear:both; height:0; display:block; visibility:hidden; }
- .cft dl { margin:10px 0; }
- .cft dl:after { content:" "; clear:both; height:0; display:block; visibility:hidden; }
- .cft dt { width:20%; clear:both; float:left; display:inline; font-weight:bold; text-align:center; }
- .cft dt .hideKey { visibility:hidden; }
- .cft dd { margin:0 0 0 21%; }
- .cft dd p.label { font-weight:bold; margin:0; }
- .cft_instruction { margin:10px; }
- .cft fieldset { border:1px solid #CCC; margin:5px; padding:5px; }
- .cft .dl_checkbox { margin:0; }
- ';
- update_option('custom_field_template_data', $options);
- }
-
-
- function get_custom_field_template_data() {
- $options = get_option('custom_field_template_data');
- return $options;
- }
-
- function custom_field_template_admin_menu() {
- add_options_page(__('Custom Field Template', 'custom-field-template'), __('Custom Field Template', 'custom-field-template'), 'manage_options', basename(__FILE__), array(&$this, 'custom_field_template_admin'));
- }
-
-
- function custom_field_template_get_the_excerpt($excerpt) {
- $options = $this->get_custom_field_template_data();
-
- if ( empty($excerpt) ) $this->is_excerpt = true;
- if ( !empty($options['custom_field_template_excerpt_shortcode']) ) return do_shortcode($excerpt);
- else return $excerpt;
- }
-
- function custom_field_template_the_content($content) {
- global $wp_query, $post, $shortcode_tags, $wp_version;
- $options = $this->get_custom_field_template_data();
-
- if ( $this->is_excerpt ) :
- $this->is_excerpt = false;
-
- return $post->post_excerpt ? $post->post_excerpt : strip_shortcodes($content);
- endif;
-
- if ( isset($options['hook']) && count($options['hook']) > 0 ) :
- $categories = get_the_category();
- $cats = array();
- foreach( $categories as $val ) :
- $cats[] = $val->cat_ID;
- endforeach;
-
- if ( !empty($options['custom_fields'][$id]['post_type']) ) :
- if ( substr($wp_version, 0, 3) < '3.0' ) :
- if ( $options['custom_fields'][$id]['post_type'] == 'post' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php')) ) :
- return;
- endif;
- if ( $options['custom_fields'][$id]['post_type'] == 'page' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php')) ) :
- return;
- endif;
- else :
- if ( $post->post_type!=$options['custom_fields'][$id]['post_type'] ) :
- return;
- endif;
- endif;
- endif;
-
- for ( $i=0; $i<count($options['hook']); $i++ ) :
- $options['hook'][$i]['content'] = stripslashes($options['hook'][$i]['content']);
- if ( is_feed() && !$options['hook'][$i]['feed'] ) break;
- if ( !empty($options['hook'][$i]['category']) ) :
- if ( is_category() || is_single() || is_feed() ) :
- if ( !empty($options['hook'][$i]['use_php']) ) :
- $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
- endif;
- $needle = explode(',', $options['hook'][$i]['category']);
- $needle = array_filter($needle);
- $needle = array_unique(array_filter(array_map('trim', $needle)));
- foreach ( $needle as $val ) :
- if ( in_array($val, $cats ) ) :
- if ( $options['hook'][$i]['position'] == 0 )
- $content .= $options['hook'][$i]['content'];
- elseif ( $options['hook'][$i]['position'] == 2 )
- $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
- else
- $content = $options['hook'][$i]['content'] . $content;
- break;
- endif;
- endforeach;
- endif;
- elseif ( $options['hook'][$i]['post_type']=='post' ) :
- if ( is_single() ) :
- if ( !empty($options['hook'][$i]['use_php']) ) :
- $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
- endif;
- if ( $options['hook'][$i]['position'] == 0 )
- $content .= $options['hook'][$i]['content'];
- elseif ( $options['hook'][$i]['position'] == 2 )
- $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
- else
- $content = $options['hook'][$i]['content'] . $content;
- endif;
- elseif ( $options['hook'][$i]['post_type']=='page' ) :
- if ( is_page() ) :
- if ( !empty($options['hook'][$i]['use_php']) ) :
- $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
- endif;
- if ( $options['hook'][$i]['position'] == 0 )
- $content .= $options['hook'][$i]['content'];
- elseif ( $options['hook'][$i]['position'] == 2 )
- $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
- else
- $content = $options['hook'][$i]['content'] . $content;
- endif;
- elseif ( $options['hook'][$i]['custom_post_type'] ) :
- $custom_post_type = explode(',', $options['hook'][$i]['custom_post_type']);
- $custom_post_type = array_filter( $custom_post_type );
- array_walk( $custom_post_type, create_function('&$v', '$v = trim($v);') );
- if ( in_array($post->post_type, $custom_post_type) ) :
- if ( !empty($options['hook'][$i]['use_php']) ) :
- $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
- endif;
- if ( $options['hook'][$i]['position'] == 0 )
- $content .= $options['hook'][$i]['content'];
- elseif ( $options['hook'][$i]['position'] == 2 )
- $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
- else
- $content = $options['hook'][$i]['content'] . $content;
- endif;
- else :
- if ( !empty($options['hook'][$i]['use_php']) ) :
- $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
- endif;
- if ( $options['hook'][$i]['position'] == 0 )
- $content .= $options['hook'][$i]['content'];
- elseif ( $options['hook'][$i]['position'] == 2 )
- $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
- else
- $content = $options['hook'][$i]['content'] . $content;
- endif;
- endfor;
- endif;
-
- return do_shortcode($content);
- }
-
- function custom_field_template_admin() {
- global $wp_version;
-
- $options = $this->get_custom_field_template_data();
-
- if( !empty($_POST["custom_field_template_set_options_submit"]) ) :
- unset($options['custom_fields']);
- $j = 0;
- for($i=0;$i<count($_POST["custom_field_template_content"]);$i++) {
- if( $_POST["custom_field_template_content"][$i] ) {
- if ( preg_match('/\[content\]|\[post_title\]|\[excerpt\]|\[action\]/i', $_POST["custom_field_template_content"][$i]) ) :
- $errormessage = __('You can not use the following words as the field key: `content`, `post_title`, and `excerpt`, and `action`.', 'custom-field-template');
- endif;
- if ( isset($_POST["custom_field_template_title"][$i]) ) $options['custom_fields'][$j]['title'] = $_POST["custom_field_template_title"][$i];
- if ( isset($_POST["custom_field_template_content"][$i]) ) $options['custom_fields'][$j]['content'] = $_POST["custom_field_template_content"][$i];
- if ( isset($_POST["custom_field_template_instruction"][$i]) ) $options['custom_fields'][$j]['instruction'] = $_POST["custom_field_template_instruction"][$i];
- if ( isset($_POST["custom_field_template_category"][$i]) ) $options['custom_fields'][$j]['category'] = $_POST["custom_field_template_category"][$i];
- if ( isset($_POST["custom_field_template_post"][$i]) ) $options['custom_fields'][$j]['post'] = $_POST["custom_field_template_post"][$i];
- if ( isset($_POST["custom_field_template_post_type"][$i]) ) $options['custom_fields'][$j]['post_type'] = $_POST["custom_field_template_post_type"][$i];
- if ( isset($_POST["custom_field_template_custom_post_type"][$i]) ) $options['custom_fields'][$j]['custom_post_type'] = $_POST["custom_field_template_custom_post_type"][$i];
- if ( isset($_POST["custom_field_template_template_files"][$i]) ) $options['custom_fields'][$j]['template_files'] = $_POST["custom_field_template_template_files"][$i];
- if ( isset($_POST["custom_field_template_disable"][$i]) ) $options['custom_fields'][$j]['disable'] = $_POST["custom_field_template_disable"][$i];
- $options['custom_fields'][$j]['format'] = isset($_POST["custom_field_template_format"][$i]) ? $_POST["custom_field_template_format"][$i] : '';
- $j++;
- }
- }
- update_option('custom_field_template_data', $options);
- $message = __('Options updated.', 'custom-field-template');
- elseif( !empty($_POST["custom_field_template_global_settings_submit"]) ) :
- $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
- $options['custom_field_template_use_multiple_insert'] = isset($_POST['custom_field_template_use_multiple_insert']) ? 1 : '';
- $options['custom_field_template_use_wpautop'] = isset($_POST['custom_field_template_use_wpautop']) ? 1 : '';
- $options['custom_field_template_use_autosave'] = isset($_POST['custom_field_template_use_autosave']) ? 1 : '';
- $options['custom_field_template_use_disable_button'] = isset($_POST['custom_field_template_use_disable_button']) ? 1 : '';
- $options['custom_field_template_disable_initialize_button'] = isset($_POST['custom_field_template_disable_initialize_button']) ? 1 : '';
- $options['custom_field_template_disable_save_button'] = isset($_POST['custom_field_template_disable_save_button']) ? 1 : '';
- $options['custom_field_template_disable_default_custom_fields'] = isset($_POST['custom_field_template_disable_default_custom_fields']) ? 1 : '';
- $options['custom_field_template_disable_quick_edit'] = isset($_POST['custom_field_template_disable_quick_edit']) ? 1 : '';
- $options['custom_field_template_disable_custom_field_column'] = isset($_POST['custom_field_template_disable_custom_field_column']) ? 1 : '';
- $options['custom_field_template_replace_the_title'] = isset($_POST['custom_field_template_replace_the_title']) ? 1 : '';
- $options['custom_field_template_deploy_box'] = isset($_POST['custom_field_template_deploy_box']) ? 1 : '';
- if ( !empty($options['custom_field_template_deploy_box']) ) :
- $options['css'] = preg_replace('/#cft /', '.cft ', $options['css']);
- $options['css'] = preg_replace('/#cft_/', '.cft_', $options['css']);
- endif;
- $options['custom_field_template_widget_shortcode'] = isset($_POST['custom_field_template_widget_shortcode']) ? 1 : '';
- $options['custom_field_template_excerpt_shortcode'] = isset($_POST['custom_field_template_excerpt_shortcode']) ? 1 : '';
- $options['custom_field_template_use_validation'] = isset($_POST['custom_field_template_use_validation']) ? 1 : '';
- $options['custom_field_template_before_list'] = isset($_POST['custom_field_template_before_list']) ? $_POST['custom_field_template_before_list'] : '';
- $options['custom_field_template_after_list'] = isset($_POST['custom_field_template_after_list']) ? $_POST['custom_field_template_after_list'] : '';
- $options['custom_field_template_before_value'] = isset($_POST['custom_field_template_before_value']) ? $_POST['custom_field_template_before_value'] : '';
- $options['custom_field_template_after_value'] = isset($_POST['custom_field_template_after_value']) ? $_POST['custom_field_template_after_value'] : '';
- $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
- $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
- $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
- $options['custom_field_template_disable_ad'] = isset($_POST['custom_field_template_disable_ad']) ? 1 : '';
- update_option('custom_field_template_data', $options);
- $message = __('Options updated.', 'custom-field-template');
- elseif ( !empty($_POST['custom_field_template_css_submit']) ) :
- $options['css'] = $_POST['custom_field_template_css'];
- update_option('custom_field_template_data', $options);
- $message = __('Options updated.', 'custom-field-template');
- elseif ( !empty($_POST['custom_field_template_shortcode_format_submit']) ) :
- unset($options['shortcode_format'], $options['shortcode_format_use_php']);
- $j = 0;
- for($i=0;$i<count($_POST["custom_field_template_shortcode_format"]);$i++) {
- if( !empty($_POST["custom_field_template_shortcode_format"][$i]) ) :
- $options['shortcode_format'][$j] = $_POST["custom_field_template_shortcode_format"][$i];
- $options['shortcode_format_use_php'][$j] = isset($_POST["custom_field_template_shortcode_format_use_php"][$i]) ? $_POST["custom_field_template_shortcode_format_use_php"][$i] : '';
- $j++;
- endif;
- }
- update_option('custom_field_template_data', $options);
- $message = __('Options updated.', 'custom-field-template');
- elseif ( !empty($_POST['custom_field_template_php_submit']) ) :
- unset($options['php']);
- for($i=0;$i<count($_POST["custom_field_template_php"]);$i++) {
- if( !empty($_POST["custom_field_template_php"][$i]) )
- $options['php'][] = $_POST["custom_field_template_php"][$i];
- }
- update_option('custom_field_template_data', $options);
- $message = __('Options updated.', 'custom-field-template');
- elseif( !empty($_POST["custom_field_tem…
Large files files are truncated, but you can click here to view the full file