Changeset 2392209
- Timestamp:
- 10/02/2020 08:27:29 AM (6 years ago)
- File:
-
- 1 edited
-
contentstudio/trunk/contentstudio-plugin.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
contentstudio/trunk/contentstudio-plugin.php
r2387022 r2392209 3 3 Plugin Name: ContentStudio 4 4 Description: ContentStudio provides you with powerful blogging & social media tools to keep your audience hooked by streamlining the process for you to discover and share engaging content on multiple blogging & social media networks 5 Version: 1.0. 55 Version: 1.0.6 6 6 Author: ContentStudio 7 7 Author URI: http://contentstudio.io/ … … 20 20 if (isset($post->ID)) { 21 21 if ($post->post_type == 'post') { 22 $meta_title = get_post_meta($post->ID, ' wpseo_title');22 $meta_title = get_post_meta($post->ID, 'contentstudio_wpseo_title'); 23 23 24 24 return $meta_title[0]; … … 29 29 30 30 add_filter('pre_get_document_title', 'cstu_add_wpseo_title'); 31 add_filter('wpseo_title', 'filter_product_wpseo_title');32 function filter_product_wpseo_title($title) {33 if( is_singular( 'product') ) {34 $title = $meta_title = sanitize_text_field($_REQUEST['post']['post_meta_title']);35 }36 return $title;37 }38 31 39 32 // Check for existing class … … 126 119 add_action('init', [$this, 'cstu_get_blog_categories']); 127 120 add_action('init', [$this, 'cstu_create_new_post']); 121 add_action('init', [$this, 'cstu_update_post']); 128 122 add_action('init', [$this, 'cstu_is_installed']); 129 123 add_action('init', [$this, 'cstu_unset_token']); … … 146 140 if ($post) { 147 141 if (isset($post->ID)) { 148 $meta_description = get_post_meta($post->ID, ' wpseo_description');142 $meta_description = get_post_meta($post->ID, 'contentstudio_wpseo_description'); 149 143 if ($meta_description) { 150 144 echo '<meta name="description" content="'.$meta_description[0].'" />'."\n"; … … 662 656 $get_posts_list = $wpdb->get_results($sql); 663 657 if (count($get_posts_list)) { 658 $cstu_post_update = get_page_by_title( $post_title, '', 'post' ); 659 $getid = 0; 660 $getid = $cstu_post_update->ID; 664 661 echo json_encode([ 665 662 'status' => false, 666 'message' => "Post already exists on your blog with title '$ post_title'.",663 'message' => "Post already exists on your blog with title '$getid'.", 667 664 ]); 668 665 die(); … … 723 720 724 721 if ($post && $post > 0) { 725 $this->cstu_download_images($post );722 $this->cstu_download_images($post_id); 726 723 } 727 724 … … 736 733 if (isset($_REQUEST['post']['featured_image']) && $_REQUEST['post']['featured_image']) { 737 734 // perform http request to see the status code of the image. 735 $checker = $_REQUEST['post']['featured_image']; 736 //error_log( print_r( $checker, true ) ); 738 737 $status_code = wp_remote_get($_REQUEST['post']['featured_image'])['response']['code']; 739 738 … … 789 788 } 790 789 790 791 /** 792 * Updates an existing WordPress post, action is called from the REMOTE ContentStudio Server. 793 * 794 */ 795 public function cstu_update_post() 796 { 797 if (isset($_REQUEST) && isset($_REQUEST['cstu_update_post']) && isset($_REQUEST['token'])) { 798 799 // validate the token 800 801 $valid = $this->do_validate_cstu_token($_REQUEST['token']); 802 if ($valid) { 803 804 // request post title is available 805 806 // if (isset($_REQUEST['post'])) { 807 // $post_title = wp_strip_all_tags($_REQUEST['post']['post_title']); 808 // // check for the post title and make sure it does not exists. 809 810 // if (isset($post_title) && $post_title) { 811 // global $wpdb; 812 // $post_title = wp_strip_all_tags($post_title); 813 // $sql = $wpdb->prepare("select ID from ".$wpdb->posts." where post_title='%s' AND post_status = 'publish'", $post_title); 814 // $get_posts_list = $wpdb->get_results($sql); 815 // if (count($get_posts_list)) { 816 // $cstu_post_update = get_page_by_title( $post_title, '', 'post' ); 817 // $getid = 0; 818 // $getid = $cstu_post_update->ID; 819 // echo json_encode([ 820 // 'status' => false, 821 // 'message' => "Post already exists on your blog with title '$getid'.", 822 // ]); 823 // die(); 824 // } 825 // } 826 // } 827 828 // get list of categories 829 830 $categories = explode(',', sanitize_text_field($_REQUEST['post']['post_category'])); 831 832 $this->kses_remove_filters(); 833 $post_id = 0; 834 if (isset($_REQUEST['post']['post_id']) && $_REQUEST['post']['post_id']) { 835 $post_id = (int) sanitize_text_field($_REQUEST['post']['post_id']); 836 } 837 838 // update the post 839 840 $post_author = sanitize_text_field($_REQUEST['post']['post_author']); 841 $post_content = $_REQUEST['post']['post_content']; 842 $post_status = sanitize_text_field($_REQUEST['post']['post_status']); 843 844 // sanitize title per https://codex.wordpress.org/Function_Reference/wp_insert_post#Security // 845 846 $post = wp_update_post([ 847 'ID' => $post_id, 848 'post_title' => $_REQUEST['post']['post_title'], 849 'post_author' => $post_author, 850 'post_content' => $post_content, 851 'post_status' => $post_status, 852 'post_category' => $categories, 853 ]); 854 855 if (! $post or $post == 0) { 856 $post = wp_update_post([ 857 'post_title' => $_REQUEST['post']['post_title'], 858 'post_author' => $post_author, 859 'post_content' => $post_content, 860 'post_status' => $post_status, 861 'post_category' => $categories, 862 ]); 863 global $wpdb; 864 $wpdb->update($wpdb->posts, ['post_title' => wp_strip_all_tags((string) $post_title)], ['ID' => $post]); 865 // slug scenario 866 } 867 868 // get post 869 870 $get_post = get_post($post); 871 872 // set the tags 873 874 if (isset($_REQUEST['post']['terms'])) { 875 $this->cstu_set_tags($get_post); 876 } 877 878 // download the image to the user server. 879 880 if ($post && $post > 0) { 881 $this->cstu_download_images($post); 882 } 883 884 // seo settings 885 886 $this->set_cstu_metadata_post($get_post); 887 $this->set_cstu_yoast_settinsg($get_post); 888 $this->set_cstu_all_in_one_seo($get_post); 889 890 // reload the post again to get the latest url. 891 892 if (isset($_REQUEST['post']['featured_image']) && $_REQUEST['post']['featured_image']) { 893 // perform http request to see the status code of the image. 894 $status_code = wp_remote_get($_REQUEST['post']['featured_image'])['response']['code']; 895 896 // if the status is valid process for upload. 897 898 if ($status_code == 301 || $status_code == 200) { 899 $img = $this->cstu_generate_image($_REQUEST['post']['featured_image'], $post); 900 if ($img['status']) { 901 echo json_encode([ 902 'status' => true, 903 'post_id' => $get_post->ID, 904 'link' => get_permalink($get_post->ID), 905 ]); 906 die(); 907 } else { 908 echo json_encode([ 909 'status' => false, 910 'warning_message' => $img['message'], 911 'post_id' => $get_post->ID, 912 'link' => get_permalink($get_post->ID), 913 ]); 914 die(); 915 } 916 } else { 917 echo json_encode([ 918 'status' => false, 919 'warning_message' => 'Post featured image seems to be down. Image HTTP status code is '.$status_code, 920 'post_id' => $get_post->ID, 921 'link' => get_permalink($get_post->ID)//get_post_permalink($get_post->ID), 922 ]); 923 die(); 924 } 925 } else { 926 echo json_encode([ 927 'status' => true, 928 'post_id' => $get_post->ID, 929 'link' => get_permalink($get_post->ID), 930 ]); // get_post_permalink($get_post->ID) 931 die(); 932 } 933 } else { 934 echo json_encode([ 935 'status' => false, 936 'message' => self::INVALID_MESSAGE_POST_API, 937 ]); 938 die(); 939 } 940 } 941 /*else { 942 echo json_encode(['status' => false, 'message' => "error"]); 943 die(); 944 }*/ 945 } 946 791 947 /** 792 948 * Set the meta description so that when we publish our content, we show that to the end-user instead of our personal one. … … 803 959 } 804 960 if ($meta_description) { 805 if (! get_post_meta($get_post->ID, ' wpseo_description')) {806 add_post_meta($get_post->ID, ' wpseo_description', $meta_description, true);961 if (! get_post_meta($get_post->ID, 'contentstudio_wpseo_description')) { 962 add_post_meta($get_post->ID, 'contentstudio_wpseo_description', $meta_description, true); 807 963 } else { 808 update_post_meta($get_post->ID, ' wpseo_description', $meta_description);964 update_post_meta($get_post->ID, 'contentstudio_wpseo_description', $meta_description); 809 965 } 810 966 } … … 815 971 816 972 if ($meta_title) { 817 if (! get_post_meta($get_post->ID, ' wpseo_title')) {818 add_post_meta($get_post->ID, ' wpseo_title', $meta_title, true);973 if (! get_post_meta($get_post->ID, 'contentstudio_wpseo_title')) { 974 add_post_meta($get_post->ID, 'contentstudio_wpseo_title', $meta_title, true); 819 975 } else { 820 update_post_meta($get_post->ID, ' wpseo_title', $meta_title);976 update_post_meta($get_post->ID, 'contentstudio_wpseo_title', $meta_title); 821 977 } 822 978 } … … 868 1024 //} 869 1025 } 870 871 872 1026 873 1027 /**
Note: See TracChangeset
for help on using the changeset viewer.