Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress: How to get plugin options from other plugin page

Tags:

wordpress

I'm writing a WordPress plugin which has a widget, and that widget displays a link on the page like e.g.:

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

Now in the /ext_page.php page, I need to get options from the plugin itself like e.g.:

$options = get_option('my_plugin_options');

But the function get_option seems not working in that page, is there any other way to get the options?

Please kindly advise, Thanks!

like image 527
Asususer Avatar asked Nov 19 '12 11:11

Asususer


People also ask

Where are my WordPress plugins options stored?

The text, metadata, and settings are stored in the WordPress database. Static files like images, JS, CSS used by the plugin are stored in the plugins directory. The users' files uploaded when working with the plugin are stored in the plugin-specific folder inside the wp-content/uploads directory.

Can you copy a WordPress plugin?

First you needs to download the whole plugin and study the core functionality,change the plugin name to a new one, change all the variables used inside it to new one. Make sure there is no functions conflicting each other. by doing all this you can duplicate it.

How do I create an option page in WordPress?

Creating custom options panels in WordPress is relatively easy. First, to create the menu item and the new page, see Adding Administration Menus. So long as you stick to this structure, WordPress will handle all of the option creation, update, saving, and redirection for you.


2 Answers

get_option() will always work on WordPress. Make sure you've written the option name well.

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

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

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

like image 137
RRikesh Avatar answered Oct 02 '22 09:10

RRikesh


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

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

Option data appears in the option_value field. If it's 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

like image 39
Jongosi Avatar answered Oct 02 '22 11:10

Jongosi