activity-log icon indicating copy to clipboard operation
activity-log copied to clipboard

Could someone please provide a quick example how to record this action?

Open netconstructor opened this issue 9 years ago • 6 comments

This is the third time over the past year I have come back to this plugin, primarily due to its slick visual organization while meeting nearly 98% of my requirements. The problem I am having here is that I simply can't figure out the proper method to create a custom action trigger entry for my specific situation.

Let me point out in advance that I am well aware that what I aim to track would likely be incapable of scaling properly to more than a few concurrent users at a time and this is perfectly fine for my situation... I simply need a basic example of how it can be done.

The nature of my situation involves a custom wordpress website which is only accessible to about 50 individuals each of which need an existing pre approved wp user account to access the site. What I need to be able to do here is simply record every single page view on this domain for each of these users. Ideally I would like the information which gets recorded to include very basic information including date/timestamp, page title, post type name, any associated categories, tags, taxonomies and potentially some specific custom field value. The purpose of these logged pageviews simply need to allow the user to view his own activity and filter/sort it and allow an admin to do the same for all or a single user.

Could someone who has some basic experience with this plugin please provide a basic example of how to achieve this basic functionality?

Thanks in advance!

netconstructor avatar Apr 18 '16 16:04 netconstructor

Most definitely, @netconstructor!

What you can do is use the aal_insert_log() method, which will allow you to insert whatever event you'd like.

You can also take a look at some examples, found in the hooks directory within the plugin.

Good luck implementing!

maor avatar Apr 18 '16 22:04 maor

Thank you for your response. I have been attempting to implimented a custom logged activity hook through your plugin but I seem to be unable to get this implimented correctly.

I want to ensure my objective is properly implimented with minimal load on the system while properly hooking/logging all pageviews to any frontend pages (no backend page views) and only for those users who are properly logged in.

In your professional expertise and direct experience could you please clarify if my objective is far more involved than it should be? If possibly and not overly complicated I would greatly appreciate if you might be able to provide the proper code to achieve this properly. Greatly appreciate your help here in advance!

netconstructor avatar Apr 22 '16 05:04 netconstructor

Bump

netconstructor avatar Apr 28 '16 13:04 netconstructor

I have and issue like this, i insert the data with aal_insert_log() but not showing in the list of logs, but is inserting in the data base, i miss something?

gfirem avatar Sep 15 '16 03:09 gfirem

Facing the same issue. as @gfirem. Any idea why the logs are not displayed in WP admin list ?

dmbostan avatar Nov 18 '16 14:11 dmbostan

Hi, resolve by my own. I use the filter aal_init_roles, see the next example.

add_filter( 'aal_init_roles', array( $this, 'aal_init_roles' ) );

public function aal_init_roles( $roles ) {
    $roles_existing          = $roles['manage_options'];
    $roles['manage_options'] = array_merge( $roles_existing, array( "CustomRole" ) );

    return $roles;
}

I insert using the next function aal_insert_log( $args );

    aal_insert_log( array(
        'action'         => "Updated",
        'object_type'    => 'CustomRole',
        'object_subtype' => "tooltips-attributes",
        'object_name'    => "Updated tooltips attributes. <div id='log_full_description' class='privanz_log_full'> " . $diff . "</div>",
    ) );

I need to insert more data in the description and i change the current type of the mysql column like the next script.

public function set_aryo_activity_log_column() {
    global $wpdb;
    $type = $wpdb->get_var( "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'wp_aryo_activity_log' AND column_name = 'object_name'" );
    if ( $type == "varchar" ) {
        $wpdb->query( "ALTER TABLE wp_aryo_activity_log CHANGE COLUMN object_name object_name blob" );
    }
}

And finally i am saving a big json inside the description i change the column into the log table using the next code and insert a code to show a popup in the footer.

    add_action( 'aal_table_list_column_description', array( $this, 'log_description' ), 10, 2 );
    add_filter( 'admin_print_footer_scripts', array( $this, 'include_in_footer' ), 50 );

public function log_description( $return, $item ) {
    if (strpos($return, 'log_full_description') !== false) {
            $return = $return . " <a class='log_more_btn' href='#'>" . __( "more", "xxx" ) . "...</a>";
    }

    return $return;
}
public function include_in_footer() {
    global $plugin_page;
    if ( 'activity_log_page' != $plugin_page || ! is_admin() ) {
        return;
    }
        ....
}

I hope this code help to other! www.gfirem.com

gfirem avatar Nov 18 '16 19:11 gfirem