Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook for modifying options before they are saved #1897

Closed
ivandotv opened this issue Aug 15, 2016 · 3 comments
Closed

Hook for modifying options before they are saved #1897

ivandotv opened this issue Aug 15, 2016 · 3 comments

Comments

@ivandotv
Copy link

I've looked to in the documentation on your site, but I can't find what I'm looking for.

I need an hook when the options are saved on the post/page / settings page / customizer but before they are saved to the database.
So basically what I need is when the user hits the save button, I need a way to get fresh options before they are saved to the database, so I can to one final manipulation of the data.

Why I need this.
I want to manipulate some options data when the data is saved, so I don't need to manipulate that data in the front end, I can just get the data from the options.

@ghost ghost added the in progress label Aug 15, 2016
@ghost ghost closed this as completed in cf256cd Aug 15, 2016
@ghost ghost removed the in progress label Aug 15, 2016
@ghost
Copy link

ghost commented Aug 15, 2016

Usage

add_action('fw_settings_options_update', '_theme_action_settings_options_update');
function _theme_action_settings_options_update($data) {
    $option_id = 'my_magic_option';

    if ($data['option_id'] !== $option_id) {
        return;
    }

    // prevent recursion
    remove_action('fw_settings_options_update', '_theme_action_settings_options_update');

    $value = fw_get_db_settings_option($option_id);

    $value = mega_extra_magic_function($value);

    fw_set_db_settings_option($option_id, $value);

    add_action('fw_settings_options_update', '_theme_action_settings_options_update');
}

@andreiglingeanu
Copy link
Collaborator

@moldcraft Shortcodes options are not covered here, right?

@ghost
Copy link

ghost commented Aug 15, 2016

@andreiglingeanu framework/helpers/database.php has settings, customizer, post and term options get/set functions.

Shortcodes don't have their database store location (post and term options have a separate post meta fw_options, settings and customizer have a separate wp_option) they are stored inside options where you place them.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants