_sections; } /** * Add a section. * * @since 1.0.0. * * @param string $id Unique ID for the section. Alphanumeric characters only. * @param string $label Name to display for the section. * @param string $description Section description. * @param string $icon URL to the icon for the display. * @param string $save_callback Function to save the content. * @param string $builder_template Path to the template used in the builder. * @param string $display_template Path to the template used for the frontend. * @param int $order The order in which to display the item. * @param string $path The path to the template files. * @return void */ public function add_section( $id, $label, $icon, $description, $save_callback, $builder_template, $display_template, $order, $path ) { $this->_sections[ $id ] = array( 'id' => $id, 'label' => $label, 'icon' => $icon, 'description' => $description, 'save_callback' => $save_callback, 'builder_template' => $builder_template, 'display_template' => $display_template, 'order' => $order, 'path' => $path, ); } /** * Remove a section. * * @since 1.0.7. * * @param string $id Unique ID for an existing section. Alphanumeric characters only. * @return void */ public function remove_section( $id ) { if ( isset( $this->_sections[ $id ] ) ) { unset( $this->_sections[ $id ] ); } } } endif; if ( ! function_exists( 'bgbn_get_sections_class' ) ) : /** * Instantiate or return the one bgbn_Sections instance. * * @since 1.0.0. * * @return bgbn_Sections */ function bgbn_get_sections_class() { return bgbn_Sections::instance(); } endif; if ( ! function_exists( 'bgbn_get_sections' ) ) : /** * Get the registered sections. * * @since 1.0.0. * * @return array The list of registered sections. */ function bgbn_get_sections() { return bgbn_get_sections_class()->get_sections(); } endif; if ( ! function_exists( 'bgbn_get_sections_by_order' ) ) : /** * Get the registered sections by the order parameter. * * @since 1.0.0. * * @return array The list of registered sections in the parameter order. */ function bgbn_get_sections_by_order() { $sections = bgbn_get_sections_class()->get_sections(); usort( $sections, 'bgbn_sorter' ); return $sections; } endif; if ( ! function_exists( 'bgbn_sorter' ) ) : /** * Callback for `usort()` that sorts sections by order. * * @since 1.0.0. * * @param mixed $a The first element. * @param mixed $b The second element. * @return mixed The result. */ function bgbn_sorter( $a, $b ) { return $a['order'] - $b['order']; } endif; if ( ! function_exists( 'bgbn_add_section' ) ) : /** * Add a section. * * @since 1.0.0. * * @param string $id Unique ID for the section. Alphanumeric characters only. * @param string $label Name to display for the section. * @param string $description Section description. * @param string $icon URL to the icon for the display. * @param string $save_callback Function to save the content. * @param string $builder_template Path to the template used in the builder. * @param string $display_template Path to the template used for the frontend. * @param int $order The order in which to display the item. * @param string $path The path to the template files. * @return void */ function bgbn_add_section( $id, $label, $icon, $description, $save_callback, $builder_template, $display_template, $order, $path ) { bgbn_get_sections_class()->add_section( $id, $label, $icon, $description, $save_callback, $builder_template, $display_template, $order, $path ); } endif; if ( ! function_exists( 'bgbn_remove_section' ) ) : /** * Remove a defined section. * * @since 1.0.7. * * @param string $id Unique ID for an existing section. Alphanumeric characters only. * @return void */ function bgbn_remove_section( $id ) { bgbn_get_sections_class()->remove_section( $id ); } endif;