retesere20

register-widgets-sample

Feb 25th, 2020
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //add_action( 'init', 'my_menu_registerss3' );
  2. public function my_menu_registerss3() {
  3. $menu_name='aamy-vustom-menu';
  4. $menu_exists = wp_get_nav_menu_object('aamy-vustom-menu');
  5. if( !$menu_exists){
  6. $menu_id = wp_create_nav_menu($menu_name);
  7. // Set up default menu items
  8. wp_update_nav_menu_item($menu_id, 0, array(
  9. 'menu-item-title' => __('Home'),
  10. 'menu-item-classes' => 'home',
  11. 'menu-item-url' => home_url( '/' ),
  12. 'menu-item-status' => 'publish'));
  13.  
  14. wp_update_nav_menu_item($menu_id, 0, array(
  15. 'menu-item-title' => __('Custom Page'),
  16. 'menu-item-url' => home_url( '/custom/' ),
  17. 'menu-item-status' => 'publish'));
  18. }
  19. // maybe it should be in: after_theme_setup
  20. register_nav_menus(array(
  21. 'menu_left_sidebarr' =>'zzleft Main Menu',
  22. 'menu_right_sidebarr' =>'zzright Main Menu'
  23. ));
  24. }
  25.  
  26.  
  27. define('my_sample_array_widgets', 'my_top_widgett,');
  28. add_action('admin_init', function(){
  29. if($GLOBALS['pagenow']== 'widgets.php'){
  30. if(isset($_GET['widget_add'])){
  31.  
  32. update_option('optname_widgets', explode(',', filter_var($_GET['widgets_list'], FILTER_SANITIZE_STRING ) ) ) ;
  33. }
  34.  
  35. add_action('admin_notices', function() {
  36. ?>
  37. <div><form action="" method="POST">enter widgets list (comma separated): <input type="text" value="<?php echo get_option('optname_widgets',my_sample_array_widgets);?>" name="widget_add" /> <input type="submit" /></form></div>
  38. <?php
  39. });
  40. }
  41. });
  42.  
  43. add_action( 'widgets_init', public function ()
  44. {
  45. $optval=get_option('optname_widgets', my_sample_array_widgets);
  46. $additional_array = !empty($GLOBALS['MyWidgetss']) ? $GLOBALS['MyWidgetss'] : array();
  47. $widgets= array_merge( explode(',',$optval), $additional_array );
  48. if (!empty($widgets) ) {
  49. foreach ($widgets as $value){
  50. register_sidebar( array('name' => $value ,'id' => strtolower($value), 'before_widget'=>'<div class="sideb_clas '.$value.'">','after_widget'=>'</div>','before_title'=>'<h2 class="sideb_around">','after_title'=>'</h2>') );
  51. }
  52. }
  53. });
RAW Paste Data