Changeset 1881615
- Timestamp:
- 05/25/2018 06:24:44 PM (8 years ago)
- Location:
- disqus-comment-system/trunk
- Files:
-
- 4 added
- 3 deleted
- 4 edited
-
README.txt (modified) (3 diffs)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.15.js (deleted)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.15.js.map (deleted)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.15.min.js (deleted)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.16.js (added)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.16.js.map (added)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.16.min.js (added)
-
admin/bundles/js/en.disqus-admin.bundle.3.0.16.min.js.map (added)
-
disqus.php (modified) (2 diffs)
-
public/class-disqus-public.php (modified) (2 diffs)
-
rest-api/class-disqus-rest-api.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
disqus-comment-system/trunk/README.txt
r1832582 r1881615 4 4 Requires at least: 4.4 5 5 Tested up to: 4.9.4 6 Stable tag: 3.0.1 56 Stable tag: 3.0.16 7 7 Requires PHP: 5.4 8 8 … … 97 97 98 98 **NOTE: It is recommended that you [backup your database](http://codex.wordpress.org/Backing_Up_Your_Database) before installing the plugin.** 99 100 https://www.youtube.com/watch?v=a4JBJXyuaFk 99 101 100 102 = Syncing comments to WordPress = … … 123 125 == Changelog == 124 126 127 = 3.0.16 = 128 129 * Add a manual syncing option that allows retroactive syncing within a selected date range 130 * Fixed bug where SSO avatar URLs were malformed (Thanks to [klaufel](https://github.com/disqus/disqus-wordpress-plugin/pull/49)) 131 125 132 = 3.0.15 = 126 133 -
disqus-comment-system/trunk/disqus.php
r1832582 r1881615 16 16 * Plugin URI: https://disqus.com/ 17 17 * Description: Disqus helps publishers increase engagement and build loyal audiences. Supports syncing comments to your database for easy backup. 18 * Version: 3.0.1 518 * Version: 3.0.16 19 19 * Author: Disqus 20 20 * Author URI: https://disqus.com/ … … 25 25 */ 26 26 27 $DISQUSVERSION = '3.0.1 5';27 $DISQUSVERSION = '3.0.16'; 28 28 29 29 // If this file is called directly, abort. -
disqus-comment-system/trunk/public/class-disqus-public.php
r1831152 r1881615 59 59 $payload_user['id'] = $user->ID; 60 60 $payload_user['username'] = $user->display_name; 61 $payload_user['avatar'] = get_avatar ( $user->ID, 92 );61 $payload_user['avatar'] = get_avatar_url( $user->ID, 92 ); 62 62 $payload_user['email'] = $user->user_email; 63 63 $payload_user['url'] = $user->user_url; … … 302 302 } 303 303 304 // Don't load embed when comments are closed on a post. These lines can solve a conflict with plugin Public Post Preview. 305 if ( ! comments_open() ) { 306 return false; 307 } 308 304 309 // Don't load embed if it's not a single post page. 305 310 if ( ! is_singular() ) { -
disqus-comment-system/trunk/rest-api/class-disqus-rest-api.php
r1831152 r1881615 118 118 ) ); 119 119 120 // Alias route for `sync/webhook` to get around plugins/services disabling "abused" routes. 121 register_rest_route( Disqus_Rest_Api::REST_NAMESPACE, 'sync/comment', array( 122 'methods' => 'POST', 123 'callback' => array( $this, 'rest_sync_webhook' ), 124 'permission_callback' => array( $this, 'rest_admin_only_permission_callback' ), 125 ) ); 126 120 127 register_rest_route( Disqus_Rest_Api::REST_NAMESPACE, 'settings', array( 121 128 array( … … 224 231 try { 225 232 switch ( $json_data['verb'] ) { 233 case 'force_sync': 234 $comment_id = $this->create_or_update_comment_from_post( $json_data['transformed_data'] ); 235 $this->log_sync_message( 'Manually synced comment "' . $json_data['transformed_data']['id'] . '" from Disqus' ); 236 return new WP_REST_Response( (string) $comment_id, 200 ); 226 237 case 'create': 227 $new_comment_id = $this->create_ comment_from_post( $json_data['transformed_data'] );238 $new_comment_id = $this->create_or_update_comment_from_post( $json_data['transformed_data'] ); 228 239 $this->log_sync_message( 'Synced new comment "' . $json_data['transformed_data']['id'] . '" from Disqus' ); 229 240 return new WP_REST_Response( (string) $new_comment_id, 201 ); 230 241 case 'update': 231 $updated_comment_id = $this-> update_comment_from_post( $json_data['transformed_data'] );242 $updated_comment_id = $this->create_or_update_comment_from_post( $json_data['transformed_data'] ); 232 243 $this->log_sync_message( 'Updated synced comment "' . $json_data['transformed_data']['id'] . '" from Disqus' ); 233 244 return new WP_REST_Response( (string) $updated_comment_id, 200 ); … … 621 632 622 633 /** 623 * Creates a comment in the WordPress database given a Disqus post. 624 * 625 * @since 3.0 634 * Queries the WordPress database for existing comment by dsq_post_id. Creates or updates if comment found 635 * in the WordPress database given a Disqus post. 636 * 637 * @since 3.0.16 626 638 * @param array $post The Disqus post object. 627 * @return int The newly created comment ID.639 * @return int The created or updated comment ID. 628 640 * @throws Exception An exception if comment can't be saved from post data. 629 641 */ 630 private function create_ comment_from_post( $post ) {642 private function create_or_update_comment_from_post( $post ) { 631 643 $this->validate_disqus_post_data( $post ); 632 644 633 // Check to make sure we haven't synced this comment yet.645 // Check for existing comment. 634 646 $comment_query = new WP_Comment_Query( array( 635 647 'meta_key' => 'dsq_post_id', … … 638 650 ) ); 639 651 640 if ( ! empty( $comment_query->comments ) ) { 641 $this->log_sync_message( 'Error syncing new comment "' . $post['id'] . '" from Disqus. Comment with this dsq_post_id already in the local database' ); 642 return 0; 643 } 644 645 $comment_data = $this->comment_data_from_post( $post ); 646 647 $new_comment_id = wp_insert_comment( $comment_data ); 648 649 return $new_comment_id; 650 } 651 652 /** 653 * Updates a comment in the WordPress database given a Disqus post. 652 $comments = $comment_query->comments; 653 if ( ! empty( $comments ) ) { 654 return $this->update_comment_from_post( $post, $comments ); 655 } 656 657 return $this->create_comment_from_post( $post ); 658 } 659 660 /** 661 * Creates a comment in the WordPress database given a Disqus post. 654 662 * 655 663 * @since 3.0 … … 658 666 * @throws Exception An exception if comment can't be saved from post data. 659 667 */ 660 private function update_comment_from_post( $post ) { 661 $this->validate_disqus_post_data( $post ); 662 663 // Check to make sure we have synced this comment already. 664 $comment_query = new WP_Comment_Query( array( 665 'meta_key' => 'dsq_post_id', 666 'meta_value' => $post['id'], 667 'number' => 1, 668 ) ); 669 670 $comments = $comment_query->comments; 671 672 if ( empty( $comments ) ) { 673 $this->log_sync_message( 'Error updating synced comment "' . $post['id'] . '" from Disqus. Comment with this dsq_post_id was not in the local database' ); 674 return 0; 675 } 676 668 private function create_comment_from_post( $post ) { 669 $comment_data = $this->comment_data_from_post( $post ); 670 671 $new_comment_id = wp_insert_comment( $comment_data ); 672 673 return $new_comment_id; 674 } 675 676 /** 677 * Updates a comment in the WordPress database given a Disqus post. 678 * 679 * @since 3.0 680 * @param array $post The Disqus post object. 681 * @param array $comments The comments found matching the dsq_post_id. 682 * @return int The newly created comment ID. 683 * @throws Exception An exception if comment can't be saved from post data. 684 */ 685 private function update_comment_from_post( $post, $comments ) { 677 686 foreach ( $comments as $comment ) { 678 687 $updated_comment_id = $comment->comment_ID; … … 717 726 */ 718 727 private function comment_data_from_post( $post ) { 719 $thread = $post['threadData'];728 $thread = array_key_exists( 'threadData', $post ) ? $post['threadData'] : $post['thread']; 720 729 $author = $post['author']; 721 730
Note: See TracChangeset
for help on using the changeset viewer.