'; ?>
widget_areas = get_option( $this->option_name ); $name = $this->get_name( trim( $_POST['us_widget_area'] ) ); $id = $this->name_to_id( $name ); if ( empty( $this->widget_areas ) ) { $this->widget_areas = array( $id => $name ); } else { $this->widget_areas = array_merge( $this->widget_areas, array( $id => $name ) ); } // New post to represent Widget Area in menu wp_insert_post( array( 'post_type' => 'us_widget_area', 'post_date' => date( 'Y-m-d H:i', time() - 86400 ), 'post_name' => $id, 'post_title' => $name, 'post_status' => 'publish', ) ); update_option( $this->option_name, $this->widget_areas ); wp_redirect( admin_url( 'widgets.php' ) ); die(); } } public function delete_widget_area() { check_ajax_referer( 'us_delete_widget_area_nonce' ); if ( ! empty( $_POST['name'] ) ) { $name = stripslashes( $_POST['name'] ); $this->widget_areas = get_option( $this->option_name ); if ( ( $id = array_search( $name, $this->widget_areas ) ) !== FALSE ) { $widget_area_post = get_page_by_path( $id, OBJECT, 'us_widget_area' ); if ( $widget_area_post ) { wp_delete_post( $widget_area_post->ID ); } unset( $this->widget_areas[$id] ); update_option( $this->option_name, $this->widget_areas ); echo "success"; } } die(); } public function get_name( $name ) { if ( empty( $GLOBALS['wp_registered_sidebars'] ) ) { return $name; } $taken = array(); foreach ( $GLOBALS['wp_registered_sidebars'] as $widget_area ) { $taken[] = $widget_area['name']; } if ( empty( $this->widget_areas ) ) { $this->widget_areas = array(); } $taken = array_merge( array( $taken ), $this->widget_areas ); if ( in_array( $name, $taken ) ) { $counter = substr( $name, - 1 ); if ( ! is_numeric( $counter ) ) { $new_name = $name . " 1"; } else { $new_name = substr( $name, 0, - 1 ) . ( (int) $counter + 1 ); } $name = $this->get_name( $new_name ); } return $name; } public function register_widget_areas() { if ( empty( $this->widget_areas ) ) { $this->widget_areas = get_option( $this->option_name ); } $args = array( 'description' => __( 'Custom Sidebar', 'us' ), 'before_widget' => '', 'before_title' => '