File: /home/zeusxp5/chuair.org/wp-content/plugins/wd-framework/meta-box.php
<?php
if ( !class_exists('wdmp_myCustomFields') ) {
class wdmp_myCustomFields {
/**
* @var string $wdmp_prefix The wdmp_prefix for storing custom fields in the postmeta table
*/
var $wdmp_prefix = '';
/**
* @var array $wdmp_postTypes An array of public custom post types, plus the standard "post" and "page" - add the custom types you want to include here
*/
var $wdmp_postTypes = array( "page", "post", "portfolio", "testimonials", "team-member", "product");
/**
* @var array $customFields Defines the custom fields available
*/
var $wdmp_customFields = array();
function __construct() {
$test = wdmp_get_posts_by_post_type("wd_product_template");
add_action( 'admin_menu', array( &$this, 'wdmp_createCustomFields' ) );
add_action( 'save_post', array( &$this, 'wdmp_saveCustomFields' ), 1, 2 );
// Comment this line out if you want to keep default custom fields meta box
add_action( 'do_meta_boxes', array( &$this, 'wdmp_removeDefaultCustomFields' ), 10, 3 );
$this->wdmp_customFields = array(
// ---------------------Team---------------------
array(
"name" => "job_title",
"title" => esc_html__("Job title" ,'wd-framework' ),
"description" => "",
"float_left" => "",
"clear_after" => "",
"type" => "text",
"classname" =>"",
"scope" => array("team-member"),
"capability" => "manage_options",
"dependency" => ""
),
array(
"name" => "team-facebook",
"title" => esc_html__("Facebook Url" ,'wd-framework' ),
"description" => "",
"float_left" => "",
"clear_after" => "",
"type" => "text",
"classname" =>"",
"scope" => array("team-member"),
"capability" => "manage_options",
"dependency" => ""
),
array(
"name" => "team-instagram",
"title" => esc_html__("Instagram Url" ,'wd-framework' ),
"description" => "",
"float_left" => "",
"clear_after" => "",
"type" => "text",
"classname" =>"",
"scope" => array("team-member"),
"capability" => "manage_options",
"dependency" => ""
),
array(
"name" => "team-twitter",
"title" => esc_html__("Twitter Url" ,'wd-framework' ),
"description" => "",
"float_left" => "",
"clear_after" => "",
"type" => "text",
"classname" =>"",
"scope" => array("team-member"),
"capability" => "manage_options",
"dependency" => ""
),
// ---------------------team/>---------------------
// ---------------------testimonail---------------------
array(
"name" => "job_title",
"title" => "Job title",
"description" => "",
"float_left" => "",
"clear_after" => "",
"type" => "text",
"classname" =>"",
"scope" => array("testimonials"),
"capability" => "manage_options",
"dependency" => ""
),
array(
"name" => "rating",
"title" => esc_html__( "Rating",'wd-framework' ),
"description" => "",
"float_left" => "",
"clear_after" => "",
"type" => "hidden",
"classname" =>"",
"scope" => array("testimonials"),
"capability" => "manage_options",
"dependency" => ""
),
// ---------------------Product ---------------------
array(
"name" => "product_custom_layout",
"title" => esc_html__("Custom layout" ,'wd-framework' ),
"description" => "",
"float_left" => "yes",
"clear_after" => "",
"type" => "selectbox",
"classname" =>"",
"values" => $this->posts_dropdown("wd_product_template"),
"scope" => array("product"),
"capability" => "manage_options",
"dependency" => ""
),
);
}
/*
* list post
*/
function posts_dropdown($posttype) {
$wd_search_form = get_posts(array('post_type' => $posttype,'itemperpage' => '99999'));
$wd_search_form_array = array(""=>"Default");
foreach ( $wd_search_form as $key => $post ) {
$wd_search_form_array[$post->ID] = $post->post_title;
}
return $wd_search_form_array;
}
/**
* Remove the default Custom Fields meta box
*/
function wdmp_removeDefaultCustomFields( $type, $context, $post ) {
foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
foreach ( $this->wdmp_postTypes as $postType ) {
remove_meta_box( 'postcustom', $postType, $context );
}
}
}
/**
* Create the new Custom Fields meta box
*/
function wdmp_createCustomFields() {
if ( function_exists( 'add_meta_box' ) ) {
foreach ( $this->wdmp_postTypes as $postType ) {
if($postType == "team-member") {
add_meta_box( 'titlebar-options-metabox', esc_html__( 'Team informations','wd-framework' ), array( &$this, 'wdmp_displayCustomFields' ), 'team-member', 'side', 'default' );
}
if($postType == "testimonials") {
add_meta_box( 'titlebar-options-metabox', esc_html__('Testimonials image' ,'wd-framework' ), array( &$this, 'wdmp_displayCustomFields' ), 'testimonials', 'side', 'default' );
}
if($postType == "product" && wd_is_active_plugin( 'wd-prooducts-box-designer/products-box-designer.php' ) ) {
add_meta_box( 'titlebar-options-metabox', esc_html__('Template layout' ,'wd-framework' ), array( &$this, 'wdmp_displayCustomFields' ), 'product', 'side', 'default' );
}
}
}
}
/**
* Display the new Custom Fields meta box
*/
function wdmp_displayCustomFields() {
global $post;
global $wdoptions_proya;
global $wdmp_fontArrays;
?>
<div class="form-wrap">
<?php
wp_nonce_field( 'titlebar-options-metabox', 'titlebar-options-metabox_wpnonce', false, true );
foreach ( $this->wdmp_customFields as $customField ) {
// Check scope
$scope = $customField[ 'scope' ];
$dependency = $customField[ 'dependency' ];
$output = false;
foreach ( $scope as $scopeItem ) {
switch ( $scopeItem ) {
default: {
if ( $post->post_type == $scopeItem ){
if($dependency != ""){
foreach ( $dependency as $dependencyKey => $dependencyValue ) {
foreach ( $dependencyValue as $dependencyVal ) {
if(isset($wdoptions_proya[$dependencyKey]) && $wdoptions_proya[$dependencyKey] == $dependencyVal){
$output = true;
break;
}
}
}
}else{
$output = true;
}
}else{
break;
}
}
}
if ( $output ) break;
}
// Check capability
if ( !current_user_can( $customField['capability'], $post->ID ) )
$output = false;
// Output if allowed
if ( $output ) { ?>
<?php
switch ( $customField[ 'type' ] ) {
case "checkbox": {
// Checkbox
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' form-required">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'><b>' . $customField[ 'title' ] . '</b></label> ';
echo '<input type="checkbox" name="' . $this->wdmp_prefix . $customField['name'] . '" id="' . $this->wdmp_prefix . $customField['name'] . '" value="yes"';
if ( get_post_meta( $post->ID, $this->wdmp_prefix . $customField['name'], true ) == "yes" )
echo ' checked="checked"';
echo '" style="width: auto;" />';
echo '</div>';
break;
}
case "selectbox": {
// Selectbox
if ( $customField[ 'float_left' ] == 'yes' ) {$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left . ' form-required">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'" ><b>' . $customField[ 'title' ] . '</b></label>';
echo '<select name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '"> ';
?>
<?php foreach ($customField['values'] as $valuesKey => $valuesValue) { ?>
<option value="<?php echo esc_attr($valuesKey); ?>" <?php if (get_post_meta( $post->ID, $this->wdmp_prefix . $customField['name'], true ) == $valuesKey ) { ?> selected="selected" <?php } ?>><?php echo esc_attr($valuesValue); ?></option>
<?php } ?>
<?php
echo '</select>';
echo '</div>';
break;
}
case "selectbox-category": {
$categories = get_categories();
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' form-required">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label> ';
echo '<select name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '"> ';
echo '<option value=""></option>';
foreach($categories as $category) :
echo '<option value="'. $category->term_id .'"';
if (get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) == $category->term_id ) { echo 'selected="selected"';}
echo '>';
echo esc_attr($category->name);
?> <?php
echo '</option>';
endforeach;
echo '</select>';
echo '</div>';
break;
}
case "image-title-image": {
wp_enqueue_media();
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('.upload_button').click(function(){
wp.media.editor.send.attachment = function(props, attachment){
jQuery('.title_image').val(attachment.url);
}
wp.media.editor.open(this);
return false;
});
});
</script>
<?php
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' form-required">';
$wd_page_bg_img = get_post_meta($post->ID, 'wd_page_title_area_bg_img', true);
//print $wd_page_bg_img;
echo '<label ><b>' . $customField[ 'title' ] . '</b> </label>';
echo '<div class="image_holder"><input type="text" id="' . $this->wdmp_prefix . $customField[ 'name' ] .'" name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" class="text_field title_image" value="'.htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ).'" /><input class="upload_button button add_image" type="button" value="Upload file"></div>';
echo '</div>';
break;
}
case "font-family": {
// Selectbox
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' ">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label> ';
echo '<select name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '"> ';
?>
<option value="" <?php if (get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) == "-1" ) { ?> selected="selected" <?php } ?>>Default</option>
<?php foreach($wdmp_fontArrays as $wdmp_fontArray) { ?>
<option <?php if (get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) == str_replace(' ', '+', $wdmp_fontArray["family"])) { echo "selected='selected'"; } ?> value="<?php echo str_replace(' ', '+', $wdmp_fontArray["family"]); ?>"><?php echo $wdmp_fontArray["family"]; ?></option>
<?php } ?>
<?php
echo '</select>';
echo '</div>';
break;
}
case "colorpicker": {
add_action( 'load-widgets.php', 'wd_load_color_picker' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
//Colorpicker
wp_enqueue_media();
wp_enqueue_script('wp-color-picker');
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script('colorpick', get_template_directory_uri() . "/inc/js/bootstrap-colorpicker.min.js", array( 'jquery' ) );
wp_enqueue_style ('colorpick', get_template_directory_uri() . "/inc/css/bootstrap-colorpicker.min.css");
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.wd-color-picker').colorpicker(
{format: 'rgba'}
);
jQuery('#wd_upload_btn').click(function(){
wp.media.editor.send.attachment = function(props, attachment){
jQuery('#wd_logo_filed').val(attachment.url);
}
wp.media.editor.open(this);
return false;
});
});
</script>
<?php
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' colorpicker_input">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
echo '<div class="colorSelector"><div style="background-color:'.htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ) .'"></div></div>';
echo '<input type="text" class="wd-color-picker" data-default-color="" name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '" value="' . htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ) . '" size="10" maxlength="10" />';
echo '</div>';
break;
}
case "textarea":
case "wysiwyg": {
// Text area
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' form-required">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
echo '<textarea name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '" columns="30" rows="3">' . htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ) . '</textarea>';
// WYSIWYG
if ( $customField[ 'type' ] == "wysiwyg" ) { ?>
<script type="text/javascript">
jQuery( document ).ready( function() {
jQuery( "<?php echo $this->wdmp_prefix . $customField[ 'name' ]; ?>" ).addClass( "mceEditor" );
if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
tinyMCE.execCommand( "mceAddControl", false, "<?php echo $this->wdmp_prefix . $customField[ 'name' ]; ?>" );
}
});
</script>
<?php }
echo '</div>';
break;
}
case "short-text-200": {
// Plain text field
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' short_text_200">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
echo '<input type="text" name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '" value="' . htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ) . '" />';
echo '</div>';
break;
}
case "hidden": {
// Plain text field
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' form-required">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
echo '<input type="hidden" class="rating-value" name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '" value="' . htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ) . '" />';
echo '</div>'; ?>
<ul class="rating">
<li data-value="1"><i class="fa fa-star"></i></li>
<li data-value="2"><i class="fa fa-star"></i></li>
<li data-value="3"><i class="fa fa-star"></i></li>
<li data-value="4"><i class="fa fa-star"></i></li>
<li data-value="5"><i class="fa fa-star"></i></li>
</ul>
<?php break;
}
default: {
// Plain text field
if ( $customField[ 'float_left' ] == 'yes'){$float_left = 'float_left';} else {$float_left = '';}
if ( $customField[ 'classname' ] != ''){$class_name = $customField[ 'classname' ];} else {$class_name = '';}
echo '<div class="form-field clearfix '.$class_name.' '. $float_left .' form-required">';
echo '<label for="' . $this->wdmp_prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
echo '<input type="text" name="' . $this->wdmp_prefix . $customField[ 'name' ] . '" id="' . $this->wdmp_prefix . $customField[ 'name' ] . '" value="' . htmlspecialchars( get_post_meta( $post->ID, $this->wdmp_prefix . $customField[ 'name' ], true ) ) . '" />';
echo '</div>';
break;
}
}
?>
<?php if ( $customField[ 'description' ] ) echo '<p>' . $customField[ 'description' ] . '</p>'; ?>
<?php if ( $customField[ 'clear_after' ] == 'yes' ) echo '<div class="clear"></div>'; ?>
<?php
}
} ?>
</div>
<?php
}
/**
* Save the new Custom Fields values
*/
function wdmp_saveCustomFields( $post_id, $post ) {
if ( !isset( $_POST[ 'titlebar-options-metabox_wpnonce' ] ) || !wp_verify_nonce( $_POST[ 'titlebar-options-metabox_wpnonce' ], 'titlebar-options-metabox' ) )
return;
if ( !current_user_can( 'edit_post', $post_id ) )
return;
if ( ! in_array( $post->post_type, $this->wdmp_postTypes ) )
return;
foreach ( $this->wdmp_customFields as $customField ) {
if ( current_user_can( $customField['capability'], $post_id ) ) {
if ( isset( $_POST[ $this->wdmp_prefix . $customField['name'] ] ) && trim( $_POST[ $this->wdmp_prefix . $customField['name'] ] !== '') ) {
$value = $_POST[ $this->wdmp_prefix . $customField['name'] ];
// Auto-paragraphs for any WYSIWYG
if ( $customField['type'] == "wysiwyg" ) $value = wpautop( $value );
update_post_meta( $post_id, $this->wdmp_prefix . $customField[ 'name' ], $value );
} else {
delete_post_meta( $post_id, $this->wdmp_prefix . $customField[ 'name' ] );
}
}
}
}
} // End Class
} // End if class exists statement
if ( class_exists('wdmp_myCustomFields') ) {
$wdmp_myCustomFields_var = new wdmp_myCustomFields();
}