type() ) { case 'text_url': $type = new CMB2_Display_Text_Url( $field ); break; case 'text_money': $type = new CMB2_Display_Text_Money( $field ); break; case 'colorpicker': $type = new CMB2_Display_Colorpicker( $field ); break; case 'checkbox': $type = new CMB2_Display_Checkbox( $field ); break; case 'wysiwyg': case 'textarea_small': $type = new CMB2_Display_Textarea( $field ); break; case 'textarea_code': $type = new CMB2_Display_Textarea_Code( $field ); break; case 'text_time': $type = new CMB2_Display_Text_Time( $field ); break; case 'text_date': case 'text_date_timestamp': case 'text_datetime_timestamp': $type = new CMB2_Display_Text_Date( $field ); break; case 'text_datetime_timestamp_timezone': $type = new CMB2_Display_Text_Date_Timezone( $field ); break; case 'select': case 'radio': case 'radio_inline': $type = new CMB2_Display_Select( $field ); break; case 'multicheck': case 'multicheck_inline': $type = new CMB2_Display_Multicheck( $field ); break; case 'taxonomy_radio': case 'taxonomy_radio_inline': case 'taxonomy_select': case 'taxonomy_radio_hierarchical': $type = new CMB2_Display_Taxonomy_Radio( $field ); break; case 'taxonomy_multicheck': case 'taxonomy_multicheck_inline': case 'taxonomy_multicheck_hierarchical': $type = new CMB2_Display_Taxonomy_Multicheck( $field ); break; case 'file': $type = new CMB2_Display_File( $field ); break; case 'file_list': $type = new CMB2_Display_File_List( $field ); break; case 'oembed': $type = new CMB2_Display_oEmbed( $field ); break; default: $type = new self( $field ); break; }// End switch. return $type; } /** * Setup our class vars * * @since 2.2.2 * @param CMB2_Field $field A CMB2 field object. */ public function __construct( CMB2_Field $field ) { $this->field = $field; $this->value = $this->field->value; } /** * Catchall method if field's 'display_cb' is NOT defined, or field type does * not have a corresponding display method * * @since 2.2.2 */ public function display() { // If repeatable. if ( $this->field->args( 'repeatable' ) ) { // And has a repeatable value. if ( is_array( $this->field->value ) ) { // Then loop and output. echo ''; } } else { $this->_display(); } } /** * Default fallback display method. * * @since 2.2.2 */ protected function _display() { print_r( $this->value ); } } class CMB2_Display_Text_Url extends CMB2_Field_Display { /** * Display url value. * * @since 2.2.2 */ protected function _display() { echo make_clickable( esc_url( $this->value ) ); } } class CMB2_Display_Text_Money extends CMB2_Field_Display { /** * Display text_money value. * * @since 2.2.2 */ protected function _display() { $this->value = $this->value ? $this->value : '0'; echo ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$' : ' ' ), $this->value; } } class CMB2_Display_Colorpicker extends CMB2_Field_Display { /** * Display color picker value. * * @since 2.2.2 */ protected function _display() { echo ' ', esc_html( $this->value ), ''; } } class CMB2_Display_Checkbox extends CMB2_Field_Display { /** * Display multicheck value. * * @since 2.2.2 */ protected function _display() { echo $this->value === 'on' ? 'on' : 'off'; } } class CMB2_Display_Select extends CMB2_Field_Display { /** * Display select value. * * @since 2.2.2 */ protected function _display() { $options = $this->field->options(); $fallback = $this->field->args( 'show_option_none' ); if ( ! $fallback && isset( $options[''] ) ) { $fallback = $options['']; } if ( ! $this->value && $fallback ) { echo $fallback; } elseif ( isset( $options[ $this->value ] ) ) { echo $options[ $this->value ]; } else { echo esc_attr( $this->value ); } } } class CMB2_Display_Multicheck extends CMB2_Field_Display { /** * Display multicheck value. * * @since 2.2.2 */ protected function _display() { if ( empty( $this->value ) || ! is_array( $this->value ) ) { return; } $options = $this->field->options(); $output = array(); foreach ( $this->value as $val ) { if ( isset( $options[ $val ] ) ) { $output[] = $options[ $val ]; } else { $output[] = esc_attr( $val ); } } echo implode( ', ', $output ); } } class CMB2_Display_Textarea extends CMB2_Field_Display { /** * Display textarea value. * * @since 2.2.2 */ protected function _display() { echo wpautop( wp_kses_post( $this->value ) ); } } class CMB2_Display_Textarea_Code extends CMB2_Field_Display { /** * Display textarea_code value. * * @since 2.2.2 */ protected function _display() { echo '' . print_r( $this->value, true ) . ''; } } class CMB2_Display_Text_Time extends CMB2_Field_Display { /** * Display text_time value. * * @since 2.2.2 */ protected function _display() { echo $this->field->get_timestamp_format( 'time_format', $this->value ); } } class CMB2_Display_Text_Date extends CMB2_Field_Display { /** * Display text_date value. * * @since 2.2.2 */ protected function _display() { echo $this->field->get_timestamp_format( 'date_format', $this->value ); } } class CMB2_Display_Text_Date_Timezone extends CMB2_Field_Display { /** * Display text_datetime_timestamp_timezone value. * * @since 2.2.2 */ protected function _display() { $field = $this->field; if ( empty( $this->value ) ) { return; } $datetime = maybe_unserialize( $this->value ); $this->value = $tzstring = ''; if ( $datetime && $datetime instanceof DateTime ) { $tz = $datetime->getTimezone(); $tzstring = $tz->getName(); $this->value = $datetime->getTimestamp(); } $date = $this->field->get_timestamp_format( 'date_format', $this->value ); $time = $this->field->get_timestamp_format( 'time_format', $this->value ); echo $date, ( $time ? ' ' . $time : '' ), ( $tzstring ? ', ' . $tzstring : '' ); } } class CMB2_Display_Taxonomy_Radio extends CMB2_Field_Display { /** * Display single taxonomy value. * * @since 2.2.2 */ protected function _display() { $taxonomy = $this->field->args( 'taxonomy' ); $types = new CMB2_Types( $this->field ); $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Radio' ); $terms = $type->get_object_terms(); $term = false; if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) { $term = get_term_by( 'slug', $default, $taxonomy ); } elseif ( ! empty( $terms ) ) { $term = $terms[ key( $terms ) ]; } if ( $term ) { $link = get_edit_term_link( $term->term_id, $taxonomy ); echo '', esc_html( $term->name ), ''; } } } class CMB2_Display_Taxonomy_Multicheck extends CMB2_Field_Display { /** * Display taxonomy values. * * @since 2.2.2 */ protected function _display() { $taxonomy = $this->field->args( 'taxonomy' ); $types = new CMB2_Types( $this->field ); $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Multicheck' ); $terms = $type->get_object_terms(); if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) { $terms = array(); if ( is_array( $default ) ) { foreach ( $default as $slug ) { $terms[] = get_term_by( 'slug', $slug, $taxonomy ); } } else { $terms[] = get_term_by( 'slug', $default, $taxonomy ); } } if ( is_array( $terms ) ) { $links = array(); foreach ( $terms as $term ) { $link = get_edit_term_link( $term->term_id, $taxonomy ); $links[] = '' . esc_html( $term->name ) . ''; } // Then loop and output. echo '
'; echo implode( ', ', $links ); echo '
'; } } } class CMB2_Display_File extends CMB2_Field_Display { /** * Display file value. * * @since 2.2.2 */ protected function _display() { if ( empty( $this->value ) ) { return; } $this->value = esc_url_raw( $this->value ); $types = new CMB2_Types( $this->field ); $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' ); $id = $this->field->get_field_clone( array( 'id' => $this->field->_id() . '_id', ) )->escaped_value( 'absint' ); $this->file_output( $this->value, $id, $type ); } protected function file_output( $url_value, $id, CMB2_Type_File_Base $field_type ) { // If there is no ID saved yet, try to get it from the url. if ( $url_value && ! $id ) { $id = CMB2_Utils::image_id_from_url( esc_url_raw( $url_value ) ); } if ( $field_type->is_valid_img_ext( $url_value ) ) { $img_size = $this->field->args( 'preview_size' ); if ( $id ) { $image = wp_get_attachment_image( $id, $img_size, null, array( 'class' => 'cmb-image-display', ) ); } else { $size = is_array( $img_size ) ? $img_size[0] : 200; $image = ''; } echo $image; } else { printf( '
%1$s %3$s
', esc_html( $field_type->_text( 'file_text', esc_html__( 'File:', 'opalestate-pro' ) ) ), $url_value, CMB2_Utils::get_file_name_from_path( $url_value ) ); } } } class CMB2_Display_File_List extends CMB2_Display_File { /** * Display file_list value. * * @since 2.2.2 */ protected function _display() { if ( empty( $this->value ) || ! is_array( $this->value ) ) { return; } $types = new CMB2_Types( $this->field ); $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' ); echo ''; } } class CMB2_Display_oEmbed extends CMB2_Field_Display { /** * Display oembed value. * * @since 2.2.2 */ protected function _display() { if ( ! $this->value ) { return; } cmb2_do_oembed( array( 'url' => $this->value, 'object_id' => $this->field->object_id, 'object_type' => $this->field->object_type, 'oembed_args' => array( 'width' => '300', ), 'field_id' => $this->field->id(), ) ); } }