WordPress: how to get plugin options from another plugin page

I am writing a WordPress plugin with widgets, and this widget displays a link on the page, for example, for example:

<a href="<?php echo plugins_url('/ext_page.php', __FILE__); ?>">Link</a> 

Now, on the / ext _page.php page, I need to get the parameters from the module itself, for example, for example:

 $options = get_option('my_plugin_options'); 

But the get_option function does not seem to work on this page, is there any other way to get the parameters?

Please consult, Thank you!

+4
source share
2 answers

get_option () will always work on WordPress. Make sure you spell the parameter name well.

You can use the default value (an empty array in this case) if the option is not found:

 $options = get_option('my_plugin_options', array() ); 

Go to the wp_options table and check if the value for my_plugin_options exists or exists.

+6
source

Another consideration, maybe the option is serialized in the wp_options database wp_options ? In this case, you can get the value as follows:

 $options = get_option('my_option', 'default text'); $option = $options['field_one']; 

These options are displayed in the option_value field. If it is serialized, it will look something like this:

 a:1:{s:11:"field_one";s:7:"foobar";} 

For reference: http://wordpress.org/support/topic/how-to-get-a-serialized-option

+1
source

Source: https://habr.com/ru/post/1446928/


All Articles