Beispiel #1
0
function nuts_type_image_field($name, $id)
{
    $imgdata = wp_get_attachment_image_src($id, 'thumbnail');
    echo '<div class="uploader">
			<div class="image-container">
				<img class="uploaded-image" id="' . $name . '_img" src="' . $imgdata[0] . '"';
    if ($id == '') {
        echo ' style="display: none"';
    }
    echo ' />
				<img class="placeholder" src="' . get_bloginfo('template_url') . '/nuts/img/no-image-placeholder.png"';
    if ($id != '') {
        echo ' style="display: none;"';
    }
    echo '  />		
				<div class="closer" style="';
    if ($id == '') {
        echo ' display: none';
    }
    echo '">
					<div class="hovermsg">Click here to remove image.</div>
				</div>
			</div>
			<input type="hidden" name="' . nuts_form_ref($name) . '" id="' . $name . '" value="' . $id . '" />
			<input class="attrib" type="hidden" name="' . nuts_get_section($name) . '_attrib[' . $name . ']" id="attrib_' . $name . '" value="' . $name . '" />
			<input class="button" type="button" name="' . $name . '_button" id="' . $name . '_button" value="Upload" />
		</div>';
}
Beispiel #2
0
function nuts_type_number_field($name, $value)
{
    global $nuts_options_array;
    if ($nuts_options_array[$name]["step"] != NULL) {
        $step = $nuts_options_array[$name]["step"];
    } else {
        $step = DEFAULT_NUMBER_STEP;
    }
    if ($nuts_options_array[$name]["min"] != NULL) {
        $min = $nuts_options_array[$name]["min"];
    } else {
        $min = DEFAULT_NUMBER_MIN;
    }
    if ($nuts_options_array[$name]["max"] != NULL) {
        $max = $nuts_options_array[$name]["max"];
    } else {
        $max = DEFAULT_NUMBER_MAX;
    }
    if ($value == "") {
        $value = $nuts_options_array[$name]["default"];
    }
    echo '<div class="number">
			<input type="number" name="' . nuts_form_ref($name) . '" id="' . $name . '" value="' . $value . '" min="' . $min . '" max="' . $max . '" step="' . $step . '" />
		</div>';
}
Beispiel #3
0
function nuts_type_color_field($name, $value)
{
    if ($value == "") {
        $value = nuts_get_default_color($name);
    }
    echo '<div class="color">
			<input id="' . $name . '" name="' . nuts_form_ref($name) . '" type="text" value="' . $value . '" class="nuts-color-field" data-default-color="' . nuts_get_default_color($name) . '" />
		</div>';
}
Beispiel #4
0
function nuts_type_text_field($name, $value)
{
    global $nuts_options_array;
    if ($nuts_options_array[$name]["size"] != NULL) {
        $size = $nuts_options_array[$name]["size"];
    } else {
        $size = DEFAULT_TEXT_SIZE;
    }
    echo '<div class="text">
			<input type="text" name="' . nuts_form_ref($name) . '" id="' . $name . '" value="' . $value . '"';
    if ($size > 0) {
        echo ' maxlength="' . $size . '"';
    }
    echo ' />
		</div>';
}
Beispiel #5
0
function nuts_type_select_field($name, $id)
{
    global $nuts_options_array;
    if ($id == '') {
        $id = $nuts_options_array[$name]["default"];
    }
    echo '<select name="' . nuts_form_ref($name) . '" id="' . $name . '" autocomplete="off">';
    foreach ($nuts_options_array[$name]["values"] as $key => $value) {
        echo '<option value="' . $key . '"';
        if ($key == $id) {
            echo ' selected';
        }
        echo '>' . $value . '</option>';
        echo $key . ' ' . $id;
    }
    echo '</select>';
}
Beispiel #6
0
function nuts_save_postdata($post_id)
{
    // Check if our nonce is set.
    if (!isset($_POST['nuts_inner_custom_box_nonce'])) {
        return $post_id;
    }
    $nonce = $_POST['nuts_inner_custom_box_nonce'];
    // Verify that the nonce is valid.
    if (!wp_verify_nonce($nonce, 'nuts_inner_custom_box')) {
        return $post_id;
    }
    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // Check the user's permissions.
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    /* OK, its safe for us to save the data now. */
    // Update the meta field in the database.
    $sections = nuts_get_sections(get_post_type($post_id));
    foreach ($sections as $section) {
        $options = nuts_options_by_section($section["name"]);
        $data = array();
        foreach ($options as $option) {
            $sn = nuts_form_ref($option["name"]);
            $data[$option["name"]] = $_POST[$sn];
        }
        $sec = explode("::", $section["name"]);
        update_post_meta($post_id, '_' . $sec[1], $data);
        unset($data);
    }
}