Loading

Paste #pqoowbk6u

  1. <?php
  2. /*
  3. Description:  Orange-Cheers Theme Comment Plugin.
  4. Version:      1.0
  5. Author:       rikakomoe
  6. Author URI:   https://github.com/cool2645/orange-cheers
  7. License:      MIT
  8. License URI:  https://opensource.org/licenses/MIT
  9. */
  10.  
  11. /*
  12.  * What is this plugin for?
  13.  *
  14.  * In WordPress one comment can have a "parent", which indicates which comment does this comment replies.
  15.  * When you reply to comments, they displays like this:
  16.  *
  17.  * Alice: Original Comment.
  18.  *       Bob: I'm the comment that replies to Alice.
  19.  *              Charlie: I'm the comment that replies to Bob.
  20.  *
  21.  * This looks awful. Instead, Orange Cheers displays comments like this by adding a "reply_id" meta against
  22.  * directly replying to them.
  23.  *
  24.  * Alice: Original Comment.
  25.  *       Bob: @Alice I'm the comment that replies to Alice.
  26.  *       Charlie: @Bob I'm the comment that replies to Bob.
  27.  *
  28.  */
  29.  
  30. add_filter('rest_allow_anonymous_comments', '__return_true');
  31.  
  32. register_rest_field('comment', 'meta', array(
  33.     'get_callback' => function ($data) {
  34.         return get_comment_meta($data['id'], 'reply_id', true);
  35.     },
  36.     'update_callback' => function ($value, $data) {
  37.         if (isset($value['reply_id'])) {
  38.             $hasmeta = get_comment_meta($data->comment_ID, 'reply_id', false);
  39.             if ($hasmeta) {
  40.                 update_comment_meta($data->comment_ID, 'reply_id', $value['reply_id']);
  41.             } else {
  42.                 add_comment_meta($data->comment_ID, 'reply_id', $value['reply_id'], true);
  43.             }
  44.         }
  45.         return true;
  46.     },));

Comments