Forum Replies Created

Viewing 15 replies - 1 through 15 (of 29 total)
  • Thread Starter hoomn

    (@hoomn)

    Yeah, it’s at the end of rtl.css. And, thank you very much, it’s working now! (I think the old CSS file was cached by Chrome…)

    Thread Starter hoomn

    (@hoomn)

    Could you please check iums881.ir again?

    If there is no active child theme on my main website, then what is the following code in the site source?

    <link rel='stylesheet' id='parent-style-css'  href='https://iums881.ir/wordpress/wp-content/themes/twentyfifteen/style.css?ver=4.1.1' type='text/css' media='all' />
    <link rel='stylesheet' id='child-style-css'  href='https://iums881.ir/wordpress/wp-content/themes/twentyfifteen-child/style.css?ver=4.1.1' type='text/css' media='all' />
    <link rel='stylesheet' id='parent-style-rtl-css'  href='https://iums881.ir/wordpress/wp-content/themes/twentyfifteen/rtl.css?ver=4.1.1' type='text/css' media='all' />
    <link rel='stylesheet' id='child-style-rtl-css'  href='https://iums881.ir/wordpress/wp-content/themes/twentyfifteen-child/style.css?ver=4.1.1' type='text/css' media='all' />

    Thread Starter hoomn

    (@hoomn)

    Thank you very much for your quick response.

    I’m using a child theme on the main website, and I have a style.css and a rtl.css, and I add every extra CSS code at the end of my rtl.css.

    I made a child theme with a rtl.css file on the test website (https://test.iums881.ir/) and then added your code to it, and it’s working fine.

    But, when I added your code to the rtl.css file on the main site (https://iums881.ir/), it’s not working!

    Could you please check it to see what’s wrong? (The latest widget on the main website is the one with the bullet list which I want to change it.)

    P.S. Your quick response would be highly appreciated since I have to revert the changes on the main website.

    Thread Starter hoomn

    (@hoomn)

    Yes, I want it to look exactly like the default WordPress archive widget. (i.e. I don’t want the bullets, and I want the lines.) (BTW, as you see, the first list doesn’t use hr for the lines and just uses HTML ul & li tags.)

    Forum: Fixing WordPress
    In reply to: Widget Style
    Thread Starter hoomn

    (@hoomn)

    Thank you for your response.

    Actually, the reason of this topic is that I couldn’t find that part in the CSS!

    I made a test blog at test.iums881.ir, and I kindly ask you to check the CSS yourself. (As I said before, I want to make the list in the second widget of this test blog to look like the list in the first widget of it.)

    Forum: Fixing WordPress
    In reply to: Widget Style
    Thread Starter hoomn

    (@hoomn)

    I’m sorry for the image link. The correct link is: https://8pic.ir/images/p8seyhud5mjtdcs72ew9.png

    And, I don’t try these changes on the website at first, so I don’t have a link. But, if it is necessary, I’ll try to make a temporary website and give you a link.

    P.S. As you see in the image, the first one has lines between items, but the second one has bullets. (Both are using ul and li HTML tags, and there is no hr or etc. in the first one.) I like the first style.

    Thread Starter hoomn

    (@hoomn)

    Thank you very much for your help!

    Now, I can add users to blogs and save the extra fields into their profiles.

    The only remaining problem is that WordPress is not checking for duplicate usernames anymore…

    Thread Starter hoomn

    (@hoomn)

    Thank you for your interest.

    As I mentioned in the 23rd post:

    • I can’t save the extra fields (first_name and last_name) into the users profiles.
    • I need the $user_id in order to use add_user_to_blog() and automatically add users to some blogs after their registration, but I don’t exactly know where too hook and how to retrieve the $user_id. (BTW, I think it would be better if I could add users to blogs after the email confirmation.)
    • And, the first if in the 18th post is preventing WordPress from checking for duplicate usernames. Is there any better fix for this issue than my suggestion in that post?
    Thread Starter hoomn

    (@hoomn)

    Could you please help me with this last part of my plugin? Don’t you have any idea dear Ipstenu?

    Thread Starter hoomn

    (@hoomn)

    Dear jkhongusc,

    I have that problem (WordPress not checking for duplicate usernames) with numeric usernames. I think it might be because WordPress first checks to see if it’s a numeric username, and then it goes to see if it’s already exist or not. (The problem is definitely with the first if in my myplugin_registration_errors you can see above.)

    And, about the extra user meta, I tried your method for first_name and last_name, but the first/last name fields in users profile were still empty after signup. Is there any way to get the $user_id and use update_user_meta()? (e.g. by hooking to wpmu_new_user?)
    That would be more beneficial for me since I also want to use add_user_to_blog(). (I want to automatically add users to blogs based on their username.)

    Thread Starter hoomn

    (@hoomn)

    Finally, I could fixed the validation step:

    function myplugin_registration_errors ($result) {
    	$error_name = $result[ 'errors' ]->get_error_message( 'user_name' );
    	if ( $error_name == __('Sorry, usernames must have letters too!') ) {
    		unset ( $result[ 'errors' ]->errors[ 'user_name' ] );
    		if ( $_POST['user_name'] < 8000000000 || $_POST['user_name'] > 10000000000 )
    			$result['errors']->add( 'user_name', __('<strong>ERROR</strong>: Username is not valid.','mydomain') );
    	}
    	if ( empty( $_POST['first_name'] ) )
    		$result['errors']->add( 'first_name', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
    	if ( empty( $_POST['last_name'] ) )
    		$result['errors']->add( 'last_name', __('<strong>ERROR</strong>: You must include a last name.','mydomain') );
    	if ( $_POST['validation_code'] != $_POST['user_name'] )
    		$result['errors']->add( 'validation_code', __('<strong>ERROR</strong>: not valid.','mydomain') );
    	return $result;
    }

    But, WordPress doesn’t check to see if the username has been already used anymore!
    What’s wrong? And, how can I fix it? Should I copy the following code from ms-functions.php to my function? Or, is there a better way to fix this issue?

    // Check if the username has been used already.
    if ( username_exists($user_name) )
    	$errors->add( 'user_name', __( 'Sorry, that username already exists!' ) );
    
    // Has someone already signed up for this username?
    $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) );
    if ( $signup != null ) {
    	$registered_at =  mysql2date('U', $signup->registered);
    	$now = current_time( 'timestamp', true );
    	$diff = $now - $registered_at;
    	// If registered more than two days ago, cancel registration and let this signup go through.
    	if ( $diff > 2 * DAY_IN_SECONDS )
    		$wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) );
    	else
    		$errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
    
    	if ( $signup->active == 0 && $signup->user_email == $user_email )
    		$errors->add('user_email_used', __('username and email used'));
    }

    —————
    Furthermore, since user_register is not called in a multisite installation, the third part of my plugin is not working anymore and I can’t save the extra registration user meta.
    Could you please tell me where I should hook and how I can update the user meta?

    Thread Starter hoomn

    (@hoomn)

    Dear jkhongusc,

    Thank you very much for your explanation.

    That’t right, and it seems that wpmu_validate_user_signup is not the correct hook for my current purpose. (By the way, can I use that wpmu_validate_user_signup to allow all numeric usernames and/or change the minimum username length? Or, do you know another hook to allow all numeric usernames and/or change the minimum username length?)

    So, how should I make all my extra form items required? And, how should I add an extra validation for the username? (i.e. allowing only a numeric username between x and y)

    P.S. As a reminder, here is my code for this purpose which works fine on a sigle site installation:

    add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
        function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
            if ( $_POST['user_login'] < 8000000000 || $_POST['user_login'] > 10000000000 )
                $errors->add( 'user_login_error', __('<strong>ERROR</strong>: not valid username','mydomain') );
            if ( empty( $_POST['first_name'] ) )
                $errors->add( 'first_name_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
            if ( empty( $_POST['last_name'] ) )
                $errors->add( 'last_name_error', __('<strong>ERROR</strong>: You must include a last name.','mydomain') );
            if ( $_POST['validation_code'] != $_POST['user_login'] )
                $errors->add( 'validation_code_error', __('<strong>ERROR</strong>: not correct','mydomain') );
    		return $errors;
        }

    Thread Starter hoomn

    (@hoomn)

    Dear Ipstenu,

    Thanks a lot for signup_extra_fields, I didn’t know about it! Now, I can add my custom fields:

    add_action('signup_extra_fields','myplugin_register_form');
        function myplugin_register_form (){
            $first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
    		$last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name']: '';
    		$validation_code = ( isset( $_POST['validation_code'] ) ) ? $_POST['validation_code']: '';
    		?>
            <p>
                <label for="first_name"><?php _e('First Name','mydomain') ?><br />
                <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
    		</p>
    		<p>
    			<label for="last_name"><?php _e('Last Name','mydomain') ?><br />
                <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="25" /></label>
            </p>
    		<p>
    			<label for="validation_code"><?php _e('Validation Code','mydomain') ?><br />
                <input type="text" name="validation_code" id="validation_code" class="input" value="<?php echo esc_attr(stripslashes($validation_code)); ?>" size="25" /></label>
            </p>
            <?php
        }

    (The code works well, but could you please confirm if it’s OK or not? Specially, if all the variables are necessary and defined in a correct way.)

    Thread Starter hoomn

    (@hoomn)

    This is my code for a single site installation, which works well:

    <?php
    
    	/*
    	Plugin Name: Custom Registration
    	Description: This plugin customizes WordPress's built-in user registration page.
    	Author: Hooman Tadbiri
    	Version: 0.1
    	*/
    
        //1. Add a new form element...
        add_action('register_form','myplugin_register_form');
        function myplugin_register_form (){
            $first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
    		$last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name']: '';
    		$validation_code = ( isset( $_POST['validation_code'] ) ) ? $_POST['validation_code']: '';
    		?>
            <p>
                <label for="first_name"><?php _e('First Name','mydomain') ?><br />
                <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
    		</p>
    		<p>
    			<label for="last_name"><?php _e('Last Name','mydomain') ?><br />
                <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="25" /></label>
            </p>
    		<p>
    			<label for="validation_code"><?php _e('Validation Code','mydomain') ?><br />
                <input type="text" name="validation_code" id="validation_code" class="input" value="<?php echo esc_attr(stripslashes($validation_code)); ?>" size="25" /></label>
            </p>
            <?php
        }
    
        //2. Add validation. In this case, we make sure first_name is required.
        add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
        function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    		if ( $_POST['user_login'] < 8000000000 || $_POST['user_login'] > 10000000000 )
    			$errors->add( 'user_login_error', __('<strong>ERROR</strong>: not valid username','mydomain') );
    		if ( empty( $_POST['first_name'] ) )
                $errors->add( 'first_name_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
            if ( empty( $_POST['last_name'] ) )
                $errors->add( 'last_name_error', __('<strong>ERROR</strong>: You must include a last name.','mydomain') );
            if ( $_POST['validation_code'] != $_POST['user_login'] )
                $errors->add( 'validation_code_error', __('<strong>ERROR</strong>: not correct','mydomain') );
    		return $errors;
        }
    
        //3. Finally, save our extra registration user meta.
        add_action('user_register', 'myplugin_user_register');
        function myplugin_user_register ($user_id) {
            if ( isset( $_POST['first_name'] ) )
                update_user_meta($user_id, 'first_name', $_POST['first_name']);
    		if ( isset( $_POST['last_name'] ) )
                update_user_meta($user_id, 'last_name', $_POST['last_name']);
        }
    
    ?>

    (Usernames must be numeric, and users must enter a validation code which is their username for instance.)

    And, this is my code for a multi-site installation, which doesn’t work:

    <?php
    
    	/*
    	Plugin Name: Custom Registration
    	Description: This plugin customizes WordPress's built-in user registration page.
    	Author: Hooman Tadbiri
    	Version: 0.1
    	*/
    
        //1. Add a new form element...
        add_action('signup_header','myplugin_register_form');
        function myplugin_register_form (){
            $first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
    		$last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name']: '';
    		$validation_code = ( isset( $_POST['validation_code'] ) ) ? $_POST['validation_code']: '';
    		?>
            <p>
                <label for="first_name"><?php _e('First Name','mydomain') ?><br />
                <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
    		</p>
    		<p>
    			<label for="last_name"><?php _e('Last Name','mydomain') ?><br />
                <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="25" /></label>
            </p>
    		<p>
    			<label for="validation_code"><?php _e('Validation Code','mydomain') ?><br />
                <input type="text" name="validation_code" id="validation_code" class="input" value="<?php echo esc_attr(stripslashes($validation_code)); ?>" size="25" /></label>
            </p>
            <?php
        }
    
        //2. Add validation. In this case, we make sure first_name is required.
        add_filter('wpmu_validate_user_signup', 'myplugin_registration_errors', 10, 3);
        function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    		if ( $_POST['user_login'] < 8000000000 || $_POST['user_login'] > 10000000000 )
    			$errors->add( 'user_login_error', __('<strong>ERROR</strong>: not valid username','mydomain') );
    		if ( empty( $_POST['first_name'] ) )
                $errors->add( 'first_name_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
            if ( empty( $_POST['last_name'] ) )
                $errors->add( 'last_name_error', __('<strong>ERROR</strong>: You must include a last name.','mydomain') );
            if ( $_POST['validation_code'] != $_POST['user_login'] )
                $errors->add( 'validation_code_error', __('<strong>ERROR</strong>: not 2','mydomain') );
    		return $errors;
        }
    
        //3. Finally, save our extra registration user meta.
        add_action('user_register', 'myplugin_user_register');
        function myplugin_user_register ($user_id) {
            if ( isset( $_POST['first_name'] ) )
                update_user_meta($user_id, 'first_name', $_POST['first_name']);
    		if ( isset( $_POST['last_name'] ) )
                update_user_meta($user_id, 'last_name', $_POST['last_name']);
        }
    
    ?>

    As a reminder, I don’t want to let my users create new blogs and I just need the “User accounts may be registered.”. The only thing I want more is to add first name, last name, and a validation field to the registration page.

    Thread Starter hoomn

    (@hoomn)

    Dear Ipstenu,

    It DOES “hide the blog sign up”, but it DOESN’T make register_form and and registration_errors work! And, I want the normal WP signup page only to use those hooks!

    Do you think it is possible to change the WP MS signup process in a way that makes those hooks working again?

Viewing 15 replies - 1 through 15 (of 29 total)