I'm creating a automated webinar plugin for wordpress and have hit a road block. What I'm trying to do is allow users to create webinars from the plugin and have their selections (bgcolor, title text, video, etc) displayed on a different theme layout than their main theme activated. However I've seemed to have hit a roadblock. My initial thought was to have users upload several page template phps and css stylesheets into their main themes folder and have those files get the details from the plugin but I'm being told by my current developer that it can't be done that way because wp_insert_post won't allow it. Not sure why that matters but that's what I'm being told and I can't seem to find a way to make it work. Any suggestions?
I'd go the myspace/vbulletin usercp way and have a plugin that captures their preferences in fields and then loads their webinars with a cutdown template. Your plugin will then write those preferences into a <style> section in the head of the page. Its easy to ensure the webinars always use the cutdown option - wordpress does that easily. Your plugin just fills in the gaps. If no info is given then it can use defaults you've coded in to ensure the page gets fleshed out.
Cutdown template? The plugin has a settings menu users will submit their webinar details including layout info. Remember this plugin is for distribution so I need a solution that will work for the masses not just on my wordpress install.
Yep, that's what I was suggesting. If not a cutdown template then one with the user's styles placed in the header so that they overwrite the default css. Steps. 1. user puts default background, images etc into their user profile for the plugin - either in the user profile section or on a page just for the plugin 2. user uploads webinar 3. user views webinar on page and the page has additional styles added to it with the settings from #1
I found the Gys Themed Categories plugin that does what I want to do but it only applies to post categories not pages which is what my webinar plugin creates. Any idea on how I can change this to apply to pages since they aren't associated to categories or tags? I've posted the code for the plugin's only file below: <?php /* Plugin Name: GYS Themed Categories Plugin URI: http://get-your-stuff.com/ Description: This plugin allows you to assign themes to each of your Wordpress categories. To assign themes to your categories, just go to Manage->Categories and you'll see a dropdown of all available themes at the bottom of the form. Get more GYS Themes and Plugins at <a href="http://get-your-stuff.com/">Get-Your-Stuff.Com</a>. Author: Mike Lopez Version: 2.1 Author URI: http://mikelopez.info/ */ if(!class_exists('GYSThemedCategories')){ class GYSThemedCategories{ function GYSThemedCategories(){ $this->BlogCharset=get_option('blog_charset'); $this->OptionName=strtoupper(get_class($this)); $this->Options=get_option($this->OptionName); } function GetOption(){ $options=func_get_args(); $option=$this->Options; foreach($options AS $o){ $option=$option[$o]; } return $option; } function SetOptions(){ $options=func_get_args(); for($i=0;$i<count($options);$i+=2){ $this->Options[$options[$i]]=$options[$i+1]; } update_option($this->OptionName,$this->Options); } // hooks // CATEGORY FORM PROCESSING function EditCategoryForm(){ $themes=get_themes(); $template=$this->GetOption('CategoryThemes',$_GET['cat_ID']); $options='<option value="">---</option>'; foreach($themes AS $theme){ $selected=$theme['Template']==$template?' selected="true" ':''; $options.='<option value="'.$theme['Template'].'"'.$selected.'>'.__($theme['Name']).' '.$theme['Version'].'</option>'; } $form=<<<STRING <div id="GYSThemedCategories"> <h3>GYS Themed Categories</h3> <table class="form-table"> <tbody> <tr class="form-field"> <th valign="top" scope="row">Category Theme</th> <td><select name="GYSThemedCategories">{$options}</select></td> </tr> </tbody> </table> </div> <script type="text/javascript"> //<![CDATA[ function GYSThemedCategories(){ try{ var x=document.getElementById('GYSThemedCategories'); var p=x.parentNode; var t=p.getElementsByTagName('p')[0]; p.insertBefore(x,t); }catch(e){} } GYSThemedCategories(); //]]> </script> STRING; echo $form; } function SaveCategory($id){ if(isset($_POST['GYSThemedCategories'])){ $catthemes=$this->GetOption('CategoryThemes'); if($_POST['GYSThemedCategories']){ $catthemes[$id]=$_POST['GYSThemedCategories']; }else{ unset($catthemes[$id]); } $this->SetOptions('CategoryThemes',$catthemes); } } // TEMPLATE PROCESSING function Template($template){ $pid=$cid=0; $perms=get_option('permalink_structure'); if($perms){ // get current URL if permalinks are set $s=empty($_SERVER['HTTPS'])?'':$_SERVER['HTTPS']=='on'?'s':''; $protocol='http'.$s; $port=$_SERVER['SERVER_PORT']=='80'?'':':'.$_SERVER['SERVER_PORT']; $url=$protocol.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; list($url)=explode('?',$url); // get Post ID from URL $pid=url_to_postid($url); // get Category ID from URL list($url)=explode('/page/',$url); // <- added for paging compatibility $cid=get_category_by_path($url,false); $cid=$cid->cat_ID; }else{ // no permalinks so we simply check GET vars $pid=$_GET['p']; $cid=$_GET['cat']; } if($pid){ // we're in a post page... so let's get the first category of this post list($cat)=wp_get_post_categories($pid); }elseif($cid){ // we're in a category page... $cat=$cid; } if($cat){ // we have our category ID now so let's get the theme for it... $theme=$this->GetOption('CategoryThemes',$cat); // change template if a theme is specified for this category if($theme)$template=$theme; } $this->Theme=$template; return $template; } function Stylesheet(){ return $this->Theme; } } } if(class_exists('GYSThemedCategories') && !isset($GYSThemedCategories)){ $GYSThemedCategories=new GYSThemedCategories(__FILE__); } if(isset($GYSThemedCategories)){ add_action('edit_category_form',array(&$GYSThemedCategories,'EditCategoryForm')); add_action('create_category',array(&$GYSThemedCategories,'SaveCategory')); add_action('edit_category',array(&$GYSThemedCategories,'SaveCategory')); add_filter('template',array(&$GYSThemedCategories,'Template')); add_filter('stylesheet',array(&$GYSThemedCategories,'Stylesheet')); } ?> Code (markup):
ASAIK all this does is let the user pick an existing template for their category. Normally the theme is dependent on the category or id. Pages already let you set a theme so there's no gain there. Your point of difference is that the user can set the theme dependent on their userid isn't it? So if my wp install had 3 users all creating pages with webinars then all 3 could have a different look and feel, right? Not quite sure why they are pages anyway, surely webinars belong in posts?
Right but they'd be able to maintain same core theme for rest of site. How does wp let you set a theme because tried with no success?
Through the interface or programmatically? Here's how you can do it programmatically: http://wordpress.stackexchange.com/questions/3761/switch-theme-on-fly Only you are switching from whatever the user wants to your custom theme but you may be better to just add to the page selected with the custom values
so when the user setups webinar details including layouts, etc...use the code from the link and it will load the associated theme for my plugin? So for example if user current theme is Twenty Ten Theme and they install my plugin and theme in their wp setup when they create a webinar using my plugin with all details will load my plugins theme for those webinar pages instead of their current theme. And visitors will still get the Twenty Ten Theme on the users homepage. Is that correct?
Yes, that's right. You can either let the user manually select the theme (which is then modified by the interface) or you can force it by overriding whatever they select.
I'd make the change at the time the page is called - that way any future changes to your plugin will be applied.
ok thanks Sarah you've been a big help ... spent all week trying to figure this out ... feeling stupid for not asking sooner lol but thanks again
I never cease to be impressed at the ways that wordpress let you mess with it. I even requested a hook once because it was missing and it was there in the very next release.
it didn't work ... function custom_load_twenty_ten_template() { return 'twentyten'; } function custom_load_twenty_ten_stylesheet() { return 'twentyten'; } add_filter( 'template', 'custom_load_twenty_ten_template' ); add_filter( 'stylesheet', 'custom_load_twenty_ten_stylesheet' ); Code (markup): Where would I place the code for wordpress to recognize it?