'."\n";
foreach ($woo_metaboxes as $woo_metabox) {
$woo_id = "woothemes_" . $woo_metabox["name"];
$woo_name = $woo_metabox["name"];
if ($template_to_show == 'seo') {
$metabox_post_type_restriction = 'undefined';
} elseif (function_exists( 'woothemes_content_builder_menu')) {
$metabox_post_type_restriction = $woo_metabox['cpt'][$post->post_type];
} else {
$metabox_post_type_restriction = 'undefined';
}
if ( ($metabox_post_type_restriction != '') && ($metabox_post_type_restriction == 'true') ) {
$type_selector = true;
} elseif ($metabox_post_type_restriction == 'undefined') {
$type_selector = true;
} else {
$type_selector = false;
}
$woo_metaboxvalue = '';
if ($type_selector) {
if(
$woo_metabox['type'] == 'text'
OR $woo_metabox['type'] == 'select'
OR $woo_metabox['type'] == 'select2'
OR $woo_metabox['type'] == 'checkbox'
OR $woo_metabox['type'] == 'textarea'
OR $woo_metabox['type'] == 'calendar'
OR $woo_metabox['type'] == 'time'
OR $woo_metabox['type'] == 'radio'
OR $woo_metabox['type'] == 'images') {
$woo_metaboxvalue = get_post_meta($post->ID,$woo_name,true);
}
if ( $woo_metaboxvalue == '' && isset( $woo_metabox['std'] ) ) {
$woo_metaboxvalue = $woo_metabox['std'];
}
if($woo_metabox['type'] == 'info'){
$output .= "\t".'
';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif($woo_metabox['type'] == 'text'){
$add_class = ''; $add_counter = '';
if($template_to_show == 'seo'){$add_class = 'word-count'; $add_counter = '0 characters, 0 words';}
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
$output .= ''.$woo_metabox['desc'] .' '. $add_counter .' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'textarea'){
$add_class = ''; $add_counter = '';
if($template_to_show == 'seo'){$add_class = 'word-count'; $add_counter = '0 characters, 0 words';}
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
$output .= ''.$woo_metabox['desc'] .' '. $add_counter.' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'calendar'){
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
$output .= ''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'time'){
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
$output .= ''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'select'){
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'select2'){
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'checkbox'){
if($woo_metaboxvalue == 'true') { $checked = ' checked="checked"';} else {$checked='';}
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
$output .= ''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif ($woo_metabox['type'] == 'radio'){
$array = $woo_metabox['options'];
if($array){
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
foreach ( $array as $id => $option ) {
if($woo_metaboxvalue == $id) { $checked = ' checked';} else {$checked='';}
$output .= '';
$output .= ''. $option .'';
}
$output .= "\t".' |
'."\n";
}
}
elseif ($woo_metabox['type'] == 'images')
{
$i = 0;
$select_value = '';
$layout = '';
foreach ($woo_metabox['options'] as $key => $option)
{
$i++;
$checked = '';
$selected = '';
if($woo_metaboxvalue != '') {
if ($woo_metaboxvalue == $key) { $checked = ' checked'; $selected = 'woo-meta-radio-img-selected'; }
}
else {
if ($option['std'] == $key) { $checked = ' checked'; }
elseif ($i == 1) { $checked = ' checked'; $selected = 'woo-meta-radio-img-selected'; }
else { $checked=''; }
}
$layout .= '';
$layout .= '
';
}
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".'';
$output .= $layout;
$output .= ''.$woo_metabox['desc'].' | '."\n";
$output .= "\t".'
'."\n";
}
elseif($woo_metabox['type'] == 'upload')
{
if(isset($woo_metabox["default"])) $default = $woo_metabox["default"];
else $default = '';
// Add support for the WooThemes Media Library-driven Uploader Module // 2010-11-09.
if ( function_exists( 'woothemes_medialibrary_uploader' ) ) {
$_value = $default;
$_value = get_post_meta( $post->ID, $woo_metabox["name"], true );
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".''. woothemes_medialibrary_uploader( $woo_metabox["name"], $_value, 'postmeta', $woo_metabox["desc"], $post->ID );
$output .= ' | '."\n";
$output .= "\t".'
'."\n";
} else {
$output .= "\t".'';
$output .= "\t\t".' | '."\n";
$output .= "\t\t".''. woothemes_uploader_custom_fields($post->ID,$woo_name,$default,$woo_metabox["desc"]);
$output .= ' | '."\n";
$output .= "\t".'
'."\n";
} // End IF Statement
}
} // End IF Statement
}
$output .= ''."\n\n";
echo $output;
}
/*-----------------------------------------------------------------------------------*/
// woothemes_uploader_custom_fields
/*-----------------------------------------------------------------------------------*/
function woothemes_uploader_custom_fields($pID,$id,$std,$desc){
// Start Uploader
$upload = get_post_meta( $pID, $id, true);
$href = cleanSource($upload);
$uploader = '';
$uploader .= '';
$uploader .= ''."\n";
$uploader .= '';
$uploader .= '';
if ( $href )
$uploader .= ''.$desc.''."\n".' ';
return $uploader;
}
/*-----------------------------------------------------------------------------------*/
// woothemes_metabox_handle
/*-----------------------------------------------------------------------------------*/
function woothemes_metabox_handle(){
$pID = '';
global $globals, $post;
$woo_metaboxes = get_option( 'woo_custom_template' );
$seo_metaboxes = get_option( 'woo_custom_seo_template' );
if(!empty($seo_metaboxes) AND get_option( 'seo_woo_hide_fields') != 'true'){
$woo_metaboxes = array_merge($woo_metaboxes,$seo_metaboxes);
}
// Sanitize post ID.
if( isset( $_POST['post_ID'] ) ) {
$pID = intval( $_POST['post_ID'] );
} // End IF Statement
// Don't continue if we don't have a valid post ID.
if ( $pID == 0 ) {
return;
} // End IF Statement
$upload_tracking = array();
if ( isset( $_POST['action'] ) && $_POST['action'] == 'editpost' ) {
foreach ($woo_metaboxes as $woo_metabox) { // On Save.. this gets looped in the header response and saves the values submitted
if($woo_metabox['type'] == 'text'
OR $woo_metabox['type'] == 'calendar'
OR $woo_metabox['type'] == 'time'
OR $woo_metabox['type'] == 'select'
OR $woo_metabox['type'] == 'select2'
OR $woo_metabox['type'] == 'radio'
OR $woo_metabox['type'] == 'checkbox'
OR $woo_metabox['type'] == 'textarea'
OR $woo_metabox['type'] == 'images' ) // Normal Type Things...
{
$var = $woo_metabox["name"];
if ( isset( $_POST[$var] ) ) {
// Sanitize the input.
$posted_value = '';
$posted_value = $_POST[$var];
// Get the current value for checking in the script.
$current_value = '';
$current_value = get_post_meta( $pID, $var, true );
// If it doesn't exist, add the post meta.
if(get_post_meta( $pID, $var ) == "") {
add_post_meta( $pID, $var, $posted_value, true );
}
// Otherwise, if it's different, update the post meta.
elseif( $posted_value != get_post_meta( $pID, $var, true ) ) {
update_post_meta( $pID, $var, $posted_value );
}
// Otherwise, if no value is set, delete the post meta.
elseif($posted_value == "") {
delete_post_meta( $pID, $var, get_post_meta( $pID, $var, true ) );
} // End IF Statement
/*
// If it doesn't exist, add the post meta.
if ( $current_value == "" && $posted_value != '' ) {
update_post_meta( $pID, $var, $posted_value );
// Otherwise, if it's different, update the post meta.
} elseif ( ( $posted_value != '' ) && ( $posted_value != $current_value ) ) {
update_post_meta( $pID, $var, $posted_value );
// Otherwise, if no value is set, delete the post meta.
} elseif ( $posted_value == "" && $current_value != '' ) {
delete_post_meta($pID, $var, $current_value );
} // End IF Statement
*/
} elseif ( ! isset( $_POST[$var] ) && $woo_metabox['type'] == 'checkbox' ) {
update_post_meta( $pID, $var, 'false' );
} else {
delete_post_meta( $pID, $var, $current_value ); // Deletes check boxes OR no $_POST
} // End IF Statement
} elseif( $woo_metabox['type'] == 'upload' ) { // So, the upload inputs will do this rather
$id = $woo_metabox['name'];
$override['action'] = 'editpost';
if(!empty($_FILES['attachement_'.$id]['name'])){ //New upload
$_FILES['attachement_'.$id]['name'] = preg_replace( '/[^a-zA-Z0-9._\-]/', '', $_FILES['attachement_'.$id]['name']);
$uploaded_file = wp_handle_upload($_FILES['attachement_' . $id ],$override);
$uploaded_file['option_name'] = $woo_metabox['label'];
$upload_tracking[] = $uploaded_file;
update_post_meta( $pID, $id, $uploaded_file['url'] );
} elseif ( empty( $_FILES['attachement_'.$id]['name'] ) && isset( $_POST[ $id ] ) ) {
// Sanitize the input.
$posted_value = '';
$posted_value = $_POST[$id];
update_post_meta($pID, $id, $posted_value);
} elseif ( $_POST[ $id ] == '' ) {
delete_post_meta( $pID, $id, get_post_meta( $pID, $id, true ) );
} // End IF Statement
} // End IF Statement
// Error Tracking - File upload was not an Image
update_option( 'woo_custom_upload_tracking', $upload_tracking );
} // End FOREACH Loop
} // End IF Statement
} // End woothemes_metabox_handle()
/*-----------------------------------------------------------------------------------*/
// woothemes_metabox_add
/*-----------------------------------------------------------------------------------*/
function woothemes_metabox_add() {
$seo_metaboxes = get_option( 'woo_custom_seo_template' );
$seo_post_types = array( 'post','page' );
if(defined( 'SEOPOSTTYPES')){
$seo_post_types_update = unserialize( constant( 'SEOPOSTTYPES') );
}
if(!empty($seo_post_types_update)){
$seo_post_types = $seo_post_types_update;
}
$woo_metaboxes = get_option( 'woo_custom_template' );
if ( function_exists( 'add_meta_box') ) {
if ( function_exists( 'get_post_types') ) {
$custom_post_list = get_post_types();
// Get the theme name for use in multiple meta boxes.
$theme_name = get_option( 'woo_themename' );
foreach ($custom_post_list as $type){
$settings = array(
'id' => 'woothemes-settings',
'title' => $theme_name . __( ' Custom Settings', 'woothemes' ),
'callback' => 'woothemes_metabox_create',
'page' => $type,
'priority' => 'normal',
'callback_args' => ''
);
// Allow child themes/plugins to filter these settings.
$settings = apply_filters( 'woothemes_metabox_settings', $settings, $type, $settings['id'] );
if ( ! empty( $woo_metaboxes ) ) {
add_meta_box( $settings['id'], $settings['title'], $settings['callback'], $settings['page'], $settings['priority'], $settings['callback_args'] );
}
//if(!empty($woo_metaboxes)) Temporarily Removed
if(array_search($type, $seo_post_types) !== false){
if(get_option( 'seo_woo_hide_fields') != 'true'){
add_meta_box( 'woothemes-seo', $theme_name . ' SEO Settings','woothemes_metabox_create',$type,'normal','high','seo' );
}
}
}
} else {
add_meta_box( 'woothemes-settings', $theme_name . ' Custom Settings','woothemes_metabox_create','post','normal' );
add_meta_box( 'woothemes-settings', $theme_name . ' Custom Settings','woothemes_metabox_create','page','normal' );
if(get_option( 'seo_woo_hide_fields') != 'true'){
add_meta_box( 'woothemes-seo', $theme_name . ' SEO Settings','woothemes_metabox_create','post','normal','high','seo' );
add_meta_box( 'woothemes-seo', $theme_name . ' SEO Settings','woothemes_metabox_create','page','normal','high','seo' );
}
}
}
}
/*-----------------------------------------------------------------------------------*/
// woothemes_metabox_header
/*-----------------------------------------------------------------------------------*/
function woothemes_metabox_header(){
?>
';
}
function woo_custom_enqueue($hook) {
if ($hook == 'post.php' OR $hook == 'post-new.php' OR $hook == 'page-new.php' OR $hook == 'page.php') {
add_action( 'admin_head', 'woothemes_metabox_header' );
wp_enqueue_script( 'jquery-ui-core' );
wp_register_script( 'jquery-ui-datepicker', get_template_directory_uri() . '/functions/js/ui.datepicker.js', array( 'jquery-ui-core' ));
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_register_script( 'jquery-input-mask', get_template_directory_uri() . '/functions/js/jquery.maskedinput-1.2.2.js', array( 'jquery' ));
wp_enqueue_script( 'jquery-input-mask' );
}
}
add_action( 'admin_enqueue_scripts', 'woo_custom_enqueue', 10, 1 );
add_action( 'edit_post', 'woothemes_metabox_handle' );
add_action( 'admin_menu', 'woothemes_metabox_add' ); // Triggers Woothemes_metabox_create
?> |