%s', $id, $field['label'] ) : ''; } else { $label = ! empty( $field['label'] ) ? sprintf( '', $id, $field['label'] ) : ''; } $type = ! empty( $field['type'] ) ? $field['type'] : 'text'; switch ( $type ) { case 'wpeditor': $input = self::wpeditor_field( $id, $value, $field ); break; case 'select': $input = self::select_field( $id, $value, $field ); break; case 'textarea': $input = self::textarea_field( $id, $value, $field ); break; case 'hidden': $input = self::hidden_field( $id, $value, $field ); break; case 'checkbox': $input = self::checkbox_field( $id, $value, $field ); break; default: $input = self::text_field( $id, $value, $field ); } if ( 'hidden' === $type ) { return $input; } else { return self::format_rows( $label, $input, $field ); } } public static function wpeditor_field( $id, $value, $field = array() ) { $settings = array( 'wpautop' => true, // use wpautop - add p tags when they press enter 'teeny' => false, // output the minimal editor config used in Press This 'tinymce' => array( 'height' => '250', // the height of the editor ), ); if ( empty( $value ) && empty( $field['allow_empty'] ) && ! empty( $field['default'] ) ) { $value = $field['default']; } ob_start(); wp_editor( stripcslashes( $value ), $id, $settings ); return ob_get_clean(); } public static function select_field( $id, $value, $field = array() ) { if ( empty( $field['options'] ) ) { return ''; } $default_value = ! empty( $field['default'] ) ? $field['default'] : ''; $allowed_values = array_keys( $field['options'] ); if ( ! in_array( $value, $allowed_values ) ) { $value = $default_value; } $attributes = self::get_field_attributes( $field ); $name = ! empty( $field['name'] ) ? $field['name'] : $id; ob_start(); ?> ', esc_attr( $id ), esc_attr( $name ), $value, $attributes ); } public static function text_field( $id, $value, $field = array() ) { $type = ! empty( $field['type'] ) ? $field['type'] : 'text'; $attributes = self::get_field_attributes( $field ); $name = ! empty( $field['name'] ) ? $field['name'] : $id; return sprintf( '', esc_attr( $id ), esc_attr( $name ), esc_attr( $type ), esc_html( $value ), $attributes ); } public static function checkbox_field( $id, $value, $field = array() ) { $attributes = self::get_field_attributes( $field ); $name = ! empty( $field['name'] ) ? $field['name'] : $id; if ( 'on' != $value && $value != '1' ) { $value = ''; } $checked = ''; if ( ! empty( $value ) ) { $checked = ' checked'; } return sprintf( '', esc_attr( $id ), esc_attr( $name ), $checked, $attributes ); } public static function textarea_field( $id, $value, $field = array() ) { $type = ! empty( $field['type'] ) ? $field['type'] : 'text'; $attributes = self::get_field_attributes( $field ); $name = ! empty( $field['name'] ) ? $field['name'] : $id; return sprintf( '', esc_attr( $id ), esc_attr( $name ), $attributes, esc_textarea( $value ) ); } public static function get_field_attributes( $field ) { $attributes = ''; if ( ! empty( $field['classes'] ) ) { $classes = $field['classes']; if ( is_array( $classes ) ) { $classes = implode( ' ', $classes ); } $attributes .= ' class="' . esc_attr( $classes ) . '"'; } if ( ! empty( $field['step'] ) ) { $attributes .= ' step="' . esc_attr( $field['step'] ) . '"'; } $datas = array(); if ( ! empty( $field['data'] ) ) { foreach ( $field['data'] as $id => $val ) { $datas[] = 'data-' . esc_attr( $id ) . '="' . esc_attr( $val ) . '"'; } } if ( ! empty( $datas ) ) { $attributes .= ' ' . implode( ' ', $datas ); } return $attributes; } public static function get_container_attributes( $field ) { $attributes = ''; if ( ! empty( $field['container_classes'] ) ) { $classes = $field['container_classes']; if ( is_array( $classes ) ) { $classes = implode( ' ', $classes ); } $attributes .= ' class="' . esc_attr( $classes ) . '"'; } $datas = array(); if ( ! empty( $field['container_data'] ) ) { foreach ( $field['container_data'] as $id => $val ) { $datas[] = 'data-' . esc_attr( $id ) . '="' . esc_attr( $val ) . '"'; } } if ( ! empty( $datas ) ) { $attributes .= ' ' . implode( ' ', $datas ); } return $attributes; } public static function container_attributes( $field ) { if ( ! empty( $field['container_classes'] ) ) { $classes = $field['container_classes']; if ( is_array( $classes ) ) { $classes = implode( ' ', $classes ); } echo ' class="' . esc_attr( $classes ) . '"'; } if ( ! empty( $field['container_data'] ) ) { foreach ( $field['container_data'] as $id => $val ) { echo ' data-' . esc_attr( $id ) . '="' . esc_attr( $val ) . '"'; } } } public static function format_rows( $label, $input, $field = array() ) { $attributes = self::get_container_attributes( $field ); $short_description = ! empty( $field['short_description'] ) ? $field['short_description'] : ''; $description = ! empty( $field['description'] ) ? $field['description'] : ''; ob_start(); if ( empty( $field['row_template'] ) || ! file_exists( RRTNGG_ABS_PATH . 'templates/fields/' . $field['row_template'] . '.php' ) ) { ?> >