<?php
/*-----------------------------------------------------------------------------------*/
/*  EXTHEM.ES
/*  PREMIUM WORDRESS THEMES
/*
/*  STOP DON'T TRY EDIT
/*  IF YOU DON'T KNOW PHP 
/*
/*-----------------------------------------------------------------------------------*/

/*
Set wp-editor in the 'Text' mode by default.
https://wordpress.stackexchange.com/questions/382306/wp-editor-visual-tab-in-meta-box-doesnt-show-content
*/
//add_filter( 'wp_default_editor', function () { return 'tinymce'; } ); 


//add_action("manage_posts_custom_column",  "poster_custom_columns");
//add_filter("manage_edit-post_columns", "poster_edit_columns");
function posters_edit_columns($columns){
    $columns['poster'] = 'Poster';
    return $columns; 
}
function posters_custom_columns($column){
    if ( $column === 'poster') {
		global $post;	  
		echo get_the_post_thumbnail( get_the_ID(), array(50, 50) );
    } 
}
/*
https://rudrastyh.com/wordpress/quick-edit-tutorial.html
*/
add_filter( 'manage_post_posts_columns', 'misha_price_and_featured_columns' ); 
function misha_price_and_featured_columns( $column_array ) {
	$column_array[ 'version' ] 	= 'Version';  	
	//$column_array[ 'size' ] 	= 'Size';
	return $column_array;
}

add_action( 'manage_posts_custom_column', 'misha_populate_both_columns', 10, 2 );
function misha_populate_both_columns( $column_name, $post_id ) {
	switch( $column_name ) {
		case 'version': {
			//if(get_post_meta( $post_id, 'wp_version_GP', true )){
			$version		= wp_strip_all_tags(get_post_meta( $post_id, 'wp_version_GP', true ));	
			//} else {
			//$version		= wp_strip_all_tags(get_post_meta( $post_id, 'wp_version', true ));	
			//}
			 
			echo $version ? ''.$version : '';
			break;
		} 
		//case 'size': {
		//	echo get_post_meta( $post_id, 'wp_sizes', true );
		//	break;
		//}
	}
} 
add_action( 'quick_edit_custom_box',  'misha_quick_edit_fields', 10, 2 );

function misha_quick_edit_fields( $column_name, $post_id ) { 
	switch( $column_name ) {
		case 'version': {
		global $post, $wpdb;
		?>
		<fieldset class="inline-edit-col-left">
		<legend class="inline-edit-legend">Version Edit <?php echo get_post_meta( $post_id, 'wp_version_GP', true ); ?></legend>
		<div class="inline-edit-col">
		
		<!--<label>
		<span class="title">The Version</span>
		<span class="input-text-wrap">
		<input readonly type="text" class="ptitle" name="current_version" value="<?php echo get_post_meta( get_the_ID(), 'wp_version_GP', true ); ?> " />
		</span>		
		</label>-->
		 
		<label>
		<span class="title">Version</span>
		<span class="input-text-wrap">
		<input type="text" class="ptitle" name="version" placeholder="edit your version"  />
		</span>		
		</label> 
		 
		<!--<label>
		<span class="titles">Version <b>(Sources)</b></span>
		<input type="text" name="wp_version" placeholder="example : 1.0 " />
		</label>-->
		</div>
		</fieldset>
						
		<fieldset class="inline-edit-col-left">
		<legend class="inline-edit-legend">Size Edit</legend>
		<div class="inline-edit-col">
		
		
		<label>
		<span class="title">Size</span>
		<span class="input-text-wrap">
		<input type="text" class="ptitle" name="size" placeholder="edit your size"  />
		</span>		
		</label> 
		</div>
		</fieldset>	
		<?php
		break;
		} 
		case 'size': {
		?>
		
			<?php
			break;
		}
	}
} 
add_action( 'save_post', 'misha_quick_edit_save' );

function misha_quick_edit_save( $post_id ){
	@ini_set('display_errors', 'off');
	if ( ! wp_verify_nonce( $_POST[ '_inline_edit' ], 'inlineeditnonce' ) ) {
	return;
	}

	$version = ! empty( $_POST[ 'version' ] ) ? $_POST[ 'version' ] : get_post_meta( $post_id, 'wp_version_GP', true );
 	update_post_meta( $post_id, 'wp_version_GP', $version );
 	update_post_meta( $post_id, 'wp_version', $version );
	
	$size = ! empty( $_POST[ 'size' ] ) ? $_POST[ 'size' ] : get_post_meta( $post_id, 'wp_sizes', true );
 	update_post_meta( $post_id, 'wp_sizes_GP', $size );
 	update_post_meta( $post_id, 'wp_sizes', $size );

	if( isset( $_POST[ 'version' ] ) ) {
        delete_post_meta( $post_id, 'update_available' );
        delete_post_meta( $post_id, 'available_version' );
    }
	
	if( isset( $_POST[ 'wp_version_GP' ] ) ) {
        delete_post_meta( $post_id, 'update_available' );
        delete_post_meta( $post_id, 'available_version' );
    }
}
  