Open webmandesign opened 7 years ago
Hi Oliver,
If you are looking for an option to add custom widget classes for the theme. You can use something like this to modify the options value :
add_action( 'after_setup_theme', 'widgetopts_add_custom_classes' );
function widgetopts_add_custom_classes(){
if( get_option( '_widgetopts_default_registered_' ) && !get_option( 'widgetopts_add_custom_classes' ) ){
$settings = unserialize( get_option( 'widgetopts_tabmodule-settings' ) );
$classes = ( isset( $settings['classes'] ) ) ? $settings['classes'] : array();
$classlists = ( isset( $classes['classlists'] ) && is_array( $classes['classlists'] ) ) ? $classes['classlists'] : array();
//your predefined classes
$theme_classes = array( 'bordered', 'blue_theme', 'modern' );
//merge
$classlists = array_merge( $classlists, $theme_classes );
//assign values
$settings['classes']['classlists'] = $classlists;
update_option( 'widgetopts_tabmodule-settings', serialize( $settings ) );
add_option( 'widgetopts_add_custom_classes', '1' );
}
}
Let me know how it goes. Thanks!
Cheers, Jeffrey
Hi Jeffrey,
Thank you for the solution, but this won't do for me, sorry. I feel like this is a bit more complicated solution as I need to create additional widgetopts_add_custom_classes
option for my future reference that I have updated the classes of the plugin.
I've tried hooking onto option_widgetopts_tabmodule-settings
filter to modify the plugin options with no luck. It somehow don't work. Probably because the plugin calls the get_option( 'option_widgetopts_tabmodule-settings' );
before the my theme's hook is being queued.
I have also noticed that you are loading all plugin files all the time, which among others also mean you are firing get_option( 'option_widgetopts_tabmodule-settings' )
all the time, even on front-end where it is not needed. Please consider optimizing your code.
I will have to wait to recommend the plugin in my themes so, sorry.
Thank you and good luck!
Regards,
Oliver
Hi Oliver,
Thank you very much for your suggestions. Will definitely make this plugin better ;) If in any case I've added some filters will let you know. Thanks!
Cheers, Jeffrey
Hi Oliver,
As part of the plugin roadmap, I've improve the pattern and performance which is currently on develop branch : https://github.com/phpbits/widget-options/tree/develop . I thought you might wanna check it out. You can create a custom class list using widgetopts_get_settings
filter.
add_filter( 'widgetopts_get_settings', 'sample_widgetopts_get_settings' );
function sample_widgetopts_get_settings( $widget_options ){
//add theme predefined classes
$classes = array( 'newsletter-box', 'modern-widget' );
//avoid error when not activated
if( 'activate' == $widget_options['classes'] && isset( $widget_options['settings']['classes'] ) && isset( $widget_options['settings']['classes']['classlists'] ) ){
$widget_options['settings']['classes']['classlists'] = array_merge( $widget_options['settings']['classes']['classlists'], $classes );
}
return $widget_options;
}
Let me know how it goes :) Thanks!
Cheers, Jeffrey
Thank you for update, Jeffrey!
I will check this as soon as possible (currently having a lot of updates to finish myself ;)).
Hi,
No problem :) Just let me know whenever you encounter any plugin issues. Thanks!
Cheers, Jeffrey
Hi,
The updates were pushed on the repository : https://wordpress.org/plugins/widget-options/ . Just in case you'll be testing it. Just let me know how it goes so that I can update/close this thread. Thank you very much!
Cheers, Jeffrey
Hi Jeffrey,
Sorry, this does not work for me still.
The problems I'm facing:
First of all, I've adapted your code so my custom classes are available also before someone adds their own classes via the plugin admin setup. I've just simply removed the isset( $widget_options['settings']['classes'] ) && isset( $widget_options['settings']['classes']['classlists'] )
portion from your code and adapted it to my needs. This is a very minor issue though, I just wanted to point it out for others using the code above.
Major issue is that when I add my custom classes using the filter, these classes are also displayed in plugin admin setup screen as such they were previously saved.
Thus allowing users to remove those classes only visually, while they still pop up in actual widget options as I add them with code. This creates user experience problem.
Also, when I click save on the plugin CSS classes settings screen, the classes I've added with a custom code are also saved to database as plugin options and I have to check for duplicates in my code later.
There is also an issue with code executing priority. I tend to hook all the theme functionality to after_setup_theme
action hook. However, your plugin runs immediately as you just call the WIDGETOPTS()
function immediately at the end of plugin.php
file. This could be fixed by hooking the function like add_action( 'init', 'WIDGETOPTS' );
instead.
Finally (at least what I have spotted now) when I set a class in a specific widget options, it does not work, the class is not being applied on my website frontend. It does not matter if I pick the class from the predefined, saved classes or I type in my own class.
As you can see, I experience quite a lot of issues with the plugin, so it seems it's not really for me, sorry. At least not as of now.
Regards,
Oliver
Hi,
Great plugin, thank you for it!
From what I can see there is no easy way to predefine a set of custom CSS classes. I am a theme author and would like to provide such a set, however, currently the only solution I can see is to hook onto and modify the serialized
widgetopts_tabmodule-settings
option. Or am I missing something and is there a different, easier solution?Please consider introducing a filter hook for this.
Thank you!
Oliver