moonorongo
5/29/2017 - 11:37 AM

[Feat Image 2] Agregar un param a featured image (en este caso transparencia #wordpress #php

[Feat Image 2] Agregar un param a featured image (en este caso transparencia #wordpress #php

<?php
// add combo to Featured image 
function add_featured_image_display_settings( $content, $post_id ) {
	$field_id    = 'qbf_opacity';
	$field_value = esc_attr( get_post_meta( $post_id, $field_id, true ) );
    $field_value = (empty($field_value))? '1.0' : $field_value;
	$field_text  = 'Opacity';

    $options_list = '';
    for($i = 1; $i <= 10; $i++) {
        $opacity = number_format(round($i / 10, 1),1);
        $selected = ($opacity == $field_value)? ' selected ' : '';
        $options_list .= '<option value="'. $opacity .'"'. $selected .'>'. $opacity .'</option>';
    }

    $field_label = 
        '<p><label for="'. $field_id .'">'. $field_text . 
        '<select name="'. $field_id .'" id="'. $field_id .'">'. 
            $options_list .
        '</select>'. 
        '</label></p>';

	return $content .= $field_label;
}
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_display_settings', 10, 2 );


// save custom combo in Featured image
function save_featured_image_display_settings( $post_ID, $post, $update ) {
	$field_id    = 'qbf_opacity';
    if(array_key_exists($field_id, $_REQUEST)) {
        $field_value = $_REQUEST[ $field_id ];    
    } else {
        $field_value = '1.0';
    }
	

	update_post_meta( $post_ID, $field_id, $field_value );
}
add_action( 'save_post', 'save_featured_image_display_settings', 10, 3 );