apply_filters( ‘cron_memory_limit’, int|string $filtered_limit )

Filters the memory limit allocated for WP-Cron event processing.

Parameters

$filtered_limitint|string
Maximum memory limit to allocate for WP-Cron.
Default WP_MAX_MEMORY_LIMIT or the original php.ini memory_limit, whichever is higher.
Accepts an integer (bytes), or a shorthand string notation, such as '256M'.

Source

$filtered_limit = apply_filters( 'cron_memory_limit', $filtered_limit );

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    // This is your callback function that adjusts the memory limit for cron tasks
    function wpdocs_cron_memory_limit( $limit ) {
        // You can modify the memory limit based on your requirements
        // For this example, let's increase the limit by 128M
        if ( is_numeric( $limit ) ) {
            $new_limit = $limit + 128;
            return $new_limit;
        }
    
        return $limit;
    }
    
    // Hook your custom function to the 'cron_memory_limit' filter
    add_filter( 'cron_memory_limit', 'wpdocs_cron_memory_limit' );
    
    // Somewhere in your code where you need to retrieve the adjusted memory limit
    $memory_limit = apply_filters( 'cron_memory_limit', ini_get( 'memory_limit' ) );
    
    echo 'Adjusted memory limit for cron tasks: ' . $memory_limit;

    In this example, we’re assuming you are working within a WordPress environment and you want to adjust the memory limit for cron tasks. The apply_filters function allows you to apply a series of filters to a specific value, in this case, the memory limit. The custom_cron_memory_limit function acts as a filter callback, adjusting the memory limit by adding 128M to it.

    When you call apply_filters('cron_memory_limit', ini_get('memory_limit')) WordPress will execute your custom function and pass the current memory limit value as an argument. Your function will then modify the limit and return the adjusted value, which will be used wherever the apply_filters function is called. Finally, the adjusted memory limit is echoed out in the example.

You must log in before being able to contribute a note or feedback.