@@ -115,7 +115,7 @@ public function shifter_heartbert_on_sitepreview_write_script() {
115115 <script>
116116 function shifter_heartbert_getajax() {
117117 var xhr= new XMLHttpRequest();
118- xhr.open("GET","<?php echo esc_url (add_query_arg ('action ' ,'nopriv_heartbeat ' ,site_url ('/wp-admin/admin-ajax.php ' ))); ?> ");
118+ xhr.open("GET","<?php echo esc_url ( add_query_arg ( 'action ' , 'nopriv_heartbeat ' , site_url ( '/wp-admin/admin-ajax.php ' ) ) ); ?> ");
119119 xhr.send();
120120 }
121121 var shifterHB = setInterval("shifter_heartbert_getajax()", 30000);
@@ -137,28 +137,62 @@ public function shifter_mail_from( $email_address ) {
137137 }
138138
139139 /**
140- * Integrations between Shifter and Algolia
140+ * Integrations between Shifter and Algolia Shared private function
141141 *
142- * @param string $shared_attributes Shared attrs .
143- * @param string $post Post.
142+ * @param string $url URL strings .
143+ * @return string Replaced URL from Shifter WP to Shifter CDN
144144 *
145- * @since 1.0 .0
145+ * @since 1.1 .0
146146 */
147- public function shifter_replace_algolia_permalink ( $ shared_attributes , $ post ) {
147+ private function replace_url_to_public_domain ( $ url ) {
148148 $ replaced_domain = getenv ( 'SHIFTER_DOMAIN ' );
149149 if ( ! $ replaced_domain ) {
150150 $ replaced_domain = getenv ( 'CF_DOMAIN ' );
151151 }
152152 if ( $ replaced_domain ) {
153- $ url = $ shared_attributes ['permalink ' ];
154153 $ parsed_url = wp_parse_url ( $ url );
155154 $ replace_target = $ parsed_url ['host ' ];
156155 if ( isset ( $ parsed_url ['port ' ] ) && $ parsed_url ['port ' ] ) {
157156 $ replace_target .= ": {$ parsed_url ['port ' ]}" ;
158157 }
159- $ shared_attributes [ ' permalink ' ] = preg_replace ( "# {$ replace_target }#i " , $ replaced_domain , $ url );
158+ return preg_replace ( "# {$ replace_target }#i " , $ replaced_domain , $ url );
160159 }
161- return $ shared_attributes ;
160+ return $ url ;
161+ }
162+
163+ /**
164+ * Integrations between Shifter and Algolia for wp_posts items
165+ *
166+ * @param string $record Shared attrs.
167+ *
168+ * @since 1.0.0
169+ */
170+ public function replace_algolia_posts_permalink ( $ record ) {
171+ $ record ['permalink ' ] = $ this ->replace_url_to_public_domain ( $ record ['permalink ' ] );
172+ return $ record ;
173+ }
174+ /**
175+ * Integrations between Shifter and Algolia for wp_terms items
176+ *
177+ * @param string $record Shared attrs.
178+ *
179+ * @since 1.1.0
180+ */
181+ public function replace_algolia_terms_permalink ( $ record ) {
182+ $ record ['permalink ' ] = $ this ->replace_url_to_public_domain ( $ record ['permalink ' ] );
183+ return $ record ;
184+ }
185+
186+ /**
187+ * Integrations between Shifter and Algolia for wp_users items
188+ *
189+ * @param string $record Shared attrs.
190+ *
191+ * @since 1.1.0
192+ */
193+ public function replace_algolia_users_posts_url ( $ record ) {
194+ $ record ['posts_url ' ] = $ this ->replace_url_to_public_domain ( $ record ['posts_url ' ] );
195+ return $ record ;
162196 }
163197
164198 /**
0 commit comments