settings_sections = $sections; return $this; } /** * Add a single section * * @param array $section */ function add_section( $section ) { $this->settings_sections[] = $section; return $this; } /** * Set settings fields * * @param array $fields settings fields array */ function set_fields( $fields ) { $this->settings_fields = $fields; return $this; } function add_field( $section, $field ) { $defaults = array( 'name' => '', 'label' => '', 'desc' => '', 'type' => 'text' ); $arg = wp_parse_args( $field, $defaults ); $this->settings_fields[$section][] = $arg; return $this; } /** * Initialize and registers the settings sections and fileds to WordPress * * Usually this should be called at `admin_init` hook. * * This function gets the initiated settings sections and fields. Then * registers them to WordPress and ready for use. */ function admin_init() { //register settings sections foreach ( $this->settings_sections as $section ) { if ( false == get_option( $section['id'] ) ) { add_option( $section['id'] ); } if ( isset($section['desc']) && !empty($section['desc']) ) { $section['desc'] = '