Last active
February 27, 2024 23:52
-
-
Save MjHead/49ebe7ecc20bff9aaf8516417ed27c38 to your computer and use it in GitHub Desktop.
Get option values for JetEngine options pages inside the PHP code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Method 1 | |
* Can be used for: Any storage type | |
* | |
* page-slug - replace this with your Option Page slug | |
* option-name - replace this with your option Name/ID | |
*/ | |
$value = jet_engine()->listings->data->get_option( 'page-slug::option-name' ); | |
/** | |
* Method 2 | |
* Can be used for: Any storage type | |
* | |
* page-slug - replace this with your Option Page slug | |
* option-name - replace this with your option Name/ID | |
*/ | |
$page = jet_engine()->options_pages->registered_pages['page-slug']; | |
$value = $page->get( 'option-name' ); | |
/** | |
* Method 3 | |
* Can be used for: Default storage type | |
* | |
* page-slug - replace this with your Option Page slug | |
* option-name - replace this with your option Name/ID | |
*/ | |
$all_options = get_option( 'page-slug', array() ); | |
$value = isset( $all_options['option-name'] ) ? $all_options['option-name'] : false; | |
/** | |
* Method 4 | |
* Can be used for: Separate storage type + `Add prefix for separate options` is DISABLED | |
* | |
* option-name - replace this with your option Name/ID | |
*/ | |
$value = get_option( 'option-name' ); | |
/** | |
* Method 5 | |
* Can be used for: Separate storage type + `Add prefix for separate options` is ENABLED | |
* | |
* page-slug - replace this with your Option Page slug | |
* option-name - replace this with your option Name/ID | |
*/ | |
$value = get_option( 'page-slug_option-name' ); |
Hooks are:
jet-engine/options-pages/after-save
jet-engine/options-pages/after-save/PAGE_SLUG
jet-engine/options-pages/updated
jet-engine/options-pages/updated/PAGE_SLUG
The only argument passed to a hook is an instance of Jet_Engine_Options_Page_Factory (\jet-engine\includes\components\options-pages\options-page.php)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jwamsterdam @Galibri
There is some update for those who want to use php to update options.
The options inside jetengine is actually save as options in the wp_option table. So the typical get_option and update_option will do.
And the mutiple field value is saved as array.
So let say you have a option page named with slug "dining-certificate-options_copy" and the field slug is "certificate-number"
Just simply: