Cron Background Job Security logo

Cron Background Job Security

Organization
wpultimatesecurity
cron-background-job-security

Use when scheduling WordPress cron events with wp_schedule_event / wp_schedule_single_event or writing the callback that runs on a cron hook. Treats cron callbacks as running without a logged-in user, re-checks authorization against stored context rather than current_user_can, keeps secrets out of cron URLs, and validates any stored input the job consumes. Prevents unauthenticated privileged actions via the cron surface.

Overview

Publisherwpultimatesecurity
RepositoryWordPress-Security-Skills
Skill namecron-background-job-security
Stars
54
Forks
3
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wpultimatesecurity on GitHub. Read the source before you install it.

Installation

Install the Cron Background Job Security AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/cron-background-job-security
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wpultimatesecurity/WordPress-Security-Skills.git /tmp/WordPress-Security-Skills
mkdir -p .claude/skills
cp -r /tmp/WordPress-Security-Skills/skills/cron-background-job-security .claude/skills/cron-background-job-security
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Cron Background Job Security in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Cron Background Job Security on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Cron Background Job Security is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Cron & background job security

When to use this skill

Use this skill whenever code schedules or runs WordPress cron events:

  • Calling wp_schedule_event() or wp_schedule_single_event().
  • Writing a callback for a cron hook (add_action( 'my_plugin_daily_sync', ... )).
  • Running jobs through wp-cron.php, including externally triggered real cron.
  • Storing context (user ids, arguments) for a job to act on later.

Cron callbacks run with no current user. current_user_can() returns false for everything, and wp-cron.php is publicly reachable. Authorization must be captured at schedule time and re-verified inside the callback against stored context, not the absent current user.

Related: see the secrets-credentials-management skill for keeping keys out of cron URLs and the capability-permission-checks skill for normal request authorization.

Core principles (and why they matter)

  1. No current_user_can() inside cron callbacks. There is no logged-in user during cron execution. Capture the acting user or capability context when scheduling and re-verify it from stored data.
  2. wp-cron.php is public. Anyone can trigger it. The callback itself must enforce authorization, not rely on the trigger being hidden.
  3. Do not put secrets in scheduled URLs or args. Cron arguments are stored in the cron option; treat them as persistent but not secret.
  4. Sanitize and validate stored args. The job reads args that were stored earlier; validate them again before acting.
  5. Use wp_next_scheduled() to prevent duplicates. Without it, reactivations or repeated init hooks can schedule the same event many times.
  6. Clean up on deactivation. Use wp_clear_scheduled_hook() so events don't run for a deactivated plugin.

Step-by-step implementation

  1. Schedule the event with wp_next_scheduled() guard:
    php
    if ( ! wp_next_scheduled( 'my_plugin_daily_sync' ) ) {
        wp_schedule_event( time(), 'daily', 'my_plugin_daily_sync' );
    }
  2. If the job needs per-object authorization, store a user id or capability context alongside the args at schedule time (e.g., the user who queued a one-time export).
  3. In the callback, re-verify the stored context:
    • Look up the user and check user_can( $user_id, $capability ).
    • Validate object ids with get_post() / get_userdata() and check ownership/permission.
  4. Sanitize every stored arg before use.
  5. Avoid passing secrets or raw user input as cron args.
  6. On plugin deactivation, clear the hook.

Supporting references

ReferenceLoad when
Cron & background job security checklistBefore final verification of the cron & background job security controls.
Secure cron jobImplementing a recurring cron job with stored authorization context and deactivation cleanup.

Common AI mistakes / anti-patterns

Mistake 1 — Using current_user_can() inside a cron callback

php
// ❌ Insecure: current_user_can is meaningless during cron; this always fails.
add_action( 'my_plugin_daily_sync', function () {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    my_plugin_sync();
} );
php
// ✅ Secure: the scheduled event itself is the authorization boundary; validate data only.
add_action( 'my_plugin_daily_sync', 'my_plugin_run_daily_sync' );
function my_plugin_run_daily_sync() {
    $settings = get_option( 'my_plugin_sync_settings', array() );
    $endpoint = isset( $settings['endpoint'] ) ? esc_url_raw( $settings['endpoint'] ) : '';
    if ( ! $endpoint ) {
        return;
    }
    // No current_user_can needed — the fact the event was scheduled is the policy.
    my_plugin_sync( $endpoint );
}

Mistake 2 — Passing a secret in the cron URL

php
// ❌ Insecure: secret lands in the cron option and may appear in logs.
wp_schedule_single_event( time(), 'my_plugin_fetch', array( 'token' => $api_secret ) );
php
// ✅ Secure: store the secret in a wp-config constant or encrypted option; pass only ids.
wp_schedule_single_event( time(), 'my_plugin_fetch', array( 'feed_id' => $feed_id ) );
// Callback reads the secret from a secure location.

Mistake 3 — Trusting $_GET passed to a cron trigger

php
// ❌ Insecure: wp-cron.php is public and $_GET is attacker-controllable.
add_action( 'my_plugin_run_export', function () {
    $user_id = (int) $_GET['user_id'];
    my_plugin_export_for_user( $user_id );
} );
php
// ✅ Secure: capture and validate context at schedule time, then re-verify inside the job.
function my_plugin_queue_export( $user_id ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return false;
    }
    $user_id = absint( $user_id );
    wp_schedule_single_event( time(), 'my_plugin_run_export', array( 'user_id' => $user_id ) );
}

add_action( 'my_plugin_run_export', 'my_plugin_run_export_callback' );
function my_plugin_run_export_callback( $args ) {
    $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : 0;
    if ( $user_id <= 0 || ! user_can( $user_id, 'read' ) ) {
        return;
    }
    my_plugin_export_for_user( $user_id );
}

Mistake 4 — Scheduling duplicate events

php
// ❌ Risky: creates a new event on every init if not guarded.
add_action( 'init', function () {
    wp_schedule_event( time(), 'hourly', 'my_plugin_hourly' );
} );
php
// ✅ Secure: guard with wp_next_scheduled().
add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'my_plugin_hourly' ) ) {
        wp_schedule_event( time(), 'hourly', 'my_plugin_hourly' );
    }
} );

Mistake 5 — Forgetting to unschedule on deactivation

php
// ❌ Risky: scheduled hooks outlive the plugin — nothing clears them.
// (No register_deactivation_hook() anywhere in the plugin.)
register_activation_hook( __FILE__, function () {
    if ( ! wp_next_scheduled( 'my_plugin_hourly' ) ) {
        wp_schedule_event( time(), 'hourly', 'my_plugin_hourly' );
    }
} );
php
// ✅ Secure: clear scheduled hooks on deactivation.
register_deactivation_hook( __FILE__, 'my_plugin_deactivate' );
function my_plugin_deactivate() {
    wp_clear_scheduled_hook( 'my_plugin_hourly' );
    wp_clear_scheduled_hook( 'my_plugin_daily_sync' );
}

Correct code examples

An integration example — schedule, callback with stored-context verification, and deactivation cleanup — is in references/secure-cron-job.php. It calls my_plugin_generate_user_export( $user_id ), a project callback your plugin must provide (the file documents the contract); adapt names and hooks to your plugin.

Checklist

  • Cron callbacks do not rely on current_user_can().
  • Per-object jobs capture the acting user/context at schedule time and re-verify it in the callback.
  • Secrets are not passed as cron arguments or embedded in cron URLs.
  • Stored cron args are sanitized and validated before use.
  • wp_next_scheduled() prevents duplicate scheduled events.
  • Custom recurrence intervals are added via the cron_schedules filter before scheduling.
  • Scheduled hooks are cleared on plugin deactivation.
  • Failures are logged without exposing secrets or internal paths.

Official references

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Cron Background Job Security AI skill do?

Use when scheduling WordPress cron events with wp_schedule_event / wp_schedule_single_event or writing the callback that runs on a cron hook. Treats cron callbacks as running without a logged-in user, re-checks authorization against stored context rather than current_user_can, keeps secrets out of cron URLs, and validates any stored input the job consumes. Prevents unauthenticated privileged actions via the cron surface.

Why use Cron Background Job Security on TypingMind?

Because you install it once and use it with any model. Cron Background Job Security is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Cron Background Job Security in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/cron-background-job-security. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Cron Background Job Security?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Cron Background Job Security?

As many as you like. As long as a model supports skills, you can use Cron Background Job Security with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Cron Background Job Security AI skill free?

Yes. It is published on GitHub by wpultimatesecurity under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇