aristath
Supreme Deity
WPMU DEV Staff
Lifetime member
Support Hamster Likes (0)
The WordPress theme customizer of WP 3.4 is simply a wonderful thing... So I was wondering if we could take advantage of its simplicity and beauty for more things.
I think it would be nice to have MarketPress's presentation options available there. After all, Presentation options belong in the presentation options of wordpress. :)
So I created a plugin that simply adds these option to the theme customizer. The options appear as expected and it's wonderful! However the changes are not applied so I was wondering if you can spot what I did wrong... Did I ommit something?
Here's my code:
<?php
/*
Plugin Name: MarketPress Customizer
*/
add_action( 'customize_register', 'mp_customize_register' );
function mp_customize_register($wp_customize){
global $mp;
$wp_customize->add_section( 'marketpress_presentation_single', array(
'title' => __( 'Single Product', 'mp' ),
'priority' => 55,
) );
$wp_customize->add_setting( 'mp[product_button_type]', array(
'default' => 'addcart',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_product_button_type', array(
'label' => __( 'Checkout Button Type', 'mp' ),
'section' => 'marketpress_presentation_single',
'settings' => 'mp[product_button_type]',
'type' => 'select',
'choices' => array(
'addcart' => 'Add to Cart',
'buynow' => 'Buy Now',
),
) );
$wp_customize->add_setting( 'mp[show_quantity]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_show_quantity', array(
'label' => __( 'Show Quantity Option', 'mp' ),
'section' => 'marketpress_presentation_single',
'settings' => 'mp[show_quantity]',
'type' => 'select',
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
) );
$wp_customize->add_setting( 'mp[show_img]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_show_img', array(
'label' => __( 'Show Product Image', 'mp' ),
'section' => 'marketpress_presentation_single',
'settings' => 'mp[show_img]',
'type' => 'select',
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
) );
$wp_customize->add_setting( 'mp[show_lightbox]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_show_lightbox', array(
'label' => __( 'Show Image Lightbox', 'mp' ),
'section' => 'marketpress_presentation_single',
'settings' => 'mp[show_lightbox]',
'type' => 'select',
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
) );
$wp_customize->add_section( 'marketpress_presentation_list', array(
'title' => __( 'Product List View', 'mp' ),
'priority' => 55,
) );
$wp_customize->add_setting( 'mp[list_view]', array(
'default' => 'list',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_list_view', array(
'label' => __( 'List View', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[list_view]',
'type' => 'select',
'choices' => array(
'list' => 'List',
'grid' => 'Grid',
),
) );
$wp_customize->add_setting( 'mp[list_button_type]', array(
'default' => 'addcart',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_list_button_type', array(
'label' => __( 'Checkout Button Type', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[list_button_type]',
'type' => 'select',
'choices' => array(
'addcart' => 'Add to Cart',
'buynow' => 'Buy Now',
),
) );
$wp_customize->add_setting( 'mp[show_thumbnail]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_show_thumbnail', array(
'label' => __( 'Show Product Thumbnail', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[show_thumbnail]',
'type' => 'select',
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
) );
$wp_customize->add_setting( 'mp[paginate]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_paginate', array(
'label' => __( 'Paginate Products', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[paginate]',
'type' => 'select',
'choices' => array(
'1' => 'Yes',
'0' => 'No',
),
) );
$wp_customize->add_setting( 'mp[per_page]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_paginate', array(
'label' => __( 'Products per page', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[per_page]',
) );
$wp_customize->add_setting( 'mp[order_by]', array(
'default' => 'sales',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_order_by', array(
'label' => __( 'Order Products By', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[order_by]',
'type' => 'select',
'choices' => array(
'title' => 'Title',
'date' => 'Date',
'ID' => 'Product ID',
'author' => 'Author',
'sales' => 'Sales',
'price' => 'Price',
'rand' => 'Random',
),
) );
$wp_customize->add_setting( 'mp[order]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'mp_order', array(
'label' => __( 'Paginate Products', 'mp' ),
'section' => 'marketpress_presentation_list',
'settings' => 'mp[order]',
'type' => 'select',
'choices' => array(
'DESC' => 'Descending',
'ASC' => 'Ascending',
),
) );
}
For better visibility you can also see it here: https://gist.github.com/3403952
Any advice?

Responses (17)
Support Kangaroo (joined March 2011) Likes (0)
Greetings aristath,
My neighbor to the South it is good to hear from you!
Once again it is apparent that your are submitting some outstanding code to the community and though I am not a coder it certainly sounds like a great function to add.
I will message our lead developer @Aaron to take a look at this outstanding submission and to offer his take on it and possible inclusion.
Thank you as always Aristath.
Cheers, Joe
Support Hamster (joined March 2012) Likes (0)
@aecnu thank you very much!! Both for the points and for notifying Aaron!
P.S. Nice pic... the view looks wonderful. Were you on vacation?
Support Kangaroo (joined March 2011) Likes (0)
Greetings aristath,
Yepper my neighbor to the South I was on vacation for approximately 10 days and here if the link for photo's thereof:
http://freegiftsgiveaway.com/Vacation2012/vacation_2012.htm
Enjoy!
Cheers, Joe
Support Hamster (joined March 2012) Likes (0)
I still haven't figured out how to make this work...
You can see the code here: https://gist.github.com/3403952 but obviously there's something missing...
Member (joined January 2012) Likes (0)
Wow !! Great contribution.
Support Hamster (joined March 2012) Likes (0)
@sachingopalakrishnan well it doesn't work yet, it just looks cool! :P
Front Line Support (joined July 2012) Likes (0)
Very cool. I'm playing around with it. I have some ideas... I might be onto something...
Front Line Support (joined July 2012) Likes (0)
Ok, so here's my understanding of what's happening. You are registering all these settings and controls etc. But all that does is create new options to be accessed by the theme. It's not modifying any existing settings. Instead, it's creating new handles that the theme itself can pull from to render a page a certain way.
I hate to say it, but I think you're just creating new options via a different API with the same names as the marketpress ones...
Front Line Support (joined July 2012) Likes (0)
For example, if you look at the code from this page...
http://codex.wordpress.org/Theme_Customization_API
That function is hooked into wp_head. So it takes the fields defined in the customizer to render new CSS on the fly within the theme.
Support Hamster (joined March 2012) Likes (0)
that's why I added
global $mp;
and the names of the settings are the ones used in marketpress, for example mp[list_view], mp[product_button_type] etc.
Since the settings with those names already exist (from marketpress), they are not "created", they are instead "referenced". At least that's what I remember reading...
Support Hamster (joined March 2012) Likes (0)
The code you referenced is just a sample. You can manipulate the settings you add in the customizer in lots of ways, not just for outputting css.
Front Line Support (joined July 2012) Likes (0)
The information you're referencing from the Settings API is just giving a name and ID to fields you are creating in the Theme Customization API. Calling "add_section" truly creates a new section with the name you chose. It doesn't care where the name came from, it just creates a new section. So it has the same name, but doesn't actually have any idea that it's at all related
So you created your User Interface. Now you're just missing a bridge between the two.... Also, I think that it would be more ideal to define the "Default" by actually retrieving the settings from marketpress. That way when the customizer opens, it will show what the current settings are.
Front Line Support (joined July 2012) Likes (0)
What I'm getting at is they are two separate systems. The Theme Customization API was made to give Theme Designers a little more flexibility without forcing them to become plugin developers. They don't actually function together in and of themselves...
Ok correction. Looks like the Theme Customization API is built on the Settings API. All the theme settings are serialized into one Setting associated with the blog. But the still technically operate on different levels.
Support Hamster (joined March 2012) Likes (0)
I'll have to disagree with that. Just because the customizer was designed having in mind presentation settings, doesn't mean that it can't be used to manipulate other settings as well!
Take for example all the options that were present before the customization API was introduced... You can change the sitename, the site info, header etc. Options that are simply displayed and altered using the customizer.
To get marketpress's mp[product_button_type] settings, you would write
get_setting('mp[product_button_type]')which is exactly what you use to get any option that's on the theme customizer!All those options are stored in the database and there's nothing in the db to differentiate them!
EDIT:
I just opened up marketpress.php and I think I understand why this is not working...
Line 5736 for example is this:
<label><input value="addcart" name="mp[product_button_type]" type="radio"<?php checked($this->get_setting('product_button_type'), 'addcart') ?> /> <?php _e('Add To Cart', 'mp') ?></label><br />I realized that I accidentally used the name of the setting ( mp[product_button_type] ) instead of the actual setting ( product_button_type )!!
I'll correct those and report back... :)
Front Line Support (joined July 2012) Likes (0)
Ok I see what you're getting at. So the setting already exists and should be accessible. It just still feels off to me... When you call "add_setting" doesn't that register a new setting to used?
I think you're reaching out the scope of that setting's existence. If the Settings of a blog were a tree, it would look kinda like this:
Settings
----Site Title
----Tagline
----Marketpress settings
----Lines for other plugins
----Theme Customizer Settings (serialized data)
----------Custom setting 1
----------Custom setting 2
So called "add_setting" on the customize object creates a new setting field within the existing blog setting of "Theme Customizer Settings"
Support Hamster (joined March 2012) Likes (0)
yeah, you're probably right... I'll have to think this through some more before re-attempting it.
Support Kangaroo (joined March 2011) Likes (0)
Greetings Everyone,
Doing some house keeping this weekend and found this ticket hanging around in the back of the ticket system.
Marking it as resolved since it has had no action for quite sometime now.
Cheers, Joe
Become a member