• Resolved reckez

    (@reckez)


    Hi there great plugin, I would love to send custom sms to users when custom emails are sent too an example of the fuction sending custom emails is below:

    	function bid_mail( $bid_id ) {
    
    		$project_id  = get_post_field( 'post_parent', $bid_id );
    		$post_author = get_post_field( 'post_author', $project_id );
    		$author      = get_userdata( $post_author );
    		if ( $author ) {
    			$message = ae_get_option( 'bid_mail_template' );
    			$bid_msg = get_post_field( 'post_content', $bid_id );
    			$message = str_replace( '[message]', $bid_msg, $message );
    			$subject = sprintf( __( "Your project posted on %s has a new bid.", ET_DOMAIN ), get_option( 'blogname' ) );
    
    			return $this->wp_mail( $author->user_email, $subject, $message, array(
    				'post'    => $project_id,
    				'user_id' => $post_author
    			), '' );
    		}
    
    		return false;
    	}

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Mostafa Soufi

    (@mostafas1990)

    Use the below functions:

    <?php
    	function bid_sms( $bid_id ) {
    
    		$project_id  = get_post_field( 'post_parent', $bid_id );
    		$post_author = get_post_field( 'post_author', $project_id );
    		$mobile		 = get_user_meta( $post_author, 'mobile', true );
    
    		if ( $mobile ) {
    			global $sms;
    			$sms->to = array($mobile);
    			$sms->msg = 'Your message';
    			$sms->SendSMS();
    		}
    
    		return false;
    	}
    Thread Starter reckez

    (@reckez)

    Thank you very much for that. I couldn’t get the user number from registration page and register it in the database. Please help. My registration page is https://vigowork.com/register
    https://vigowork.com/register/?role=freelancer
    https://vigowork.com/register/?role=employer

    They both use a single registration.php file. How to get phone number on registration? Thanks a lot

    Thread Starter reckez

    (@reckez)

    Also how to get specific post author meta number? Thank you.

    U must try to add an <input> element in your Registration Forms and then save it to your Database.

    An input element like this :

    <input type="tel" name="usr_tel">

    After that, U can handle your SMS actions, what u want $_POST or $_GET from your forms or saved Data in your Database, Same as get_user_meta() function that we have on past replies.

    Thread Starter reckez

    (@reckez)

    This is my input in registration.php, I have tried for hours to save it to database but can’t. what do I do from here? do i put some code in functions.php file? please help

    	<div class="fre-input-field">
    								<input type="number" name="user_phone" id="user_phone" placeholder="<?php _e("Mobile Number, DON'T USE + e.g 49xxxxx ", ET_DOMAIN);?>">
    							</div>
    • This reply was modified 6 years, 2 months ago by reckez.
    Thread Starter reckez

    (@reckez)

    I found this in a core file of the theme, am i in the right place?

    	public function insert( $user_data ) {
    
    		//the insert function could not have the ID
    		if ( isset( $user_data['ID'] ) ) {
    			unset( $user_data['ID'] );
    		}
    
    		 if ( ! $user_data['user_login'] || ! preg_match( '/^[a-z\d_]{2,20}$/i', $user_data['user_login'] ) ) {
    		 	return new WP_Error( 'username_invalid', __( "Username only lowercase letters (a-z) and numbers are allowed. e.g johndoe or johndoe1990", ET_DOMAIN ) );
    		 }
    		if ( ! isset( $user_data['user_email'] ) || ! $user_data['user_email'] || $user_data['user_email'] == '' || ! is_email( $user_data['user_email'] ) ) {
    			return new WP_Error( 'email_invalid', __( "Email field is invalid.", ET_DOMAIN ) );
    		}
    		if ( ! isset( $user_data['user_pass'] ) || ! $user_data['user_pass'] || $user_data['user_pass'] == '' ) {
    			return new WP_Error( 'pass_invalid', __( "Password field is required.", ET_DOMAIN ) );
    		}
    		if ( ! isset( $user_data['user_phone'] ) || ! $user_data['user_phone'] || $user_data['user_phone'] == '' ) {
    			return new WP_Error( 'pass_invalid', __( "Phone Number field is required.", ET_DOMAIN ) );
    		}
    		if ( isset( $user_data['repeat_pass'] ) && $user_data['user_pass'] != $user_data['repeat_pass'] ) {
    			return new WP_Error( 'pass_invalid', __( "Repeat Passwords mismatch.", ET_DOMAIN ) );
    		}
    
    		$user_data = apply_filters( 'ae_pre_insert_user', $user_data );
    		if ( ! $user_data || is_wp_error( $user_data ) ) {
    			return $user_data;
    		}
    	
    		//check role for users
    		if ( ! isset( $user_data['role'] ) ) {
    			$user_data['role'] = 'author';
    		}
    		/**
    		 * insert user by wp_insert_user
    		 */
    		$result    = wp_insert_user( $user_data );
    		$user_pass = $user_data['user_pass'];
    
    		if ( $result != false && ! is_wp_error( $result ) ) {
    
    			/**
    			 * update user meta data
    			 */
    			foreach ( $this->meta_data as $key => $value ) {
    
    				// update if meta data exist
    				if ( isset( $user_data[ $value ] ) ) {
    					update_user_meta( $result, $value, $user_data[ $value ] );
    				}
    			}

    Ofc u need to save data first from your forms with update_user_meta() and then u can get the value from your DB with get_user_meta().

    Check these links:
    https://codex.www.ads-software.com/Function_Reference/update_user_meta
    https://codex.www.ads-software.com/Function_Reference/get_user_meta

    Thread Starter reckez

    (@reckez)

    I did it like this, is this correct?

    	/**
    		 * insert user by wp_insert_user
    		 */
    		$result    = wp_insert_user( $user_data );
    		$user_pass = $user_data['user_pass'];
    		$mobile    = $user_data['user_phone'];
    
    		if ( $result != false && ! is_wp_error( $result ) ) {
    
    			/**
    			 * update user meta data
    			 */
    			foreach ( $this->meta_data as $key => $value ) {
    
    				// update if meta data exist
    				if ( isset( $user_data[ $value ] ) ) {
    					update_user_meta( $result, $value, $user_data[ $value ], $mobile );
    				}
    			}
    • This reply was modified 6 years, 2 months ago by reckez.
    • This reply was modified 6 years, 2 months ago by reckez.
    Thread Starter reckez

    (@reckez)

    Mohammad, it worked. the data saved into the database but sadly didn’t fire a website registration sms to the user like email. here’s the code i wrote for it.

    	function register_mail( $user_id ) {
    		$user       = new WP_User( $user_id );
    		$user_email = $user->user_email;
    
    		$subject = sprintf( __( "Congratulations! You have successfully registered on %s.", ET_DOMAIN ), get_option( 'blogname' ) );
    
    		if ( ae_get_option( 'user_confirm' ) ) {
    			$message = ae_get_option( 'confirm_mail_template' );
    		} else {
    			$message = ae_get_option( 'register_mail_template' );
    		}
    		$this->wp_mail( $user_email, $subject, $message, array(
    			'user_id' => $user_id
    		) );
    
    		// Send email notice to admin when had user register
    		if ( ae_get_option( 'sendmail_admin' ) ) {
    			wp_new_user_notification( $user_id );
    		}
    	}
    	
    	
    		function register_sms( $user_id ) {
    	$user       = new WP_User( $user_id );
    		$mobile = $user->user_phone;
    		
    if ( ae_get_option( 'user_confirm' ) ) {
    			$message = ae_get_option( 'confirm_mail_template' );
    		} else {
    			$message = ae_get_option( 'register_mail_template' );
    		}
    
    		if ( $mobile ) {
    			global $sms;
    			$sms->to = array($mobile);
    			$sms->msg = '$message';
    			$sms->SendSMS();
    		}
    
    		return false;
    	}
    Thread Starter reckez

    (@reckez)

    please help

    As I said, u must use get_user_meta() if u store the mobile number on user meta, your code must become like this :
    $mobile = get_user_meta($user_id, 'your_mobile_key_field');

    And if not, check what value have $mobile Variable with export PHP functions like these: var_dump($mobile) or echo var_export($mobile, true) and others.

    I think Your problem now is, u can’t retrieve the phone number from the DB that’s all, all other things seems right on your code.

    Thread Starter reckez

    (@reckez)

    This is it, still didn’t work. last help please

    	function register_mail( $user_id ) {
    		$user       = new WP_User( $user_id );
    		$user_email = $user->user_email;
    
    		$subject = sprintf( __( "Congratulations! You have successfully registered on %s.", ET_DOMAIN ), get_option( 'blogname' ) );
    
    		if ( ae_get_option( 'user_confirm' ) ) {
    			$message = ae_get_option( 'confirm_mail_template' );
    		} else {
    			$message = ae_get_option( 'register_mail_template' );
    		}
    		$this->wp_mail( $user_email, $subject, $message, array(
    			'user_id' => $user_id
    		) );
    
    		// Send email notice to admin when had user register
    		if ( ae_get_option( 'sendmail_admin' ) ) {
    			wp_new_user_notification( $user_id );
    		}
    	}
    	
    	
    	function register_sms( $user_id ) {
    	$user       = new WP_User( $user_id );
    		$mobile = get_user_meta($user_id, 'user_phone');
    		
    if ( ae_get_option( 'user_confirm' ) ) {
    			$message = ae_get_option( 'confirm_mail_template' );
    		} else {
    			$message = ae_get_option( 'register_mail_template' );
    		}
    
    		if ( $mobile ) {
    			global $sms;
    			$sms->to = array($mobile);
    			$sms->msg = '$message';
    			$sms->SendSMS();
    		}
    
    		return false;
    	}

    The only thing that can help u on this process I suggesting you use:
    var_dump(get_user_meta($user_id, 'user_phone'));
    for check what value come from DB.

    Good luck.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Send sms to specific user’ is closed to new replies.