e107help.org Q&A
0 like 0 dislike
I've got a plugin with a lot of preferences, wich are stored under an array with the pligin name, ie:

plugin_preferences =» (pref1 =» val1, pref2 =» val2, ... and so on)

I'm trying to retrieve, for instance, pref2, using the core function e107::getpref, but i only manage to get the full plugin_preferences array...

Can the getpref function retrieve only the preference i need from inside the array???
e107 version 2
closed
in Core by (310 points) 25 40 48

3 Answers

0 like 0 dislike
Best answer

Documentation is here: http://e107.org/developer-manual/classes-and-methods#preferences

$perPage = e107::pref('faqs', 'faqs_per_page');

Alternatively:

$pref = e107::getPref('plugin_name'); // Returns array

$example_pref['example_pref']; // returns the 'example_pref' from array 

by (2.8k points) 7 10 10

Somehow, with me, your first option doesn't worked with me:

$perPage = e107::pref('faqs', 'faqs_per_page');

So had to stick to this one:

$pref = e107::getPref('plugin_name'); // Returns array

$example_pref['example_pref']; // returns the 'example_pref' from array 

0 like 0 dislike
I use this method:

Note: pluginname is the plugin preferences you are wanting to call, and then the value

$pref_server = e107::pref('pluginname', 'server');
$pref_url = e107::pref('pluginname', 'url');
$pref_cfn = e107::pref('pluginname', 'cache_file_name');
$pref_ctl = e107::pref('pluginname', 'cache_time_life');

 

AN Example - I created the plugin called Cars - the pref's would be called cars, differecnt values would be color, size, and condition. To call them I would do this:

$pref_color = e107::pref('cars', 'color');

$pref_size = e107::pref('cars', 'size');

$pref_condition = e107::pref('cars', 'condition');

 

Does that awsner your question?
by (459 points) 17 37 50
0 like 0 dislike
If i'm allowed a small "off topic", what's the best practice on retrieving prefs?

Just keep calling the e107::pref in plugin, shortcodes, etc., or call it once, on plugin start code, and store it on a plugin variable wich would be available to shortcode, code, etc, in the plugin???
by (310 points) 25 40 48
It depends. Usually in shortcodes we do the second way (see above). But then again, it all depends on how many preferences you'll need to call. Normally I prefer getting the array so I can just refer to that all the time, rather than doing individual retrieves. Unfortunately there is no real 'standard', so you just have to see how other plugins do it and go from there.
996 questions
1,389 answers
2,527 comments
2,512 users