Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So, I've been building a theme options page, one of the purposes of which is to get some style values to pass to my php stylesheet in the url.

Here's what I have:

/* Get all theme settings */

global $options;

$options = get_option( 'theme_options' );

/* ...and set 'em up! */

$stylevar = '?ts='.$options['thumbsize'].'?bg='.$options['bg_color'].'?tc='.$options['text_color'].'?hc='.$options['heading_color'].'?nc='.$options['nav_buttons_color'].'';

/* Enqueue */

if( !is_admin() ){

// This format works
wp_register_style('style', (get_bloginfo('stylesheet_directory') . '/lib/css/style.php?ts='.$options['thumbsize'].''));

// This doesn't
wp_register_style('style', (get_bloginfo('stylesheet_directory') . '/lib/css/style.php'.$stylevar.''));

wp_enqueue_style('style');

}

So two things are happening:

  1. I am getting a WP debug error I'd like to address: Notice: Undefined index etc. Presumably this has to do with not doing an isset check?
  2. Putting all the settings in a variable is failing, giving me: "style.php?ts=200%3Fbg%3D%3Ftc%3D%3Fhc%3D%3Fnc%3D&ver=3.2.1" type="text/css".

Here's where the schooling comes in. Is there a cleaner way of writing this? Could the options all be output with some king of loop? ... and how do I fix it?

Willing to learn, please teach :-)

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

PHP (as usual) has some nifty stuff, namely http_build_query() for putting together URL requests.

However for some reason (historically) PHP4 compatibility and encoding issues currently WP maintains fork of that function internally and offers build_query() wrapper, as well as nifty higher level function for URL manipulation add_query_arg() and remove_query_arg().

share|improve this answer
    
Interesting reading! The problem (or choice I made) was not to include the wp_blog_header file to load into my dynamic stylesheet. (I think) this means I can't use the WP functions as the style file is outside of the template schema. But I'll have a go at building the query string, and just use the old $_GET method... –  Niels Jul 21 '11 at 16:03
    
I mean retrieving the data from the query might have to be done the old fashioned way :-) –  Niels Jul 21 '11 at 16:09
    
Now does it stand to reason that since the function accepts an array, that I could build that array from my stored options?... hmmm, going to work on that. Now, time for bed (2:00 AM)... –  Niels Jul 21 '11 at 16:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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