88namespace Cloudinary \Media ;
99
1010use Cloudinary \Settings \Setting ;
11+ use WP_Post ;
1112
1213/**
1314 * Class Global Transformations.
@@ -245,22 +246,19 @@ public function get_transformations( $type ) {
245246 */
246247 public function get_taxonomy_transformations ( $ type ) {
247248 $ return_transformations = '' ;
248- $ maybe_post_id = apply_filters ( 'cloudinary_post_id_taxonomy ' , null );
249- if ( in_the_loop () || $ maybe_post_id ) {
250- $ post = get_post ( $ maybe_post_id );
251- if ( ! empty ( $ post ) ) {
252- $ transformations = array ();
253- $ terms = $ this ->get_terms ( $ post ->ID );
254- if ( ! empty ( $ terms ) ) {
255- foreach ( $ terms as $ item ) {
256- $ transformation = $ this ->get_term_transformations ( $ item ['term ' ]->term_id , $ type );
257- if ( ! empty ( $ transformation [ $ type . '_freeform ' ] ) ) {
258- $ transformations [] = trim ( $ transformation [ $ type . '_freeform ' ] );
259- }
249+ $ post = $ this ->get_current_post ();
250+ if ( $ post ) {
251+ $ transformations = array ();
252+ $ terms = $ this ->get_terms ( $ post ->ID );
253+ if ( ! empty ( $ terms ) ) {
254+ foreach ( $ terms as $ item ) {
255+ $ transformation = $ this ->get_term_transformations ( $ item ['term ' ]->term_id , $ type );
256+ if ( ! empty ( $ transformation [ $ type . '_freeform ' ] ) ) {
257+ $ transformations [] = trim ( $ transformation [ $ type . '_freeform ' ] );
260258 }
261- // Join the freeform.
262- $ return_transformations = implode ( '/ ' , (array ) $ transformations );
263259 }
260+ // Join the freeform.
261+ $ return_transformations = implode ( '/ ' , (array ) $ transformations );
264262 }
265263 }
266264
@@ -273,10 +271,9 @@ public function get_taxonomy_transformations( $type ) {
273271 * @return bool
274272 */
275273 public function is_taxonomy_overwrite () {
276- $ apply_type = false ;
277- $ maybe_post_id = apply_filters ( 'cloudinary_post_id_taxonomy ' , null );
278- if ( in_the_loop () || $ maybe_post_id ) {
279- $ post = get_post ();
274+ $ apply_type = false ;
275+ $ post = $ this ->get_current_post ();
276+ if ( $ post ) {
280277 $ apply_type = get_post_meta ( $ post ->ID , self ::META_APPLY_KEY . '_terms ' , true );
281278 }
282279
@@ -565,6 +562,23 @@ public function save_overwrite_transformations_featured_image( $post_id ) {
565562 }
566563 }
567564
565+ /**
566+ * Get the current post.
567+ *
568+ * @return WP_Post|null
569+ */
570+ protected function get_current_post () {
571+ /**
572+ * Filter the post ID.
573+ *
574+ * @hook cloudinary_post_id
575+ * @default null
576+ *
577+ * @return {WP_Post|null}
578+ */
579+ return get_post ( apply_filters ( 'cloudinary_post_id ' , null ) );
580+ }
581+
568582 /**
569583 * Setup hooks for the filters.
570584 */
0 commit comments