<?php 


add_Action('init', function(){

 

	if( $_GET['process_channel'] ){
		wyi_run_import();
		 
	}
	$last_import_run = (int)get_option('last_import_run');
 
	if( $last_import_run !== 0     ){
		if( time() - $last_import_run > 60*60*5   ){
		 
			wyi_run_import();
			update_option('last_import_run', time() );
		}
	}else{
	 
		wyi_run_import();
		update_option('last_import_run', time() );
	}
 });
	



add_filter('the_content', 'ayi_the_content');
function ayi_the_content( $content ){
	global $post;
	$config = get_option('ayi_options'); 
	if( get_post_meta( $post->ID, 'youtube_id', true ) ){
		
		
		// geting related content
		$this_cat = get_the_category( $post->ID );
		
		$args = array(
			'showposts' => 3,
			'cat' => $this_cat[0]->term_id,
			'post__not_in' => array( $post->ID )
		);
		$all_posts = get_posts( $args );
		
		
		$all_related = array();
		
		if( count($all_posts) > 0 )
		foreach( $all_posts as $sinlge_post ){
			
			$src_full = wp_get_attachment_image_src(get_post_thumbnail_id($sinlge_post->ID), 'full' ); 
			
			$all_related[] = '
				<div class="single_prod">
						<a href="'.get_permalink( $sinlge_post->ID ).'" >
							<img src="'.$src_full[0].'" />
						</a>
						
						<div class="prod_title">
						<a href="'.get_permalink( $sinlge_post->ID ).'" >
							'.$sinlge_post->post_title.'
						</a>
						</div>
						
				</div>';
		}
		
		$related_posts = '
		<div class="related_block">
			<h4>Related Video Posts</h4>
			<div class="related_content">'.implode( '', $all_related ).'</div>
		</div>
		';
		
	

	
		$content = $content.$related_posts;
		
		if( $config['show_top_ads'] == 'yes' ){
			$content_tops_ads = '
			<div class="top_ads_block">'.stripslashes( $config['top_ads_text'] ).'</div>';


			$content = str_replace('<div class="post_content_bl">', $content_tops_ads.'<div class="post_content_bl">', $content );

		}
		if( $config['show_bottom_ads'] == 'yes' ){
			$content = $content.'
			<div class="bottom_ads_block">'.stripslashes( $config['bottom_ads_text'] ).'</div>
			';
		}
		
	}

	return $content;
}


function rm_wpautop($content) {
    global $post;
    // Get the keys and values of the custom fields:
    //$rmwpautop = get_post_meta($post->ID, 'wpautop', true);
    // Remove the filter
    remove_filter('the_content', 'wpautop');
    if ('false' === $rmwpautop) {
    } else {
        add_filter('the_content', 'wpautop');
    }
    return $content;
}
// Hook into the Plugin API
add_filter('the_content', 'rm_wpautop', 9);


function sample_admin_notice__success() {
	
	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
	if( !is_plugin_active('wp-social-sharing/index.php') ){
	
			?>
			<div class="notice notice-success is-dismissible">
				<p><?php _e( 'We recommend that you install the <a href="https://wordpress.org/plugins/wp-social-sharing/" target="_blank">WP Social Sharing Plugin</a>', 'sample-text-domain' ); ?></p>
			</div>
			<?php
	}
}
add_action( 'admin_notices', 'sample_admin_notice__success' );

?>