Filter uncanny-automator-pro

peepso_activity_insert_data

Filters activity data before it's inserted into the database, allowing modification of the content.

add_filter( 'peepso_activity_insert_data', $callback, 10, 1 );

Description

Filters the data array before a new activity post is inserted into the PeepSo database. Developers can modify properties like `act_owner_id`, `act_module_id`, `act_external_id`, `act_access`, and `act_ip` to customize activity data. This hook fires just before the database insertion.


Usage

add_filter( 'peepso_activity_insert_data', 'your_function_name', 10, 1 );

Parameters

$a_act_data (mixed)
This parameter contains an array of data that will be inserted into the PeepSo activity stream.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the data being inserted into the PeepSo activity table.
 * This example adds a custom field 'act_custom_data' to the activity entry.
 *
 * @param array $a_act_data The array of data for the activity entry.
 * @return array Modified array of data for the activity entry.
 */
add_filter( 'peepso_activity_insert_data', function( $a_act_data ) {

    // Ensure $a_act_data is an array before proceeding.
    if ( ! is_array( $a_act_data ) ) {
        return $a_act_data; // Return as is if not an array
    }

    // Assume we have a relevant user ID or context to add custom data.
    // In a real scenario, you'd likely get this from global variables,
    // other filters, or passed context. For this example, we'll use a placeholder.
    $user_context_data = get_user_meta( get_current_user_id(), 'user_specific_activity_context', true );

    // Add a custom field to the activity data.
    // This assumes your PeepSo activity table has a column for custom data,
    // or you might be using a separate table/mechanism to store this.
    // For demonstration, let's assume a field named 'act_custom_data'.
    if ( ! empty( $user_context_data ) ) {
        $a_act_data['act_custom_data'] = json_encode( $user_context_data );
    } else {
        $a_act_data['act_custom_data'] = 'default_context'; // Or some other default
    }

    // You can also modify existing fields if needed.
    // For example, to ensure a specific module ID is always set:
    if ( isset( $a_act_data['act_module_id'] ) && $a_act_data['act_module_id'] == 5 ) {
        // This is already module 5, maybe do something else or do nothing.
    }

    // Always return the modified data array.
    return $a_act_data;

}, 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

uncanny-automator-pro/src/integrations/peepso/actions/peepso-createactivitypost.php:157

'act_owner_id'    => $user_id,
			'act_module_id'   => 1,
			'act_external_id' => $id,
			'act_access'      => $privacy,
			'act_ip'          => PeepSo::get_ip_address(),
		);

		$a_act_data = apply_filters( 'peepso_activity_insert_data', $a_act_data );

		global $wpdb;
		$res = $wpdb->insert( $wpdb->prefix . $table_name, $a_act_data );

		if ( ! is_int( $res ) ) {
			$error_message                       = sprintf( __( 'Unable to create activities entry: %s', 'uncanny-automator-pro' ), $wpdb->last_error );
			$action_data['complete_with_errors'] = true;


Scroll to Top