Advertisement
arie_cristianD

add_compatible_to_widget

Jul 12th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. /**
  2.  * List JNews Widget Items
  3.  */
  4. add_action(
  5.     'plugins_loaded',
  6.     function() {
  7.         if ( isset( $_GET['page'] ) && 'widget-importer-exporter' === $_GET['page'] ) {
  8.             add_filter( 'jnews_load_register_widget', '__return_true' );
  9.         }
  10.     },
  11.     1
  12. );
  13.  
  14. /**
  15.  * Import JNews Widget Areas
  16.  */
  17. add_filter(
  18.     'wie_import_data',
  19.     function( $value ) {
  20.         $new_widget_area  = array_keys( get_object_vars( $value ) );
  21.         $widget_area_key  = 'jnews-widget-list';
  22.         $current_location = get_option( $widget_area_key );
  23.  
  24.         if ( is_array( $current_location ) ) {
  25.             $new_location = array_merge( $current_location, $new_widget_area );
  26.         } else {
  27.             $new_location = $new_widget_area;
  28.         }
  29.  
  30.         foreach ( $new_location as $widget ) {
  31.             register_sidebar(
  32.                 array(
  33.                     'id'            => sanitize_title( $widget ),
  34.                     'name'          => $widget,
  35.                     'before_widget' => '<div class="widget %2$s" id="%1$s">',
  36.                     'before_title'  => '',
  37.                     'after_title'   => '',
  38.                     'after_widget'  => '</div>',
  39.                 )
  40.             );
  41.         }
  42.  
  43.         update_option( $widget_area_key, $new_location );
  44.  
  45.         return $value;
  46.     }
  47. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement