Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Nelio Handler for replacing the external image with self-hosted image
- */
- function mlsbd_nelio_replacement($post_ID)
- {
- $nelio_url = get_post_meta($post_ID, '_nelioefi_url', true);
- $mlsbd_url = get_post_meta($post_ID, '_mlsbd_featured_url', true);
- $mlsbd_url = !empty($mlsbd_url) ? $mlsbd_url['original'] : '';
- $key = '598565ba4f08c775b47b7f7a293be1f846de766edfb975a4e1cf9c0c8723b53888d3ba89fea152f04aed94c0b698fe871cf31699e07199e0f1c37aee1a5b55cc';
- if ($nelio_url === '' || $nelio_url === $mlsbd_url) {
- return true;
- }
- $json = json_encode(array(
- 'payload' => array(
- $nelio_url
- )
- ));
- $res = wp_remote_post('https://image-cdn.mlsbd.co/post.php', array(
- 'sslverify' => false,
- 'timeout' => 30,
- 'body' => array(
- 'secure_key' => $key,
- 'encoded_json' => urlencode(base64_encode($json))
- )
- ));
- $body = json_decode($res['body']);
- $result = $body->result[0];
- $compressed_jpg_img = $result->compressed->jpg;
- $compressed_webp_img = $result->compressed->webp;
- $original_img = $result->original;
- $status = $res['response']['code'];
- $meta_value = array(
- 'webp' => $compressed_webp_img,
- 'jpg' => $compressed_jpg_img,
- 'original' => $original_img
- );
- if ($status == 200 && $compressed_jpg_img != null && $compressed_webp_img != null) {
- $success = add_post_meta($post_ID, '_mlsbd_featured_url', $meta_value, true);
- if ($success === false) {
- update_post_meta($post_ID, '_mlsbd_featured_url', $meta_value);
- }
- }
- }
- add_action('save_post', 'mlsbd_nelio_replacement', 1000);
- /**
- * Replace HTTP links with HTTPS in post content
- */
- function mlsbd_http_to_https($content)
- {
- return str_replace('href="http://', 'href="https://', $content);
- }
- add_action('the_content', 'mlsbd_http_to_https');
- /**
- * Nelio Handler for replacing the external image with self-hosted image
- */
- function mlsbd_nelio_replacement($post_ID)
- {
- $nelio_url = get_post_meta($post_ID, '_nelioefi_url', true);
- $mlsbd_url = get_post_meta($post_ID, '_mlsbd_featured_url', true);
- $mlsbd_url = !empty($mlsbd_url) ? $mlsbd_url['original'] : '';
- $key = '598565ba4f08c775b47b7f7a293be1f846de766edfb975a4e1cf9c0c8723b53888d3ba89fea152f04aed94c0b698fe871cf31699e07199e0f1c37aee1a5b55cc';
- if ($nelio_url === '' || $nelio_url === $mlsbd_url) {
- return true;
- }
- $json = json_encode(array(
- 'payload' => array(
- $nelio_url
- )
- ));
- $res = wp_remote_post('https://image-cdn.mlsbd.co/post.php', array(
- 'sslverify' => false,
- 'timeout' => 30,
- 'body' => array(
- 'secure_key' => $key,
- 'encoded_json' => urlencode(base64_encode($json))
- )
- ));
- $body = json_decode($res['body']);
- $result = $body->result[0];
- $compressed_jpg_img = $result->compressed->jpg;
- $compressed_webp_img = $result->compressed->webp;
- $original_img = $result->original;
- $status = $res['response']['code'];
- $meta_value = array(
- 'webp' => $compressed_webp_img,
- 'jpg' => $compressed_jpg_img,
- 'original' => $original_img
- );
- if ($status == 200 && $compressed_jpg_img != null && $compressed_webp_img != null) {
- $success = add_post_meta($post_ID, '_mlsbd_featured_url', $meta_value, true);
- if ($success === false) {
- update_post_meta($post_ID, '_mlsbd_featured_url', $meta_value);
- }
- }
- }
- add_action('save_post', 'mlsbd_nelio_replacement', 1000);
- /**
- * Replace HTTP links with HTTPS in post content
- */
- function mlsbd_http_to_https($content)
- {
- return str_replace('href="http://', 'href="https://', $content);
- }
- add_action('the_content', 'mlsbd_http_to_https');
Add Comment
Please, Sign In to add comment