WordPress.org

Ready to get started?Download WordPress

Forums

about do_action and add_action (2 posts)

  1. grosbouff
    Member
    Posted 5 years ago #

    Hi;
    I'm creating a new (fantastic!) plugin... :)

    I have a little problem using do_action and add_action :

    I got a function

    function classifieds_manage_classified_save_step {
    ...
    	///CHECK DATA WITH PHP FILE
    	do_action('classifieds_manage_step_check_data');
    ...
    }

    If false is returned somewhere in that function, my object is not saved.

    Somewhere else; I put

    //MANAGE|CHECK
    add_action( 'classifieds_manage_step_check_data','classifieds_manage_step_settings_check_data');

    So; the function classifieds_manage_step_settings_check_data is called where I have do_action('classifieds_manage_step_check_data');.

    That function classifieds_manage_step_settings_check_data returns 'true' or 'false'; but how can I "transmit" it to function classifieds_manage_classified_save_step ?

    Have I to use arguments somewhere and how ?

    Thanks !

  2. Dion Hulse
    WordPress Dev
    Posted 5 years ago #

    Have a look into filters.

    Filters filter a value, Ie:

    function auth($user, $pass) {
    $authed = false;
    $authed = apply_filters('auth_user', $authed, $user, $pass);
    return $authed;
    }
    add_filter('auth_user', 'dd_is_great', 10, 3); //10 = default priority, 2 = i want 3 args to be passed through instead of 1
    function dd_is_great($authed, $user, $pass) {
     if ( 'dd32' == $user && 'grockenhiem' == $pass )
       return true;
     else
      return $authed;
    }

    In other words.. Actions are Actions, They fire to say something has happened. Filters filter a variable, Its the best way to return data..

    I'm not sure using filters or actions is the best method at all for you.. Maybe wrapping everything in a class could be a possibility

Topic Closed

This topic has been closed to new replies.

About this Topic