'', 'label' => '', // Alias of title. 'type' => 'text', 'tab' => 'text', 'name' => '', 'description' => '', 'desc' => '', // Alias of description. 'content' => '', // For html content. 'default' => null, 'show_default' => false, 'default_label' => false, 'placeholder' => '', 'choices' => array(), 'options' => array(), // Alias of options. ) ); if ( empty( $args['choices'] ) ) { $args['choices'] = $args['options']; } if ( empty( $args['description'] ) ) { $args['description'] = $args['desc']; } if ( empty( $args['title'] ) ) { $args['title'] = $args['label']; } unset( $args['label'], $args['options'], $args['desc'] ); $args['type'] = sanitize_text_field( $args['type'] ); return $args; } /** * Get all registered fields * * @return array */ public function get_all_fields() { return $this->fields; } /** * Get all registered tabs * * @return array */ public function get_all_tabs() { return $this->tabs; } /** * Set using tabs or not * * @param boolean $using Is using tab or not. */ public function using_tabs( $using ) { $this->using_tabs = $using; } /** * Set values for fields * * @param mixed $values Value to set. */ public function set_values( $values ) { $this->values = $values; } /** * Set Group name * * @param string $name Group name. */ public function set_group_name( $name ) { $this->group_name = $name; } /** * Get data from submitted form * * @return array */ public function get_submitted_values() { $data = $this->group_name && isset( $_REQUEST[ $this->group_name ] ) ? wp_unslash( $_REQUEST[ $this->group_name ] ) : wp_unslash( $_REQUEST ); // WPCS: XSS OK. $submitted_data = array(); foreach ( $this->fields as $field ) { if ( 'multiple_checkbox' == $field['type'] ) { foreach ( (array) $field['choices'] as $key => $label ) { $value = isset( $data[ $key ] ) ? $data[ $key ] : null; $submitted_data[ $key ] = $value; } } elseif ( $field['name'] ) { $value = isset( $data[ $field['name'] ] ) ? $data[ $field['name'] ] : null; $submitted_data[ $field['name'] ] = $value; } } return $submitted_data; } /** * Add a tab * * @param string $tab_id Tab ID. * @param array $args Settings. */ public function add_tab( $tab_id, $args ) { $args = wp_parse_args( $args, array( 'title' => '', 'icon' => '', ) ); $args['_id'] = $tab_id; $this->tabs[ $tab_id ] = $args; } /** * Add field * * @param array $args Settings. */ public function add_field( $args ) { $this->fields[] = $this->parse_args( $args ); } /** * Add fields * * @param array $fields Settings. */ public function add_fields( $fields ) { foreach ( $fields as $field ) { $this->add_field( $field ); } } /** * Reset fields */ public function reset_fields() { $this->fields = array(); } /** * Render input fields * * @param string $tab_id Tab ID. */ private function render_fields( $tab_id = false ) { foreach ( $this->fields as $field ) { if ( $tab_id ) { if ( $tab_id != $field['tab'] ) { continue; } } $cb = apply_filters( 'starterblog_render_field_cb', false, $field ); $_in_class = false; if ( ! is_callable( $cb ) ) { if ( method_exists( $this, 'field_' . $field['type'] ) ) { $cb = array( $this, 'field_' . $field['type'] ); $_in_class = true; } } ob_start(); if ( $cb ) { call_user_func_array( $cb, array( $field ) ); } $content = ob_get_clean(); if ( $content ) { $this->before_field( $field ); if ( $_in_class ) { $this->label( $field ); } echo '
'', ) ) ?> get_value( $args ); $image = wp_parse_args( $value, array( 'url' => '', 'id' => '', ) ); $args = wp_parse_args( $args, array( 'select_label' => __( 'Select image', 'starter-blog' ), 'remove_label' => __( 'Remove', 'starter-blog' ), ) ); $img = StarterBlog()->get_media( $image ); ?>