widget_areas = $this->get_widget_areas(); array_push( $this->widget_areas, $_POST['kernel_add-widget-input'] ); $this->save_widget_areas(); wp_redirect( admin_url( 'widgets.php' ) ); die(); } } public function save_widget_areas() { set_theme_mod( 'widget_areas', array_unique( $this->widget_areas ) ); } /* Register and display the custom widget area */ public function register_sidebars() { // Get widget areas if ( empty( $this->widget_areas ) ) { $this->widget_areas = $this->get_widget_areas(); } // Original widget areas is empty $this->orig = array(); // Save widget areas if ( ! empty( $this->orig ) && $this->orig != $this->widget_areas ) { $this->widget_areas = array_unique( array_merge( $this->widget_areas, $this->orig ) ); $this->save_widget_areas(); } // If widget areas are defined add a sidebar area for each if ( is_array( $this->widget_areas ) ) { foreach ( array_unique( $this->widget_areas ) as $widget_area ) { $args = array( 'id' => sanitize_key( $widget_area ), 'name' => $widget_area, 'class' => 'kernel_custom', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ); register_sidebar( $args ); } } } /* Return the widget areas array */ public function get_widget_areas() { // If the single instance hasn't been set, set it now. if ( ! empty( $this->widget_areas ) ) { return $this->widget_areas; } // Get widget areas saved in theem mod $widget_areas = kernel_get_mod( 'widget_areas' ); // If theme mod isn't empty set to class widget area var if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) { $this->widget_areas = array_unique( array_merge( $this->widget_areas, $widget_areas ) ); } // Return widget areas return $this->widget_areas; } /* Delete widget_areas */ public function kernel_delete_widget_area() { // Check_ajax_referer('delete-kernel_widget_area-nonce'); if ( ! empty( $_REQUEST['name'] ) ) { $name = strip_tags( ( stripslashes( $_REQUEST['name'] ) ) ); $this->widget_areas = $this->get_widget_areas(); $key = array_search($name, $this->widget_areas ); if ( $key >= 0 ) { unset( $this->widget_areas[$key] ); $this->save_widget_areas(); } echo "widget_area-deleted"; } die(); } /* Enqueue JS for the customizer controls */ public function scripts() { // Load scripts wp_enqueue_style( 'dashicons' ); wp_enqueue_script( 'kernel_widget-areas', get_template_directory_uri() . '/assets/admin/js/widget_areas.js', array('jquery'), time(), true ); // Get widgets $widgets = array(); if ( ! empty( $this->widget_areas ) ) { foreach ( $this->widget_areas as $widget ) { $widgets[$widget] = 1; } } // Localize script wp_localize_script( 'kernel_widget-areas', 'kernelWidgetAreasLocalize', array( 'count' => count( $this->orig ), 'delete' => esc_html__( 'Delete', 'kernel' ), 'confirm' => esc_html__( 'Confirm', 'kernel' ), 'cancel' => esc_html__( 'Cancel', 'kernel' ), ) ); } /* Adds inline CSS */ public function inline_css() { ?>