Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Store the Profile ID
- * Since we can not ge the profile ID using um_user_permissions_filter filter
- * we globalise it now so we can access it later.
- * @version 1.0
- */
- add_action( 'um_after_follow_button_profile', 'mycredpro_save_profile_id_global', 1 );
- function mycredpro_save_profile_id_global( $user_id ) {
- global $mycred_em_profile_id, $mycred_em_charge;
- $mycred_em_profile_id = $user_id;
- $mycred_em_charge = false;
- }
- /**
- * Stop Message
- * Stop a user from sending a message if the parties
- * do not fulfill our requirements.
- * @version 1.0
- */
- add_filter( 'um_user_permissions_filter', 'mycredpro_stop_um_message', 10, 2 );
- function mycredpro_stop_um_message( $roles, $user_id ) {
- global $mycred_em_profile_id, $mycred_em_charge;
- if ( ! function_exists( 'mycred' ) ) return $roles;
- // In case you use multiple point types and need to use a custom type,
- // you enter your custom point type key here. For default leave as is.
- $point_type = 'mycred_default';
- // Next lets load myCRED
- $mycred = mycred( $point_type );
- // The cost of the message.
- $cost = 5;
- if ( $mycred_em_profile_id !== NULL && $mycred_em_profile_id != $user_id ) {
- // Get user objects so we can check roles
- $sender = get_userdata( $user_id );
- $senders_roles = $sender->roles;
- $recipient = get_userdata( $mycred_em_profile_id );
- $recipients_roles = $recipient->roles;
- // Check if this is a conversation between a buyer and seller (based of WP Roles)
- if ( in_array( 'verkoper', $senders_roles ) && in_array( 'koper', $recipients_roles ) ) {
- // Get senders balance
- $balance = $mycred->get_users_balance( $user_id, $point_type );
- // Sorry but not enough funds, show error message
- if ( $balance < $cost ) {
- $roles['can_start_pm'] = false;
- }
- else {
- $mycred_em_charge = true;
- }
- }
- }
- return $roles;
- }
- /**
- * Charge Conversation
- * Charges the conversaion between two parties.
- * @version 1.0
- */
- add_action( 'um_after_new_message', 'mycredpro_charge_um_conversation', 10, 3 );
- function mycredpro_charge_um_conversation( $user1, $user2, $conversation_id ) {
- global $mycred_em_charge;
- // See if we should charge this instance.
- if ( $mycred_em_charge !== true ) return;
- // Ok, if we got this far, we can send messages. Lets make sure myCRED is installed.
- if ( ! function_exists( 'mycred' ) ) return;
- // In case you use multiple point types and need to use a custom type,
- // you enter your custom point type key here. For default leave as is.
- $point_type = 'mycred_default';
- // Next lets load myCRED
- $mycred = mycred( $point_type );
- // The cost of the message.
- $cost = 5;
- // Now, lets charge!
- $mycred->add_creds(
- 'um_sent_message',
- $user1,
- 0 - $cost,
- 'New message sent to %display_name%',
- $user2,
- array( 'ref_type' => 'user' ), // This allows the use of user related template tags
- $point_type
- );
- // Now, lets give the seller the points
- $mycred->add_creds(
- 'um_received_message',
- $user2,
- $cost,
- 'New message from %display_name%',
- $user1,
- array( 'ref_type' => 'user' ), // This allows the use of user related template tags
- $point_type
- );
- }
Add Comment
Please, Sign In to add comment