@@ -21,192 +21,192 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Key_Validation_Service { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A {@link Wordlift_Log_Service} instance. |
|
| 26 | - * |
|
| 27 | - * @since 3.14.0 |
|
| 28 | - * @access private |
|
| 29 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 30 | - */ |
|
| 31 | - private $log; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var Ttl_Cache |
|
| 35 | - */ |
|
| 36 | - private $ttl_cache_service; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Create a {@link Wordlift_Key_Validation_Service} instance. |
|
| 40 | - * |
|
| 41 | - * @since 3.14.0 |
|
| 42 | - */ |
|
| 43 | - public function __construct() { |
|
| 44 | - |
|
| 45 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 46 | - |
|
| 47 | - add_action( 'admin_init', array( $this, 'wl_load_plugin' ) ); |
|
| 48 | - /** |
|
| 49 | - * Filter: wl_feature__enable__notices. |
|
| 50 | - * |
|
| 51 | - * @param bool whether notices need to be enabled or not. |
|
| 52 | - * |
|
| 53 | - * @return bool |
|
| 54 | - * @since 3.27.6 |
|
| 55 | - */ |
|
| 56 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 57 | - add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' ); |
|
| 61 | - |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Validate the provided key. |
|
| 66 | - * |
|
| 67 | - * @param string $key WordLift's key to validate. |
|
| 68 | - * |
|
| 69 | - * @return WP_Error|array The response or WP_Error on failure. |
|
| 70 | - * @since 3.9.0 |
|
| 71 | - */ |
|
| 72 | - public function get_account_info( $key ) { |
|
| 73 | - |
|
| 74 | - $this->log->debug( 'Validating key...' ); |
|
| 75 | - |
|
| 76 | - $response = Default_Api_Service::get_instance()->get( |
|
| 77 | - '/accounts/info', |
|
| 78 | - array( |
|
| 79 | - 'Authorization' => "Key $key", |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param $response \Wordlift\Api\Response |
|
| 85 | - * |
|
| 86 | - * @since 3.38.5 |
|
| 87 | - * This action is fired when the key is validated. |
|
| 88 | - */ |
|
| 89 | - do_action( 'wl_key_validation_response', $response ); |
|
| 90 | - |
|
| 91 | - return $response->get_response(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - private function key_validation_request( $key ) { |
|
| 95 | - $response = $this->get_account_info( $key ); |
|
| 96 | - |
|
| 97 | - if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) { |
|
| 98 | - throw new \Exception( __( 'An error occurred, please contact us at [email protected]', 'wordlift' ) ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $res_body = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 102 | - |
|
| 103 | - $url = $res_body['url']; |
|
| 104 | - |
|
| 105 | - $enabled_features = array_keys( array_filter( $res_body['features'] ) ); |
|
| 106 | - $plugin_features = array( |
|
| 107 | - Entity_Type_Setter::STARTER_PLAN, |
|
| 108 | - Entity_Type_Setter::PROFESSIONAL_PLAN, |
|
| 109 | - Entity_Type_Setter::BUSINESS_PLAN |
|
| 110 | - ); |
|
| 111 | - |
|
| 112 | - if ( count( array_intersect( $enabled_features, $plugin_features ) ) === 0 ) { |
|
| 113 | - throw new \Exception( __( 'This key is not valid. Start building your Knowledge Graph by purchasing a WordLift subscription <a href=\'https://wordlift.io/pricing/\'>here</a>.', 'wordlift' ) ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // Considering that production URL may be filtered. |
|
| 117 | - $home_url = get_option( 'home' ); |
|
| 118 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 119 | - |
|
| 120 | - if ( isset( $url ) && $url !== $site_url ) { |
|
| 121 | - throw new \Exception( __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ) ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return true; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Check if key is valid |
|
| 129 | - * |
|
| 130 | - * @param $key string |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function is_key_valid( $key ) { |
|
| 135 | - try { |
|
| 136 | - $this->key_validation_request( $key ); |
|
| 137 | - |
|
| 138 | - return true; |
|
| 139 | - } catch ( \Exception $e ) { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * This function is hooked to the `wl_validate_key` AJAX call. |
|
| 146 | - * |
|
| 147 | - * @since 3.9.0 |
|
| 148 | - */ |
|
| 149 | - public function validate_key() { |
|
| 150 | - |
|
| 151 | - // Ensure we don't have garbage before us. |
|
| 152 | - ob_clean(); |
|
| 153 | - |
|
| 154 | - // Check if we have a key. |
|
| 155 | - if ( ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 156 | - wp_send_json_error( 'The key parameter is required.' ); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $this->ttl_cache_service->delete( 'is_key_valid' ); |
|
| 160 | - |
|
| 161 | - try { |
|
| 162 | - $this->key_validation_request( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 163 | - wp_send_json_success( |
|
| 164 | - array( |
|
| 165 | - 'valid' => true, |
|
| 166 | - 'message' => '', |
|
| 167 | - ) |
|
| 168 | - ); |
|
| 169 | - |
|
| 170 | - } catch ( \Exception $e ) { |
|
| 171 | - Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
| 172 | - wp_send_json_success( |
|
| 173 | - array( |
|
| 174 | - 'valid' => false, |
|
| 175 | - 'message' => $e->getMessage(), |
|
| 176 | - 'api_url' => Default_Api_Service::get_instance()->get_base_url(), |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * This function is hooked `admin_init` to check _wl_blog_url. |
|
| 184 | - */ |
|
| 185 | - public function wl_load_plugin() { |
|
| 186 | - |
|
| 187 | - $wl_blog_url = get_option( '_wl_blog_url' ); |
|
| 188 | - $home_url = get_option( 'home' ); |
|
| 189 | - |
|
| 190 | - if ( ! $wl_blog_url ) { |
|
| 191 | - update_option( '_wl_blog_url', $home_url, true ); |
|
| 192 | - } elseif ( $wl_blog_url !== $home_url ) { |
|
| 193 | - update_option( '_wl_blog_url', $home_url, true ); |
|
| 194 | - Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
| 195 | - set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 ); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * This function is hooked to the `admin_notices` to show admin notification. |
|
| 202 | - */ |
|
| 203 | - public function wl_key_update_notice() { |
|
| 204 | - if ( get_transient( 'wl-key-error-msg' ) ) { |
|
| 205 | - ?> |
|
| 24 | + /** |
|
| 25 | + * A {@link Wordlift_Log_Service} instance. |
|
| 26 | + * |
|
| 27 | + * @since 3.14.0 |
|
| 28 | + * @access private |
|
| 29 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 30 | + */ |
|
| 31 | + private $log; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var Ttl_Cache |
|
| 35 | + */ |
|
| 36 | + private $ttl_cache_service; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Create a {@link Wordlift_Key_Validation_Service} instance. |
|
| 40 | + * |
|
| 41 | + * @since 3.14.0 |
|
| 42 | + */ |
|
| 43 | + public function __construct() { |
|
| 44 | + |
|
| 45 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 46 | + |
|
| 47 | + add_action( 'admin_init', array( $this, 'wl_load_plugin' ) ); |
|
| 48 | + /** |
|
| 49 | + * Filter: wl_feature__enable__notices. |
|
| 50 | + * |
|
| 51 | + * @param bool whether notices need to be enabled or not. |
|
| 52 | + * |
|
| 53 | + * @return bool |
|
| 54 | + * @since 3.27.6 |
|
| 55 | + */ |
|
| 56 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 57 | + add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' ); |
|
| 61 | + |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Validate the provided key. |
|
| 66 | + * |
|
| 67 | + * @param string $key WordLift's key to validate. |
|
| 68 | + * |
|
| 69 | + * @return WP_Error|array The response or WP_Error on failure. |
|
| 70 | + * @since 3.9.0 |
|
| 71 | + */ |
|
| 72 | + public function get_account_info( $key ) { |
|
| 73 | + |
|
| 74 | + $this->log->debug( 'Validating key...' ); |
|
| 75 | + |
|
| 76 | + $response = Default_Api_Service::get_instance()->get( |
|
| 77 | + '/accounts/info', |
|
| 78 | + array( |
|
| 79 | + 'Authorization' => "Key $key", |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param $response \Wordlift\Api\Response |
|
| 85 | + * |
|
| 86 | + * @since 3.38.5 |
|
| 87 | + * This action is fired when the key is validated. |
|
| 88 | + */ |
|
| 89 | + do_action( 'wl_key_validation_response', $response ); |
|
| 90 | + |
|
| 91 | + return $response->get_response(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + private function key_validation_request( $key ) { |
|
| 95 | + $response = $this->get_account_info( $key ); |
|
| 96 | + |
|
| 97 | + if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) { |
|
| 98 | + throw new \Exception( __( 'An error occurred, please contact us at [email protected]', 'wordlift' ) ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $res_body = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 102 | + |
|
| 103 | + $url = $res_body['url']; |
|
| 104 | + |
|
| 105 | + $enabled_features = array_keys( array_filter( $res_body['features'] ) ); |
|
| 106 | + $plugin_features = array( |
|
| 107 | + Entity_Type_Setter::STARTER_PLAN, |
|
| 108 | + Entity_Type_Setter::PROFESSIONAL_PLAN, |
|
| 109 | + Entity_Type_Setter::BUSINESS_PLAN |
|
| 110 | + ); |
|
| 111 | + |
|
| 112 | + if ( count( array_intersect( $enabled_features, $plugin_features ) ) === 0 ) { |
|
| 113 | + throw new \Exception( __( 'This key is not valid. Start building your Knowledge Graph by purchasing a WordLift subscription <a href=\'https://wordlift.io/pricing/\'>here</a>.', 'wordlift' ) ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // Considering that production URL may be filtered. |
|
| 117 | + $home_url = get_option( 'home' ); |
|
| 118 | + $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
| 119 | + |
|
| 120 | + if ( isset( $url ) && $url !== $site_url ) { |
|
| 121 | + throw new \Exception( __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ) ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return true; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Check if key is valid |
|
| 129 | + * |
|
| 130 | + * @param $key string |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function is_key_valid( $key ) { |
|
| 135 | + try { |
|
| 136 | + $this->key_validation_request( $key ); |
|
| 137 | + |
|
| 138 | + return true; |
|
| 139 | + } catch ( \Exception $e ) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * This function is hooked to the `wl_validate_key` AJAX call. |
|
| 146 | + * |
|
| 147 | + * @since 3.9.0 |
|
| 148 | + */ |
|
| 149 | + public function validate_key() { |
|
| 150 | + |
|
| 151 | + // Ensure we don't have garbage before us. |
|
| 152 | + ob_clean(); |
|
| 153 | + |
|
| 154 | + // Check if we have a key. |
|
| 155 | + if ( ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 156 | + wp_send_json_error( 'The key parameter is required.' ); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $this->ttl_cache_service->delete( 'is_key_valid' ); |
|
| 160 | + |
|
| 161 | + try { |
|
| 162 | + $this->key_validation_request( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 163 | + wp_send_json_success( |
|
| 164 | + array( |
|
| 165 | + 'valid' => true, |
|
| 166 | + 'message' => '', |
|
| 167 | + ) |
|
| 168 | + ); |
|
| 169 | + |
|
| 170 | + } catch ( \Exception $e ) { |
|
| 171 | + Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
| 172 | + wp_send_json_success( |
|
| 173 | + array( |
|
| 174 | + 'valid' => false, |
|
| 175 | + 'message' => $e->getMessage(), |
|
| 176 | + 'api_url' => Default_Api_Service::get_instance()->get_base_url(), |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * This function is hooked `admin_init` to check _wl_blog_url. |
|
| 184 | + */ |
|
| 185 | + public function wl_load_plugin() { |
|
| 186 | + |
|
| 187 | + $wl_blog_url = get_option( '_wl_blog_url' ); |
|
| 188 | + $home_url = get_option( 'home' ); |
|
| 189 | + |
|
| 190 | + if ( ! $wl_blog_url ) { |
|
| 191 | + update_option( '_wl_blog_url', $home_url, true ); |
|
| 192 | + } elseif ( $wl_blog_url !== $home_url ) { |
|
| 193 | + update_option( '_wl_blog_url', $home_url, true ); |
|
| 194 | + Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
| 195 | + set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 ); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * This function is hooked to the `admin_notices` to show admin notification. |
|
| 202 | + */ |
|
| 203 | + public function wl_key_update_notice() { |
|
| 204 | + if ( get_transient( 'wl-key-error-msg' ) ) { |
|
| 205 | + ?> |
|
| 206 | 206 | <div class="updated notice is-dismissible error"> |
| 207 | 207 | <p><?php esc_html( get_transient( 'wl-key-error-msg' ) ); ?></p> |
| 208 | 208 | </div> |
| 209 | 209 | <?php |
| 210 | - } |
|
| 211 | - } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | use Wordlift\Post\Post_Adapter; |
| 33 | 33 | // If this file is called directly, abort. |
| 34 | 34 | if ( ! defined( 'WPINC' ) ) { |
| 35 | - die; |
|
| 35 | + die; |
|
| 36 | 36 | } |
| 37 | 37 | define( |
| 38 | - 'WORDLIFT_PLUGIN_FILE', |
|
| 39 | - __FILE__ |
|
| 38 | + 'WORDLIFT_PLUGIN_FILE', |
|
| 39 | + __FILE__ |
|
| 40 | 40 | ); |
| 41 | 41 | define( 'WORDLIFT_VERSION', '3.40.7' ); |
| 42 | 42 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @since 3.33.6 |
| 51 | 51 | */ |
| 52 | 52 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
| 53 | - return; |
|
| 53 | + return; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -79,33 +79,33 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | function activate_wordlift() { |
| 81 | 81 | |
| 82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 82 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 83 | 83 | |
| 84 | - $log->info( 'Activating WordLift...' ); |
|
| 84 | + $log->info( 'Activating WordLift...' ); |
|
| 85 | 85 | |
| 86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 87 | - Wordlift_Activator::activate(); |
|
| 86 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 87 | + Wordlift_Activator::activate(); |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 91 | - * |
|
| 92 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 93 | - * @since 3.19.2 |
|
| 94 | - */ |
|
| 95 | - Wordlift_Http_Api::activate(); |
|
| 96 | - |
|
| 97 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
| 98 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 99 | - flush_rewrite_rules(); |
|
| 100 | - /** |
|
| 101 | - * @since 3.27.7 |
|
| 102 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 103 | - */ |
|
| 104 | - Top_Entities::activate(); |
|
| 89 | + /** |
|
| 90 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 91 | + * |
|
| 92 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 93 | + * @since 3.19.2 |
|
| 94 | + */ |
|
| 95 | + Wordlift_Http_Api::activate(); |
|
| 96 | + |
|
| 97 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
| 98 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 99 | + flush_rewrite_rules(); |
|
| 100 | + /** |
|
| 101 | + * @since 3.27.7 |
|
| 102 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 103 | + */ |
|
| 104 | + Top_Entities::activate(); |
|
| 105 | 105 | |
| 106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
| 107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
| 108 | - } |
|
| 106 | + if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
| 107 | + wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,23 +115,23 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | function deactivate_wordlift() { |
| 117 | 117 | |
| 118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 119 | - Wordlift_Deactivator::deactivate(); |
|
| 120 | - Wordlift_Http_Api::deactivate(); |
|
| 121 | - Ttl_Cache_Cleaner::deactivate(); |
|
| 122 | - /** |
|
| 123 | - * @since 3.27.7 |
|
| 124 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 125 | - */ |
|
| 126 | - Top_Entities::deactivate(); |
|
| 127 | - /** |
|
| 128 | - * @since 3.27.8 |
|
| 129 | - * Remove notification flag on deactivation. |
|
| 130 | - */ |
|
| 131 | - Key_Validation_Notice::remove_notification_flag(); |
|
| 132 | - flush_rewrite_rules(); |
|
| 133 | - |
|
| 134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
| 118 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 119 | + Wordlift_Deactivator::deactivate(); |
|
| 120 | + Wordlift_Http_Api::deactivate(); |
|
| 121 | + Ttl_Cache_Cleaner::deactivate(); |
|
| 122 | + /** |
|
| 123 | + * @since 3.27.7 |
|
| 124 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 125 | + */ |
|
| 126 | + Top_Entities::deactivate(); |
|
| 127 | + /** |
|
| 128 | + * @since 3.27.8 |
|
| 129 | + * Remove notification flag on deactivation. |
|
| 130 | + */ |
|
| 131 | + Key_Validation_Notice::remove_notification_flag(); |
|
| 132 | + flush_rewrite_rules(); |
|
| 133 | + |
|
| 134 | + wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
| 135 | 135 | |
| 136 | 136 | } |
| 137 | 137 | |
@@ -154,84 +154,84 @@ discard block |
||
| 154 | 154 | * @since 1.0.0 |
| 155 | 155 | */ |
| 156 | 156 | function run_wordlift() { |
| 157 | - /** |
|
| 158 | - * Filter: wl_feature__enable__widgets. |
|
| 159 | - * |
|
| 160 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 161 | - * |
|
| 162 | - * @return bool |
|
| 163 | - * @since 3.27.6 |
|
| 164 | - */ |
|
| 165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 169 | - } |
|
| 170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Filter: wl_feature__enable__analysis |
|
| 174 | - * |
|
| 175 | - * @param bool Whether to send api request to analysis or not |
|
| 176 | - * |
|
| 177 | - * @return bool |
|
| 178 | - * @since 3.27.6 |
|
| 179 | - */ |
|
| 180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 182 | - } else { |
|
| 183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $plugin = new Wordlift(); |
|
| 187 | - $plugin->run(); |
|
| 188 | - |
|
| 189 | - // Initialize the TTL Cache Cleaner. |
|
| 190 | - new Ttl_Cache_Cleaner(); |
|
| 191 | - |
|
| 192 | - // Load the new Post Adapter. |
|
| 193 | - new Post_Adapter(); |
|
| 194 | - |
|
| 195 | - // Load the API Data Hooks. |
|
| 196 | - new Api_Data_Hooks(); |
|
| 197 | - |
|
| 198 | - add_action( |
|
| 199 | - 'plugins_loaded', |
|
| 200 | - function () { |
|
| 201 | - // All features from registry should be initialized here. |
|
| 202 | - $features_registry = Features_Registry::get_instance(); |
|
| 203 | - $features_registry->initialize_all_features(); |
|
| 204 | - }, |
|
| 205 | - 5 |
|
| 206 | - ); |
|
| 207 | - |
|
| 208 | - add_action( |
|
| 209 | - 'plugins_loaded', |
|
| 210 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 211 | - function () use ( $plugin ) { |
|
| 212 | - |
|
| 213 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 214 | - |
|
| 215 | - // Register the Dataset module, requires `$api_service`. |
|
| 216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 218 | - |
|
| 219 | - /* |
|
| 157 | + /** |
|
| 158 | + * Filter: wl_feature__enable__widgets. |
|
| 159 | + * |
|
| 160 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 161 | + * |
|
| 162 | + * @return bool |
|
| 163 | + * @since 3.27.6 |
|
| 164 | + */ |
|
| 165 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 166 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 167 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 168 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 169 | + } |
|
| 170 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Filter: wl_feature__enable__analysis |
|
| 174 | + * |
|
| 175 | + * @param bool Whether to send api request to analysis or not |
|
| 176 | + * |
|
| 177 | + * @return bool |
|
| 178 | + * @since 3.27.6 |
|
| 179 | + */ |
|
| 180 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 181 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 182 | + } else { |
|
| 183 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $plugin = new Wordlift(); |
|
| 187 | + $plugin->run(); |
|
| 188 | + |
|
| 189 | + // Initialize the TTL Cache Cleaner. |
|
| 190 | + new Ttl_Cache_Cleaner(); |
|
| 191 | + |
|
| 192 | + // Load the new Post Adapter. |
|
| 193 | + new Post_Adapter(); |
|
| 194 | + |
|
| 195 | + // Load the API Data Hooks. |
|
| 196 | + new Api_Data_Hooks(); |
|
| 197 | + |
|
| 198 | + add_action( |
|
| 199 | + 'plugins_loaded', |
|
| 200 | + function () { |
|
| 201 | + // All features from registry should be initialized here. |
|
| 202 | + $features_registry = Features_Registry::get_instance(); |
|
| 203 | + $features_registry->initialize_all_features(); |
|
| 204 | + }, |
|
| 205 | + 5 |
|
| 206 | + ); |
|
| 207 | + |
|
| 208 | + add_action( |
|
| 209 | + 'plugins_loaded', |
|
| 210 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 211 | + function () use ( $plugin ) { |
|
| 212 | + |
|
| 213 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 214 | + |
|
| 215 | + // Register the Dataset module, requires `$api_service`. |
|
| 216 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 217 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 218 | + |
|
| 219 | + /* |
|
| 220 | 220 | * Require the Entity annotation cleanup module. |
| 221 | 221 | * |
| 222 | 222 | * @since 3.34.6 |
| 223 | 223 | */ |
| 224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
| 224 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
| 225 | 225 | |
| 226 | - /* |
|
| 226 | + /* |
|
| 227 | 227 | * Import LOD entities. |
| 228 | 228 | * |
| 229 | 229 | * @since 3.35.0 |
| 230 | 230 | */ |
| 231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
| 231 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
| 232 | 232 | |
| 233 | - } |
|
| 234 | - ); |
|
| 233 | + } |
|
| 234 | + ); |
|
| 235 | 235 | |
| 236 | 236 | } |
| 237 | 237 | |
@@ -245,45 +245,45 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | function wordlift_plugin_autoload_register() { |
| 247 | 247 | |
| 248 | - spl_autoload_register( |
|
| 249 | - function ( $class_name ) { |
|
| 248 | + spl_autoload_register( |
|
| 249 | + function ( $class_name ) { |
|
| 250 | 250 | |
| 251 | - // Bail out if these are not our classes. |
|
| 252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 251 | + // Bail out if these are not our classes. |
|
| 252 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 256 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 257 | 257 | |
| 258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 258 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 259 | 259 | |
| 260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 261 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 260 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 261 | + $file = 'class-' . $matches[2] . '.php'; |
|
| 262 | 262 | |
| 263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 263 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 264 | 264 | |
| 265 | - if ( ! file_exists( $full_path ) ) { |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 265 | + if ( ! file_exists( $full_path ) ) { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - require_once $full_path; |
|
| 269 | + require_once $full_path; |
|
| 270 | 270 | |
| 271 | - return true; |
|
| 272 | - } |
|
| 273 | - ); |
|
| 271 | + return true; |
|
| 272 | + } |
|
| 273 | + ); |
|
| 274 | 274 | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | function wl_block_categories( $categories ) { |
| 278 | - return array_merge( |
|
| 279 | - $categories, |
|
| 280 | - array( |
|
| 281 | - array( |
|
| 282 | - 'slug' => 'wordlift', |
|
| 283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 284 | - ), |
|
| 285 | - ) |
|
| 286 | - ); |
|
| 278 | + return array_merge( |
|
| 279 | + $categories, |
|
| 280 | + array( |
|
| 281 | + array( |
|
| 282 | + 'slug' => 'wordlift', |
|
| 283 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
| 284 | + ), |
|
| 285 | + ) |
|
| 286 | + ); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -291,19 +291,19 @@ discard block |
||
| 291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
| 292 | 292 | */ |
| 293 | 293 | function wl_enqueue_leaflet( $in_footer = false ) { |
| 294 | - // Leaflet. |
|
| 295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
| 296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
| 294 | + // Leaflet. |
|
| 295 | + wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
| 296 | + wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | add_filter( 'block_categories', 'wl_block_categories', 10 ); |
| 300 | 300 | |
| 301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
| 302 | 302 | add_filter( |
| 303 | - 'wl_feature__enable__dataset', |
|
| 304 | - function ( $value ) { |
|
| 305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
| 306 | - } |
|
| 303 | + 'wl_feature__enable__dataset', |
|
| 304 | + function ( $value ) { |
|
| 305 | + return apply_filters( 'wl_features__enable__dataset', $value ); |
|
| 306 | + } |
|
| 307 | 307 | ); |
| 308 | 308 | |
| 309 | 309 | require_once __DIR__ . '/modules/food-kg/load.php'; |
@@ -312,26 +312,26 @@ discard block |
||
| 312 | 312 | require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
| 313 | 313 | |
| 314 | 314 | add_action( |
| 315 | - 'update_plugins_adthrive.wordlift.io', |
|
| 316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
| 317 | - // Bail out if it's not our plugin. |
|
| 318 | - $update_uri = $plugin_data['UpdateURI']; |
|
| 319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
| 320 | - return $update; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
| 324 | - |
|
| 325 | - if ( is_wp_error( $response ) ) { |
|
| 326 | - return $update; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - try { |
|
| 330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
| 331 | - } catch ( Exception $e ) { |
|
| 332 | - return $update; |
|
| 333 | - } |
|
| 334 | - }, |
|
| 335 | - 10, |
|
| 336 | - 3 |
|
| 315 | + 'update_plugins_adthrive.wordlift.io', |
|
| 316 | + function ( $update, $plugin_data, $plugin_file ) { |
|
| 317 | + // Bail out if it's not our plugin. |
|
| 318 | + $update_uri = $plugin_data['UpdateURI']; |
|
| 319 | + if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
| 320 | + return $update; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
| 324 | + |
|
| 325 | + if ( is_wp_error( $response ) ) { |
|
| 326 | + return $update; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + try { |
|
| 330 | + return json_decode( wp_remote_retrieve_body( $response ) ); |
|
| 331 | + } catch ( Exception $e ) { |
|
| 332 | + return $update; |
|
| 333 | + } |
|
| 334 | + }, |
|
| 335 | + 10, |
|
| 336 | + 3 |
|
| 337 | 337 | ); |