Plugin Author
myCred
(@designbymerovingi)
Hey Luis.
1. [mycred_send]
This shortcode allows the current user to send points to a pre-set user (if they can afford it). In your example, you have set that the current user, if has enough points, can send 0.01 points to the post author as a “Post Appreciation”.
For this shortcode to work, the shortcode must be inside the loop!
2. [mycred_share_this]
This is a custom shortcode you got from the online tutorial. This shortcode awards points to the current user who clicks on the link and not the author, unless you customized it yourself.
So you can let the current user “Vote” for a post by giving that user 0.01 points but the share feature is for the current user and has no effect on the post author.
how can I change the shortcode to the id is always the author?
i tried change:
// If no id exists, make one
if ( empty( $atts['id'] ) ) {
$id = str_replace( array( 'http://', 'https://', 'http%3A%2F%2F', 'https%3A%2F%2F' ), 'hs', $atts['href'] );
$id = str_replace( array( '/', '-', '_', ':', '.', '?', '=', '+', '\\', '%2F' ), '', $id );
$atts['id'] = $id;
}
for this
if ( $atts['id'] == 'author' ) {
// You can not use this outside the loop
$author = get_the_author_meta( 'ID' );
if ( empty( $atts['id'] ) ) $author = $GLOBALS['post']->post_author;
$atts['id'] = $author;
}
but don’t work
Plugin Author
myCred
(@designbymerovingi)
Hey Luis.
First of all, any changes you make to the plugin files will be lost the next time you update myCRED so this is not a good solution.
Second, you are confusing the element ID with the User ID. The ID you are quoting is the element ID and is required as link clicks are encoded to prevent users from manipulating the code before clicking on the link.
If you want to change how a specific feature in myCRED works, you should replace it. Most functions in myCRED are pluggable meaning you can override them via your theme or plugin.
Now in this example, you are looking to change who gets points when a user clicks on a link. To do this, you would need to do three things:
1. You would need to copy the myCRED_Hook_Click_Links class and adjust it to award points to the post author instead of the current user.
http://pastebin.com/1FEqRGdd
2. Copy the mycred_render_shortcode_link function and adjust it to pass along the post ID as well so we know which post author to award points to.
http://pastebin.com/XrbmvZSU
3. Create your own link script that is used instead of what comes with myCRED.
http://pastebin.com/AZyHwQku
In the code snippets I have linked above I have marked all changes with “ADJUSTMENT” in order to show you what I have done. Just copy and paste these codes into your themes functions.php file, adjust them to your needs (i.e. where you save the js file) and you are set.
As you can see the only changes I have made is to pass along the post ID to the myCRED_Hook_Click_Links class via the AJAX call in order to know which post author to award.
Right now you will notice that I have left the login check in-place which means that users must be logged in for the author to get points. If this does not suit your needs, you would need to remove the login checks and adjust the ajax call action.