Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
netconstructor opened this issue Apr 18, 2016 · 6 comments
Assignees

Comments

@netconstructor
Copy link

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!

@maor
Copy link
Contributor

maor commented Apr 18, 2016

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!

@netconstructor
Copy link
Author

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
Copy link
Author

Bump

@gfirem
Copy link

gfirem commented Sep 15, 2016

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?

@dmbostan
Copy link

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

@gfirem
Copy link

gfirem commented Nov 18, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants