Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode( 'mycred_conditional_link', 'mycred_render_conditional_link' );
- function mycred_render_conditional_link( $atts, $content ) {
- // Make sure myCRED is installed
- if ( ! function_exists( 'mycred' ) ) return 'myCRED is not installed';
- $atts = shortcode_atts( array(
- 'id' => '',
- 'rel' => '',
- 'class' => '',
- 'href' => '',
- 'title' => '',
- 'target' => '',
- 'style' => '',
- 'amount' => 0,
- 'ctype' => 'mycred_default',
- 'min_balance' => 0,
- 'hreflang' => '', // for advanced users
- 'media' => '', // for advanced users
- 'type' => '' // for advanced users
- ), $atts );
- // Check minimum balance requirement
- if ( $atts['min_balance'] > 0 && is_single() ) {
- global $post;
- $mycred = mycred( $atts['ctype'] );
- $author_id = $post->post_author;
- $balance = $mycred->get_users_balance( $author_id, $atts['ctype'] );
- // If balance is lower than the limit we return nothing.
- if ( $balance < $mycred->number( $atts['min_balance'] ) )
- return '';
- }
- // Let myCRED run the mycred_link shortcode.
- return mycred_render_shortcode_link( $atts, $content );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement