Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Overwrite the mycred_give shortcode
- * Runs after myCRED has registered the shortcode in order for us
- * to remove it and replace it with our own.
- */
- add_action( 'mycred_init', 'custom_mycred_start' );
- function custom_mycred_start() {
- remove_shortcode( 'mycred_give' );
- add_shortcode( 'mycred_give', 'mycred_custom_render_shortcode_give' );
- }
- if ( ! function_exists( 'mycred_custom_render_shortcode_give' ) ) :
- function mycred_custom_render_shortcode_give( $atts, $content )
- {
- if ( ! is_user_logged_in() ) return;
- extract( shortcode_atts( array(
- 'amount' => NULL,
- 'user_id' => '',
- 'log' => '',
- 'ref' => 'gift',
- 'limit' => 0,
- 'type' => 'mycred_default'
- ), $atts ) );
- if ( $amount === NULL )
- return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Amount missing!', 'mycred' );
- if ( empty( $log ) )
- return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Log Template Missing!', 'mycred' );
- $mycred = mycred_get_settings();
- if ( empty( $user_id ) )
- $user_id = get_current_user_id();
- // Check for exclusion
- if ( $mycred->exclude_user( $user_id ) ) return;
- // Prep amount
- $amount = $mycred->number( $amount );
- // Daily limit handling
- if ( $limit == 'daily' ) {
- // Todays date as a numeric value
- $today = (int) date_i18n( 'Ymd' );
- // Check if user has received points today
- if ( $mycred->has_entry( $ref, $today, $user_id ) ) return;
- // Save today as a reference id to check for
- $mycred->add_creds(
- $ref,
- $user_id,
- $amount,
- $log,
- $today,
- '',
- $type
- );
- }
- // Default limit handling
- else {
- $limit = abs( $limit );
- if ( $limit != 0 && mycred_count_ref_instances( $ref, $user_id ) >= $limit ) return;
- $mycred->add_creds(
- $ref,
- $user_id,
- $amount,
- $log,
- '',
- '',
- $type
- );
- }
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement