Created
August 24, 2016 21:29
-
-
Save ebinnion/423ae37f25fad6cabf4faea045db1691 to your computer and use it in GitHub Desktop.
This plugin creates filler content every minute via cron. It is meant to be used as a debugging plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Meaty Filler Content via Cron | |
Plugin URI: https://manofhustle.com | |
Description: Debug plugin which creates meaty filler content from the cron. | |
Version: 0.1.0 | |
Author: ebinnion | |
Author URI: https://manofhustle.com | |
*/ | |
register_activation_hook( __FILE__, 'register_meaty_filler_cron' ); | |
register_deactivation_hook( __FILE__, 'deregister_meaty_filler_cron' ); | |
function register_meaty_filler_cron() { | |
if ( ! wp_next_scheduled( 'create_filler_content_every_minute' ) ) { | |
wp_schedule_event( time() + 1, '1min', 'create_filler_content' ); | |
} | |
} | |
function deregister_meaty_filler_cron() { | |
wp_clear_scheduled_hook( 'create_filler_content' ); | |
} | |
function add_minute_cron_schedule( $schedules ) { | |
if( ! isset( $schedules['1min'] ) ) { | |
$schedules['1min'] = array( | |
'interval' => 60, | |
'display' => __( 'Every minute' ) | |
); | |
} | |
return $schedules; | |
} | |
add_filter( 'cron_schedules', 'add_minute_cron_schedule' ); | |
function create_meaty_filler_content_in_cron() { | |
$url = add_query_arg( | |
array( | |
'type' => 'meat-and-filler', | |
'paras' => random_int( 1, 25 ), | |
'format' => 'text' | |
), | |
'https://baconipsum.com/api' | |
); | |
$content = wp_remote_get( $url ); | |
if( is_wp_error( $content ) ) { | |
return; | |
} | |
wp_insert_post( array( | |
'post_title' => 'Meaty filler content from cron', | |
'post_content' => $content['body'], | |
'post_status' => 'publish', | |
'post_author' => is_user_logged_in() ? get_current_user_id() : 1 | |
) ); | |
} | |
add_action( 'create_filler_content', 'create_meaty_filler_content_in_cron' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment