Skip to content

Commit b1dc0ec

Browse files
authored
Merge pull request #731 from cloudinary/fix/double-replace-call
dont capture on REST, check if content is empty
2 parents 83e8311 + 9f0f6ed commit b1dc0ec

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

php/class-string-replace.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ protected function admin_filters() {
7373
*/
7474
protected function public_filters() {
7575
add_action( 'template_include', array( $this, 'init_debug' ), PHP_INT_MAX );
76-
add_action( 'parse_request', array( $this, 'init' ), - 1000 ); // Not crazy low, but low enough to catch most cases, but not too low that it may break AMP.
76+
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { // Not needed on REST API.
77+
add_action( 'parse_request', array( $this, 'init' ), - 1000 ); // Not crazy low, but low enough to catch most cases, but not too low that it may break AMP.
78+
}
7779
}
7880

7981
/**
8082
* Add filters for REST API.
8183
*/
8284
protected function add_rest_filters() {
83-
$types = get_post_types_by_support( 'author' );
85+
$types = get_post_types();
8486
foreach ( $types as $type ) {
8587
$post_type = get_post_type_object( $type );
8688
// Check if this is a rest supported type.
@@ -255,7 +257,7 @@ public function replace_strings( $content, $context = 'view' ) {
255257
}
256258
if ( Utils::looks_like_json( $content ) ) {
257259
$json_maybe = json_decode( $content, true );
258-
if ( $json_maybe ) {
260+
if ( ! empty( $json_maybe ) ) {
259261
$content = $json_maybe;
260262
}
261263
}
@@ -264,7 +266,8 @@ public function replace_strings( $content, $context = 'view' ) {
264266
$content = self::do_replace( $content );
265267
}
266268
self::reset();
267-
$last_content = isset( $json_maybe ) ? wp_json_encode( $content ) : $content;
269+
$last_content = ! empty( $json_maybe ) ? wp_json_encode( $content ) : $content;
270+
268271
return $last_content;
269272
}
270273

0 commit comments

Comments
 (0)