0 )
$this->edit_meta_value( $_REQUEST['post'] );
exit();
}
if ( is_user_logged_in() && isset($_REQUEST['id']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' ) {
echo $this->load_custom_field( $_REQUEST['id'] );
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 ( substr($wp_version, 0, 3) >= '2.7' ) {
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') );
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 {
require_once(ABSPATH . 'wp-admin/includes/template.php');
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');
}
}
function add_quick_edit_custom_box($column_name, $type) {
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 .= '
' . "\n";
echo $out;
}
function custom_field_template_admin_head() {
global $wp_version;
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=') ) {
?>
$val) :
if ( substr($key, 0, 1) == '_' || !$val[0] ) continue;
$content .= '' . $key . '
' . "\n";
foreach($val as $val2) :
$val2 = htmlspecialchars($val2, ENT_QUOTES);
if ( $flag ) :
$content .= '' . $val2 . '
' . "\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 .= '' . $before_content . '[[[break]]]' . '
' . $after_content . '
' . "\n";
$flag = 1;
else :
$content .= '' . $val2 . '
' . "\n";
endif;
else :
if ( strlen($val2) > 50 ) :
$before_content = substr($val2, 0, 50);
$after_content = substr($val2, 50);
$content .= '' . $before_content . '[[[break]]]' . '
' . $after_content . '
' . "\n";
$flag = 1;
else :
$content .= '' . $val2 . '
' . "\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 .= '';
else :
$output .= ' ';
endif;
endif;
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) {
$options = $this->get_custom_field_template_data();
$out = '' . "\n";
echo $out;
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 = '' . __('Settings') . '';
$links = array_merge( array($settings_link), $links);
}
return $links;
}
function custom_field_template_admin_scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-form' );
}
function install_custom_field_template_data() {
$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
mediaButton = true';
$options['shortcode_format'][0] = '
| Plan | [Plan] |
| Favorite Fruits | [Favorite Fruits] |
Miles Walked | [Miles Walked] |
| Temper Level | [Temper Level] |
| Hidden Thought | [Hidden Thought] |
';
update_option('custom_field_template_data', $options);
}
function install_custom_field_template_css() {
$options = get_option('custom_field_template_data');
$options['css'] = '#cft dl { clear:both; margin:0; padding:0; width:100%; }
#cft dt { float:left; font-weight:bold; margin:0; text-align:center; width:20%; }
#cft dt .hideKey { visibility:hidden; }
#cft dd { float:left; margin:0; text-align:left; width:80%; }
#cft dd p.label { font-weight:bold; margin:0; }
#cft_instruction { margin:10px; }
';
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'), 8, basename(__FILE__), array(&$this, 'custom_field_template_admin'));
}
function custom_field_template_the_content($content) {
global $wp_query, $post;
$options = $this->get_custom_field_template_data();
if ( count($options['hook']) > 0 ) :
$categories = get_the_category();
$cats = array();
foreach( $categories as $val ) :
$cats[] = $val->cat_ID;
endforeach;
for ( $i=0; $iget_custom_field_template_data();
if($_POST["custom_field_template_set_options_submit"]) :
unset($options['custom_fields']);
$j = 0;
$options['custom_field_template_replace_keys_by_labels'] = $_POST['custom_field_template_replace_keys_by_labels'];
$options['custom_field_template_use_multiple_insert'] = $_POST['custom_field_template_use_multiple_insert'];
$options['custom_field_template_use_wpautop'] = $_POST['custom_field_template_use_wpautop'];
$options['custom_field_template_use_autosave'] = $_POST['custom_field_template_use_autosave'];
for($i=0;$iinstall_custom_field_template_data();
$this->install_custom_field_template_css();
$options = $this->get_custom_field_template_data();
$message = __('Options resetted.', 'custom-field-template');
elseif ($_POST['custom_field_template_delete_options_submit']) :
delete_option('custom_field_template_data');
$options = $this->get_custom_field_template_data();
$message = __('Options deleted.', 'custom-field-template');
endif;
?>
ex.
[Plan]
type = textfield
size = 35
hideKey = true
| type | text or textfield | checkbox | radio | select | textarea |
| hideKey | hideKey = true | hideKey = true | hideKey = true | hideKey = true | hideKey = true |
| label | label = ABC | label = DEF | label = GHI | label = JKL | label = MNO |
size | size = 30 | | | | |
| value | | value = apple # orange # banana | value = apple # orange # banana | value = apple # orange # banana |
|
| valueLabel | | valueLabel = apples # oranges # bananas | valueLabel = apples # oranges # bananas | valueLabel = apples # oranges # bananas |
|
| default | default = orange | default = orange # banana | default = orange | default = orange | default = orange |
| clearButton | | | clearButton = true | | |
| rows | | | | | rows = 4 |
| cols | | | | | cols = 40 |
| tinyMCE | | | | | tinyMCE = true |
| mediaButton | | | | | mediaButton = true |
| code | code = 0 | code = 0 | code = 0 | code = 0 | code = 0 |
| editCode | editCode = 0 | editCode = 0 | editCode = 0 | editCode = 0 | editCode = 0 |
| level | level = 1 | level = 3 | level = 5 | level = 7 | level = 9 |
| insertTag | insertTag = true | insertTag = true | insertTag = true | insertTag = true | insertTag = true |
| output | output = true | output = true | output = true | output = true | output = true |
| outputCode | outputCode = 0 | outputCode = 0 | outputCode = 0 | outputCode = 0 | outputCode = 0 |
| blank | blank = true | blank = true | blank = true | blank = true | blank = true |
| sort | sort = asc | sort = desc | sort = asc | sort = desc | sort = asc |
| search | search = true | search = true | search = true | search = true | search = true |
| class | class = text | class = checkbox | class = radio | class = select | class = textarea |
get_custom_field_template_data();
if ( !$options['custom_fields'][$id] )
return null;
$custom_fields = $this->parse_ini_str( $options['custom_fields'][$id]['content'], true );
return $custom_fields;
}
function make_textfield( $name, $sid, $size = 25, $default, $hideKey, $label, $code, $class ) {
$options = $this->get_custom_field_template_data();
$title = $name;
$name = $this->sanitize_name( $name );
if ( is_numeric($code) ) :
eval(stripcslashes($options['php'][$code]));
endif;
if( isset( $_REQUEST[ 'post' ] ) ) {
$value = get_post_meta( $_REQUEST[ 'post' ], $title );
if ( $value ) {
$value = $value[ $sid ];
}
} else {
$value = $default;
}
if ( $enforced_value ) :
$value = $enforced_value;
endif;
if ( $hideKey == true ) $hide = ' class="hideKey"';
if ( !empty($class) ) $class = ' class="' . $class . '"';
if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
$title = stripcslashes($label);
$out .=
'' .
'- ' . $title . '
' .
'- ';
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
$out .= '
' . stripcslashes($label) . '
';
$out .= ' ' .
'
';
return $out;
}
function make_checkbox( $name, $sid, $value, $valueLabel, $checked, $hideKey, $label, $code, $class ) {
$options = $this->get_custom_field_template_data();
$title = $name;
$name = $this->sanitize_name( $name );
if ( !$value ) $value = "true";
if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 ) {
$selected = get_post_meta( $_REQUEST[ 'post' ], $title );
if ( $selected ) {
if ( in_array(stripcslashes($value), $selected) ) $checked = 'checked="checked"';
}
} else {
if( $checked == true ) $checked = 'checked="checked"';
}
if ( $hideKey == true ) $hide = ' class="hideKey"';
if ( !empty($class) ) $class = ' class="' . $class . '"';
if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
$title = stripcslashes($label);
$out .=
'' .
'- ' . $title . '
' .
'- ';
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
$out .= '
' . stripcslashes($label) . '
';
$out .= '
';
$out .= '
';
return $out;
}
function make_radio( $name, $sid, $values, $valueLabel, $clearButton, $default, $hideKey, $label, $code, $class ) {
$options = $this->get_custom_field_template_data();
$title = $name;
$name = $this->sanitize_name( $name );
if ( is_numeric($code) ) :
eval(stripcslashes($options['php'][$code]));
endif;
if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 ) {
$selected = get_post_meta( $_REQUEST[ 'post' ], $title );
$selected = $selected[ $sid ];
} else {
$selected = $default;
}
if ( $hideKey == true ) $hide = ' class="hideKey"';
if ( !empty($class) ) $class = ' class="' . $class . '"';
if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
$title = stripcslashes($label);
$out .=
'' .
'- ' . $title . '';
if( $clearButton == true ) {
$out .= '';
}
$out .=
'
' .
'- ';
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
$out .= '
' . stripcslashes($label) . '
';
$i = 0;
foreach( $values as $val ) {
$id = $name . '_' . $this->sanitize_name( $val );
$checked = ( trim( $val ) == trim( $selected ) ) ? 'checked="checked"' : '';
$out .=
'
';
$i++;
}
$out .= '
';
return $out;
}
function make_select( $name, $sid, $values, $valueLabel, $default, $hideKey, $label, $code, $class ) {
$options = $this->get_custom_field_template_data();
$title = $name;
$name = $this->sanitize_name( $name );
if ( is_numeric($code) ) :
eval(stripcslashes($options['php'][$code]));
endif;
if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 ) {
$selected = get_post_meta( $_REQUEST[ 'post' ], $title );
if ( $selected ) {
$selected = $selected[ $sid ];
}
} else {
$selected = $default;
}
if ( $hideKey == true ) $hide = ' class="hideKey"';
if ( !empty($class) ) $class = ' class="' . $class . '"';
if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
$title = stripcslashes($label);
$out .=
'' .
'- ' . $title . '
' .
'- ';
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
$out .= '
' . stripcslashes($label) . '
';
$out .= '
';
return $out;
}
function make_textarea( $name, $sid, $rows, $cols, $tinyMCE, $mediaButton, $default, $hideKey, $label, $code, $class ) {
$options = $this->get_custom_field_template_data();
global $wp_version;
$title = $name;
$name = $this->sanitize_name( $name );
if ( is_numeric($code) ) :
eval(stripcslashes($options['php'][$code]));
endif;
if( isset( $_REQUEST[ 'post' ] ) ) {
$value = get_post_meta( $_REQUEST[ 'post' ], $title );
$value = $value[ $sid ];
} else {
$value = $default;
}
$rand = rand();
if( $tinyMCE == true ) {
$out = '';
}
if ( substr($wp_version, 0, 3) >= '2.5' ) {
if ( !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') && !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) {
if ( $mediaButton == true ) {
$media_upload_iframe_src = "media-upload.php";
$media_title = __('Add Media');
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src?type=image");
$image_title = __('Add an Image');
$video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src?type=video");
$video_title = __('Add Video');
$audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src?type=audio");
$audio_title = __('Add Audio');
$media = <<
EOF;
}
$switch = '';
}
}
if ( $hideKey == true ) $hide = ' class="hideKey"';
if ( !empty($class) ) $class = ' class="' . $class . '"';
if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] )
$title = stripcslashes($label);
$out .=
'' .
'- ' . $title . '
' . $media . $switch . ' ' .
'- ';
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
$out .= '
' . stripcslashes($label) . '
';
$out .= ' ' .
'
';
return $out;
}
function load_custom_field( $id = 0 ) {
global $userdata;
get_currentuserinfo();
$level = $userdata->user_level;
$options = $this->get_custom_field_template_data();
$fields = $this->get_custom_fields( $id );
if( $fields == null)
return;
if ( $options['custom_fields'][$id]['instruction'] )
$out .= '' . stripcslashes($options['custom_fields'][$id]['instruction']) . '
';
$out .= '';
$out .= '';
foreach( $fields as $title => $data ) {
for($i = 0; $i $level ) continue;
endif;
if( $data[$i]['type'] == 'break' ) {
$out .= '
';
}
else if( $data[$i]['type'] == 'textfield' || $data[$i]['type'] == 'text' ) {
$out .= $this->make_textfield( $title, $i, $data[$i]['size'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
}
else if( $data[$i]['type'] == 'checkbox' ) {
$out .=
$this->make_checkbox( $title, $i, $data[$i]['value'], $data[$i]['valueLabel'], $data[$i]['checked'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
}
else if( $data[$i]['type'] == 'radio' ) {
$out .=
$this->make_radio(
$title, $i, explode( '#', $data[$i]['value'] ), explode( '#', $data[$i]['valueLabel'] ), $data[$i]['clearButton'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
}
else if( $data[$i]['type'] == 'select' ) {
$out .=
$this->make_select(
$title, $i, explode( '#', $data[$i]['value'] ), explode( '#', $data[$i]['valueLabel'] ), $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
}
else if( $data[$i]['type'] == 'textarea' ) {
if ( $options['tinyMCE'][$_REQUEST['post']][$this->sanitize_name($title)][$i] ) $data[$i]['rows'] = $options['tinyMCE'][$_REQUEST['post']][$this->sanitize_name($title)][$i];
$out .=
$this->make_textarea( $title, $i, $data[$i]['rows'], $data[$i]['cols'], $data[$i]['tinyMCE'], $data[$i]['mediaButton'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
}
}
}
$out .= '
';
$out .= '
';
return $out;
}
function insert_custom_field() {
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();
}
if ( substr($wp_version, 0, 3) < '2.5' ) {
$out .= '