michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
340 stars 71 forks source link

Is compiler action available to retrieve the saved data #159

Closed premiumsupport365 closed 10 years ago

premiumsupport365 commented 10 years ago

Hello michael

Thanks for your awesome work. I Need to know whether you have compiler action in the framework. What I need is to retrieve the saved data, using get options method once the option page is saved. So that I can get the settings and perform certain functions through that.

ghost commented 10 years ago

Great description, what I am looking for in project am working on.

michaeluno commented 10 years ago

I'm not familiar with the phrase "compiler action" so having a hard time understanding the question.

To retrieve saved option values, there are different ways. You may do either of the followings.

premiumsupport365 commented 10 years ago

Hi michael

Sorry if I am not clear. I will try to explain clearly this time. forget the word compiler at all. What I need is an action method like add_action. For example if I am saving options in a page, after that an event or action need to be performed so that I can execute my functions after the save . there is no confusion in gettting options just need to call the function.

if you are familiar with dynamik theme or any other themes. they will write the code to the file in uploads so that those files will be included to the site. It avoids repeated query to database and can be utilized in various ways.

so I needed a way that I can execute the functions after the options are saved.

michaeluno commented 10 years ago

I see.

The framework has the submit_{...} action hooks but they are executed before the options are saved. Maybe submit_after_{...} action hooks need to be added.

However, for the options of forms in generic pages added by the framework, you can use the WordPress built-in action hook, updated_option_{option key}.

Inside the extended class, add an action like this.

add_action( "update_option_{$this->oProp->sOptionKey}", array( $this, 'replyToDoAfterSavingOptions' ) );

Then define the callback function like this.

    /**
    * Fires after the value of an option has been successfully updated.
    *
    * @param mixed  $vOldOptions     The old option value.
    * @param mixed  $vNewOptions     The new option value.
    */    
    public function replyToDoAfterSavingOptions( $vOldOptions, $vNewOptions ) {

        // Do your stuff

    }    
premiumsupport365 commented 10 years ago

Hi michael

thanks for your guidelines. I have placed the add_action and the function.

I get the following error

Parse error: syntax error, unexpected 'add_action' (T_STRING), expecting function (T_FUNCTION)

sounds like I need to add the action inside the function. but If I do so I couldnt see anything happening.

can you advise mate..

here is the pastebin version http://pastebin.com/imPQ6Uz2

I have added the comment as //zebra modified in the places where i put your code.

michaeluno commented 10 years ago

Sorry, forgot to say that you need to add it (the line that calls add_action() ) inside the setUp() function.

premiumsupport365 commented 10 years ago

Awesome , working like a charm mate :)

michaeluno commented 10 years ago

Glad it helped!

ghost commented 10 years ago

That's awesome Michael. Your a genius. Hope the beer i Sent yesterday made it to your dinner table on time.

Thanks for the awesome support and being a real gentleman about it.

michaeluno commented 10 years ago

Haha, you are welcome and thanks for the donation!

michaeluno commented 10 years ago

I've added the submit_after_{...} action hooks in 3.3.1b. Download.

This saves a line of calling add_action() if you use it in the extended class declaration.

    public function submit_after_APF_Demo( $aInput, $aOldInput, $oAdminPage ) {    // submit_after_{instantited class name}
       // Do your stuff here
       // AdminPageFramework_Debug::log( $aInput );
    }