@@ -43,15 +43,6 @@ class Cdn_Plugin {
4343 */
4444 private $ _attachments_action = array ();
4545
46- /**
47- * Helper for content filtering.
48- *
49- * @var _Cdn_Plugin_ContentFilter
50- *
51- * @since x.x.x
52- */
53- private $ _content_filter_helper = null ;
54-
5546 /**
5647 * Constructor for initializing CDN plugin configuration and debug flag.
5748 *
@@ -69,7 +60,6 @@ public function __construct() {
6960 */
7061 public function run () {
7162 $ cdn_engine = $ this ->_config ->get_string ( 'cdn.engine ' );
72- $ this ->_content_filter_helper = new _Cdn_Plugin_ContentFilter ();
7363
7464 add_filter ( 'cron_schedules ' , array ( $ this , 'cron_schedules ' ) ); // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected
7565 add_filter ( 'w3tc_footer_comment ' , array ( $ this , 'w3tc_footer_comment ' ) );
@@ -105,10 +95,6 @@ public function run() {
10595 add_filter ( 'wp_prepare_attachment_for_js ' , array ( $ this , 'wp_prepare_attachment_for_js ' ), 0 );
10696 }
10797
108- if ( $ this ->_config ->get_boolean ( 'cdn.admin.media_library ' ) ) {
109- add_filter ( 'rest_post_dispatch ' , array ( $ this , 'rest_post_dispatch ' ), 10 , 3 );
110- }
111-
11298 // Start rewrite engine.
11399 \add_action ( 'init ' , array ( $ this , 'maybe_can_cdn ' ), 10 , 0 );
114100
@@ -949,49 +935,6 @@ public function w3tc_footer_comment_after( $buffer, $replaced_urls ) {
949935
950936 return $ buffer ;
951937 }
952-
953- /**
954- * Filters REST API responses to replace media links with CDN URLs.
955- *
956- * @param \WP_HTTP_Response $response Response object.
957- * @param \WP_REST_Server $server Server instance.
958- * @param \WP_REST_Request $request Current request object.
959- *
960- * @return \WP_HTTP_Response Modified response object.
961- */
962- public function rest_post_dispatch ( $ response , $ server , $ request ) {
963- if ( ! ( $ response instanceof \WP_REST_Response ) ) {
964- return $ response ;
965- }
966-
967- $ data = $ response ->get_data ();
968-
969- /*
970- * The responses we want to adjust will be arrays.
971- * But other responses may be objects, which will throw an error
972- * if we try to access them as arrays.
973- */
974- if ( ! is_array ( $ data ) ) {
975- return $ response ;
976- }
977-
978- if ( isset ( $ data ['content ' ] ) ) {
979- if ( is_array ( $ data ['content ' ] ) ) {
980- if ( isset ( $ data ['content ' ]['raw ' ] ) ) {
981- $ data ['content ' ]['raw ' ] = $ this ->_content_filter_helper ->replace_all_links ( $ data ['content ' ]['raw ' ] );
982- }
983- if ( isset ( $ data ['content ' ]['rendered ' ] ) ) {
984- $ data ['content ' ]['rendered ' ] = $ this ->_content_filter_helper ->replace_all_links ( $ data ['content ' ]['rendered ' ] );
985- }
986- } elseif ( is_string ( $ data ['content ' ] ) ) {
987- $ data ['content ' ] = $ this ->_content_filter_helper ->replace_all_links ( $ data ['content ' ] );
988- }
989-
990- $ response ->set_data ( $ data );
991- }
992-
993- return $ response ;
994- }
995938}
996939
997940/**
0 commit comments