Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get Payment Buttons
- * Returns all payment buttons a user can use to pay for a given post.
- * @since 1.7
- * @version 1.1
- */
- if ( ! function_exists( 'mycred_sell_content_payment_buttons' ) ) :
- function mycred_sell_content_payment_buttons( $user_id = NULL, $post_id = NULL ) {
- if ( $user_id === NULL || $post_id === NULL ) return false;
- $settings = mycred_sell_content_settings();
- $post = get_post( $post_id );
- $result = false;
- if ( ! empty( $settings['type'] ) ) {
- $buttons = array();
- foreach ( $settings['type'] as $point_type ) {
- // Load point type
- $mycred = mycred( $point_type );
- $setup = mycred_get_option( 'mycred_sell_this_' . $point_type );
- $price = mycred_get_content_price( $post_id, $point_type, $user_id );
- $status = $setup['status'];
- // Manual mode
- if ( $settings['filters'][ $post->post_type ]['by'] == 'manual' ) {
- $suffix = ( $point_type != MYCRED_DEFAULT_TYPE_KEY ) ? '_' . $point_type : '';
- $manual_setup = (array) get_post_meta( $post_id, 'myCRED_sell_content' . $suffix, true );
- if ( ! empty( $manual_setup ) && array_key_exists( 'status', $manual_setup ) )
- $status = $manual_setup['status'];
- }
- // Point type not enabled
- if ( $status == 'disabled' ) continue;
- // Make sure we are not excluded from this type
- if ( $mycred->exclude_user( $user_id ) ) continue;
- // Make sure we can afford to pay
- if ( $mycred->get_users_balance( $user_id, $point_type ) < $price ) continue;
- $button_label = str_replace( '%price%', $mycred->format_creds( $price ), $setup['button_label'] );
- $button = '<button type="button" class="mycred-buy-this-content-button ' . $setup['button_classes'] . '" data-pid="' . $post_id . '" data-type="' . $point_type . '">' . $button_label . '</button>';
- $buttons[] = apply_filters( 'mycred_sell_this_button', $button, $post, $setup, $mycred );
- }
- if ( ! empty( $buttons ) )
- $result = implode( ' ', $buttons );
- }
- // Return a string of buttons or false if user can not afford
- return apply_filters( 'mycred_sellcontent_buttons', $result, $user_id, $post_id );
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement