| @@ -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,36 +69,32 @@ | ||
| 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 | |
| 83 | + /* | |
| 84 | + * Comment likes are gated on the Likes settings, so when the Likes module is | |
| 85 | + * off this module still needs the per-post metabox that carries them. | |
| 86 | + */ | |
| 74 | 87 | if ( ! Jetpack::is_module_active( 'likes' ) ) { |
| 75 | - $active = Jetpack::get_active_modules(); | |
| 76 | - | |
| 77 | - if ( in_array( 'publicize', $active, true ) && ! in_array( 'sharedaddy', $active, true ) ) { | |
| 78 | - // we have a sharing page but not the global options area. | |
| 79 | - add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 ); | |
| 80 | - add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 ); | |
| 81 | - } | |
| 82 | - | |
| 83 | - if ( ! in_array( 'sharedaddy', $active, true ) ) { | |
| 84 | - add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) ); | |
| 85 | - add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 ); | |
| 86 | - add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 ); | |
| 87 | - add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) ); | |
| 88 | - } else { | |
| 88 | + if ( Jetpack::is_module_active( 'sharedaddy' ) ) { | |
| 89 | 89 | add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) ); |
| 90 | 90 | add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) ); |
| 91 | + } else { | |
| 92 | + add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) ); | |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | 95 | add_action( 'save_post', array( $this->settings, 'meta_box_save' ) ); |
| 94 | 96 | add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) ); |
| 95 | - add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 ); | |
| 96 | - add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_callback' ), 20 ); | |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |