Never mind it was working, I was just looking in the wrong place for the answer, one of those “Staring at the screen to long” moments, as soon as I woke up I spotted it.
For anyone that’s interested it’s for selecting multiple category ID’s to pass to external plugins, I am just adapting a tile theme to insert available plugins (or widgets) into the space where a post would be. So not only do you get posts as part of the index tiles, you can now get ad’s (via AdRotate and recent category news from Special Recent Posts) randomly added to the mix. The theme option is basically so you can supply a random category (selected) to the recent posts call. I build an array of known available (i.e.. active) plugins, build the parameters and functions and store the calling function in an array. Then at user selected intervals insert a plugin rather than a post.
Not very exciting and I’m sure it’s been done time and time again, but hey, might as well give it a go.
Using the above options builds a Select statement as follows :
<select id="categories" name="options[categories][]" multiple="multiple" size="10" style="width: 100px;" >
<?php
$settings = get_option( 'options', $options );
$arg = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'taxonomy' => 'category');
$siteCategories = get_categories($arg);
foreach ($siteCategories as $siteCat) {
$siteCatID = $siteCat->cat_ID;
$siteCatName = $siteCat->cat_name;
if (in_array($siteCatID, $settings['categories']))
echo "<option value='${siteCatID}' selected='selected'>$siteCatName</option>";
else
echo "<option value='${siteCatID}'>$siteCatName</option>";
}
?>
</select>
So now, when I insert a “Special Posts” Plugin I can supply random categories from the list selected rather than just the default.
If you’re interested in the actual code that builds an active plugin list with associated arrays and functions, here it is.
// Lets start by using the wordpress built in functions to find out what we have
// and what's active that we recognise.
// Our returning array will contain a numerical index, a name and the code needed
// to make it work.
// These are the plugins we currently know about and know how to insert them via
// PHP into the main html output.
$specialposts = array('name' => 'Special Recent Posts', 'function' => create_function('', '$settings = get_option("infinity_options"); $totalCats = count($settings["categories"]); $randCat = $settings["categories"][rand(0, $totalCats - 1)]; $randName = get_cat_name($randCat); $args = array("srp_widget_title" => "$randName Recent Articles", "srp_number_post_option" => "3", "srp_filter_cat_option" => $randCat); special_recent_posts($args);'));
$wp125 = array('name' => 'WP125', 'function' => create_function('', 'echo "<center>"; wp125_write_ads(); echo "</center>"; '));
$adrotate = array ('name' => 'AdRotate', 'function' => create_function('', 'echo adrotate_group("1");'));
$knownplugins = array ($specialposts, $wp125, $adrotate);
$knownpluginsno = count($knownplugins);
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$allplugins = get_plugins();
$activeplugins = 0;
foreach ($allplugins as $plugin => $pdata) {
// Check all plugins against our list of known plugins
for ($i=0; $i<($knownpluginsno); $i++) {
if ((strcmp($pdata['Name'], $knownplugins[$i]['name']) == 0) and is_plugin_active($plugin)) {
$siteplugins[$activeplugins++] = $knownplugins[$i];
}
}
}
return $siteplugins;
Anyway, I hope that helps add inspiration to someone, somewhere, some time ??
Onwards and upwards as they say.
D.