设置默认的小工具配置
首先了解一下小工具在数据库中的体现:
第一:
打开`wp_options`相关配置项'sidebars_widgets':
SELECT *
FROM `wp_options`
WHERE option_name = 'sidebars_widgets'
LIMIT 0 , 30
s:30:"hp-section-sorting-widget-area"; a:9:{ i:0;s:15:"blogs_section-1"; i:1;s:19:"portfolio_section-1"; i:2;s:17:"service_section-1"; i:3;s:15:"video_section-1"; i:4;s:21:"testimonial_section-1"; i:5;s:15:"media_gallery-2"; i:6;s:17:"pricing_section-1"; i:7;s:15:"teams_section-1"; i:8;s:19:"contactus_section-1"; }
可以通过命令获取:get_option('sidebars_widgets');
第二:打开各小工具的配置
widget_XX(小工具名),值就是小工具的配置
根据如上值
/** * Set new widgets on theme activate * @param string $old_theme * @param WP_Theme $WP_theme */ function onepage_default_widgets() { $sidebar_option = get_option('sidebars_widgets'); if ($sidebar_option && empty($sidebar_option['hp-section-sorting-widget-area'])) { $widget_value = array(); //配置各小工具的值
$widget_value[1] = array(); $widget_value['_multiwidget'] = '1';
update_option('widget_service_section', $widget_value); update_option('widget_blogs_section', $widget_value); update_option('widget_portfolio_section', $widget_value); update_option('widget_video_section', $widget_value); update_option('widget_testimonial_section', $widget_value); update_option('widget_pricing_section', $widget_value); update_option('widget_teams_section', $widget_value); update_option('widget_contactus_section', $widget_value);
$sidebars_widgets["hp-section-sorting-widget-area"] = array( "service_section-1", "blogs_section-1", "portfolio_section-1", "video_section-1", "testimonial_section-1", "pricing_section-1", "teams_section-1", "contactus_section-1" ); // save new widgets to DB update_option('sidebars_widgets', $sidebars_widgets); } }
挂在'after_setup_theme'钩子上
add_action('after_setup_theme', 'onepage_default_widgets');
posted @
2019-03-10 15:52 赵蔚冬 阅读(
...) 评论(
...) 编辑 收藏