Action
uncanny-automator
automator_database_views_before
Fires before Automator's database views are rendered, allowing modification of the query or data.
add_action( 'automator_database_views_before', $callback, 10, 1 );
Description
Fires before Automator plugin creates or updates database views. Developers can hook into this action to perform custom setup or validation tasks related to view generation, ensuring consistency before any database modifications occur.
Usage
add_action( 'automator_database_views_before', 'your_function_name', 10, 1 );
Examples
/**
* Example of using the 'automator_database_views_before' action hook.
* This function demonstrates how you might intercept the view generation process
* to perform some pre-checks or logging before the actual views are created or updated.
*
* @param Automator_DB $automator_db The instance of the Automator_DB class.
*/
function my_automator_custom_view_logic( $automator_db ) {
// Log that the view generation process is about to start.
error_log( 'Automator: Pre-check for database view generation initiated.' );
// You could add a conditional check here. For example, maybe you only want to
// allow view creation during specific maintenance windows.
$current_time = current_time( 'timestamp' );
$maintenance_start = strtotime( '2023-10-27 02:00:00' ); // Example maintenance start time
$maintenance_end = strtotime( '2023-10-27 04:00:00' ); // Example maintenance end time
if ( $current_time >= $maintenance_start && $current_time <= $maintenance_end ) {
error_log( 'Automator: View generation is allowed during this maintenance window.' );
// Proceed with view generation (this is handled by the core function itself)
} else {
error_log( 'Automator: View generation is NOT allowed outside the maintenance window. Skipping for now.' );
// In a real scenario, you might prevent the core logic from running if this were a filter.
// Since this is an action, we can just log and exit gracefully, the core function will still run.
// If you needed to STOP the core function, a filter would be more appropriate.
}
// You could also potentially inspect the automator_db object for more context.
// For instance, if you had custom settings you wanted to check.
// Example: if ( $automator_db->some_custom_method_to_check_settings() ) { ... }
}
add_action( 'automator_database_views_before', 'my_automator_custom_view_logic', 10, 1 ); // Priority 10, accepts 1 argument
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/class-automator-db.php:386
public function automator_generate_views() {
do_action( 'automator_database_views_before' );
if ( AUTOMATOR_DATABASE_VIEWS_VERSION !== automator_get_option( 'uap_database_views_version', 0 ) ) {
self::create_views();
}
do_action( 'automator_activation_views_after' );
}