• Resolved hoyce

    (@hoyce)


    I’m about to create a plugin that changes the validation criterias in the wp-signup.php

    My approach is to create a plugin that hooks a filter to the wpmu_validate_blog_signup hook and modifies the WP_Error object that comes from the wpmu_validate_blog_signup function.

    Something like this:

    function filter_new_signup_criterias($content) {
      // Check if the error exist
      // If the error exist, remove it and revalidate with 2 characters.
      // Add a new error if the current blogname is shorter than 2 characters.
    }
    
    add_filter('wpmu_validate_blog_signup','filter_new_signup_criterias');

    What I can’t understand (maybe it’s not possible?) is how to remove an existing error from the WP_Error object?

    In my case I would like to remove the error with error code: “blogname” and error message: “Site name must be at least 4 characters” and change the criteria so that it can take blog names with only 2 characters.

Viewing 1 replies (of 1 total)
  • Thread Starter hoyce

    (@hoyce)

    What I did in my case was to sort out all outer possibilities of errors until the “Site name must be at least 4 characters” was the only one left. In that case I:

    1. Cleaned the given WP_Error object.

    2. Revalidated the blogname with:

    if (onlyOneBlogNameError($errors)) { // If there is only one blogname validation error.
      // Check if the string length is < 4
      if (toShortBlognameForWP($blogname)) {
    
        // Create a new error object.
        $new_errors = new WP_Error;
    
        // Check if string length is < 2
        if (toShortBlognameForMyPlugin($blogname)) {
    
          // add blogname error to new error object.
          $new_errors->add( 'blogname', __( "Site name must be at least 2 characters", "new-signup-form" ) );
        }
    
      // add the new error object to the returning result.
      $prev_results['errors'] = $new_errors;
    }

    3. …and then return the result.

Viewing 1 replies (of 1 total)
  • The topic ‘Change validation criteria when creating new blogs on wp-signup.php’ is closed to new replies.