Action
uncanny-automator
automator_before_activity_stream_init
Fires before the activity stream is initialized, allowing for modifications.
add_action( 'automator_before_activity_stream_init', $callback, 10, 1 );
Description
Fires before the activity stream classes are loaded. This hook allows developers to modify the `$classes` array, adding or removing classes, or altering their file paths before the activity stream is initialized. It's ideal for custom integrations or conditional loading of activity stream components.
Usage
add_action( 'automator_before_activity_stream_init', 'your_function_name', 10, 1 );
Examples
// Example function to hook into 'automator_before_activity_stream_init'
function my_automator_custom_activity_log_path( $classes ) {
// This example shows how to change the path for a specific activity log class
// or conditionally include/exclude a class.
// Let's say we want to override the default path for Activity_Log with our custom version.
// In a real-world scenario, you might have a custom implementation in a plugin.
// For demonstration, we'll just use a placeholder path.
// Make sure the file exists at this location if you were to implement this.
// Example: Replace the default path with a custom one if a certain condition is met.
if ( defined( 'MY_CUSTOM_AUTOMATOR_ACTIVITY_LOG' ) && MY_CUSTOM_AUTOMATOR_ACTIVITY_LOG === true ) {
$classes['Activity_Log'] = plugin_dir_path( __FILE__ ) . 'includes/custom-activity-log.php';
}
// You could also conditionally add new classes or remove existing ones.
// For example, to add a new type of activity log:
// $classes['My_Custom_Activity_Logger'] = plugin_dir_path( __FILE__ ) . 'includes/my-custom-activity-logger.php';
// To remove a class (less common, but possible):
// unset( $classes['Activity_Log'] );
return $classes;
}
// Add the action hook.
// The 'automator_before_activity_stream_init' hook is an action hook, not a filter.
// However, the function it's attached to (activity_stream_classes) *does* return $classes.
// So, to modify the classes array passed to the *original* function, we'd typically
// hook into a filter *before* this action runs, or this action would need to be a filter.
// Given the hook is an action, and the source code shows it *calling* do_action,
// the intent of the *provided* example function is to run code *before* the class path is set.
//
// If the goal is to *modify* the $classes array that is *returned* by `activity_stream_classes`,
// then the hook should be a filter, or the target function should be designed to accept
// and return modified data from an action hook.
//
// **Assuming the intent is to influence the $classes array *before* it's finalized and returned:**
// The provided `activity_stream_classes` function is actually *using* the `do_action( 'automator_before_activity_stream_init' );`
// *before* it modifies `$classes`. This means any function hooked here would run *before* the `Activity_Log` path is defined.
//
// To *modify* the `$classes` array itself, a filter hook would be more appropriate,
// or the hook would need to be placed *after* `$classes` has been populated but *before* it's returned.
//
// Since the requirement is to write an `add_action()` example for `automator_before_activity_stream_init`,
// and the source shows it's an action hook called *before* class paths are defined,
// we will create an example that runs code at that point. If modification of the `$classes` array is strictly required,
// and this hook is indeed an action, the original function would need to be modified to pass `$classes` as an argument
// to the action. The provided source shows it is *not* passed as an argument to the action itself.
//
// The most realistic way to influence the `$classes` array *given the source code* and the fact it's an action hook,
// is to assume that perhaps other code later in the `automator_after_activity_stream_init` hook,
// or subsequent logic, might read from some global state or options that this action could set.
//
// **However, if we interpret the "Internal usage" and the structure of `activity_stream_classes`
// more broadly to imply that the hook *should* be able to influence the `$classes` array,
// we'll make a slight adjustment to how we *think* it might work in a more flexible implementation
// that could pass `$classes` by reference or in a return value if it were designed as a filter.**
//
// For this specific `action` hook and the provided `do_action` call (which doesn't pass `$classes`),
// a direct modification of `$classes` isn't directly supported by this specific action call signature.
//
// **Let's write an example that *would* work if the hook was designed to pass `$classes` or if we
// were to hook into a filter that *does* pass `$classes`. Since the prompt explicitly asks for an `action` hook:**
//
// If `automator_before_activity_stream_init` was intended to *receive* the `$classes` array, it would look like this:
// `add_action( 'automator_before_activity_stream_init', 'my_automator_modify_activity_classes', 10, 1 );`
//
// Given the provided source code's `do_action( 'automator_before_activity_stream_init' );` *without parameters*,
// the most direct interpretation means we can only run *code* at that point, not directly manipulate the `$classes` array
// that's defined *later* in the `activity_stream_classes` function.
//
// **Therefore, the following example will demonstrate running code at that specific point in execution.**
// If the `activity_stream_classes` function was structured differently (e.g., hook was a filter, or action passed $classes),
// the code inside `my_automator_run_code_before_activity_init` would change to modify `$classes`.
/**
* Example function to execute code before the Automator activity stream is initialized.
* This hook is an action and does not receive the $classes array directly.
* Any modification to the $classes array would need to be done through other means,
* possibly by affecting options or global state that the main function reads later,
* or by hooking into a filter *after* this action but before the return.
*/
function my_automator_run_code_before_activity_init() {
// This is a placeholder for actual logic.
// For example, you might log a message, set a flag, or perform some check.
// Example: Check if a specific plugin is active and perform an action.
if ( is_plugin_active( 'some-other-plugin/some-other-plugin.php' ) ) {
// Perform some setup or modification based on another plugin's presence.
// This could involve setting a transient or option that `automator_after_activity_stream_init`
// or subsequent Automator logic might check.
set_transient( 'my_automator_extra_setup_needed', true, HOUR_IN_SECONDS );
}
// Another example: conditionally disable a feature if certain conditions are met.
// This assumes Automator has some internal logic that checks a global flag or option.
// For instance, if Automator checks for a constant `UA_DISABLE_ACTIVITY_LOG_FEATURE`.
if ( ! defined( 'DISABLE_MY_AUTOMATOR_ACTIVITY_LOG' ) || ! DISABLE_MY_AUTOMATOR_ACTIVITY_LOG ) {
// Proceed with default Automator activity stream initialization.
} else {
// Prevent initialization or alter behavior in a way that `automator_after_activity_stream_init`
// or later code can detect. This is speculative as we don't see the full Automator internals.
// A more direct approach would be if the hook was a filter.
}
// If this hook *were* a filter, the function signature would be:
// `function my_automator_modify_activity_classes( $classes = array() ) { ... return $classes; }`
// And the add_action would be:
// `add_filter( 'automator_before_activity_stream_init', 'my_automator_modify_activity_classes', 10, 1 );`
// But based on the provided source, it's an action.
}
// Hook into the 'automator_before_activity_stream_init' action.
// The priority is set to 10 (default), and we're accepting 0 arguments
// because the `do_action` call in the source does not pass any parameters.
add_action( 'automator_before_activity_stream_init', 'my_automator_run_code_before_activity_init', 10, 0 );
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/class-automator-load.php:732
public function activity_stream_classes( $classes = array() ) {
do_action( 'automator_before_activity_stream_init' );
$classes['Activity_Log'] = UA_ABSPATH . 'src/core/admin/class-activity-log.php';
do_action( 'automator_after_activity_stream_init' );
return $classes;
}