Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

sohinc on "WP Custom Update - Want to update post automatically"

$
0
0

Hi guys, So i have this plugin that i had got developed a year ago called WP Custom Update(code below). What this does is if you enter your post id in the plugin it will simply update that post every 10, 20 or 30 minutes. So its basically refreshing your post like if you were to manually go into your post edit and hit the update button. I would like to change the functionality of this and instead of having to enter the post id i would like all post that gets published to the site to be updated automatically as if i just opened the post and hit update button. I also would like this update to only happen once instead of happening over and over again. Thanks

Wp Custom Update (code)

<?php
/*
Plugin Name: WP Custom Update
Plugin URI: mailto:lampfreaks@gmail.com
Description: A plugin will update a set of post ids in a particular interval.
Author: Thamizhchelvan
Version: 1.0
Author URI: http://thamizhchelvan.com/
*/

//################### START OF ADMIN SETTINGS ################################################/

function wpcu_menuitems(){
	add_submenu_page('options-general.php', 'Custom Update', 'Custom Update Settings', 8, 'wpcu_custom_settings', 'wpcu_custom_settings');
}

add_action('admin_menu', 'wpcu_menuitems');

function wpcu_custom_settings(){
	if(isset($_POST['wpcu_thirty'])){

		update_option('wpcu_thirty',$_POST['wpcu_thirty']);
		update_option('wpcu_twenty',$_POST['wpcu_twenty']);
		update_option('wpcu_ten',$_POST['wpcu_ten']);
	}

	?>
<div class="icon32" id="icon-options-general"><br/></div>
<h2>Custom Product Updates</h2>
<BR />
<center>
<form method="post">
<table width="100%">

<tr><td>Post/Page IDs - 30 Minutes Interval</td><td><input class="regular-text" value="<?php echo get_option('wpcu_thirty');?>" type="text" name="wpcu_thirty" />[Enter seperated by comma] Example:1,3,45,67</td></tr>

<tr><td>Post/Page IDs - 20 Minutes Interval</td><td><input class="regular-text" value="<?php echo get_option('wpcu_twenty');?>" type="text" name="wpcu_twenty" /></td></tr>

<tr><td>Post/Page IDs - 10 Minutes Interval</td><td><input class="regular-text" value="<?php echo get_option('wpcu_ten');?>" type="text" name="wpcu_ten" /></td></tr>

<tr><td></td>&nbsp;<td><input type="submit" value="Save" /></td></tr>
</table>
</form>
</center>

	<?php
}

//################### END OF ADMIN SETTINGS ################################################/
add_filter( 'cron_schedules', 'wpcu_corn_schedules');
function wpcu_corn_schedules(){
	return array(
		'in_per_ten_minute' => array(
			'interval' => 60 * 10,
			'display' => 'In every Ten Mintues'
		),
		'in_per_twenty_minute' => array(
			'interval' => 60 * 20,
			'display' => 'In every Twenty Mintues'
		),
		'in_per_thirty_minute' => array(
			'interval' => 60 * 30,
			'display' => 'In every Thirty Mintues'
		)

	);
}

if(!wp_next_scheduled('wpcu_ten_minute_event' )){
	wp_schedule_event( time(), 'in_per_ten_minute', 'wpcu_ten_minute_event' );
}

if(!wp_next_scheduled('wpcu_twenty_minute_event' )){
	wp_schedule_event( time(), 'in_per_twenty_minute', 'wpcu_twenty_minute_event' );
}

if(!wp_next_scheduled('wpcu_thirty_minute_event' )){
	wp_schedule_event( time(), 'in_per_thirty_minute', 'wpcu_thirty_minute_event' );
}

add_action('wpcu_ten_minute_event', 'wpcu_update_ten');
add_action('wpcu_twenty_minute_event', 'wpcu_update_twenty');
add_action('wpcu_thirty_minute_event', 'wpcu_update_thirty');

function wpcu_update_ten(){
	wpcu_update_postids('wpcu_ten');
}

function wpcu_update_twenty(){
	wpcu_update_postids('wpcu_twenty');
}

function wpcu_update_thirty(){
	wpcu_update_postids('wpcu_thirty');
}
function wpcu_update_postids($interval){
	$post_ids = get_option($interval);
	if($post_ids != ''){
		$postids = explode(",",$post_ids);
		foreach($postids as $pid){
			$postid = trim($pid);
			$update_post = array();
			$update_post['ID'] = $postid;
			wp_update_post($update_post);
			MPT_backoffice::create_thumb($postid);
		}
	}
}
?>

Viewing all articles
Browse latest Browse all 8245

Trending Articles