| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Comment Likes |
| 4 | - * Module Description: Increase visitor engagement by adding a Like button to comments. | |
| 4 | + * Module Description: Enable visitors to like individual comments and boost engagement. | |
| 5 | 5 | * Sort Order: 39 |
| 6 | 6 | * Recommendation Order: 17 |
| 7 | 7 | * First Introduced: 5.1 |
| 8 | 8 | * Requires Connection: Yes |
| @@ -14,8 +14,12 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | use Automattic\Jetpack\Assets; |
| 17 | 17 | |
| 18 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 19 | + exit( 0 ); | |
| 20 | +} | |
| 21 | + | |
| 18 | 22 | Assets::add_resource_hint( '//widgets.wp.com', 'dns-prefetch' ); |
| 19 | 23 | |
| 20 | 24 | require_once __DIR__ . '/likes/jetpack-likes-master-iframe.php'; |
| 21 | 25 | require_once __DIR__ . '/likes/jetpack-likes-settings.php'; |
| @@ -65,28 +69,36 @@ | ||
| 65 | 69 | private function __construct() { |
| 66 | 70 | $this->settings = new Jetpack_Likes_Settings(); |
| 67 | 71 | $this->blog_id = Jetpack_Options::get_option( 'id' ); |
| 68 | 72 | $url_parts = wp_parse_url( home_url() ); |
| 69 | - $this->domain = $url_parts['host']; | |
| 70 | 73 | |
| 74 | + // Abort if domain can't be determined. | |
| 75 | + if ( ! $url_parts || ! isset( $url_parts['host'] ) ) { | |
| 76 | + return; | |
| 77 | + } | |
| 78 | + $this->domain = $url_parts['host']; | |
| 79 | + | |
| 71 | 80 | add_action( 'template_redirect', array( $this, 'frontend_init' ) ); |
| 72 | 81 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 73 | 82 | |
| 74 | 83 | if ( ! Jetpack::is_module_active( 'likes' ) ) { |
| 75 | - $active = Jetpack::get_active_modules(); | |
| 84 | + $active = Jetpack::get_active_modules(); | |
| 85 | + $sharedaddy_active = in_array( 'sharedaddy', $active, true ); | |
| 76 | 86 | |
| 77 | - if ( ! in_array( 'sharedaddy', $active, true ) && ! in_array( 'publicize', $active, true ) ) { | |
| 78 | - // we don't have a sharing page yet. | |
| 87 | + if ( $this->settings->needs_own_sharing_menu( $sharedaddy_active ) ) { | |
| 88 | + /* | |
| 89 | + * Sharedaddy is what registers Settings > Sharing, and it is off, so we | |
| 90 | + * register that screen ourselves; the Likes settings that gate comment | |
| 91 | + * likes are displayed on it. | |
| 92 | + */ | |
| 79 | 93 | add_action( 'admin_menu', array( $this->settings, 'sharing_menu' ) ); |
| 80 | - } | |
| 81 | - | |
| 82 | - if ( in_array( 'publicize', $active, true ) && ! in_array( 'sharedaddy', $active, true ) ) { | |
| 94 | + } elseif ( in_array( 'publicize', $active, true ) && ! $sharedaddy_active ) { | |
| 83 | 95 | // we have a sharing page but not the global options area. |
| 84 | 96 | add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 ); |
| 85 | 97 | add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 ); |
| 86 | 98 | } |
| 87 | 99 | |
| 88 | - if ( ! in_array( 'sharedaddy', $active, true ) ) { | |
| 100 | + if ( ! $sharedaddy_active ) { | |
| 89 | 101 | add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) ); |
| 90 | 102 | add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 ); |
| 91 | 103 | add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 ); |
| 92 | 104 | add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) ); |
| @@ -210,8 +222,12 @@ | ||
| 210 | 222 | $comment_id = $comment->comment_ID; |
| 211 | 223 | } |
| 212 | 224 | |
| 213 | 225 | if ( empty( $content ) || empty( $comment_id ) ) { |
| 226 | + return $content; | |
| 227 | + } | |
| 228 | + | |
| 229 | + if ( empty( $comment->comment_approved ) ) { | |
| 214 | 230 | return $content; |
| 215 | 231 | } |
| 216 | 232 | |
| 217 | 233 | // In case master iframe hasn't been loaded. This could be the case when Post Likes module is disabled, |