Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Código de ejemplo de cómo crear un cron en WordPress
Plugin Name: Ejemplo Cron
Description: Plugin para mostrar cómo funciona el cron de WordPress
Version: 1.0
Author: Jhon Marreros Guzmán
Author URI:
License: GPL2
License URI:
// Activación del Plugin
register_activation_hook( __FILE__, 'dcms_plugin_activation' );
function dcms_plugin_activation() {
if( ! wp_next_scheduled( 'dcms_my_cron_hook' ) ) {
wp_schedule_event( current_time( 'timestamp' ), '5seconds', 'dcms_my_cron_hook' );
// Desactivación del plugin
register_deactivation_hook( __FILE__, 'dcms_plugin_desativation' );
function dcms_plugin_desativation() {
wp_clear_scheduled_hook( 'dcms_my_cron_hook' );
// Acción personalizada
add_action( 'dcms_my_cron_hook', 'dcms_my_process' );
function dcms_my_process() {
error_log('Mi evento se ejecutó: '.Date("h:i:sa"));
//Registro de intervalos
add_filter( 'cron_schedules', 'dcms_my_custom_schedule');
function dcms_my_custom_schedule( $schedules ) {
$schedules['5seconds'] = array(
'interval' => 5,
'display' =>__('5 seconds','dcms_lang_domain')
return $schedules;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment