Changeset 2899060
- Timestamp:
- 04/14/2023 09:16:11 AM (3 years ago)
- Location:
- advance-faq-block/trunk
- Files:
-
- 6 edited
-
advance-faq-block.php (modified) (1 diff)
-
inc/appsero/src/Client.php (modified) (15 diffs)
-
inc/appsero/src/Insights.php (modified) (48 diffs)
-
inc/appsero/src/License.php (modified) (51 diffs)
-
inc/appsero/src/Updater.php (modified) (18 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
advance-faq-block/trunk/advance-faq-block.php
r2886650 r2899060 5 5 * Requires at least: 6.1 6 6 * Requires PHP: 7.0 7 * Version: 1.0. 17 * Version: 1.0.2 8 8 * Author: Sydur Rahman 9 9 * Author URI: https://sydurrahman.com/ -
advance-faq-block/trunk/inc/appsero/src/Client.php
r2886650 r2899060 1 1 <?php 2 2 3 namespace Appsero; 3 4 … … 32 33 /** 33 34 * The plugin/theme file path 35 * 34 36 * @example .../wp-content/plugins/test-slug/test-slug.php 35 37 * … … 40 42 /** 41 43 * Main plugin file 44 * 42 45 * @example test-slug/test-slug.php 43 46 * … … 48 51 /** 49 52 * Slug of the plugin 53 * 50 54 * @example test-slug 51 55 * … … 69 73 70 74 /** 71 * textdomain75 * Textdomain 72 76 * 73 77 * @var string … … 96 100 private $license; 97 101 98 /**102 /** 99 103 * Initialize the class 100 104 * 101 * @param string $hash hash of the plugin102 * @param string $name readable name of the plugin103 * @param string $file main plugin file path105 * @param string $hash hash of the plugin 106 * @param string $name readable name of the plugin 107 * @param string $file main plugin file path 104 108 */ 105 109 public function __construct( $hash, $name, $file ) { … … 117 121 */ 118 122 public function insights() { 119 120 if ( ! class_exists( __NAMESPACE__ . '\Insights') ) { 123 if ( ! class_exists( __NAMESPACE__ . '\Insights' ) ) { 121 124 require_once __DIR__ . '/Insights.php'; 122 125 } … … 138 141 */ 139 142 public function updater() { 140 141 if ( ! class_exists( __NAMESPACE__ . '\Updater') ) { 143 if ( ! class_exists( __NAMESPACE__ . '\Updater' ) ) { 142 144 require_once __DIR__ . '/Updater.php'; 143 145 } … … 159 161 */ 160 162 public function license() { 161 162 if ( ! class_exists( __NAMESPACE__ . '\License') ) { 163 if ( ! class_exists( __NAMESPACE__ . '\License' ) ) { 163 164 require_once __DIR__ . '/License.php'; 164 165 } … … 191 192 */ 192 193 protected function set_basename_and_slug() { 193 194 194 if ( strpos( $this->file, WP_CONTENT_DIR . '/themes/' ) === false ) { 195 195 $this->basename = plugin_basename( $this->file ); 196 196 197 list( $this->slug, $mainfile ) = explode( '/', $this->basename );197 list( $this->slug, $mainfile ) = explode( '/', $this->basename ); 198 198 199 199 require_once ABSPATH . 'wp-admin/includes/plugin.php'; … … 202 202 203 203 $this->project_version = $plugin_data['Version']; 204 $this->type = 'plugin';204 $this->type = 'plugin'; 205 205 } else { 206 206 $this->basename = str_replace( WP_CONTENT_DIR . '/themes/', '', $this->file ); 207 207 208 list( $this->slug, $mainfile ) = explode( '/', $this->basename );208 list( $this->slug, $mainfile ) = explode( '/', $this->basename ); 209 209 210 210 $theme = wp_get_theme( $this->slug ); 211 211 212 212 $this->project_version = $theme->version; 213 $this->type = 'theme';213 $this->type = 'theme'; 214 214 } 215 215 … … 220 220 * Send request to remote endpoint 221 221 * 222 * @param array $params223 * @param string $route224 * 225 * @return array|WP_Error Array of results including HTTP headers or WP_Error if the request failed.222 * @param array $params 223 * @param string $route 224 * 225 * @return array|WP_Error array of results including HTTP headers or WP_Error if the request failed 226 226 */ 227 227 public function send_request( $params, $route, $blocking = false ) { 228 228 $url = $this->endpoint() . $route; 229 229 230 $headers = array(230 $headers = [ 231 231 'user-agent' => 'Appsero/' . md5( esc_url( home_url() ) ) . ';', 232 232 'Accept' => 'application/json', 233 ]; 234 235 $response = wp_remote_post( 236 $url, 237 [ 238 'method' => 'POST', 239 'timeout' => 30, 240 'redirection' => 5, 241 'httpversion' => '1.0', 242 'blocking' => $blocking, 243 'headers' => $headers, 244 'body' => array_merge( $params, [ 'client' => $this->version ] ), 245 'cookies' => [], 246 ] 233 247 ); 234 248 235 $response = wp_remote_post( $url, array(236 'method' => 'POST',237 'timeout' => 30,238 'redirection' => 5,239 'httpversion' => '1.0',240 'blocking' => $blocking,241 'headers' => $headers,242 'body' => array_merge( $params, array( 'client' => $this->version ) ),243 'cookies' => array()244 ) );245 246 249 return $response; 247 250 } … … 250 253 * Check if the current server is localhost 251 254 * 252 * @return bool ean255 * @return bool 253 256 */ 254 257 public function is_local_server() { 255 $is_local = i n_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ));258 $is_local = isset( $_SERVER['REMOTE_ADDR'] ) && in_array( $_SERVER['REMOTE_ADDR'], [ '127.0.0.1', '::1' ], true ); 256 259 257 260 return apply_filters( 'appsero_is_local', $is_local ); … … 261 264 * Translate function _e() 262 265 */ 266 // phpcs:ignore 263 267 public function _etrans( $text ) { 264 268 call_user_func( '_e', $text, $this->textdomain ); … … 268 272 * Translate function __() 269 273 */ 274 // phpcs:ignore 270 275 public function __trans( $text ) { 271 276 return call_user_func( '__', $text, $this->textdomain ); -
advance-faq-block/trunk/inc/appsero/src/Insights.php
r2886650 r2899060 1 1 <?php 2 2 3 namespace Appsero; 3 4 4 5 /** 5 6 * Appsero Insights … … 21 22 * Wheather to the notice or not 22 23 * 23 * @var bool ean24 * @var bool 24 25 */ 25 26 protected $show_notice = true; … … 30 31 * @var array 31 32 */ 32 protected $extra_data = array();33 protected $extra_data = []; 33 34 34 35 /** … … 40 41 41 42 /** 42 * @var bool ean43 * @var bool 43 44 */ 44 45 private $plugin_data = false; 45 46 46 47 47 /** 48 48 * Initialize the class 49 49 * 50 * @param $client51 50 * @param null $name 52 51 * @param null $file 53 52 */ 54 53 public function __construct( $client, $name = null, $file = null ) { 55 56 54 if ( is_string( $client ) && ! empty( $name ) && ! empty( $file ) ) { 57 55 $client = new Client( $client, $name, $file ); … … 92 90 * @return \self 93 91 */ 94 public function add_extra( $data = array()) {92 public function add_extra( $data = [] ) { 95 93 $this->extra_data = $data; 96 94 … … 101 99 * Set custom notice text 102 100 * 103 * @param string $text101 * @param string $text 104 102 * 105 103 * @return \self 106 104 */ 107 public function notice( $text='' ) {105 public function notice( $text = '' ) { 108 106 $this->notice = $text; 109 107 … … 117 115 */ 118 116 public function init() { 119 if ( $this->client->type == 'plugin' ) {117 if ( $this->client->type === 'plugin' ) { 120 118 $this->init_plugin(); 121 } else if ( $this->client->type== 'theme' ) {119 } elseif ( $this->client->type === 'theme' ) { 122 120 $this->init_theme(); 123 121 } … … 132 130 $this->init_common(); 133 131 134 add_action( 'switch_theme', array( $this, 'deactivation_cleanup' ));135 add_action( 'switch_theme', array( $this, 'theme_deactivated' ), 12, 3 );132 add_action( 'switch_theme', [ $this, 'deactivation_cleanup' ] ); 133 add_action( 'switch_theme', [ $this, 'theme_deactivated' ], 12, 3 ); 136 134 } 137 135 … … 144 142 // plugin deactivate popup 145 143 if ( ! $this->is_local_server() ) { 146 add_filter( 'plugin_action_links_' . $this->client->basename, array( $this, 'plugin_action_links' ));147 add_action( 'admin_footer', array( $this, 'deactivate_scripts' ));144 add_filter( 'plugin_action_links_' . $this->client->basename, [ $this, 'plugin_action_links' ] ); 145 add_action( 'admin_footer', [ $this, 'deactivate_scripts' ] ); 148 146 } 149 147 150 148 $this->init_common(); 151 149 152 register_activation_hook( $this->client->file, array( $this, 'activate_plugin' ));153 register_deactivation_hook( $this->client->file, array( $this, 'deactivation_cleanup' ));150 register_activation_hook( $this->client->file, [ $this, 'activate_plugin' ] ); 151 register_deactivation_hook( $this->client->file, [ $this, 'deactivation_cleanup' ] ); 154 152 } 155 153 … … 160 158 */ 161 159 protected function init_common() { 162 163 160 if ( $this->show_notice ) { 164 161 // tracking notice 165 add_action( 'admin_notices', array( $this, 'admin_notice' ));166 } 167 168 add_action( 'admin_init', array( $this, 'handle_optin_optout' ));162 add_action( 'admin_notices', [ $this, 'admin_notice' ] ); 163 } 164 165 add_action( 'admin_init', [ $this, 'handle_optin_optout' ] ); 169 166 170 167 // uninstall reason 171 add_action( 'wp_ajax_' . $this->client->slug . '_submit-uninstall-reason', array( $this, 'uninstall_reason_submission' ));168 add_action( 'wp_ajax_' . $this->client->slug . '_submit-uninstall-reason', [ $this, 'uninstall_reason_submission' ] ); 172 169 173 170 // cron events 174 add_filter( 'cron_schedules', array( $this, 'add_weekly_schedule' ));175 add_action( $this->client->slug . '_tracker_send_event', array( $this, 'send_tracking_data' ));171 add_filter( 'cron_schedules', [ $this, 'add_weekly_schedule' ] ); 172 add_action( $this->client->slug . '_tracker_send_event', [ $this, 'send_tracking_data' ] ); 176 173 // add_action( 'admin_init', array( $this, 'send_tracking_data' ) ); // test 177 174 } … … 180 177 * Send tracking data to AppSero server 181 178 * 182 * @param boolean$override179 * @param bool $override 183 180 * 184 181 * @return void … … 211 208 $all_plugins = $this->get_all_plugins(); 212 209 213 $users = get_users( array( 214 'role' => 'administrator', 215 'orderby' => 'ID', 216 'order' => 'ASC', 217 'number' => 1, 218 'paged' => 1, 219 ) ); 220 221 $admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false; 222 $first_name = $last_name = ''; 210 $users = get_users( 211 [ 212 'role' => 'administrator', 213 'orderby' => 'ID', 214 'order' => 'ASC', 215 'number' => 1, 216 'paged' => 1, 217 ] 218 ); 219 220 $admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false; 221 $first_name = ''; 222 $last_name = ''; 223 223 224 224 if ( $admin_user ) { … … 227 227 } 228 228 229 $data = array(229 $data = [ 230 230 'url' => esc_url( home_url() ), 231 231 'site' => $this->get_site_name(), … … 243 243 'tracking_skipped' => false, 244 244 'is_local' => $this->is_local_server(), 245 );245 ]; 246 246 247 247 // Add Plugins 248 if ( $this->plugin_data) {249 250 $plugins_data = array(); 251 252 foreach ($all_plugins['active_plugins'] as $slug => $plugin) {253 $slug = strstr($slug, '/', true); 254 if ( ! $slug) {248 if ( $this->plugin_data ) { 249 $plugins_data = []; 250 251 foreach ( $all_plugins['active_plugins'] as $slug => $plugin ) { 252 $slug = strstr( $slug, '/', true ); 253 254 if ( ! $slug ) { 255 255 continue; 256 256 } 257 257 258 $plugins_data[ $slug ] = array(259 'name' => isset($plugin['name']) ? $plugin['name'] : '',260 'version' => isset($plugin['version']) ? $plugin['version'] : '',261 );262 } 263 264 if ( array_key_exists($this->client->slug, $plugins_data)) {265 unset( $plugins_data[$this->client->slug]);266 } 267 258 $plugins_data[ $slug ] = [ 259 'name' => isset( $plugin['name'] ) ? $plugin['name'] : '', 260 'version' => isset( $plugin['version'] ) ? $plugin['version'] : '', 261 ]; 262 } 263 264 if ( array_key_exists( $this->client->slug, $plugins_data ) ) { 265 unset( $plugins_data[ $this->client->slug ] ); 266 } 267 268 268 $data['plugins'] = $plugins_data; 269 269 } 270 270 271 // Add metadata 272 if ( $extra = $this->get_extra_data() ) { 271 // Add Metadata 272 $extra = $this->get_extra_data(); 273 274 if ( $extra ) { 273 275 $data['extra'] = $extra; 274 276 } … … 300 302 } 301 303 302 return array();304 return []; 303 305 } 304 306 … … 309 311 */ 310 312 protected function data_we_collect() { 311 $data = array(313 $data = [ 312 314 'Server environment details (php, mysql, server, WordPress versions)', 313 315 'Number of users in your site', … … 316 318 'Site name and URL', 317 319 'Your name and email address', 318 );319 320 if ( $this->plugin_data) {321 array_splice( $data, 4, 0, ["active plugins' name"]);320 ]; 321 322 if ( $this->plugin_data ) { 323 array_splice( $data, 4, 0, [ "active plugins' name" ] ); 322 324 } 323 325 … … 333 335 $allow_tracking = get_option( $this->client->slug . '_allow_tracking', 'no' ); 334 336 335 return $allow_tracking == 'yes';337 return $allow_tracking === 'yes'; 336 338 } 337 339 … … 348 350 * Check if the notice has been dismissed or enabled 349 351 * 350 * @return bool ean352 * @return bool 351 353 */ 352 354 public function notice_dismissed() { 353 355 $hide_notice = get_option( $this->client->slug . '_tracking_notice', null ); 354 356 355 if ( 'hide' == $hide_notice ) {357 if ( 'hide' === $hide_notice ) { 356 358 return true; 357 359 } … … 363 365 * Check if the current server is localhost 364 366 * 365 * @return bool ean367 * @return bool 366 368 */ 367 369 private function is_local_server() { 368 369 $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'localhost'; 370 $ip = isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1'; 370 $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : 'localhost'; 371 $ip = isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '127.0.0.1'; 371 372 $is_local = false; 372 373 373 if ( in_array( $ip,array( '127.0.0.1', '::1' ))374 if ( in_array( $ip, [ '127.0.0.1', '::1' ], true ) 374 375 || ! strpos( $host, '.' ) 375 || in_array( strrchr( $host, '.' ), array( '.test', '.testing', '.local', '.localhost', '.localdomain' ))376 || in_array( strrchr( $host, '.' ), [ '.test', '.testing', '.local', '.localhost', '.localdomain' ], true ) 376 377 ) { 377 378 $is_local = true; … … 387 388 */ 388 389 private function schedule_event() { 389 $hook_name = $this->client->slug . '_tracker_send_event';390 $hook_name = wp_unslash( $this->client->slug . '_tracker_send_event' ); 390 391 391 392 if ( ! wp_next_scheduled( $hook_name ) ) { … … 409 410 */ 410 411 public function admin_notice() { 411 412 412 if ( $this->notice_dismissed() ) { 413 413 return; … … 427 427 } 428 428 429 $optin_url = add_query_arg( $this->client->slug . '_tracker_optin', 'true' );430 $optout_url = add_query_arg( $this->client->slug . '_tracker_optout', 'true' );429 $optin_url = wp_nonce_url( add_query_arg( $this->client->slug . '_tracker_optin', 'true' ), '_wpnonce' ); 430 $optout_url = wp_nonce_url( add_query_arg( $this->client->slug . '_tracker_optout', 'true' ), '_wpnonce' ); 431 431 432 432 if ( empty( $this->notice ) ) { … … 436 436 } 437 437 438 $policy_url = 'https:// ' . 'appsero.com/privacy-policy/';438 $policy_url = 'https://appsero.com/privacy-policy/'; 439 439 440 440 $notice .= ' (<a class="' . $this->client->slug . '-insights-data-we-collect" href="#">' . $this->client->__trans( 'what we collect' ) . '</a>)'; … … 443 443 444 444 echo '<div class="updated"><p>'; 445 echo $notice;446 echo '</p><p class="submit">';447 echo ' <a href="' . esc_url( $optin_url ) . '" class="button-primary button-large">' . $this->client->__trans( 'Allow' ) . '</a>';448 echo ' <a href="' . esc_url( $optout_url ) . '" class="button-secondary button-large">' . $this->client->__trans( 'No thanks' ) . '</a>';445 echo $notice; 446 echo '</p><p class="submit">'; 447 echo ' <a href="' . esc_url( $optin_url ) . '" class="button-primary button-large">' . $this->client->__trans( 'Allow' ) . '</a>'; 448 echo ' <a href="' . esc_url( $optout_url ) . '" class="button-secondary button-large">' . $this->client->__trans( 'No thanks' ) . '</a>'; 449 449 echo '</p></div>'; 450 450 … … 458 458 459 459 /** 460 * handle the optin/optout460 * Handle the optin/optout 461 461 * 462 462 * @return void 463 463 */ 464 464 public function handle_optin_optout() { 465 466 if ( isset( $_GET[ $this->client->slug . '_tracker_optin' ] ) && $_GET[ $this->client->slug . '_tracker_optin' ] == 'true' ) { 465 if ( ! isset( $_GET['_wpnonce'] ) ) { 466 return; 467 } 468 469 if ( ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), '_wpnonce' ) ) { 470 return; 471 } 472 473 if ( isset( $_GET[ $this->client->slug . '_tracker_optin' ] ) && $_GET[ $this->client->slug . '_tracker_optin' ] === 'true' ) { 467 474 $this->optin(); 468 475 469 wp_ redirect( remove_query_arg( $this->client->slug . '_tracker_optin' ) );476 wp_safe_redirect( remove_query_arg( $this->client->slug . '_tracker_optin' ) ); 470 477 exit; 471 478 } 472 479 473 if ( isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && $_GET[ $this->client->slug . '_tracker_optout' ]== 'true' ) {480 if ( isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && $_GET[ $this->client->slug . '_tracker_optout' ] === 'true' ) { 474 481 $this->optout(); 475 482 476 wp_ redirect( remove_query_arg( $this->client->slug . '_tracker_optout' ) );483 wp_safe_redirect( remove_query_arg( $this->client->slug . '_tracker_optout' ) ); 477 484 exit; 478 485 } … … 492 499 $this->send_tracking_data(); 493 500 494 /* *501 /* 495 502 * Fires when the user has opted in tracking. 496 503 */ … … 511 518 $this->clear_schedule_event(); 512 519 513 /* *520 /* 514 521 * Fires when the user has opted out tracking. 515 522 */ … … 520 527 * Get the number of post counts 521 528 * 522 * @param string$post_type523 * 524 * @return int eger529 * @param string $post_type 530 * 531 * @return int 525 532 */ 526 533 public function get_post_count( $post_type ) { 527 534 global $wpdb; 528 535 529 return (int) $wpdb->get_var( "SELECT count(ID) FROM $wpdb->posts WHERE post_type = '$post_type' and post_status = 'publish'"); 536 return (int) $wpdb->get_var( 537 $wpdb->prepare( 538 "SELECT count(ID) FROM $wpdb->posts WHERE post_type = %s and post_status = %s", 539 [ $post_type, 'publish' ] 540 ) 541 ); 530 542 } 531 543 … … 538 550 global $wpdb; 539 551 540 $server_data = array();552 $server_data = []; 541 553 542 554 if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) { 555 // phpcs:ignore 543 556 $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; 544 557 } … … 548 561 } 549 562 550 $server_data['mysql_version'] = $wpdb->db_version();563 $server_data['mysql_version'] = $wpdb->db_version(); 551 564 552 565 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() ); … … 565 578 */ 566 579 private function get_wp_info() { 567 $wp_data = array();580 $wp_data = []; 568 581 569 582 $wp_data['memory_limit'] = WP_MEMORY_LIMIT; 570 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG') && WP_DEBUG ) ? 'Yes' : 'No';583 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No'; 571 584 $wp_data['locale'] = get_locale(); 572 585 $wp_data['version'] = get_bloginfo( 'version' ); … … 596 609 597 610 $plugins = get_plugins(); 598 $active_plugins_keys = get_option( 'active_plugins', array());599 $active_plugins = array();611 $active_plugins_keys = get_option( 'active_plugins', [] ); 612 $active_plugins = []; 600 613 601 614 foreach ( $plugins as $k => $v ) { 602 615 // Take care of formatting the data how we want it. 603 $formatted = array();604 $formatted['name'] = strip_tags( $v['Name'] );616 $formatted = []; 617 $formatted['name'] = wp_strip_all_tags( $v['Name'] ); 605 618 606 619 if ( isset( $v['Version'] ) ) { 607 $formatted['version'] = strip_tags( $v['Version'] );620 $formatted['version'] = wp_strip_all_tags( $v['Version'] ); 608 621 } 609 622 610 623 if ( isset( $v['Author'] ) ) { 611 $formatted['author'] = strip_tags( $v['Author'] );624 $formatted['author'] = wp_strip_all_tags( $v['Author'] ); 612 625 } 613 626 614 627 if ( isset( $v['Network'] ) ) { 615 $formatted['network'] = strip_tags( $v['Network'] );628 $formatted['network'] = wp_strip_all_tags( $v['Network'] ); 616 629 } 617 630 618 631 if ( isset( $v['PluginURI'] ) ) { 619 $formatted['plugin_uri'] = strip_tags( $v['PluginURI'] );620 } 621 622 if ( in_array( $k, $active_plugins_keys ) ) {632 $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] ); 633 } 634 635 if ( in_array( $k, $active_plugins_keys, true ) ) { 623 636 // Remove active plugins from list so we can show active and inactive separately 624 unset( $plugins[ $k] );625 $active_plugins[ $k] = $formatted;637 unset( $plugins[ $k ] ); 638 $active_plugins[ $k ] = $formatted; 626 639 } else { 627 $plugins[$k] = $formatted; 628 } 629 } 630 631 return array( 'active_plugins' => $active_plugins, 'inactive_plugins' => $plugins ); 640 $plugins[ $k ] = $formatted; 641 } 642 } 643 644 return [ 645 'active_plugins' => $active_plugins, 646 'inactive_plugins' => $plugins, 647 ]; 632 648 } 633 649 … … 638 654 */ 639 655 public function get_user_counts() { 640 $user_count = array();656 $user_count = []; 641 657 $user_count_data = count_users(); 642 658 $user_count['total'] = $user_count_data['total_users']; … … 657 673 * Add weekly cron schedule 658 674 * 659 * @param array $schedules675 * @param array $schedules 660 676 * 661 677 * @return array 662 678 */ 663 679 public function add_weekly_schedule( $schedules ) { 664 665 $schedules['weekly'] = array( 680 $schedules['weekly'] = [ 666 681 'interval' => DAY_IN_SECONDS * 7, 667 682 'display' => 'Once Weekly', 668 );683 ]; 669 684 670 685 return $schedules; … … 686 701 // re-schedule and delete the last sent time so we could force send again 687 702 $hook_name = $this->client->slug . '_tracker_send_event'; 703 688 704 if ( ! wp_next_scheduled( $hook_name ) ) { 689 705 wp_schedule_event( time(), 'weekly', $hook_name ); … … 703 719 $this->clear_schedule_event(); 704 720 705 if ( 'theme' == $this->client->type ) {721 if ( 'theme' === $this->client->type ) { 706 722 delete_option( $this->client->slug . '_tracking_last_send' ); 707 723 delete_option( $this->client->slug . '_allow_tracking' ); … … 714 730 * Hook into action links and modify the deactivate link 715 731 * 716 * @param array$links732 * @param array $links 717 733 * 718 734 * @return array 719 735 */ 720 736 public function plugin_action_links( $links ) { 721 722 737 if ( array_key_exists( 'deactivate', $links ) ) { 723 738 $links['deactivate'] = str_replace( '<a', '<a class="' . $this->client->slug . '-deactivate-link"', $links['deactivate'] ); … … 733 748 */ 734 749 private function get_uninstall_reasons() { 735 $reasons = array(736 array( 737 'id' => 'could-not-understand',738 'text' => $this->client->__trans( "Couldn't understand" ),739 'placeholder' => $this->client->__trans( 'Would you like us to assist you?' ),740 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23"><g fill="none"><g fill="#3B86FF"><path d="M11.5 0C17.9 0 23 5.1 23 11.5 23 17.9 17.9 23 11.5 23 10.6 23 9.6 22.9 8.8 22.7L8.8 22.6C9.3 22.5 9.7 22.3 10 21.9 10.3 21.6 10.4 21.3 10.4 20.9 10.8 21 11.1 21 11.5 21 16.7 21 21 16.7 21 11.5 21 6.3 16.7 2 11.5 2 6.3 2 2 6.3 2 11.5 2 13 2.3 14.3 2.9 15.6 2.7 16 2.4 16.3 2.2 16.8L2.1 17.1 2.1 17.3C2 17.5 2 17.7 2 18 0.7 16.1 0 13.9 0 11.5 0 5.1 5.1 0 11.5 0ZM6 13.6C6 13.7 6.1 13.8 6.1 13.9 6.3 14.5 6.2 15.7 6.1 16.4 6.1 16.6 6 16.9 6 17.1 6 17.1 6.1 17.1 6.1 17.1 7.1 16.9 8.2 16 9.3 15.5 9.8 15.2 10.4 15 10.9 15 11.2 15 11.4 15 11.6 15.2 11.9 15.4 12.1 16 11.6 16.4 11.5 16.5 11.3 16.6 11.1 16.7 10.5 17 9.9 17.4 9.3 17.7 9 17.9 9 18.1 9.1 18.5 9.2 18.9 9.3 19.4 9.3 19.8 9.4 20.3 9.3 20.8 9 21.2 8.8 21.5 8.5 21.6 8.1 21.7 7.9 21.8 7.6 21.9 7.3 21.9L6.5 22C6.3 22 6 21.9 5.8 21.9 5 21.8 4.4 21.5 3.9 20.9 3.3 20.4 3.1 19.6 3 18.8L3 18.5C3 18.2 3 17.9 3.1 17.7L3.1 17.6C3.2 17.1 3.5 16.7 3.7 16.3 4 15.9 4.2 15.4 4.3 15 4.4 14.6 4.4 14.5 4.6 14.2 4.6 13.9 4.7 13.7 4.9 13.6 5.2 13.2 5.7 13.2 6 13.6ZM11.7 11.2C13.1 11.2 14.3 11.7 15.2 12.9 15.3 13 15.4 13.1 15.4 13.2 15.4 13.4 15.3 13.8 15.2 13.8 15 13.9 14.9 13.8 14.8 13.7 14.6 13.5 14.4 13.2 14.1 13.1 13.5 12.6 12.8 12.3 12 12.2 10.7 12.1 9.5 12.3 8.4 12.8 8.3 12.8 8.2 12.8 8.1 12.8 7.9 12.8 7.8 12.4 7.8 12.2 7.7 12.1 7.8 11.9 8 11.8 8.4 11.7 8.8 11.5 9.2 11.4 10 11.2 10.9 11.1 11.7 11.2ZM16.3 5.9C17.3 5.9 18 6.6 18 7.6 18 8.5 17.3 9.3 16.3 9.3 15.4 9.3 14.7 8.5 14.7 7.6 14.7 6.6 15.4 5.9 16.3 5.9ZM8.3 5C9.2 5 9.9 5.8 9.9 6.7 9.9 7.7 9.2 8.4 8.2 8.4 7.3 8.4 6.6 7.7 6.6 6.7 6.6 5.8 7.3 5 8.3 5Z"/></g></g></svg>' 741 ),742 array( 743 'id' => 'found-better-plugin',744 'text' => $this->client->__trans( 'Found a better plugin' ),745 'placeholder' => $this->client->__trans( 'Which plugin?' ),750 $reasons = [ 751 [ 752 'id' => 'could-not-understand', 753 'text' => $this->client->__trans( "Couldn't understand" ), 754 'placeholder' => $this->client->__trans( 'Would you like us to assist you?' ), 755 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23"><g fill="none"><g fill="#3B86FF"><path d="M11.5 0C17.9 0 23 5.1 23 11.5 23 17.9 17.9 23 11.5 23 10.6 23 9.6 22.9 8.8 22.7L8.8 22.6C9.3 22.5 9.7 22.3 10 21.9 10.3 21.6 10.4 21.3 10.4 20.9 10.8 21 11.1 21 11.5 21 16.7 21 21 16.7 21 11.5 21 6.3 16.7 2 11.5 2 6.3 2 2 6.3 2 11.5 2 13 2.3 14.3 2.9 15.6 2.7 16 2.4 16.3 2.2 16.8L2.1 17.1 2.1 17.3C2 17.5 2 17.7 2 18 0.7 16.1 0 13.9 0 11.5 0 5.1 5.1 0 11.5 0ZM6 13.6C6 13.7 6.1 13.8 6.1 13.9 6.3 14.5 6.2 15.7 6.1 16.4 6.1 16.6 6 16.9 6 17.1 6 17.1 6.1 17.1 6.1 17.1 7.1 16.9 8.2 16 9.3 15.5 9.8 15.2 10.4 15 10.9 15 11.2 15 11.4 15 11.6 15.2 11.9 15.4 12.1 16 11.6 16.4 11.5 16.5 11.3 16.6 11.1 16.7 10.5 17 9.9 17.4 9.3 17.7 9 17.9 9 18.1 9.1 18.5 9.2 18.9 9.3 19.4 9.3 19.8 9.4 20.3 9.3 20.8 9 21.2 8.8 21.5 8.5 21.6 8.1 21.7 7.9 21.8 7.6 21.9 7.3 21.9L6.5 22C6.3 22 6 21.9 5.8 21.9 5 21.8 4.4 21.5 3.9 20.9 3.3 20.4 3.1 19.6 3 18.8L3 18.5C3 18.2 3 17.9 3.1 17.7L3.1 17.6C3.2 17.1 3.5 16.7 3.7 16.3 4 15.9 4.2 15.4 4.3 15 4.4 14.6 4.4 14.5 4.6 14.2 4.6 13.9 4.7 13.7 4.9 13.6 5.2 13.2 5.7 13.2 6 13.6ZM11.7 11.2C13.1 11.2 14.3 11.7 15.2 12.9 15.3 13 15.4 13.1 15.4 13.2 15.4 13.4 15.3 13.8 15.2 13.8 15 13.9 14.9 13.8 14.8 13.7 14.6 13.5 14.4 13.2 14.1 13.1 13.5 12.6 12.8 12.3 12 12.2 10.7 12.1 9.5 12.3 8.4 12.8 8.3 12.8 8.2 12.8 8.1 12.8 7.9 12.8 7.8 12.4 7.8 12.2 7.7 12.1 7.8 11.9 8 11.8 8.4 11.7 8.8 11.5 9.2 11.4 10 11.2 10.9 11.1 11.7 11.2ZM16.3 5.9C17.3 5.9 18 6.6 18 7.6 18 8.5 17.3 9.3 16.3 9.3 15.4 9.3 14.7 8.5 14.7 7.6 14.7 6.6 15.4 5.9 16.3 5.9ZM8.3 5C9.2 5 9.9 5.8 9.9 6.7 9.9 7.7 9.2 8.4 8.2 8.4 7.3 8.4 6.6 7.7 6.6 6.7 6.6 5.8 7.3 5 8.3 5Z"/></g></g></svg>', 756 ], 757 [ 758 'id' => 'found-better-plugin', 759 'text' => $this->client->__trans( 'Found a better plugin' ), 760 'placeholder' => $this->client->__trans( 'Which plugin?' ), 746 761 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23"><g fill="none"><g fill="#3B86FF"><path d="M17.1 14L22.4 19.3C23.2 20.2 23.2 21.5 22.4 22.4 21.5 23.2 20.2 23.2 19.3 22.4L19.3 22.4 14 17.1C15.3 16.3 16.3 15.3 17.1 14L17.1 14ZM8.6 0C13.4 0 17.3 3.9 17.3 8.6 17.3 13.4 13.4 17.2 8.6 17.2 3.9 17.2 0 13.4 0 8.6 0 3.9 3.9 0 8.6 0ZM8.6 2.2C5.1 2.2 2.2 5.1 2.2 8.6 2.2 12.2 5.1 15.1 8.6 15.1 12.2 15.1 15.1 12.2 15.1 8.6 15.1 5.1 12.2 2.2 8.6 2.2ZM8.6 3.6L8.6 5C6.6 5 5 6.6 5 8.6L5 8.6 3.6 8.6C3.6 5.9 5.9 3.6 8.6 3.6L8.6 3.6Z"/></g></g></svg>', 747 ),748 array( 749 'id' => 'not-have-that-feature',750 'text' => $this->client->__trans( "Missing a specific feature"),751 'placeholder' => $this->client->__trans( 'Could you tell us more about that feature?' ),762 ], 763 [ 764 'id' => 'not-have-that-feature', 765 'text' => $this->client->__trans( 'Missing a specific feature' ), 766 'placeholder' => $this->client->__trans( 'Could you tell us more about that feature?' ), 752 767 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="17" viewBox="0 0 24 17"><g fill="none"><g fill="#3B86FF"><path d="M19.4 0C19.7 0.6 19.8 1.3 19.8 2 19.8 3.2 19.4 4.4 18.5 5.3 17.6 6.2 16.5 6.7 15.2 6.7 15.2 6.7 15.2 6.7 15.2 6.7 14 6.7 12.9 6.2 12 5.3 11.2 4.4 10.7 3.3 10.7 2 10.7 1.3 10.8 0.6 11.1 0L7.6 0 7 0 6.5 0 6.5 5.7C6.3 5.6 5.9 5.3 5.6 5.1 5 4.6 4.3 4.3 3.5 4.3 3.5 4.3 3.5 4.3 3.4 4.3 1.6 4.4 0 5.9 0 7.9 0 8.6 0.2 9.2 0.5 9.7 1.1 10.8 2.2 11.5 3.5 11.5 4.3 11.5 5 11.2 5.6 10.8 6 10.5 6.3 10.3 6.5 10.2L6.5 10.2 6.5 17 6.5 17 7 17 7.6 17 22.5 17C23.3 17 24 16.3 24 15.5L24 0 19.4 0Z"/></g></g></svg>', 753 ),754 array( 755 'id' => 'is-not-working',756 'text' => $this->client->__trans( 'Not working' ),757 'placeholder' => $this->client->__trans( 'Could you tell us a bit more whats not working?' ),768 ], 769 [ 770 'id' => 'is-not-working', 771 'text' => $this->client->__trans( 'Not working' ), 772 'placeholder' => $this->client->__trans( 'Could you tell us a bit more whats not working?' ), 758 773 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23"><g fill="none"><g fill="#3B86FF"><path d="M11.5 0C17.9 0 23 5.1 23 11.5 23 17.9 17.9 23 11.5 23 5.1 23 0 17.9 0 11.5 0 5.1 5.1 0 11.5 0ZM11.8 14.4C11.2 14.4 10.7 14.8 10.7 15.4 10.7 16 11.2 16.4 11.8 16.4 12.4 16.4 12.8 16 12.8 15.4 12.8 14.8 12.4 14.4 11.8 14.4ZM12 7C10.1 7 9.1 8.1 9 9.6L10.5 9.6C10.5 8.8 11.1 8.3 11.9 8.3 12.7 8.3 13.2 8.8 13.2 9.5 13.2 10.1 13 10.4 12.2 10.9 11.3 11.4 10.9 12 11 12.9L11 13.4 12.5 13.4 12.5 13C12.5 12.4 12.7 12.1 13.5 11.6 14.4 11.1 14.9 10.4 14.9 9.4 14.9 8 13.7 7 12 7Z"/></g></g></svg>', 759 ),760 array( 761 'id' => 'looking-for-other',762 'text' => $this->client->__trans( "Not what I was looking"),763 'placeholder' => $this->client->__trans( 'Could you tell us a bit more?' ),774 ], 775 [ 776 'id' => 'looking-for-other', 777 'text' => $this->client->__trans( 'Not what I was looking' ), 778 'placeholder' => $this->client->__trans( 'Could you tell us a bit more?' ), 764 779 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="17" viewBox="0 0 24 17"><g fill="none"><g fill="#3B86FF"><path d="M23.5 9C23.5 9 23.5 8.9 23.5 8.9 23.5 8.9 23.5 8.9 23.5 8.9 23.4 8.6 23.2 8.3 23 8 22.2 6.5 20.6 3.7 19.8 2.6 18.8 1.3 17.7 0 16.1 0 15.7 0 15.3 0.1 14.9 0.2 13.8 0.6 12.6 1.2 12.3 2.7L11.7 2.7C11.4 1.2 10.2 0.6 9.1 0.2 8.7 0.1 8.3 0 7.9 0 6.3 0 5.2 1.3 4.2 2.6 3.4 3.7 1.8 6.5 1 8 0.8 8.3 0.6 8.6 0.5 8.9 0.5 8.9 0.5 8.9 0.5 8.9 0.5 8.9 0.5 9 0.5 9 0.2 9.7 0 10.5 0 11.3 0 14.4 2.5 17 5.5 17 7.3 17 8.8 16.1 9.8 14.8L14.2 14.8C15.2 16.1 16.7 17 18.5 17 21.5 17 24 14.4 24 11.3 24 10.5 23.8 9.7 23.5 9ZM5.5 15C3.6 15 2 13.2 2 11 2 8.8 3.6 7 5.5 7 7.4 7 9 8.8 9 11 9 13.2 7.4 15 5.5 15ZM18.5 15C16.6 15 15 13.2 15 11 15 8.8 16.6 7 18.5 7 20.4 7 22 8.8 22 11 22 13.2 20.4 15 18.5 15Z"/></g></g></svg>', 765 ),766 array( 767 'id' => 'did-not-work-as-expected',768 'text' => $this->client->__trans( "Didn't work as expected" ),769 'placeholder' => $this->client->__trans( 'What did you expect?' ),780 ], 781 [ 782 'id' => 'did-not-work-as-expected', 783 'text' => $this->client->__trans( "Didn't work as expected" ), 784 'placeholder' => $this->client->__trans( 'What did you expect?' ), 770 785 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23"><g fill="none"><g fill="#3B86FF"><path d="M11.5 0C17.9 0 23 5.1 23 11.5 23 17.9 17.9 23 11.5 23 5.1 23 0 17.9 0 11.5 0 5.1 5.1 0 11.5 0ZM11.5 2C6.3 2 2 6.3 2 11.5 2 16.7 6.3 21 11.5 21 16.7 21 21 16.7 21 11.5 21 6.3 16.7 2 11.5 2ZM12.5 12.9L12.7 5 10.2 5 10.5 12.9 12.5 12.9ZM11.5 17.4C12.4 17.4 13 16.8 13 15.9 13 15 12.4 14.4 11.5 14.4 10.6 14.4 10 15 10 15.9 10 16.8 10.6 17.4 11.5 17.4Z"/></g></g></svg>', 771 ),772 array( 773 'id' => 'other',774 'text' => $this->client->__trans( 'Others' ),775 'placeholder' => $this->client->__trans( 'Could you tell us a bit more?' ),786 ], 787 [ 788 'id' => 'other', 789 'text' => $this->client->__trans( 'Others' ), 790 'placeholder' => $this->client->__trans( 'Could you tell us a bit more?' ), 776 791 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="23" viewBox="0 0 24 6"><g fill="none"><g fill="#3B86FF"><path d="M3 0C4.7 0 6 1.3 6 3 6 4.7 4.7 6 3 6 1.3 6 0 4.7 0 3 0 1.3 1.3 0 3 0ZM12 0C13.7 0 15 1.3 15 3 15 4.7 13.7 6 12 6 10.3 6 9 4.7 9 3 9 1.3 10.3 0 12 0ZM21 0C22.7 0 24 1.3 24 3 24 4.7 22.7 6 21 6 19.3 6 18 4.7 18 3 18 1.3 19.3 0 21 0Z"/></g></g></svg>', 777 ),778 );792 ], 793 ]; 779 794 780 795 return $reasons; … … 787 802 */ 788 803 public function uninstall_reason_submission() { 804 if ( ! isset( $_POST['nonce'] ) ) { 805 return; 806 } 789 807 790 808 if ( ! isset( $_POST['reason_id'] ) ) { … … 792 810 } 793 811 794 if ( ! wp_verify_nonce( sanitize_ text_field($_POST['nonce']), 'appsero-security-nonce' ) ) {812 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'appsero-security-nonce' ) ) { 795 813 wp_send_json_error( 'Nonce verification failed' ); 796 814 } … … 800 818 } 801 819 802 $data = $this->get_tracking_data(); 803 $data['reason_id'] = sanitize_text_field( $_POST['reason_id'] ); 804 $data['reason_info'] = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( sanitize_text_field($_REQUEST['reason_info']) ) ) : ''; 820 $data['reason_id'] = sanitize_text_field( wp_unslash( $_POST['reason_id'] ) ); 821 $data['reason_info'] = isset( $_REQUEST['reason_info'] ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['reason_info'] ) ) ) : ''; 805 822 806 823 $this->client->send_request( $data, 'deactivate' ); 807 824 808 /* *809 * Fire after the plugin _uninstall_reason_submitted 825 /* 826 * Fire after the plugin _uninstall_reason_submitted 810 827 */ 811 828 do_action( $this->client->slug . '_uninstall_reason_submitted', $data ); … … 822 839 global $pagenow; 823 840 824 if ( 'plugins.php' != $pagenow ) {841 if ( 'plugins.php' !== $pagenow ) { 825 842 return; 826 843 } 827 844 828 845 $this->deactivation_modal_styles(); 829 $reasons = $this->get_uninstall_reasons();830 $custom_reasons = apply_filters( 'appsero_custom_deactivation_reasons', array());846 $reasons = $this->get_uninstall_reasons(); 847 $custom_reasons = apply_filters( 'appsero_custom_deactivation_reasons', [], $this->client ); 831 848 ?> 832 849 … … 849 866 <?php } ?> 850 867 </ul> 851 <?php if ( $custom_reasons && is_array( $custom_reasons ) ) :?>868 <?php if ( $custom_reasons && is_array( $custom_reasons ) ) { ?> 852 869 <ul class="wd-de-reasons wd-de-others-reasons"> 853 870 <?php foreach ( $custom_reasons as $reason ) { ?> … … 861 878 <?php } ?> 862 879 </ul> 863 <?php endif;?>880 <?php } ?> 864 881 <div class="wd-dr-modal-reason-input"><textarea></textarea></div> 865 882 <p class="wd-dr-modal-reasons-bottom"> 866 <?php867 echo sprintf(868 $this->client->__trans( 'We share your data with <a href="%1$s" target="_blank">Appsero</a> to troubleshoot problems & make product improvements. <a href="%2$s" target="_blank">Learn more</a> about how Appsero handles your data.'),869 esc_url( 'https://appsero.com/' ),870 esc_url( 'https://appsero.com/privacy-policy' )871 );872 ?>883 <?php 884 echo sprintf( 885 $this->client->__trans( 'We share your data with <a href="%1$s" target="_blank">Appsero</a> to troubleshoot problems & make product improvements. <a href="%2$s" target="_blank">Learn more</a> about how Appsero handles your data.' ), 886 esc_url( 'https://appsero.com/' ), 887 esc_url( 'https://appsero.com/privacy-policy' ) 888 ); 889 ?> 873 890 </p> 874 891 </div> 875 892 876 893 <div class="wd-dr-modal-footer"> 877 <a href="#" class="dont-bother-me wd-dr-button-secondary"><?php $this->client->_etrans( "Skip & Deactivate"); ?></a>894 <a href="#" class="dont-bother-me wd-dr-button-secondary"><?php $this->client->_etrans( 'Skip & Deactivate' ); ?></a> 878 895 <button class="wd-dr-button-secondary wd-dr-cancel-modal"><?php $this->client->_etrans( 'Cancel' ); ?></button> 879 896 <button class="wd-dr-submit-modal"><?php $this->client->_etrans( 'Submit & Deactivate' ); ?></button> … … 970 987 /** 971 988 * Run after theme deactivated 972 * @param string $new_name 973 * @param object $new_theme 974 * @param object $old_theme 989 * 990 * @param string $new_name 991 * @param object $new_theme 992 * @param object $old_theme 993 * 975 994 * @return void 976 995 */ 977 996 public function theme_deactivated( $new_name, $new_theme, $old_theme ) { 978 997 // Make sure this is appsero theme 979 if ( $old_theme->get_template() == $this->client->slug ) {998 if ( $old_theme->get_template() === $this->client->slug ) { 980 999 $this->client->send_request( $this->get_tracking_data(), 'deactivate' ); 981 1000 } … … 1025 1044 $skipped = get_option( $this->client->slug . '_tracking_skipped' ); 1026 1045 1027 $data = array(1046 $data = [ 1028 1047 'hash' => $this->client->hash, 1029 1048 'previously_skipped' => false, 1030 );1049 ]; 1031 1050 1032 1051 if ( $skipped === 'yes' ) { … … 1200 1219 <?php 1201 1220 } 1202 1203 1221 } -
advance-faq-block/trunk/inc/appsero/src/License.php
r2886650 r2899060 2 2 3 3 namespace Appsero; 4 4 5 5 /** 6 6 * Appsero License Checker … … 8 8 * This class will check, active and deactive license 9 9 */ 10 class License 11 { 10 class License { 12 11 13 12 /** … … 65 64 * @param Appsero\Client 66 65 */ 67 public function __construct(Client $client) 68 { 66 public function __construct( Client $client ) { 69 67 $this->client = $client; 70 68 71 $this->option_key = 'appsero_' . md5( $this->client->slug) . '_manage_license';69 $this->option_key = 'appsero_' . md5( $this->client->slug ) . '_manage_license'; 72 70 73 71 $this->schedule_hook = $this->client->slug . '_license_check_event'; 74 72 75 73 // Creating WP Ajax Endpoint to refresh license remotely 76 add_action( "wp_ajax_appsero_refresh_license_" . $this->client->hash, array($this, 'refresh_license_api'));74 add_action( 'wp_ajax_appsero_refresh_license_' . $this->client->hash, [ $this, 'refresh_license_api' ] ); 77 75 78 76 // Run hook to check license status daily 79 add_action( $this->schedule_hook, array($this, 'check_license_status'));77 add_action( $this->schedule_hook, [ $this, 'check_license_status' ] ); 80 78 81 79 // Active/Deactive corn schedule … … 94 92 * @return License 95 93 */ 96 public function set_option_key($key) 97 { 94 public function set_option_key( $key ) { 98 95 $this->option_key = $key; 99 96 … … 108 105 * @return string|null 109 106 */ 110 public function get_license() 111 { 112 return get_option($this->option_key, null); 107 public function get_license() { 108 return get_option( $this->option_key, null ); 113 109 } 114 110 … … 118 114 * @return bool 119 115 */ 120 public function check($license_key) 121 { 122 $route = 'public/license/' . $this->client->hash . '/check'; 123 124 return $this->send_request($license_key, $route); 116 public function check( $license_key ) { 117 $route = 'public/license/' . $this->client->hash . '/check'; 118 119 return $this->send_request( $license_key, $route ); 125 120 } 126 121 … … 130 125 * @return bool 131 126 */ 132 public function activate($license_key) 133 { 134 $route = 'public/license/' . $this->client->hash . '/activate'; 135 136 return $this->send_request($license_key, $route); 127 public function activate( $license_key ) { 128 $route = 'public/license/' . $this->client->hash . '/activate'; 129 130 return $this->send_request( $license_key, $route ); 137 131 } 138 132 … … 142 136 * @return bool 143 137 */ 144 public function deactivate($license_key) 145 { 146 $route = 'public/license/' . $this->client->hash . '/deactivate'; 147 148 return $this->send_request($license_key, $route); 138 public function deactivate( $license_key ) { 139 $route = 'public/license/' . $this->client->hash . '/deactivate'; 140 141 return $this->send_request( $license_key, $route ); 149 142 } 150 143 … … 152 145 * Send common request 153 146 * 154 * @param $license_key155 * @param $route156 *157 147 * @return array 158 148 */ 159 protected function send_request($license_key, $route) 160 { 161 $params = array( 149 protected function send_request( $license_key, $route ) { 150 $params = [ 162 151 'license_key' => $license_key, 163 'url' => esc_url( home_url()),152 'url' => esc_url( home_url() ), 164 153 'is_local' => $this->client->is_local_server(), 165 );166 167 $response = $this->client->send_request( $params, $route, true);168 169 if ( is_wp_error($response)) {170 return array(154 ]; 155 156 $response = $this->client->send_request( $params, $route, true ); 157 158 if ( is_wp_error( $response ) ) { 159 return [ 171 160 'success' => false, 172 'error' => $response->get_error_message() 173 );174 } 175 176 $response = json_decode( wp_remote_retrieve_body($response), true);177 178 if ( empty($response) || isset($response['exception'])) {179 return array(161 'error' => $response->get_error_message(), 162 ]; 163 } 164 165 $response = json_decode( wp_remote_retrieve_body( $response ), true ); 166 167 if ( empty( $response ) || isset( $response['exception'] ) ) { 168 return [ 180 169 'success' => false, 181 'error' => $this->client->__trans( 'Unknown error occurred, Please try again.'),182 );183 } 184 185 if ( isset($response['errors']) && isset($response['errors']['license_key'])) {186 $response = array(170 'error' => $this->client->__trans( 'Unknown error occurred, Please try again.' ), 171 ]; 172 } 173 174 if ( isset( $response['errors'] ) && isset( $response['errors']['license_key'] ) ) { 175 $response = [ 187 176 'success' => false, 188 'error' => $response['errors']['license_key'][0] 189 );177 'error' => $response['errors']['license_key'][0], 178 ]; 190 179 } 191 180 … … 196 185 * License Refresh Endpoint 197 186 */ 198 public function refresh_license_api() 199 { 187 public function refresh_license_api() { 200 188 $this->check_license_status(); 201 189 202 190 return wp_send_json( 203 array(204 'message' => 'License refreshed successfully.' 205 ),191 [ 192 'message' => 'License refreshed successfully.', 193 ], 206 194 200 207 195 ); … … 215 203 * @return void 216 204 */ 217 public function add_settings_page($args = array()) 218 { 219 $defaults = array( 205 public function add_settings_page( $args = [] ) { 206 $defaults = [ 220 207 'type' => 'menu', // Can be: menu, options, submenu 221 208 'page_title' => 'Manage License', … … 226 213 'position' => null, 227 214 'parent_slug' => '', 228 );229 230 $this->menu_args = wp_parse_args( $args, $defaults);231 232 add_action( 'admin_menu', array($this, 'admin_menu'), 99);215 ]; 216 217 $this->menu_args = wp_parse_args( $args, $defaults ); 218 219 add_action( 'admin_menu', [ $this, 'admin_menu' ], 99 ); 233 220 } 234 221 … … 238 225 * @return void 239 226 */ 240 public function admin_menu() 241 { 242 switch ($this->menu_args['type']) { 227 public function admin_menu() { 228 switch ( $this->menu_args['type'] ) { 243 229 case 'menu': 244 230 $this->create_menu_page(); … … 258 244 * License menu output 259 245 */ 260 public function menu_output() 261 { 262 if (isset($_POST['submit'])) { 263 $this->license_form_submit($_POST); 264 } 246 public function menu_output() { 247 // process form data is submitted 248 $this->license_form_submit(); 265 249 266 250 $license = $this->get_license(); 267 $action = ( $license && isset($license['status']) && 'activate' == sanitize_text_field($license['status'])) ? 'deactive' : 'active';251 $action = ( $license && isset( $license['status'] ) && 'activate' === $license['status'] ) ? 'deactive' : 'active'; 268 252 $this->licenses_style(); 269 ?>253 ?> 270 254 271 255 <div class="wrap appsero-license-settings-wrapper"> … … 273 257 274 258 <?php 275 $this->show_license_page_notices();276 do_action('before_appsero_license_section');259 $this->show_license_page_notices(); 260 do_action( 'before_appsero_license_section' ); 277 261 ?> 278 262 279 263 <div class="appsero-license-settings appsero-license-section"> 280 <?php $this->show_license_page_card_header( $license); ?>264 <?php $this->show_license_page_card_header( $license ); ?> 281 265 282 266 <div class="appsero-license-details"> 283 267 <p> 284 <?php printf( $this->client->__trans('Activate <strong>%s</strong> by your license key to get professional support and automatic update from your WordPress dashboard.'), $this->client->name); ?>268 <?php printf( $this->client->__trans( 'Activate <strong>%s</strong> by your license key to get professional support and automatic update from your WordPress dashboard.' ), $this->client->name ); ?> 285 269 </p> 286 <form method="post" action="<?php $this->form_action_url(); ?>"novalidate="novalidate" spellcheck="false">270 <form method="post" novalidate="novalidate" spellcheck="false"> 287 271 <input type="hidden" name="_action" value="<?php echo $action; ?>"> 288 <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name); ?>">272 <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>"> 289 273 <div class="license-input-fields"> 290 274 <div class="license-input-key"> 291 275 <svg enable-background="new 0 0 512 512" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> 292 <path d="m463.75 48.251c-64.336-64.336-169.01-64.335-233.35 1e-3 -43.945 43.945-59.209 108.71-40.181 167.46l-185.82 185.82c-2.813 2.813-4.395 6.621-4.395 10.606v84.858c0 8.291 6.709 15 15 15h84.858c3.984 0 7.793-1.582 10.605-4.395l21.211-21.226c3.237-3.237 4.819-7.778 4.292-12.334l-2.637-22.793 31.582-2.974c7.178-0.674 12.847-6.343 13.521-13.521l2.974-31.582 22.793 2.651c4.233 0.571 8.496-0.85 11.704-3.691 3.193-2.856 5.024-6.929 5.024-11.206v-27.929h27.422c3.984 0 7.793-1.582 10.605-4.395l38.467-37.958c58.74 19.043 122.38 4.929 166.33-39.046 64.336-64.335 64.336-169.01 0-233.35zm-42.435 106.07c-17.549 17.549-46.084 17.549-63.633 0s-17.549-46.084 0-63.633 46.084-17.549 63.633 0 17.548 46.084 0 63.633z" />276 <path d="m463.75 48.251c-64.336-64.336-169.01-64.335-233.35 1e-3 -43.945 43.945-59.209 108.71-40.181 167.46l-185.82 185.82c-2.813 2.813-4.395 6.621-4.395 10.606v84.858c0 8.291 6.709 15 15 15h84.858c3.984 0 7.793-1.582 10.605-4.395l21.211-21.226c3.237-3.237 4.819-7.778 4.292-12.334l-2.637-22.793 31.582-2.974c7.178-0.674 12.847-6.343 13.521-13.521l2.974-31.582 22.793 2.651c4.233 0.571 8.496-0.85 11.704-3.691 3.193-2.856 5.024-6.929 5.024-11.206v-27.929h27.422c3.984 0 7.793-1.582 10.605-4.395l38.467-37.958c58.74 19.043 122.38 4.929 166.33-39.046 64.336-64.335 64.336-169.01 0-233.35zm-42.435 106.07c-17.549 17.549-46.084 17.549-63.633 0s-17.549-46.084 0-63.633 46.084-17.549 63.633 0 17.548 46.084 0 63.633z"/> 293 277 </svg> 294 <input type="text" value="<?php echo $this->get_input_license_value($action, $license); ?>" placeholder="<?php echo esc_attr($this->client->__trans('Enter your license key to activate')); ?>" name="license_key" <?php echo ('deactive' == $action) ? 'readonly="readonly"' : ''; ?> /> 278 <input type="text" value="<?php echo $this->get_input_license_value( $action, $license ); ?>" 279 placeholder="<?php echo esc_attr( $this->client->__trans( 'Enter your license key to activate' ) ); ?>" name="license_key" 280 <?php echo ( 'deactive' === $action ) ? 'readonly="readonly"' : ''; ?> 281 /> 295 282 </div> 296 <button type="submit" name="submit" class="<?php echo 'deactive' == $action ? 'deactive-button' : ''; ?>">297 <?php echo $action == 'active' ? $this->client->__trans('Activate License') : $this->client->__trans('Deactivate License'); ?>283 <button type="submit" name="submit" class="<?php echo 'deactive' === $action ? 'deactive-button' : ''; ?>"> 284 <?php echo $action === 'active' ? $this->client->__trans( 'Activate License' ) : $this->client->__trans( 'Deactivate License' ); ?> 298 285 </button> 299 286 </div> … … 301 288 302 289 <?php 303 if ('deactive' == $action && isset($license['remaining'])) { 304 $this->show_active_license_info($license); 305 } ?> 290 if ( 'deactive' === $action && isset( $license['remaining'] ) ) { 291 $this->show_active_license_info( $license ); 292 } 293 ?> 306 294 </div> 307 295 </div> <!-- /.appsero-license-settings --> 308 296 309 <?php do_action( 'after_appsero_license_section'); ?>297 <?php do_action( 'after_appsero_license_section' ); ?> 310 298 </div> 311 <?php299 <?php 312 300 } 313 301 … … 315 303 * License form submit 316 304 */ 317 public function license_form_submit($form) 318 { 319 if (!isset($form['_nonce'], $form['_action'])) { 320 $this->error = $this->client->__trans('Please add all information'); 321 305 public function license_form_submit() { 306 if ( ! isset( $_POST['_nonce'] ) ) { 322 307 return; 323 308 } 324 309 325 if ( !wp_verify_nonce(sanitize_text_field($form['_nonce']), $this->client->name)) {326 $this->error = $this->client->__trans( "You don't have permission to manage license.");310 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_nonce'] ) ), $this->client->name ) ) { 311 $this->error = $this->client->__trans( 'Nonce vefification failed.' ); 327 312 328 313 return; 329 314 } 330 315 331 switch (sanitize_text_field($form['_action'])) { 316 if ( ! current_user_can( 'manage_options' ) ) { 317 $this->error = $this->client->__trans( 'You don\'t have permission to manage license.' ); 318 319 return; 320 } 321 322 $license_key = isset( $_POST['license_key'] ) ? sanitize_text_field( wp_unslash( $_POST['license_key'] ) ) : ''; 323 $action = isset( $_POST['_action'] ) ? sanitize_text_field( wp_unslash( $_POST['_action'] ) ) : ''; 324 325 switch ( $action ) { 332 326 case 'active': 333 $this->active_client_license( $form);327 $this->active_client_license( $license_key ); 334 328 break; 335 329 336 330 case 'deactive': 337 $this->deactive_client_license( $form);331 $this->deactive_client_license(); 338 332 break; 339 333 340 334 case 'refresh': 341 $this->refresh_client_license( $form);335 $this->refresh_client_license(); 342 336 break; 343 337 } … … 347 341 * Check license status on schedule 348 342 */ 349 public function check_license_status() 350 { 343 public function check_license_status() { 351 344 $license = $this->get_license(); 352 345 353 if ( isset($license['key']) && !empty($license['key'])) {354 $response = $this->check( $license['key']);355 356 if ( isset($response['success']) && $response['success']) {346 if ( isset( $license['key'] ) && ! empty( $license['key'] ) ) { 347 $response = $this->check( $license['key'] ); 348 349 if ( isset( $response['success'] ) && $response['success'] ) { 357 350 $license['status'] = 'activate'; 358 351 $license['remaining'] = $response['remaining']; … … 367 360 } 368 361 369 update_option( $this->option_key, $license, false);362 update_option( $this->option_key, $license, false ); 370 363 } 371 364 } … … 374 367 * Check this is a valid license 375 368 */ 376 public function is_valid() 377 { 378 if (null !== $this->is_valid_license) { 369 public function is_valid() { 370 if ( null !== $this->is_valid_license ) { 379 371 return $this->is_valid_license; 380 372 } … … 382 374 $license = $this->get_license(); 383 375 384 if ( !empty($license['key']) && isset($license['status']) && $license['status'] == 'activate') {376 if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] === 'activate' ) { 385 377 $this->is_valid_license = true; 386 378 } else { … … 394 386 * Check this is a valid license 395 387 */ 396 public function is_valid_by($option, $value) 397 { 388 public function is_valid_by( $option, $value ) { 398 389 $license = $this->get_license(); 399 390 400 if ( !empty($license['key']) && isset($license['status']) && $license['status'] == 'activate') {401 if ( isset($license[$option]) && $license[$option] == $value) {391 if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] === 'activate' ) { 392 if ( isset( $license[ $option ] ) && $license[ $option ] === $value ) { 402 393 return true; 403 394 } … … 410 401 * Styles for licenses page 411 402 */ 412 private function licenses_style() 413 { 414 ?> 403 private function licenses_style() { 404 ?> 415 405 <style type="text/css"> 416 406 .appsero-license-section { … … 420 410 box-sizing: border-box; 421 411 } 422 423 412 .appsero-license-settings { 424 413 background-color: #fff; 425 414 box-shadow: 0px 3px 10px rgba(16, 16, 16, 0.05); 426 415 } 427 428 416 .appsero-license-settings * { 429 417 box-sizing: border-box; 430 418 } 431 432 419 .appsero-license-title { 433 420 background-color: #F8FAFB; … … 437 424 padding: 10px 20px; 438 425 } 439 440 426 .appsero-license-title svg { 441 427 width: 30px; … … 443 429 fill: #0082BF; 444 430 } 445 446 431 .appsero-license-title span { 447 432 font-size: 17px; … … 449 434 margin-left: 10px; 450 435 } 451 452 436 .appsero-license-details { 453 437 padding: 20px; 454 438 } 455 456 439 .appsero-license-details p { 457 440 font-size: 15px; 458 441 margin: 0 0 20px 0; 459 442 } 460 461 443 .license-input-key { 462 444 position: relative; … … 464 446 max-width: 72%; 465 447 } 466 467 448 .license-input-key input { 468 449 background-color: #F9F9F9; … … 476 457 box-shadow: 0 0 0 transparent; 477 458 } 478 479 459 .license-input-key input:focus { 480 460 outline: 0 none; … … 482 462 box-shadow: 0 0 0 transparent; 483 463 } 484 485 464 .license-input-key svg { 486 465 width: 22px; … … 491 470 top: 13px; 492 471 } 493 494 472 .license-input-fields { 495 473 display: flex; … … 499 477 width: 100%; 500 478 } 501 502 479 .license-input-fields button { 503 480 color: #fff; … … 512 489 border: 1px solid #0082BF; 513 490 } 514 515 491 .license-input-fields button.deactive-button { 516 492 background-color: #E40055; 517 493 border-color: #E40055; 518 494 } 519 520 495 .license-input-fields button:focus { 521 496 outline: 0 none; 522 497 } 523 524 498 .active-license-info { 525 499 display: flex; 526 500 } 527 528 501 .single-license-info { 529 502 min-width: 220px; 530 503 flex: 0 0 30%; 531 504 } 532 533 505 .single-license-info h3 { 534 506 font-size: 18px; 535 507 margin: 0 0 12px 0; 536 508 } 537 538 509 .single-license-info p { 539 510 margin: 0; 540 511 color: #00C000; 541 512 } 542 543 513 .single-license-info p.occupied { 544 514 color: #E40055; 545 515 } 546 547 516 .appsero-license-right-form { 548 517 margin-left: auto; 549 518 } 550 551 519 .appsero-license-refresh-button { 552 520 padding: 6px 10px 4px 10px; … … 558 526 cursor: pointer; 559 527 } 560 561 528 .appsero-license-refresh-button .dashicons { 562 529 color: #fff; … … 564 531 } 565 532 </style> 566 <?php533 <?php 567 534 } 568 535 … … 570 537 * Show active license information 571 538 */ 572 private function show_active_license_info($license) 573 { 574 ?> 539 private function show_active_license_info( $license ) { 540 ?> 575 541 <div class="active-license-info"> 576 542 <div class="single-license-info"> 577 <h3><?php $this->client->_etrans( 'Activations Remaining'); ?></h3>578 <?php if ( empty($license['activation_limit'])) { ?>579 <p><?php $this->client->_etrans( 'Unlimited'); ?></p>543 <h3><?php $this->client->_etrans( 'Activations Remaining' ); ?></h3> 544 <?php if ( empty( $license['activation_limit'] ) ) { ?> 545 <p><?php $this->client->_etrans( 'Unlimited' ); ?></p> 580 546 <?php } else { ?> 581 547 <p class="<?php echo $license['remaining'] ? '' : 'occupied'; ?>"> 582 <?php printf( $this->client->__trans('%1$d out of %2$d'), $license['remaining'], $license['activation_limit']); ?>548 <?php printf( $this->client->__trans( '%1$d out of %2$d' ), $license['remaining'], $license['activation_limit'] ); ?> 583 549 </p> 584 550 <?php } ?> 585 551 </div> 586 552 <div class="single-license-info"> 587 <h3><?php $this->client->_etrans( 'Expires in'); ?></h3>553 <h3><?php $this->client->_etrans( 'Expires in' ); ?></h3> 588 554 <?php 589 if ( false !== $license['expiry_days']) {555 if ( false !== $license['expiry_days'] ) { 590 556 $occupied = $license['expiry_days'] > 21 ? '' : 'occupied'; 591 557 echo '<p class="' . $occupied . '">' . $license['expiry_days'] . ' days</p>'; 592 558 } else { 593 echo '<p>' . $this->client->__trans('Never') . '</p>'; 594 } ?> 559 echo '<p>' . $this->client->__trans( 'Never' ) . '</p>'; 560 } 561 ?> 595 562 </div> 596 563 </div> … … 601 568 * Show license settings page notices 602 569 */ 603 private function show_license_page_notices() 604 { 605 if (!empty($this->error)) { 606 ?> 570 private function show_license_page_notices() { 571 if ( ! empty( $this->error ) ) { 572 ?> 607 573 <div class="notice notice-error is-dismissible appsero-license-section"> 608 574 <p><?php echo $this->error; ?></p> 609 575 </div> 610 <?php611 } 612 613 if ( !empty($this->success)) {614 ?>576 <?php 577 } 578 579 if ( ! empty( $this->success ) ) { 580 ?> 615 581 <div class="notice notice-success is-dismissible appsero-license-section"> 616 582 <p><?php echo $this->success; ?></p> 617 583 </div> 618 <?php584 <?php 619 585 } 620 586 echo '<br />'; … … 624 590 * Card header 625 591 */ 626 private function show_license_page_card_header($license) 627 { 592 private function show_license_page_card_header( $license ) { 628 593 ?> 629 594 <div class="appsero-license-title"> 630 595 <svg enable-background="new 0 0 299.995 299.995" version="1.1" viewBox="0 0 300 300" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> 631 <path d="m150 161.48c-8.613 0-15.598 6.982-15.598 15.598 0 5.776 3.149 10.807 7.817 13.505v17.341h15.562v-17.341c4.668-2.697 7.817-7.729 7.817-13.505 0-8.616-6.984-15.598-15.598-15.598z" />632 <path d="m150 85.849c-13.111 0-23.775 10.665-23.775 23.775v25.319h47.548v-25.319c-1e-3 -13.108-10.665-23.775-23.773-23.775z" />633 <path d="m150 1e-3c-82.839 0-150 67.158-150 150 0 82.837 67.156 150 150 150s150-67.161 150-150c0-82.839-67.161-150-150-150zm46.09 227.12h-92.173c-9.734 0-17.626-7.892-17.626-17.629v-56.919c0-8.491 6.007-15.582 14.003-17.25v-25.697c0-27.409 22.3-49.711 49.711-49.711 27.409 0 49.709 22.3 49.709 49.711v25.697c7.993 1.673 14 8.759 14 17.25v56.919h2e-3c0 9.736-7.892 17.629-17.626 17.629z" />596 <path d="m150 161.48c-8.613 0-15.598 6.982-15.598 15.598 0 5.776 3.149 10.807 7.817 13.505v17.341h15.562v-17.341c4.668-2.697 7.817-7.729 7.817-13.505 0-8.616-6.984-15.598-15.598-15.598z"/> 597 <path d="m150 85.849c-13.111 0-23.775 10.665-23.775 23.775v25.319h47.548v-25.319c-1e-3 -13.108-10.665-23.775-23.773-23.775z"/> 598 <path d="m150 1e-3c-82.839 0-150 67.158-150 150 0 82.837 67.156 150 150 150s150-67.161 150-150c0-82.839-67.161-150-150-150zm46.09 227.12h-92.173c-9.734 0-17.626-7.892-17.626-17.629v-56.919c0-8.491 6.007-15.582 14.003-17.25v-25.697c0-27.409 22.3-49.711 49.711-49.711 27.409 0 49.709 22.3 49.709 49.711v25.697c7.993 1.673 14 8.759 14 17.25v56.919h2e-3c0 9.736-7.892 17.629-17.626 17.629z"/> 634 599 </svg> 635 <span><?php echo $this->client->__trans( 'Activate License'); ?></span>636 637 <?php if ( $license && $license['key']) :?>638 <form method="post" class="appsero-license-right-form" action="<?php $this->form_action_url(); ?>" novalidate="novalidate" spellcheck="false">639 <input type="hidden" name="_action" value="refresh">640 <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce($this->client->name); ?>">641 <button type="submit" name="submit" class="appsero-license-refresh-button">642 <span class="dashicons dashicons-update"></span>643 <?php echo $this->client->__trans('Refresh License'); ?>644 </button>645 </form>646 <?php endif;?>600 <span><?php echo $this->client->__trans( 'Activate License' ); ?></span> 601 602 <?php if ( $license && $license['key'] ) { ?> 603 <form method="post" class="appsero-license-right-form" novalidate="novalidate" spellcheck="false"> 604 <input type="hidden" name="_action" value="refresh"> 605 <input type="hidden" name="_appsero_license_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>"> 606 <button type="submit" name="submit" class="appsero-license-refresh-button"> 607 <span class="dashicons dashicons-update"></span> 608 <?php echo $this->client->__trans( 'Refresh License' ); ?> 609 </button> 610 </form> 611 <?php } ?> 647 612 648 613 </div> 649 <?php614 <?php 650 615 } 651 616 … … 653 618 * Active client license 654 619 */ 655 private function active_client_license($form) 656 { 657 if (empty($form['license_key'])) { 658 $this->error = $this->client->__trans('The license key field is required.'); 620 private function active_client_license( $license_key ) { 621 if ( empty( $license_key ) ) { 622 $this->error = $this->client->__trans( 'The license key field is required.' ); 659 623 660 624 return; 661 625 } 662 626 663 $license_key = sanitize_text_field($form['license_key']); 664 $response = $this->activate($license_key); 665 666 if (!$response['success']) { 667 $this->error = $response['error'] ? $response['error'] : $this->client->__trans('Unknown error occurred.'); 627 $response = $this->activate( $license_key ); 628 629 if ( ! $response['success'] ) { 630 $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.' ); 668 631 669 632 return; 670 633 } 671 634 672 $data = array(635 $data = [ 673 636 'key' => $license_key, 674 637 'status' => 'activate', … … 679 642 'source_id' => $response['source_identifier'], 680 643 'recurring' => $response['recurring'], 681 ); 682 683 update_option($this->option_key, $data, false); 684 685 /** 686 * Fires after license activated 687 */ 688 do_action($this->client->slug . '_license_activated', $response); 689 690 $this->success = $this->client->__trans('License activated successfully.'); 644 ]; 645 646 update_option( $this->option_key, $data, false ); 647 648 $this->success = $this->client->__trans( 'License activated successfully.' ); 691 649 } 692 650 … … 694 652 * Deactive client license 695 653 */ 696 private function deactive_client_license($form) 697 { 654 private function deactive_client_license() { 698 655 $license = $this->get_license(); 699 656 700 if ( empty($license['key'])) {701 $this->error = $this->client->__trans( 'License key not found.');657 if ( empty( $license['key'] ) ) { 658 $this->error = $this->client->__trans( 'License key not found.' ); 702 659 703 660 return; 704 661 } 705 662 706 $response = $this->deactivate( sanitize_text_field($license['key']));707 708 $data = array(663 $response = $this->deactivate( $license['key'] ); 664 665 $data = [ 709 666 'key' => '', 710 667 'status' => 'deactivate', 711 );712 713 update_option( $this->option_key, $data, false);714 715 if ( !$response['success']) {716 $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.');668 ]; 669 670 update_option( $this->option_key, $data, false ); 671 672 if ( ! $response['success'] ) { 673 $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.' ); 717 674 718 675 return; 719 676 } 720 677 721 /** 722 * Fires after license deactivated 723 */ 724 do_action($this->client->slug . '_license_deactivated', $response); 725 726 $this->success = $this->client->__trans('License deactivated successfully.'); 678 $this->success = $this->client->__trans( 'License deactivated successfully.' ); 727 679 } 728 680 … … 730 682 * Refresh Client License 731 683 */ 732 private function refresh_client_license($form = null) 733 { 684 private function refresh_client_license() { 734 685 $license = $this->get_license(); 735 686 736 if (!$license || !isset($license['key']) || empty($license['key'])) { 737 $this->error = $this->client->__trans("License key not found"); 687 if ( ! $license || ! isset( $license['key'] ) || empty( $license['key'] ) ) { 688 $this->error = $this->client->__trans( 'License key not found' ); 689 738 690 return; 739 691 } … … 741 693 $this->check_license_status(); 742 694 743 /** 744 * Fires after license refreshed 745 */ 746 do_action($this->client->slug . '_license_refreshed'); 747 748 $this->success = $this->client->__trans('License refreshed successfully.'); 695 $this->success = $this->client->__trans( 'License refreshed successfully.' ); 749 696 } 750 697 … … 752 699 * Add license menu page 753 700 */ 754 private function create_menu_page() 755 { 701 private function create_menu_page() { 756 702 call_user_func( 757 'add_ ' . 'menu' . '_page',703 'add_menu_page', 758 704 $this->menu_args['page_title'], 759 705 $this->menu_args['menu_title'], 760 706 $this->menu_args['capability'], 761 707 $this->menu_args['menu_slug'], 762 array($this, 'menu_output'),708 [ $this, 'menu_output' ], 763 709 $this->menu_args['icon_url'], 764 710 $this->menu_args['position'] … … 769 715 * Add submenu page 770 716 */ 771 private function create_submenu_page() 772 { 717 private function create_submenu_page() { 773 718 call_user_func( 774 'add_ ' . 'submenu' . '_page',719 'add_submenu_page', 775 720 $this->menu_args['parent_slug'], 776 721 $this->menu_args['page_title'], … … 778 723 $this->menu_args['capability'], 779 724 $this->menu_args['menu_slug'], 780 array($this, 'menu_output'),725 [ $this, 'menu_output' ], 781 726 $this->menu_args['position'] 782 727 ); … … 786 731 * Add submenu page 787 732 */ 788 private function create_options_page() 789 { 733 private function create_options_page() { 790 734 call_user_func( 791 'add_ ' . 'options' . '_page',735 'add_options_page', 792 736 $this->menu_args['page_title'], 793 737 $this->menu_args['menu_title'], 794 738 $this->menu_args['capability'], 795 739 $this->menu_args['menu_slug'], 796 array($this, 'menu_output'),740 [ $this, 'menu_output' ], 797 741 $this->menu_args['position'] 798 742 ); … … 802 746 * Schedule daily sicense checker event 803 747 */ 804 public function schedule_cron_event() 805 { 806 if (!wp_next_scheduled($this->schedule_hook)) { 807 wp_schedule_event(time(), 'daily', $this->schedule_hook); 808 809 wp_schedule_single_event(time() + 20, $this->schedule_hook); 748 public function schedule_cron_event() { 749 if ( ! wp_next_scheduled( $this->schedule_hook ) ) { 750 wp_schedule_event( time(), 'daily', $this->schedule_hook ); 751 752 wp_schedule_single_event( time() + 20, $this->schedule_hook ); 810 753 } 811 754 } … … 814 757 * Clear any scheduled hook 815 758 */ 816 public function clear_scheduler() 817 { 818 wp_clear_scheduled_hook($this->schedule_hook); 759 public function clear_scheduler() { 760 wp_clear_scheduled_hook( $this->schedule_hook ); 819 761 } 820 762 … … 822 764 * Enable/Disable schedule 823 765 */ 824 private function run_schedule() 825 { 826 switch ($this->client->type) { 766 private function run_schedule() { 767 switch ( $this->client->type ) { 827 768 case 'plugin': 828 register_activation_hook( $this->client->file, array($this, 'schedule_cron_event'));829 register_deactivation_hook( $this->client->file, array($this, 'clear_scheduler'));769 register_activation_hook( $this->client->file, [ $this, 'schedule_cron_event' ] ); 770 register_deactivation_hook( $this->client->file, [ $this, 'clear_scheduler' ] ); 830 771 break; 831 772 832 773 case 'theme': 833 add_action( 'after_switch_theme', array($this, 'schedule_cron_event'));834 add_action( 'switch_theme', array($this, 'clear_scheduler'));774 add_action( 'after_switch_theme', [ $this, 'schedule_cron_event' ] ); 775 add_action( 'switch_theme', [ $this, 'clear_scheduler' ] ); 835 776 break; 836 777 } … … 838 779 839 780 /** 840 * Form action URL841 */842 private function form_action_url()843 {844 $url = add_query_arg(845 $_GET,846 admin_url(basename($_SERVER['SCRIPT_NAME']))847 );848 849 echo apply_filters('appsero_client_license_form_action', $url);850 }851 852 /**853 781 * Get input license key 854 782 * 855 * @param $action856 *857 783 * @return $license 858 784 */ 859 private function get_input_license_value($action, $license) 860 { 861 if ('active' == $action) { 862 return isset($license['key']) ? $license['key'] : ''; 863 } 864 865 if ('deactive' == $action) { 866 $key_length = strlen($license['key']); 785 private function get_input_license_value( $action, $license ) { 786 if ( 'active' === $action ) { 787 return isset( $license['key'] ) ? $license['key'] : ''; 788 } 789 790 if ( 'deactive' === $action ) { 791 $key_length = strlen( $license['key'] ); 867 792 868 793 return str_pad( 869 substr( $license['key'], 0, $key_length / 2),794 substr( $license['key'], 0, $key_length / 2 ), 870 795 $key_length, 871 796 '*' -
advance-faq-block/trunk/inc/appsero/src/Updater.php
r2886650 r2899060 1 1 <?php 2 2 3 namespace Appsero; 4 5 use stdClass; 3 6 4 7 /** … … 17 20 18 21 /** 22 * Cache key 23 * 24 * @var string 25 */ 26 protected $cache_key; 27 28 /** 19 29 * Initialize the class 20 30 * … … 22 32 */ 23 33 public function __construct( Client $client ) { 24 25 34 $this->client = $client; 26 35 $this->cache_key = 'appsero_' . md5( $this->client->slug ) . '_version_info'; 27 36 28 37 // Run hooks. 29 if ( $this->client->type == 'plugin' ) {38 if ( $this->client->type === 'plugin' ) { 30 39 $this->run_plugin_hooks(); 31 } elseif ( $this->client->type == 'theme' ) {40 } elseif ( $this->client->type === 'theme' ) { 32 41 $this->run_theme_hooks(); 33 42 } … … 40 49 */ 41 50 public function run_plugin_hooks() { 42 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_plugin_update' ));43 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );51 add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'check_plugin_update' ] ); 52 add_filter( 'plugins_api', [ $this, 'plugins_api_filter' ], 10, 3 ); 44 53 } 45 54 … … 50 59 */ 51 60 public function run_theme_hooks() { 52 add_filter( 'pre_set_site_transient_update_themes', array( $this, 'check_theme_update' ));61 add_filter( 'pre_set_site_transient_update_themes', [ $this, 'check_theme_update' ] ); 53 62 } 54 63 … … 60 69 61 70 if ( ! is_object( $transient_data ) ) { 62 $transient_data = new \stdClass;63 } 64 65 if ( 'plugins.php' == $pagenow && is_multisite() ) {71 $transient_data = new stdClass(); 72 } 73 74 if ( 'plugins.php' === $pagenow && is_multisite() ) { 66 75 return $transient_data; 67 76 } … … 74 83 75 84 if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { 76 77 85 unset( $version_info->sections ); 78 86 … … 85 93 } 86 94 87 $transient_data->last_checked = time();95 $transient_data->last_checked = time(); 88 96 $transient_data->checked[ $this->client->basename ] = $this->client->project_version; 89 97 } … … 95 103 * Get version info from database 96 104 * 97 * @return Object or Boolean105 * @return object or Boolean 98 106 */ 99 107 private function get_cached_version_info() { … … 101 109 102 110 // If updater page then fetch from API now 103 if ( 'update-core.php' == $pagenow ) {111 if ( 'update-core.php' === $pagenow ) { 104 112 return false; // Force to fetch data 105 113 } … … 107 115 $value = get_transient( $this->cache_key ); 108 116 109 if ( ! $value && ! isset( $value->name ) ) {117 if ( ! $value && ! isset( $value->name ) ) { 110 118 return false; // Cache is expired 111 119 } … … 143 151 */ 144 152 private function get_project_latest_version() { 145 146 153 $license = $this->client->license()->get_license(); 147 154 148 $params = array(155 $params = [ 149 156 'version' => $this->client->project_version, 150 157 'name' => $this->client->name, … … 152 159 'basename' => $this->client->basename, 153 160 'license_key' => ! empty( $license ) && isset( $license['key'] ) ? $license['key'] : '', 154 );161 ]; 155 162 156 163 $route = 'update/' . $this->client->hash . '/check'; … … 186 193 * Updates information on the "View version x.x details" page with custom data. 187 194 * 188 * @param mixed $data189 * @param string $action190 * @param object $args195 * @param mixed $data 196 * @param string $action 197 * @param object $args 191 198 * 192 199 * @return object $data 193 200 */ 194 201 public function plugins_api_filter( $data, $action = '', $args = null ) { 195 196 if ( $action != 'plugin_information' ) { 202 if ( $action !== 'plugin_information' ) { 197 203 return $data; 198 204 } 199 205 200 if ( ! isset( $args->slug ) || ( $args->slug != $this->client->slug ) ) {206 if ( ! isset( $args->slug ) || ( $args->slug !== $this->client->slug ) ) { 201 207 return $data; 202 208 } … … 212 218 213 219 if ( ! is_object( $transient_data ) ) { 214 $transient_data = new \stdClass;215 } 216 217 if ( 'themes.php' == $pagenow && is_multisite() ) {220 $transient_data = new stdClass(); 221 } 222 223 if ( 'themes.php' === $pagenow && is_multisite() ) { 218 224 return $transient_data; 219 225 } … … 226 232 227 233 if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { 228 229 234 // If new version available then set to `response` 230 235 if ( version_compare( $this->client->project_version, $version_info->new_version, '<' ) ) { … … 235 240 } 236 241 237 $transient_data->last_checked = time();242 $transient_data->last_checked = time(); 238 243 $transient_data->checked[ $this->client->slug ] = $this->client->project_version; 239 244 } … … 255 260 return $version_info; 256 261 } 257 258 262 } -
advance-faq-block/trunk/readme.txt
r2886650 r2899060 3 3 Tags: FAQ block, Gutenberg block, Gutenberg FAQ block, Frequently Asked Questions, FAQs, FAQ section 4 4 Requires at least: 6.1 5 Tested up to: 6. 15 Tested up to: 6.2 6 6 Requires PHP: 7.0 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPL-2.0+ 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.txt … … 16 16 17 17 == Screenshots == 18 19 2. Screenshot_1.png 18 1. FAQ Block 20 19 21 20 == Changelog == 22 21 22 = 1.0.2 = 23 - Tested WP 6.2 Compatibility 24 - Updated: Appsero update 25 23 26 = 1.0.1 = 24 *Intrigate Appsero27 - Intrigate Appsero 25 28 26 29 = 1.0.0 = 27 *Release30 - Release 28 31 29 32
Note: See TracChangeset
for help on using the changeset viewer.