Forums

do_action (6 posts)

  1. phibertek
    Member
    Posted 6 years ago #

    I need help trying to understand how do_action works. I am trying to modify the login function of WordPress. I'm looking for the do_action('wp_authenicate', array(&user_login &user_pass));

    But I can't find a reference to it anywhere. I know it has something to do with filters, but I can't locate in the code where authentication happens. Please help.

    Code of do_action

    function do_action($tag, $arg = '') {
    global $wp_filter;
    $extra_args = array_slice(func_get_args(), 2);
    if ( is_array($arg) )
    $args = array_merge($arg, $extra_args);
    else
    $args = array_merge(array($arg), $extra_args);

    merge_filters($tag);

    if ( !isset($wp_filter[$tag]) ) {
    return;
    }

    foreach ($wp_filter[$tag] as $priority => $functions) {
    if ( !is_null($functions) ) {
    foreach($functions as $function) {

    $function_name = $function['function'];
    $accepted_args = $function['accepted_args'];

    if ( $accepted_args == 1 ) {
    if ( is_array($arg) )
    $the_args = $arg;
    else
    $the_args = array($arg);
    } elseif ( $accepted_args > 1 ) {
    $the_args = array_slice($args, 0, $accepted_args);
    } elseif ( $accepted_args == 0 ) {
    $the_args = NULL;
    } else {
    $the_args = $args;
    }
    $string = call_user_func_array($function_name, $the_args);
    }
    }
    }
    }

  2. Michael
    Member
    Posted 6 years ago #

    wp_authenicate isn't a function, just a trigger that can be used for a plugin.

    wp_login() (in pluggable.php) is what WordPress uses for the authentication.

  3. phibertek
    Member
    Posted 6 years ago #

    What I don't understand is how is this a trigger for wp_login in pluggable.php. A little further down in the code (wp-login.php)it actually calls wp_login directly. Can you help me understand this? I would like to pass WP an already encrypted string.

    do_action('wp_authenticate', array(&$user_login, &$user_pass));
    ....
    ....
    ....

    if ( wp_login($user_login, $user_pass, $using_cookie) ) {
    if ( !$using_cookie )
    wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
    do_action('wp_login', $user_login);
    wp_redirect($redirect_to);
    exit;
    } else {
    if ( $using_cookie )
    $error = __('Your session has expired.');
    }
    }

    -Phibertek

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    What I don't understand is how is this a trigger for wp_login in pluggable.php.

    It's not. wp_authenticate is an action, but it's there as a hook for plugins. It's not used anywhere in WordPress itself.

    What exactly is it that are you trying to do? It sounds like you're looking at a lot of irrelevant code for your purposes.

  5. phibertek
    Member
    Posted 6 years ago #

    I'm trying to bypass the login feature of WordPress and making it automatic. Once a user is logged into another application, it logs them into WP without being challenged. Unfortunately, the password that I am passing is already encrypted md5(). So, I want to change wp-login.php to disable encrypting it again, rather just compare the hashed strings.

    -Phibertek

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Okay, but wp_login is one of the pluggable functions. That means you can simply replace the function entirely with whatever you like, in a plugin.

    So just make a normal WordPress plugin and in there, create a function called wp_login. And presto, your wp_login will override the built in one. Simple, eh?

    Edit: Actually, looking at 2.1.3, this sort of functionality appears to already be built in. If you're on the same site, you can just double md5 hash the password, put it in WordPress's normal cookie, and you should be immediately logged in.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.