Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Created August 24, 2016 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebinnion/423ae37f25fad6cabf4faea045db1691 to your computer and use it in GitHub Desktop.
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.
<?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