• Resolved joashenrique

    (@joashenrique)


    Hello everything is fine?

    Is it possible to notify all WordPress users when a form is submitted?

    I know that it is possible to register all existing e-mails from users of my site, but it would be more practical if a query parameter were the currently registered users and already notified everyone. That way I wouldn’t have to register a new email on the form when a new user registers on my site.

Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    Here’s the code I’m using:

    Unfortunately it didn’t work out.

    add_filter( 'forminator_cform_render_fields', function( $wrappers, $model_id ) {
    	//Replace your Form ID
        if ( $model_id != 7993 ) {
            return $wrappers;
        }
    
        $select_fields_data = array(
            'select-4' => 'users',
        );
    
        foreach ( $wrappers as $wrapper_key => $wrapper ) {
            if ( ! isset( $wrapper[ 'fields' ] ) ) {
                continue;
            }
    
            if ( isset( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) && ! empty( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) ) {
    			//Add the user roles in the array and the field you want to display
    	    	$users = get_users( array( 'role__in' => array( 'Subscriber', 'Administrator' ), 'fields' => array( 'display_name' ) ) );;
                if ( ! empty( $users ) ) {
                    $new_options = array();
    	        	$user_names = array();
                    foreach( $users as $u ) {
                        $new_options[] = array(
                            'label' => $u->display_name,
                            'value' => $u->display_name,
                            'limit' => '',
                            'key'   => forminator_unique_key(),
                        );
    					$user_names['options'] = $new_options;
                    }
    				$select_field = Forminator_API::get_form_field( $model_id, $wrapper['fields'][0]['element_id'], true );
    				if ( $select_field ) {
    					Forminator_API::update_form_field( $model_id, $wrapper['fields'][0]['element_id'], $user_names );
    					$wrappers[ $wrapper_key ][ 'fields' ][ 0 ][ 'options' ] = $new_options;
    				}
                }
            }
        }
    
        return $wrappers;
        
    },10,2);
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @joashenrique

    I read your earlier post and I think we may have missed important part here. You wrote:

    When adding the code in wp-content -> mu-plugins -> wpmudev-hosting -> wpmudev-hosting.js unfortunately the form still doesn’t work correctly

    This isn’t correct location. This code should:

    1) be in a .php file and not in .js file so you can name the file e.g. “forminator-select-users.php” and put that code into it. Remember to add the PHP opening tag in the first line (before the rest of the code) like this:

    <?php

    2) and the file itself should be exactly in this path: “/wp-content/mu-plugins” and not in any other folder/sub-folder there.

    Kind regards,
    Adam

    Thread Starter joashenrique

    (@joashenrique)

    Oh, thank you very much.

    Now it worked.

    Thank you for being patient with me.

    Finally, I would like to know if it is possible to list user names alphabetically?

    Hi @joashenrique,

    Glad to hear is working now, please check this line:

    //Add the user roles in the array and the field you want to display
    	    	$users = get_users( array( 'role__in' => array( 'Subscriber' ), 'fields' => array( 'display_name' ) ) );

    The get_users() is a WordPress function that gets the users to fill the dropdown, you can customize it following its Codex here: https://developer.www.ads-software.com/reference/functions/get_users/

    Still, I modify the query for you,

    $users = get_users( array( 'role__in' => array( 'Subscriber', 'orderby' => 'display_name', 'order' => 'ASC' ), 'fields' => array( 'display_name' ) ) );

    You might need to change ASC or DESC according to your needs.

    Let us know if you require further assistance.

    Best regards,
    Laura

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @joashenrique ,

    We haven’t heard from you for over a week now, so it looks like the code provided by Laura worked for you.

    Feel free to re-open this topic if needed.

    Kind regards
    Kasia

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Notify all users’ is closed to new replies.