Пример #1
0
/**
 * Prints the box content.
 * 
 * @param WP_Post $post The object for the current post/page.
 */
function caviar_meta_box_callback($post)
{
    // Add a nonce field so we can check for it later.
    wp_nonce_field('caviar_save_meta_box_data', 'caviar_meta_box_nonce');
    /*
     * Use get_post_meta() to retrieve an existing value
     * from the database and use the value for the form.
     */
    $txtName = get_post_meta($post->ID, '_txtName', true);
    $txtAddress = get_post_meta($post->ID, '_txtAddress', true);
    $txtWebsite = get_post_meta($post->ID, '_txtWebsite', true);
    $chkFood = get_post_meta($post->ID, '_chkFood', true);
    $selHobby = get_post_meta($post->ID, '_selHobby', true);
    $selTrans = get_post_meta($post->ID, '_selTrans', true);
    $itemFeatures = get_post_meta($post->ID, '_itemFeatures', true);
    $gender = get_post_meta($post->ID, '_gender', true);
    $colorMeta = get_post_meta($post->ID, '_colorMeta', true);
    $edAboutMe = get_post_meta($post->ID, '_edAboutMe', true);
    $selCats = get_post_meta($post->ID, '_selCats', true);
    $upPhoto = get_post_meta($post->ID, '_upPhoto', true);
    $upLicense = get_post_meta($post->ID, '_upLicense', true);
    $rePersonalData = get_post_meta($post->ID, '_rePersonalData', true);
    // var_dump($rePersonalData);
    $fields = array('title' => array('title' => 'Feature', 'type' => 'text'), 'desc' => array('title' => 'Price', 'type' => 'textarea'), 'pic' => array('id' => 'repeaterPic', 'title' => 'Picture', 'type' => 'upload'), 'featured' => array('title' => 'Featured', 'type' => 'checkbox', 'options' => array('1' => 'Yes', '2' => 'No', '3' => 'Undecided')));
    $fieldx = array('name' => array('title' => 'Name', 'type' => 'text'), 'gender' => array('title' => 'Feature', 'type' => 'radioimage', 'options' => array('1' => 'http://placeimg.com/100/100/arch', '2' => 'http://placeimg.com/100/100/tech')), 'pic' => array('id' => 'profilePic', 'title' => 'Picture', 'type' => 'upload'));
    $fieldControl = new Field_Controls();
    $fieldControl->upload('Photo', 'upPhoto', array('name' => 'upPhoto', 'value' => $upPhoto, 'class' => 'single previewImage', 'placeholder' => esc_html__('Image URL', 'claypress')));
    $fieldControl->upload('License Url', 'upLicense', array('name' => 'upLicense', 'value' => $upLicense, 'class' => 'single previewImage', 'placeholder' => esc_html__('Driving License url', 'claypress')));
    $fieldControl->text('Name', 'txtName', array('value' => esc_attr($txtName), 'attr' => array('data-test1' => 'test1', 'data-validate' => 'true')));
    $fieldControl->text('Website', 'txtWebsite', array('type' => 'url', 'value' => esc_attr($txtWebsite)));
    $fieldControl->textarea('Address', 'txtAddress', array('value' => $txtAddress));
    $fieldControl->select('Transportation?', 'selTrans', array('name' => 'selTrans', 'value' => $selTrans, 'class' => 'widefat chosen-select'), array('car' => 'Car', 'bike' => 'Bike', 'train' => 'Train'));
    $fieldControl->select('Hobby?', 'selHobby', array('name' => 'selHobby', 'multiple' => 'multiple', 'value' => $selHobby, 'class' => 'widefat chosen-select'), array('Out Door' => array('football' => 'Football', 'basketball' => 'Basketball', 'tennis' => 'Tennis', 'swimming' => 'Swimming'), 'Indoor' => array('reading' => 'Reading', 'writing' => 'Writing'), 'Extreme' => array('basejump' => 'Base Jumping', 'surving' => 'Surving', 'diving' => 'Diving')));
    $fieldControl->checkbox('Food?', 'chkFood', array('name' => 'chkFood', 'value' => $chkFood, 'class' => 'widefat'), array('fruit' => 'Fruit', 'vegetable' => 'Vegetable', 'bread' => 'Bread'));
    // $fieldControl->radio('Gender', 'gender', array('name' => 'gender', 'value' => $gender, 'attr' => array('data-test1' => 'test1')), array('male' => 'Male', 'female' => 'Female', 'other' => 'Other'));
    // $fieldControl->radiopill('Gender', 'gender', array('name' => 'gender', 'value' => $gender, 'attr' => array('data-test1' => 'test1')), array('male' => 'Male', 'female' => 'Female', 'other' => 'Other'));
    $fieldControl->radioimage('Gender', 'gender', array('name' => 'gender', 'value' => $gender, 'attr' => array('data-test1' => 'test1')), array('male' => 'http://placeimg.com/100/100/nature', 'female' => 'http://placeimg.com/100/100/tech', 'other' => 'http://placeimg.com/100/100/arch'));
    $fieldControl->colorpicker('Fav Color', 'colorMeta', array('class' => 'widefat', 'value' => $colorMeta, 'attr' => array('data-color' => 'test1')));
    $fieldControl->editor('About me', 'edAboutMe', array('value' => $edAboutMe), array('textarea_rows' => '5'));
    // $fieldControl->taxonomy('Category', 'selCats', array('name' =>  'selCats', 'type' => 'select', 'value' => $selCats), 'post_tag', '');
    $fieldControl->repeaterField('Repeated Feature', 'itemFeatures', array('name' => 'itemFeatures', 'value' => $itemFeatures), $fields);
    $fieldControl->repeaterField('Personal data', 'rePersonalData', array('name' => 'rePersonalData', 'value' => $rePersonalData), $fieldx);
}