PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.0
Post Grid Gutenberg Blocks – PostX v5.1.0
5.1.1 5.1.0 5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 All 240 releases
← All changes | addons/dynamic_content/includes/DCService.php +30 -186 5.0.21 → 5.1.0 View file →
@@ -93,14 +93,9 @@
93 93 */
94 94 public static function get_dc_content_for_image( $post_id, $content_src ) {
95 95 $res = '';
96 96
97 - if (
98 - str_starts_with( $content_src, 'acf_' ) ||
99 - str_starts_with( $content_src, 'cmeta_' ) ||
100 - str_starts_with( $content_src, 'pods_' ) ||
101 - str_starts_with( $content_src, 'mb_' )
102 - ) {
97 + if ( self::is_field_key( $content_src ) ) {
103 98 $res = self::get_field_value( $post_id, $content_src );
104 99 } elseif (
105 100 str_starts_with( $content_src, 'link_' )
106 101 ) {
@@ -140,14 +135,9 @@
140 135 } elseif ( str_starts_with( $content_src, 'post_' ) ) {
141 136 $text = self::get_post_info( $post_id, $content_src );
142 137 } elseif ( str_starts_with( $content_src, 'a_' ) ) {
143 138 $text = self::get_author_info( $post_id, $content_src );
144 - } elseif (
145 - str_starts_with( $content_src, 'acf_' ) ||
146 - str_starts_with( $content_src, 'cmeta_' ) ||
147 - str_starts_with( $content_src, 'pods_' ) ||
148 - str_starts_with( $content_src, 'mb_' )
149 - ) {
139 + } elseif ( self::is_field_key( $content_src ) ) {
150 140 $text = self::get_field_value( $post_id, $content_src );
151 141 }
152 142
153 143 if ( ! empty( $text ) && ! empty( $max_length ) && is_string( $max_length ) && intval( $max_length ) > 0 ) {
@@ -213,14 +203,9 @@
213 203 } elseif ( str_starts_with( $dcField['contentSrc'], 'post_' ) ) {
214 204 $text = self::get_post_info( $dcField['postId'], $dcField['contentSrc'] );
215 205 } elseif ( str_starts_with( $dcField['contentSrc'], 'a_' ) ) {
216 206 $text = self::get_author_info( $dcField['postId'], $dcField['contentSrc'] );
217 - } elseif (
218 - str_starts_with( $dcField['contentSrc'], 'acf_' ) ||
219 - str_starts_with( $dcField['contentSrc'], 'cmeta_' ) ||
220 - str_starts_with( $dcField['contentSrc'], 'pods_' ) ||
221 - str_starts_with( $dcField['contentSrc'], 'mb_' )
222 - ) {
207 + } elseif ( self::is_field_key( $dcField['contentSrc'] ) ) {
223 208 $text = self::get_field_value( $dcField['postId'], $dcField['contentSrc'] );
224 209 }
225 210
226 211 if ( ! empty( $text ) && ! empty( $dcField['maxCharLen'] ) && intval( $dcField['maxCharLen'] ) > 0 ) {
@@ -271,45 +256,21 @@
271 256 $post_id = isset( $post->ID ) ? $post->ID : '';
272 257 }
273 258 }
274 259
275 - if ( self::check_prefix_and_remove( $meta_key, 'cmeta_' ) ) {
260 + if ( self::check_prefix( $meta_key, 'cmeta_' ) ) {
276 261 if ( empty( $post_id ) ) {
277 262 return '';
278 263 }
279 - return get_post_meta( $post_id, $meta_key, true );
264 + return get_post_meta( $post_id, self::maybe_remove_prefix( $meta_key, 'cmeta_' ), true );
280 265 }
281 266
282 - if ( self::check_prefix_and_remove( $meta_key, 'acf_' ) ) {
283 - if ( class_exists( 'ACF' ) ) {
284 - if ( ! empty( $post_id ) ) {
285 - $value = get_field( $meta_key, $post_id );
286 - return self::extract_acf_value( $value );
287 - } else {
288 - return get_field( $meta_key, false );
289 - }
290 - }
267 + // Other field sources are answered by PostX Pro.
268 + $value = apply_filters( 'ultp_dc_field_value', null, $meta_key, $post_id );
269 + if ( null !== $value ) {
270 + return $value;
291 271 }
292 272
293 - if ( self::check_prefix_and_remove( $meta_key, 'mb_' ) ) {
294 - if ( function_exists( 'rwmb_get_value' ) ) {
295 - $value = rwmb_get_value( $meta_key, array(), $post_id );
296 - return self::extract_mb_value( $value, $meta_key, $post_id );
297 - }
298 - }
299 -
300 - if ( self::check_prefix_and_remove( $meta_key, 'pods_' ) ) {
301 - if ( function_exists( 'pods' ) ) {
302 - $pods = pods( get_post_type( $post_id ), $post_id );
303 - if ( is_object( $pods ) && method_exists( $pods, 'exists' ) &&
304 - $pods->exists() && method_exists( $pods, 'field' )
305 - ) {
306 - $value = $pods->field( $meta_key );
307 - return self::extract_pods_value( $value );
308 - }
309 - }
310 - }
311 -
312 273 return '';
313 274 }
314 275
315 276 /**
@@ -455,13 +416,9 @@
455 416 $post_id = isset( $post->ID ) ? $post->ID : '';
456 417 }
457 418 }
458 419
459 - if ( self::check_prefix( $key, 'acf_' ) ||
460 - self::check_prefix( $key, 'mb_' ) ||
461 - self::check_prefix( $key, 'cmeta_' ) ||
462 - self::check_prefix( $key, 'pods_' )
463 - ) {
420 + if ( self::is_field_key( $key ) ) {
464 421 $res = self::get_field_value( $post_id, $key );
465 422 } else {
466 423 $author_id = absint( get_post_field( 'post_author', $post_id ) );
467 424 $key = self::maybe_remove_prefix( $key, 'link_' );
@@ -573,11 +530,13 @@
573 530
574 531 if ( is_singular() ) {
575 532 $title = get_the_title();
576 533 } elseif ( is_search() ) {
534 + /* translators: %s: Search query. */
577 535 $title = sprintf( esc_html__( 'Search Results for: %s', 'ultimate-post' ), get_search_query() );
578 536
579 537 if ( get_query_var( 'paged' ) ) {
538 + /* translators: %s: Page number. */
580 539 $title .= sprintf( esc_html__( ' – Page %s', 'ultimate-post' ), get_query_var( 'paged' ) );
581 540 }
582 541 } elseif ( is_category() ) {
583 542 $title = single_cat_title( '', false );
@@ -604,133 +563,8 @@
604 563 return $title;
605 564 }
606 565
607 566 /**
608 - * Formats ACF value based upon data type
609 - *
610 - * @since 4.1.1
611 - *
612 - * @param array|string $value ACF Meta Value.
613 - *
614 - * @return string
615 - */
616 - private static function extract_acf_value( $value ) {
617 - if ( is_array( $value ) ) {
618 - $image_id = absint( $value['id'] );
619 - $value = wp_get_attachment_image_src( $image_id );
620 - } elseif ( is_numeric( $value ) ) {
621 - return $value;
622 - }
623 -
624 - return $value;
625 - }
626 -
627 - /**
628 - * Formats Pods value based upon data type
629 - *
630 - * @since 4.1.1
631 - *
632 - * @param array|string $value Pods Meta Value.
633 - *
634 - * @return string
635 - */
636 - private static function extract_pods_value( $value ) {
637 - if ( is_array( $value ) ) {
638 -
639 - // Single image
640 - if ( isset( $value['guid'] ) ) {
641 - return $value['guid'];
642 - }
643 -
644 - // Multi image
645 - if ( isset( $value[0]['guid'] ) ) {
646 - return $value[0]['guid'];
647 - }
648 -
649 - // Repeater
650 - if ( isset( $value[0] ) &&
651 - ( is_string( $value[0] ) || is_numeric( $value[0] ) || is_bool( $value[0] ) )
652 - ) {
653 - return $value[0];
654 - }
655 -
656 - return '';
657 - }
658 -
659 - return $value;
660 - }
661 -
662 - /**
663 - * Formats Meta Box value based upon data type
664 - *
665 - * @since 4.1.1
666 - *
667 - * @param array|string $value
668 - *
669 - * @return string
670 - */
671 - private static function extract_mb_value( $custom_fields, $meta_key, $post_id ) {
672 -
673 - if ( ! is_array( $custom_fields ) ) {
674 - return strval( $custom_fields );
675 - }
676 -
677 - $field_data = rwmb_get_field_settings( $meta_key, array(), $post_id );
678 -
679 - // Process the first element if its an array
680 - foreach ( $custom_fields as $field ) {
681 - $field_type = $field_data['type'];
682 - $field_value = '';
683 -
684 - switch ( $field_type ) {
685 - case 'checkbox':
686 - case 'radio':
687 - $field_value = isset( $field['checked'] ) ? 'checked' : '';
688 - break;
689 - case 'select':
690 - case 'radio_list':
691 - case 'checkbox_list':
692 - case 'taxonomy':
693 - case 'taxonomy_advanced':
694 - case 'post':
695 - case 'post_advanced':
696 - case 'post_checkbox_list':
697 - case 'post_select':
698 - $field_value = isset( $field['selected'] ) ? $field['selected'] : '';
699 - break;
700 - case 'file':
701 - case 'file_input':
702 - case 'file_advanced':
703 - case 'file_upload':
704 - $field_value = isset( $field['url'] ) ? $field['url'] : $field['id'];
705 - break;
706 - case 'single_image':
707 - $field_value = wp_get_attachment_image_url( $custom_fields['ID'], 'full' );
708 - break;
709 - case 'image':
710 - case 'image_advanced':
711 - case 'image_upload':
712 - case 'plupload_image':
713 - case 'thickbox_image':
714 - $field_value = wp_get_attachment_image_url( $field['ID'], 'full' );
715 - break;
716 - case 'date':
717 - case 'datetime':
718 - case 'time':
719 - $field_value = $field['date'];
720 - break;
721 - default:
722 - $field_value = $field['value'];
723 - break;
724 - }
725 -
726 - return $field_value;
727 - }
728 -
729 - return '';
730 - }
731 -
732 - /**
733 567 * Properly decodes HTML chars from string
734 568 *
735 569 * @param mixed $str
736 570 * @return mixed
@@ -753,8 +587,26 @@
753 587 public static function limit_str( $str, $limit ) {
754 588 return join( ' ', array_slice( explode( ' ', $str ), 0, $limit ) );
755 589 }
756 590
591 + /**
592 + * Whether a dynamic content key is a custom field
593 + *
594 + * Plain custom metas (`cmeta_`) are handled here; other field sources are answered by PostX Pro.
595 + *
596 + * @param string $key Key with its prefix.
597 + * @return bool
598 + */
599 + private static function is_field_key( $key ) {
600 + if ( ! is_string( $key ) || '' === $key ) {
601 + return false;
602 + }
603 + if ( self::check_prefix( $key, 'cmeta_' ) ) {
604 + return true;
605 + }
606 + return (bool) apply_filters( 'ultp_dc_is_field_key', false, $key );
607 + }
608 +
757 609 private static function check_prefix( $key, $prefix ) {
758 610 return substr( $key, 0, strlen( $prefix ) ) === $prefix;
759 611 }
760 612
@@ -762,14 +614,6 @@
762 614 if ( substr( $key, 0, strlen( $prefix ) ) === $prefix ) {
763 615 return substr( $key, strlen( $prefix ) );
764 616 }
765 617 return $key;
766 - }
767 -
768 - private static function check_prefix_and_remove( &$key, $prefix ) {
769 - if ( substr( $key, 0, strlen( $prefix ) ) === $prefix ) {
770 - $key = substr( $key, strlen( $prefix ) );
771 - return true;
772 - }
773 - return false;
774 618 }
775 619 }