From e27979a2dd6e8025e2232fbe9b7c28a6ca12e45c Mon Sep 17 00:00:00 2001 From: andrii-pukhalevych Date: Thu, 21 May 2020 16:46:29 +0300 Subject: [PATCH 1/4] code refactor use strict checks, use single quotes and fix typos --- .../sample-plugin/slm-sample-plugin.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php b/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php index e92524d..fd18841 100644 --- a/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php +++ b/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php @@ -47,7 +47,7 @@ function sample_license_management_page() { // Check for error in the response if (is_wp_error($response)){ - echo "Unexpected Error! The query returned with an error."; + echo 'Unexpected Error! The query returned with an error.'; } //var_dump($response);//uncomment it if you want to look at the full response @@ -58,9 +58,9 @@ function sample_license_management_page() { // TODO - Do something with it. //var_dump($license_data);//uncomment it to look at the data - if($license_data->result == 'success'){//Success was returned for the license activation + if('success' === $license_data->result){//Success was returned for the license activation - //Uncomment the followng line to see the message that returned from the license server + //Uncomment the following line to see the message that returned from the license server echo '
The following message was returned from the server: '.$license_data->message; //Save the license key in the options table @@ -69,7 +69,7 @@ function sample_license_management_page() { else{ //Show error to the user. Probably entered incorrect license key. - //Uncomment the followng line to see the message that returned from the license server + //Uncomment the following line to see the message that returned from the license server echo '
The following message was returned from the server: '.$license_data->message; } @@ -95,7 +95,7 @@ function sample_license_management_page() { // Check for error in the response if (is_wp_error($response)){ - echo "Unexpected Error! The query returned with an error."; + echo 'Unexpected Error! The query returned with an error.'; } //var_dump($response);//uncomment it if you want to look at the full response @@ -106,18 +106,18 @@ function sample_license_management_page() { // TODO - Do something with it. //var_dump($license_data);//uncomment it to look at the data - if($license_data->result == 'success'){//Success was returned for the license activation + if('success' === $license_data->result){//Success was returned for the license activation - //Uncomment the followng line to see the message that returned from the license server + //Uncomment the following line to see the message that returned from the license server echo '
The following message was returned from the server: '.$license_data->message; - //Remove the licensse key from the options table. It will need to be activated again. + //Remove the license key from the options table. It will need to be activated again. update_option('sample_license_key', ''); } else{ //Show error to the user. Probably entered incorrect license key. - //Uncomment the followng line to see the message that returned from the license server + //Uncomment the following line to see the message that returned from the license server echo '
The following message was returned from the server: '.$license_data->message; } @@ -141,4 +141,4 @@ function sample_license_management_page() { '; -} \ No newline at end of file +} From f3304ae50f6689986a6c29a10191a3bac45a90fe Mon Sep 17 00:00:00 2001 From: andrii-pukhalevych Date: Thu, 21 May 2020 17:11:47 +0300 Subject: [PATCH 2/4] strict type checks and basic code refactor --- .../sample-plugin/slm-sample-plugin.php | 14 ++++---- .../includes/slm-api-listener.php | 26 +++++++------- .../includes/slm-debug-logger.php | 15 ++++---- .../includes/slm-init-time-tasks.php | 8 ++--- .../includes/slm-third-party-integration.php | 6 ++-- .../includes/slm-utility.php | 6 ++-- .../js/wplm-custom-admin.js | 6 ++-- .../menu/includes/slm-list-table-class.php | 22 ++++++------ .../menu/slm-add-licenses.php | 30 ++++++++-------- .../menu/slm-admin-functions.php | 6 ++-- .../menu/slm-lic-settings.php | 2 +- .../menu/slm-list-licenses-class.php | 35 ++++++++----------- software-license-manager/slm_bootstrap.php | 6 ++-- software-license-manager/slm_installer.php | 8 ++--- 14 files changed, 91 insertions(+), 99 deletions(-) diff --git a/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php b/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php index fd18841..15a1db0 100644 --- a/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php +++ b/software-license-manager/client-side-examples/sample-plugin/slm-sample-plugin.php @@ -46,7 +46,7 @@ function sample_license_management_page() { $response = wp_remote_get($query, array('timeout' => 20, 'sslverify' => false)); // Check for error in the response - if (is_wp_error($response)){ + if (is_wp_error($response)) { echo 'Unexpected Error! The query returned with an error.'; } @@ -58,15 +58,14 @@ function sample_license_management_page() { // TODO - Do something with it. //var_dump($license_data);//uncomment it to look at the data - if('success' === $license_data->result){//Success was returned for the license activation + if ('success' === $license_data->result) {//Success was returned for the license activation //Uncomment the following line to see the message that returned from the license server echo '
The following message was returned from the server: '.$license_data->message; //Save the license key in the options table update_option('sample_license_key', $license_key); - } - else{ + } else { //Show error to the user. Probably entered incorrect license key. //Uncomment the following line to see the message that returned from the license server @@ -94,7 +93,7 @@ function sample_license_management_page() { $response = wp_remote_get($query, array('timeout' => 20, 'sslverify' => false)); // Check for error in the response - if (is_wp_error($response)){ + if (is_wp_error($response)) { echo 'Unexpected Error! The query returned with an error.'; } @@ -106,15 +105,14 @@ function sample_license_management_page() { // TODO - Do something with it. //var_dump($license_data);//uncomment it to look at the data - if('success' === $license_data->result){//Success was returned for the license activation + if ('success' === $license_data->result) {//Success was returned for the license activation //Uncomment the following line to see the message that returned from the license server echo '
The following message was returned from the server: '.$license_data->message; //Remove the license key from the options table. It will need to be activated again. update_option('sample_license_key', ''); - } - else{ + } else { //Show error to the user. Probably entered incorrect license key. //Uncomment the following line to see the message that returned from the license server diff --git a/software-license-manager/includes/slm-api-listener.php b/software-license-manager/includes/slm-api-listener.php index 87dd098..b6dc195 100644 --- a/software-license-manager/includes/slm-api-listener.php +++ b/software-license-manager/includes/slm-api-listener.php @@ -27,7 +27,7 @@ function __construct() { } function creation_api_listener() { - if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_create_new') { + if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) === 'slm_create_new') { //Handle the licene creation API query global $slm_debug_logger; @@ -42,9 +42,9 @@ function creation_api_listener() { do_action('slm_api_listener_slm_create_new'); $fields = array(); - if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])){ + if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])) { $fields['license_key'] = strip_tags($_REQUEST['license_key']);//Use the key you pass via the request - }else{ + } else { $fields['license_key'] = uniqid($lic_key_prefix);//Use random generated key } $fields['lic_status'] = isset( $_REQUEST['lic_status'] ) ? wp_unslash( strip_tags( $_REQUEST['lic_status'] ) ) : 'pending'; @@ -85,7 +85,7 @@ function creation_api_listener() { */ function activation_api_listener() { - if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_activate') { + if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) === 'slm_activate') { //Handle the license activation API query global $slm_debug_logger; @@ -112,22 +112,22 @@ function activation_api_listener() { $sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key); $reg_domains = $wpdb->get_results($sql_prep2, OBJECT); if ($retLic) { - if ($retLic->lic_status == 'blocked') { + if ('blocked' === $retLic->lic_status) { $args = (array('result' => 'error', 'message' => 'Your License key is blocked', 'error_code' => SLM_Error_Codes::LICENSE_BLOCKED)); SLM_API_Utility::output_api_response($args); - } elseif ($retLic->lic_status == 'expired') { + } elseif ('expired' === $retLic->lic_status) { $args = (array('result' => 'error', 'message' => 'Your License key has expired', 'error_code' => SLM_Error_Codes::LICENSE_EXPIRED)); SLM_API_Utility::output_api_response($args); } if (count($reg_domains) < floor($retLic->max_allowed_domains)) { foreach ($reg_domains as $reg_domain) { - if (isset($_REQUEST['migrate_from']) && (trim($_REQUEST['migrate_from']) == $reg_domain->registered_domain)) { + if (isset($_REQUEST['migrate_from']) && (trim($_REQUEST['migrate_from']) === $reg_domain->registered_domain)) { $wpdb->update($reg_table, array('registered_domain' => $fields['registered_domain']), array('registered_domain' => trim(strip_tags($_REQUEST['migrate_from'])))); $args = (array('result' => 'success', 'message' => 'Registered domain has been updated')); SLM_API_Utility::output_api_response($args); } - if ($fields['registered_domain'] == $reg_domain->registered_domain) { + if ($fields['registered_domain'] === $reg_domain->registered_domain) { $args = (array('result' => 'error', 'message' => 'License key already in use on ' . $reg_domain->registered_domain, 'error_code' => SLM_Error_Codes::LICENSE_IN_USE)); SLM_API_Utility::output_api_response($args); } @@ -146,7 +146,7 @@ function activation_api_listener() { //Lets loop through the domains to see if it is being used on an existing domain or not. foreach ($reg_domains as $reg_domain) { - if ($fields['registered_domain'] == $reg_domain->registered_domain) { + if ($fields['registered_domain'] === $reg_domain->registered_domain) { //Not used on an existing domain. Return error: LICENSE_IN_USE_ON_DOMAIN_AND_MAX_REACHED $args = (array('result' => 'error', 'message' => 'Reached maximum activation. License key already in use on ' . $reg_domain->registered_domain, 'error_code' => SLM_Error_Codes::LICENSE_IN_USE_ON_DOMAIN_AND_MAX_REACHED)); SLM_API_Utility::output_api_response($args); @@ -165,7 +165,7 @@ function activation_api_listener() { } function deactivation_api_listener() { - if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_deactivate') { + if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) === 'slm_deactivate') { //Handle the license deactivation API query global $slm_debug_logger; @@ -188,9 +188,9 @@ function deactivation_api_listener() { $registered_dom_table = SLM_TBL_LIC_DOMAIN; $sql_prep = $wpdb->prepare("DELETE FROM $registered_dom_table WHERE lic_key=%s AND registered_domain=%s", $license_key, $registered_domain); $delete = $wpdb->query($sql_prep); - if ($delete === false) { + if (false === $delete) { $slm_debug_logger->log_debug("Error - failed to delete the registered domain from the database."); - } else if ($delete == 0) { + } else if (0 == $delete) { $args = (array('result' => 'error', 'message' => 'The license key on this domain is already inactive', 'error_code' => SLM_Error_Codes::DOMAIN_ALREADY_INACTIVE)); SLM_API_Utility::output_api_response($args); } else { @@ -201,7 +201,7 @@ function deactivation_api_listener() { } function check_api_listener() { - if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_check') { + if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) === 'slm_check') { //Handle the license check API query global $slm_debug_logger; diff --git a/software-license-manager/includes/slm-debug-logger.php b/software-license-manager/includes/slm-debug-logger.php index f0ab6ae..2d5c160 100644 --- a/software-license-manager/includes/slm-debug-logger.php +++ b/software-license-manager/includes/slm-debug-logger.php @@ -26,7 +26,7 @@ function __construct() $this->log_folder_path = WP_LICENSE_MANAGER_PATH . '/logs'; //Check config and if debug is enabled then set the enabled flag to true $options = get_option('slm_plugin_options'); - if(!empty($options['enable_debug'])){//Debugging is enabled + if (!empty($options['enable_debug'])) {//Debugging is enabled $this->debug_enabled = true; } } @@ -39,10 +39,9 @@ function get_debug_timestamp() function get_debug_status($level) { $size = count($this->debug_status); - if($level >= $size){ + if ($level >= $size) { return 'UNKNOWN'; - } - else{ + } else { return $this->debug_status[$level]; } } @@ -57,7 +56,7 @@ function get_section_break($section_break) function reset_log_file($file_name='') { - if(empty($file_name)){ + if (empty($file_name)) { $file_name = $this->default_log_file; } $debug_log_file = $this->log_folder_path.'/'.$file_name; @@ -69,9 +68,9 @@ function reset_log_file($file_name='') function append_to_file($content,$file_name) { - if(empty($file_name))$file_name = $this->default_log_file; + if (empty($file_name))$file_name = $this->default_log_file; $debug_log_file = $this->log_folder_path.'/'.$file_name; - $fp=fopen($debug_log_file,'a'); + $fp=fopen($debug_log_file, 'a'); fwrite($fp, $content); fclose($fp); } @@ -102,7 +101,7 @@ function log_debug_cron($message,$level=0,$section_break=false) static function log_debug_st($message,$level=0,$section_break=false,$file_name='') { $options = get_option('slm_plugin_options'); - if(empty($options['enable_debug'])){//Debugging is disabled + if (empty($options['enable_debug'])) {//Debugging is disabled return; } $content = '['.date('m/d/Y g:i A').'] - STATUS : '. $message . "\n"; diff --git a/software-license-manager/includes/slm-init-time-tasks.php b/software-license-manager/includes/slm-init-time-tasks.php index be2667d..928f094 100644 --- a/software-license-manager/includes/slm-init-time-tasks.php +++ b/software-license-manager/includes/slm-init-time-tasks.php @@ -2,7 +2,7 @@ class SLM_Init_Time_Tasks{ - function __construct(){ + function __construct() { $this->load_scripts(); //Add other init time operations here @@ -15,12 +15,12 @@ function load_scripts() wp_enqueue_script('jquery'); //Load all admin side scripts and styles only - if(is_admin()) + if (is_admin()) { wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('wplm-custom-admin-js', WP_LICENSE_MANAGER_URL . '/js/wplm-custom-admin.js', array( 'jquery-ui-dialog' ));//admin only custom js code - if (isset($_GET['page']) && $_GET['page'] == 'wp_lic_mgr_addedit') {//Only include if we are in the license add/edit interface + if (isset($_GET['page']) && 'wp_lic_mgr_addedit' === $_GET['page']) {//Only include if we are in the license add/edit interface wp_enqueue_style('jquery-ui-style', WP_LICENSE_MANAGER_URL .'/css/jquery-ui.css'); } //wp_enqueue_style('dialogStylesheet', includes_url().'css/jquery-ui-dialog.css'); @@ -33,7 +33,7 @@ function slm_daily_cron_event_handler() do_action('slm_daily_cron_event_triggered'); - if ( isset($options['enable_auto_key_expiry']) && $options['enable_auto_key_expiry'] == '1'){ + if ( isset($options['enable_auto_key_expiry']) && '1' == $options['enable_auto_key_expiry']) { //Do the auto key expiry task SLM_Debug_Logger::log_debug_st("SLM daily cronjob - auto expiry of license key is enabled."); SLM_Utility::do_auto_key_expiry(); diff --git a/software-license-manager/includes/slm-third-party-integration.php b/software-license-manager/includes/slm-third-party-integration.php index 367a890..d18e0e8 100644 --- a/software-license-manager/includes/slm-third-party-integration.php +++ b/software-license-manager/includes/slm-third-party-integration.php @@ -15,7 +15,7 @@ function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) //Check if this is a recurring payment. if ( function_exists('is_paypal_recurring_payment') ) { $recurring_payment = is_paypal_recurring_payment($payment_data); - if( $recurring_payment ){ + if ( $recurring_payment ) { $slm_debug_logger->log_debug("This is a recurring payment. No need to create a new license key."); do_action('slm_estore_recurring_payment_received', $payment_data, $cart_items); return $body; @@ -26,7 +26,7 @@ function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) $prod_id = $current_cart_item['item_number']; $item_name = $current_cart_item['item_name']; $quantity = $current_cart_item['quantity']; - if(empty($quantity)){ + if (empty($quantity)) { $quantity = 1; } $slm_debug_logger->log_debug('License Manager - Item Number: ' . $prod_id . ', Quantity: ' . $quantity . ', Item Name: ' . $item_name); @@ -52,7 +52,7 @@ function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) return $body; } -function slm_estore_check_and_create_key_for_qty($retrieved_product, $payment_data, $cart_items, $item_name, $quantity){ +function slm_estore_check_and_create_key_for_qty($retrieved_product, $payment_data, $cart_items, $item_name, $quantity) { $prod_key_data = ""; for ($i = 0; $i < $quantity; $i++) { $prod_key_data .= slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items, $item_name); diff --git a/software-license-manager/includes/slm-utility.php b/software-license-manager/includes/slm-utility.php index 2fdb8f5..2ab3c2f 100644 --- a/software-license-manager/includes/slm-utility.php +++ b/software-license-manager/includes/slm-utility.php @@ -12,15 +12,15 @@ static function do_auto_key_expiry() { $sql_prep = $wpdb->prepare("SELECT * FROM $tbl_name WHERE lic_status !=%s", 'expired');//Load the non-expired keys $licenses = $wpdb->get_results($sql_prep, OBJECT); - if(!$licenses){ + if (!$licenses) { SLM_Debug_Logger::log_debug_st("do_auto_key_expiry() - no license keys found."); return false; } - foreach($licenses as $license){ + foreach ($licenses as $license) { $key = $license->license_key; $expiry_date = $license->date_expiry; - if ($expiry_date == '0000-00-00'){ + if ('0000-00-00' === $expiry_date) { SLM_Debug_Logger::log_debug_st("This key (".$key.") doesn't have a valid expiry date set. The expiry of this key will not be checked."); continue; } diff --git a/software-license-manager/js/wplm-custom-admin.js b/software-license-manager/js/wplm-custom-admin.js index fb6639a..abdff10 100644 --- a/software-license-manager/js/wplm-custom-admin.js +++ b/software-license-manager/js/wplm-custom-admin.js @@ -1,7 +1,7 @@ -jQuery(document).ready(function($){ +jQuery(function(){ //Add date picker listener on date fields - if ($.fn.datepicker){ - $('.wplm_pick_date').datepicker({ + if (jQuery.fn.datepicker) { + jQuery('.wplm_pick_date').datepicker({ dateFormat : 'yy-mm-dd' }); } diff --git a/software-license-manager/menu/includes/slm-list-table-class.php b/software-license-manager/menu/includes/slm-list-table-class.php index 82e9df9..6e11922 100644 --- a/software-license-manager/menu/includes/slm-list-table-class.php +++ b/software-license-manager/menu/includes/slm-list-table-class.php @@ -149,7 +149,7 @@ function set_pagination_args( $args ) { * @return array */ function get_pagination_arg( $key ) { - if ( 'page' == $key ) + if ( 'page' === $key ) return $this->get_pagenum(); if ( isset( $this->_pagination_args[$key] ) ) @@ -281,7 +281,7 @@ function bulk_actions() { echo "\n"; foreach ( $this->_actions as $name => $title ) { - $class = 'edit' == $name ? ' class="hide-if-no-js"' : ''; + $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; echo "\t\n"; } @@ -400,7 +400,7 @@ function view_switcher( $current_mode ) {
$title ) { - $class = ( $current_mode == $mode ) ? 'class="current"' : ''; + $class = ( $current_mode === $mode ) ? 'class="current"' : ''; echo "$title\n"; } ?> @@ -440,7 +440,7 @@ function comments_bubble( $post_id, $pending_comments ) { function get_pagenum() { $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0; - if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) + if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) $pagenum = $this->_pagination_args['total_pages']; return max( 1, $pagenum ); @@ -504,7 +504,7 @@ function pagination( $which ) { '‹' ); - if ( 'bottom' == $which ) + if ( 'bottom' === $which ) $html_current_page = $current; else $html_current_page = sprintf( "", @@ -643,7 +643,7 @@ function print_column_headers( $with_id = true ) { else $current_orderby = ''; - if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) + if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) $current_order = 'desc'; else $current_order = 'asc'; @@ -664,7 +664,7 @@ function print_column_headers( $with_id = true ) { $style = ' style="' . $style . '"'; - if ( 'cb' == $column_key ) + if ( 'cb' === $column_key ) $class[] = 'check-column'; elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) $class[] = 'num'; @@ -672,8 +672,8 @@ function print_column_headers( $with_id = true ) { if ( isset( $sortable[$column_key] ) ) { list( $orderby, $desc_first ) = $sortable[$column_key]; - if ( $current_orderby == $orderby ) { - $order = 'asc' == $current_order ? 'desc' : 'asc'; + if ( $current_orderby === $orderby ) { + $order = 'asc' === $current_order ? 'desc' : 'asc'; $class[] = 'sorted'; $class[] = $current_order; } else { @@ -746,7 +746,7 @@ function get_table_classes() { * @access protected */ function display_tablenav( $which ) { - if ( 'top' == $which ) + if ( 'top' === $which ) wp_nonce_field( 'bulk-' . $this->_args['plural'] ); ?>
@@ -837,7 +837,7 @@ function single_row_columns( $item ) { $attributes = "$class$style"; - if ( 'cb' == $column_name ) { + if ( 'cb' === $column_name ) { echo ''; echo $this->column_cb( $item ); echo ''; diff --git a/software-license-manager/menu/slm-add-licenses.php b/software-license-manager/menu/slm-add-licenses.php index d98801c..108d9e6 100644 --- a/software-license-manager/menu/slm-add-licenses.php +++ b/software-license-manager/menu/slm-add-licenses.php @@ -54,7 +54,7 @@ function wp_lic_mgr_add_licenses_menu() { if (isset($_POST['save_record'])) { //Check nonce - if ( !isset($_POST['slm_add_edit_nonce_val']) || !wp_verify_nonce($_POST['slm_add_edit_nonce_val'], 'slm_add_edit_nonce_action' )){ + if ( !isset($_POST['slm_add_edit_nonce_val']) || !wp_verify_nonce($_POST['slm_add_edit_nonce_val'], 'slm_add_edit_nonce_action' )) { //Nonce check failed. wp_die("Error! Nonce verification failed for license save action."); } @@ -77,13 +77,13 @@ function wp_lic_mgr_add_licenses_menu() { $product_ref = $_POST['product_ref']; $subscr_id = $_POST['subscr_id']; - if(empty($created_date)){ + if (empty($created_date)) { $created_date = $current_date; } - if(empty($renewed_date)){ + if (empty($renewed_date)) { $renewed_date = $current_date; } - if(empty($expiry_date)){ + if (empty($expiry_date)) { $expiry_date = $current_date_plus_1year; } @@ -109,24 +109,24 @@ function wp_lic_mgr_add_licenses_menu() { if (empty($id)) {//Insert into database $result = $wpdb->insert( $lk_table, $fields); $id = $wpdb->insert_id; - if($result === false){ + if ($result === false) { $errors .= __('Record could not be inserted into the database!', 'slm'); } } else { //Update record $where = array('id'=>$id); $updated = $wpdb->update($lk_table, $fields, $where); - if($updated === false){ + if (false === $updated) { //TODO - log error $errors .= __('Update of the license key table failed!', 'slm'); } } - if(empty($errors)){ + if (empty($errors)) { $message = "Record successfully saved!"; echo '

'; echo $message; echo '

'; - }else{ + } else { echo '
' . $errors . '
'; } @@ -199,7 +199,7 @@ function wp_lic_mgr_add_licenses_menu() { if ($id != '') { echo ''; } else { - if(!isset($editing_record)){//Create an empty object + if (!isset($editing_record)) {//Create an empty object $editing_record = new stdClass(); } //Auto generate unique key @@ -227,10 +227,10 @@ function wp_lic_mgr_add_licenses_menu() { License Status @@ -337,7 +337,7 @@ function wp_lic_mgr_add_licenses_menu() { $id, 'key' => $license_key); $extra_output = apply_filters('slm_add_edit_interface_above_submit','', $data); - if(!empty($extra_output)){ + if (!empty($extra_output)) { echo $extra_output; } ?> @@ -374,7 +374,7 @@ function wp_lic_mgr_add_licenses_menu() { $.get( '' + '?action=del_reistered_domain&id=' + id, function( data ) { - if ( 'success' == data ) { + if ( 'success' === data ) { $msg.addClass( 'success' ).html( 'Deleted' ); var $tr = $link.parents( 'tr:first' ); diff --git a/software-license-manager/menu/slm-admin-functions.php b/software-license-manager/menu/slm-admin-functions.php index 187722f..cfeb433 100644 --- a/software-license-manager/menu/slm-admin-functions.php +++ b/software-license-manager/menu/slm-admin-functions.php @@ -20,9 +20,9 @@ function wp_lic_mgr_admin_fnc_menu() { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $returnValue = curl_exec($ch); - $msg = ""; - if ($returnValue == "Success") { - $msg .= "Success message returned from the remote host."; + $msg = ''; + if ('Success' === $returnValue) { + $msg .= 'Success message returned from the remote host.'; } echo '

'; echo 'Request sent to the specified URL!'; diff --git a/software-license-manager/menu/slm-lic-settings.php b/software-license-manager/menu/slm-lic-settings.php index 79b294c..05fb007 100644 --- a/software-license-manager/menu/slm-lic-settings.php +++ b/software-license-manager/menu/slm-lic-settings.php @@ -14,7 +14,7 @@ function wp_lic_mgr_settings_menu() { function wp_lic_mgr_general_settings() { - if (isset($_REQUEST['slm_reset_log'])){ + if (isset($_REQUEST['slm_reset_log'])) { //$slm_logger = new SLM_Debug_Logger(); global $slm_debug_logger; $slm_debug_logger->reset_log_file("log.txt"); diff --git a/software-license-manager/menu/slm-list-licenses-class.php b/software-license-manager/menu/slm-list-licenses-class.php index 9f06e53..969d58f 100644 --- a/software-license-manager/menu/slm-list-licenses-class.php +++ b/software-license-manager/menu/slm-list-licenses-class.php @@ -6,7 +6,7 @@ class WPLM_List_Licenses extends WP_List_Table { - function __construct(){ + function __construct() { global $status, $page; //Set parent defaults @@ -18,11 +18,11 @@ function __construct(){ } - function column_default($item, $column_name){ - return $item[$column_name]; + function column_default($item, $column_name) { + return $item[$column_name]; } - function column_id($item){ + function column_id($item) { $row_id = $item['id']; $actions = array( 'edit' => sprintf('Edit', $row_id), @@ -35,7 +35,7 @@ function column_id($item){ } - function column_cb($item){ + function column_cb($item) { return sprintf( '', /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label @@ -43,12 +43,8 @@ function column_cb($item){ ); } - function column_active($item){ - if ($item['active'] == 1){ - return 'active'; - } else{ - return 'inactive'; - } + function column_active($item) { + return 1 == $item['active'] ? 'active' : 'inactive'; } function get_columns() { @@ -87,20 +83,19 @@ function get_bulk_actions() { } function process_bulk_action() { - if('delete'===$this->current_action()) - { + if ('delete'===$this->current_action()) { //Process delete bulk actions - if(!isset($_REQUEST['item'])){ + if (!isset($_REQUEST['item'])) { $error_msg = '

'.__('Error - Please select some records using the checkboxes', 'slm').'

'; echo '
'.$error_msg.'
'; return; - }else { - $nvp_key = $this->_args['singular']; - $records_to_delete = $_GET[$nvp_key]; - foreach ($records_to_delete as $row){ + } else { + $nvp_key = $this->_args['singular']; + $records_to_delete = $_GET[$nvp_key]; + foreach ($records_to_delete as $row) { SLM_Utility::delete_license_key_by_row_id($row); - } - echo '

Selected records deleted successfully!

'; + } + echo '

Selected records deleted successfully!

'; } } } diff --git a/software-license-manager/slm_bootstrap.php b/software-license-manager/slm_bootstrap.php index a59c51a..072ccb0 100644 --- a/software-license-manager/slm_bootstrap.php +++ b/software-license-manager/slm_bootstrap.php @@ -8,7 +8,7 @@ Description: Software license management solution for your web applications (WordPress plugins, Themes, PHP based membership script etc.) */ -if(!defined('ABSPATH')){ +if (!defined('ABSPATH')) { exit; //Exit if accessed directly } @@ -25,7 +25,7 @@ include_once('slm_plugin_core.php'); //Activation handler -function slm_activate_handler(){ +function slm_activate_handler() { //Do installer task slm_db_install(); @@ -37,7 +37,7 @@ function slm_activate_handler(){ register_activation_hook(__FILE__,'slm_activate_handler'); //Deactivation handler -function slm_deactivate_handler(){ +function slm_deactivate_handler() { //Clear the daily cron event wp_clear_scheduled_hook('slm_daily_cron_event'); diff --git a/software-license-manager/slm_installer.php b/software-license-manager/slm_installer.php index 7a91968..1cb9047 100644 --- a/software-license-manager/slm_installer.php +++ b/software-license-manager/slm_installer.php @@ -1,19 +1,19 @@ charset)){ +if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; -}else{ +} else { $charset_collate = "DEFAULT CHARSET=utf8"; } -if (!empty($wpdb->collate)){ +if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE $wpdb->collate"; } From f773b172f60450a6b59726754e3f0a9e6664a764 Mon Sep 17 00:00:00 2001 From: andrii-pukhalevych Date: Thu, 21 May 2020 17:16:49 +0300 Subject: [PATCH 3/4] do not use copy of jQuery (may cause problems on some configurations) --- .../menu/slm-add-licenses.php | 22 +++++++++---------- .../menu/slm-list-licenses-class.php | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/software-license-manager/menu/slm-add-licenses.php b/software-license-manager/menu/slm-add-licenses.php index 108d9e6..c358ba0 100644 --- a/software-license-manager/menu/slm-add-licenses.php +++ b/software-license-manager/menu/slm-add-licenses.php @@ -352,26 +352,26 @@ function wp_lic_mgr_add_licenses_menu() {