Hey oomskaap
Thank you for your question. The following code does exactly the same thing as your code assuming it is placed in your page template file:
if ( class_exists( 'myCRED_Core' ) && is_user_logged_in() && !mycred_exclude_user( get_current_user_id() ) ) {
global $post;
mycred_add( 'points_for_page_view', get_current_user_id(), 300, 'Points for viewing page', $post->ID );
}
The above code translates into: If myCRED is activated, the current user is logged in and the user is not excluded, add 300 points to the current user with the reference “points_for_page_view” and the page ID as reference id. The reference is used by the log to allow users (and you) to filter results according to reference. myCRED will replace underscores with whitespaces and return each word in upper case so make sure the reference is explanatory.
You can find more information about the mycred_add function in our Codex. In this above example, the log will be populated with “Points for viewing page.”. If you want to take advantage of the template tags to for example include the page title you would do it as follows:
if ( class_exists( 'myCRED_Core' ) && is_user_logged_in() && !mycred_exclude_user( get_current_user_id() ) ) {
global $post;
mycred_add( 'points_for_page_view', get_current_user_id(), 300, 'Points for viewing the page %post_title%', $post->ID, array( 'ref_type' => 'post' ) );
}
As you can see the differernce here beside us using the %post_title% template tag is to pass on a sixth variable to mycred_add which is an array defining that the template tag is for posts (no matter post type). This way when myCRED presents your log, the template tag is replaced with the post title.
I am using class_exists in the above codes but of course a function_exists check for mycred_add would also work.
Let me know if you have any issues or further queries.
Update
I forgot to include the mycred_exclude_user check to make sure the current user is not excluded (since you can exclude users if you want).