• Resolved iamonlythird

    (@iamonlythird)


    I hope that you do not mind me flooding this board with questions. Many of which will certainly be useful for people that migrate from CubePoints.

    I will post all questions in separate threads so that they are easier to find for other users.

    In CubePoints, the following code:

    cp_show_logs(cp_currentUser(), 15 , false);

    Gives this:
    http://i.imgur.com/TgGpHJL.png

    How can I do this using myCRED? Ideally, without the User tab, it is not needed because the user is viewing only their own log.

    http://wordpress.org/plugins/mycred/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author myCred

    (@designbymerovingi)

    myCRED comes with several different shortcodes to help you achiieve these type of lists.
    One of these shortcodes is the mycred_history shortcode which allows you to show log entries for all users or a specific users with a few options at your disposal.

    Of course if the shortcode is not good enough, there is the myCRED_Query_Log class which is used by all log lists in myCRED. With it you can query almost anything from the myCRED Log.

    Thread Starter iamonlythird

    (@iamonlythird)

    Stellar documentation here, something that Cubepoints truly was lacking. Another reason to migrate here.

    Just a typographical issue to note. On the mycred_history page, you may want to change instances of “Show current users” to “Show current user’s” which is the accurate grammar.

    Plugin Author myCred

    (@designbymerovingi)

    Yes, I learned the lesson regarding documentation a long time ago. I decided early on that myCRED will have everything documented. Thanks for the grammar check.

    Thread Starter iamonlythird

    (@iamonlythird)

    @gabriel
    Should I be able to execute the following in the backend (custom plugin page in wp-admin):
    <?php do_shortcode( '[mycred_history number="20"]' ) ?>

    Plugin Author myCred

    (@designbymerovingi)

    No the shortcodes in that form is not available in the admin area. The functions that renders them are available though! You can find them in mycred/includes/mycred-shortcodes.php.

    For the mycred_history you would need to use the mycred_render_shortcode_history function.

    Thread Starter iamonlythird

    (@iamonlythird)

    Gabriel I am trying to figure out how to use the myCRED_Query_Log class to display a log table like this for current_user (without the User tab): http://i.imgur.com/TgGpHJL.png

    If you have time, can you please demonstrate how that can be done, I am lost in the codex page.

    Plugin Author myCred

    (@designbymerovingi)

    Hey

    From the myCRED_Query_Log documentation:

    $log = new myCRED_Query_Log( $args );
    unset( $log->headers['column-username'] );
    $log->display();
    Thread Starter iamonlythird

    (@iamonlythird)

    I executed that, it didn’t work, adding args user_id=1 for example worked fine. I will need to get the current user id, correct?

    EDIT: That was wrong, it still did not work. How do I make that code work for current_user?

    Plugin Author myCred

    (@designbymerovingi)

    Can you show me what you are trying to do?

    Thread Starter iamonlythird

    (@iamonlythird)

    Sure, sorry about the confusion. Within a custom plugin page in wp-admin, I want to display the log as that image that I linked above (no user tab). I want to display the log of the current_user that is logged in.

    I tried the following that you suggested:

    $log = new myCRED_Query_Log( $args );
    unset( $log->headers['column-username'] );
    $log->display();

    But it did not work. It shows two warnings:

    Warning: Invalid argument supplied for foreach() in /home/user/public_html/wp-content/plugins/mycred/includes/mycred-log.php on line 273
    
    Warning: Invalid argument supplied for foreach() in /home/user/public_html/wp-content/plugins/mycred/includes/mycred-log.php on line 283

    And then displays a "No log entries found" box.

    So I am guessing that I need to adjust that code so that it finds current_user ID and displays the log for this user, correct? Please let me know if I am not making sense.

    Plugin Author myCred

    (@designbymerovingi)

    Ok so you do not pass on any arguments to the myCRED_Query_Log() class? $args represent where your arguments should go, just pasing that in will not work.

    If you look at the documentation of the class you can see that if you want to query the log for a given user, you can do so by either:

    $log = new myCRED_Query_Log( 'user_id=1' );

    or

    $log = new myCRED_Query_Log( array( 'user_id' => 1 ) );

    You can find a complete list of examples of what is supported here.

    Thread Starter iamonlythird

    (@iamonlythird)

    Here was the problem. This didn’t work:
    $log = new myCRED_Query_Log( 'user_id=1' );

    It showed history of all users, not just user with ID 1.

    However, this:
    $log = new myCRED_Query_Log( array( 'user_id' => 1 ) );
    Worked fine.

    Plugin Author myCred

    (@designbymerovingi)

    Now with that query that works, you can combine it with the above snippet to remove the user name column. Of course, if you don’t want the table structure myCRED creates, you can build your own loop.

    Thread Starter iamonlythird

    (@iamonlythird)

    Excellent, thank you for the support. On a side note, I might have found a bug earlier today in a different area of the plugin. It is very minor, I will double check and post it within the hour.

    Thread Starter iamonlythird

    (@iamonlythird)

    Never mind the bug report, it was a local issue.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Display log in custom plugin page’ is closed to new replies.