0

Actually I am developing a new free plugin for Wordpress partially based on this plugin FrameWork: Sunrise framewok, each option's name will start like this:

my_plugin_

So everytime i need to echo and option i simply write:

echo get_option('my_plugin_option_example') 

And everything is working as expected.

Now I would like to create an import/export page (and this isn't the problem, I have already managed how to create the new tab).

What I can't understand is how to add this funcionality as (for what I know) this function:

get_alloptions()

is deprecated. I became aware of this function here: wpNettuts And now I am afraid that it will become useless soon. Is there anyone who has a solution for this problem?

1

The Codex suggests that you use wp_load_alloptions instead.

I would suggest that you therefore use wp_load_alloptions. That technically answers the question, I think.

wp_load_alloptions will pull all of the options out of the options table and your question does not explain why you need to do that. Are you actually needing to pull only your my_plugin_* options, because that would be a different answer? If so, there is no "get options by wildcard" function that I know of, but it isn't hard to construct.

function get_options_by_wildcard($prefix = '') {
  if (empty($prefix)) return false;
  global $wpdb;
  $ret = array();
  $options = $wpdb->get_results(
    $wpdb->prepare("SELECT option_name,option_value FROM {$wpdb->options} WHERE option_name LIKE %s",$prefix.'%'),
    ARRAY_A
  );
  if (!empty($options)) {
    foreach ($options as $v) {
      $ret[$v['option_name']] = maybe_unserialize($v['option_value']);
    }
  }
  return (!empty($ret)) ? $ret : false;
}
var_dump(get_options_by_wildcard('my_plugin_'));

Your plugin should "know" what its one options are so you should be able to do it by looping through the plugin options without needing another query. For example, assuming your plugin is a class and your available plugin options are stored in the class variable plugin_options:

function get_my_plugin_options() {
  $ret = array();
  foreach ($this->plugin_options as $v) {
    $ret[$v] = get_option($v);
  }
  return $ret;
}
var_dump(get_my_plugin_options());
  • Maybe I was not clear (lack of english knowledge here :D ) anyway what I would like to do is to add Import/Export functionality to my plugin settings so the user will be able to export his Settings and import them into a different installation. Exporting all website options is not needed I only need my plugin's option. – Downloadtaky Jul 14 '13 at 19:46
-1

here is your answer, I believe it will help you out

https://pippinsplugins.com/building-settings-import-export-feature/

  • 1
    May you please elaborate on how this article will solve the answer? – Ethan Jinks O'Sullivan Sep 28 '16 at 2:56
  • It would be great if you post the crux of the answer here. – bravokeyl Sep 28 '16 at 3:25
  • the question is simple that article is mostly irrelevant to it – Mark Kaplun Sep 28 '16 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.