Filter
uncanny-automator
automator_dashboard_recent_articles_posts_expiration
Filters the expiration duration for recent articles displayed on the Automator dashboard in seconds.
add_filter( 'automator_dashboard_recent_articles_posts_expiration', $callback, 10, 1 );
Description
Filters the expiration time for cached recent articles in the Automator dashboard. Developers can modify this value to control how often the dashboard fetches fresh article data, impacting performance and data freshness. The default is one day.
Usage
add_filter( 'automator_dashboard_recent_articles_posts_expiration', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Filter hook: automator_dashboard_recent_articles_posts_expiration
*
* Example: Extend the default expiration time for recent articles cache.
*
* The default expiration is DAY_IN_SECONDS. This example changes it to 2 days.
*/
add_filter( 'automator_dashboard_recent_articles_posts_expiration', 'my_automator_recent_articles_expiration', 10, 1 );
function my_automator_recent_articles_expiration( $expiration_time ) {
// Extend the expiration time from DAY_IN_SECONDS to 2 days.
// DAY_IN_SECONDS is a WordPress constant representing seconds in a day (86400).
$two_days_in_seconds = DAY_IN_SECONDS * 2;
// Return the new expiration time in seconds.
return $two_days_in_seconds;
}
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/services/dashboard/recent-articles.php:70
public function __construct() {
$this->api_url = $this->api_base_url . "?automator_dashboard=yes&_embed=wp:term&per_page={$this->per_page}";
///wp-json/wp/v2/posts?automator_dashboard=yes&_embed=wp:term&per_page=4
$this->expiration = apply_filters( 'automator_dashboard_recent_articles_posts_expiration', DAY_IN_SECONDS );
}