Skip to content

Commit

Permalink
Merge pull request #200 from yekenuk/7.0.6
Browse files Browse the repository at this point in the history
7.0.6
  • Loading branch information
alicolville committed Jan 13, 2019
2 parents d20c146 + 4fbdf15 commit 6e042ba
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 23 deletions.
2 changes: 1 addition & 1 deletion includes/admin-pages/awards/page-awards-add-update.php
Expand Up @@ -109,7 +109,7 @@ function ws_ls_awards_add_update_page() {
<label for="title"><?php echo __('Title', WE_LS_SLUG); ?></label>
</div>
<div class="ws-ls-cell">
<input type="text" name="title" id="title" size="40" maxlength="40" class="<?php if ( true === $validation_fail && true === empty( $award['title'] ) ) { echo 'ws-ls-mandatory-field'; } ?>" value="<?php echo ( false === empty( $award['title'] ) ) ? esc_attr( $award['title'] ) : ''; ?>"/><span class="ws-ls-mandatory">*</span>
<input type="text" name="title" id="title" size="40" maxlength="200" class="<?php if ( true === $validation_fail && true === empty( $award['title'] ) ) { echo 'ws-ls-mandatory-field'; } ?>" value="<?php echo ( false === empty( $award['title'] ) ) ? esc_attr( $award['title'] ) : ''; ?>"/><span class="ws-ls-mandatory">*</span>

</div>
</div>
Expand Down
5 changes: 2 additions & 3 deletions includes/functions.php
Expand Up @@ -679,11 +679,10 @@ function ws_ls_display_notice($text, $type = 'success') {
echo sprintf(' <div class="notice notice-%s">
<p>%s</p>
</div>',
esc_html($type),
esc_html($text)
wp_kses_post( $type ),
wp_kses_post( $text )
);
}

/**
* If QS value detected, display data saved message
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/globals.php
Expand Up @@ -16,7 +16,7 @@
define('WE_LS_UPGRADE_TO_PRO_PLUS_URL', 'https://weight.yeken.uk/get-pro-plus/');
define('WE_LS_FREE_TRIAL_URL', 'https://weight.yeken.uk/trial/');
define('WE_LS_UPGRADE_TO_PRO_PLUS_UPGRADE_URL', 'https://weight.yeken.uk/get-pro-plus-existing-license-holders/');
define('WE_LS_CDN_CHART_JS', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js');
define('WE_LS_CDN_CHART_JS', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js');
define('WE_LS_CACHE_TIME', 15 * MINUTE_IN_SECONDS);
define('WE_LS_CACHE_STATS_TABLE', 'stats-table-html');
define('WE_LS_CACHE_KEY_TARGET', 'target-data');
Expand Down
62 changes: 62 additions & 0 deletions includes/license.php
Expand Up @@ -31,6 +31,68 @@ function ws_ls_has_a_valid_pro_plus_license() {
return ('pro-plus' == ws_ls_has_a_valid_license());
}

/**
* Return the number of days until the license expires
*
* @return int|null
*/
function ws_ls_how_many_days_until_license_expires() {

$license_type = ws_ls_has_a_valid_license();

// Only Pro or Pro plus licenses can expire
if ( true === in_array( $license_type, ['pro', 'pro-plus'] ) ) {

$license = ws_ls_license();

$license_decoded = ws_ls_license_decode( $license );

if ( false === empty( $license_decoded ) ) {

$expiry_date = new DateTime( $license_decoded['expiry-date'] );
$todays_date = new DateTime();

$difference = $todays_date->diff( $expiry_date );

return ( true === isset( $difference->days ) ) ? (int) $difference->days : NULL;

}
}
return NULL;
}

/**
* Display an admin notice if license is expiring within 14 days
*/
function ws_ls_display_license_expiry_warning() {

if ( false === ws_ls_has_a_valid_license() ) {
return;
}

$days_until_expiry = ws_ls_how_many_days_until_license_expires();

if ( true === empty( $days_until_expiry ) ) {
return;
}

if ( $days_until_expiry > 14 ) {
return;
}

printf('<div class="notice notice-warning" id="ws-ls-admin-notice" data-wsmd5="">
<p><strong>%s</strong>: %s. <a href="%s?hash=%s" rel="noopener noreferrer" target="_blank" >Renew your license now</a></p>
</div>',
__('Weight Tracker License', WE_LS_SLUG ),
__('Your license expires in less than 14 days. Please renew your license as soon as possible', WE_LS_SLUG ),
WE_LS_UPGRADE_TO_PRO_PLUS_URL,
ws_ls_generate_site_hash()

);

}
add_action('admin_notices', 'ws_ls_display_license_expiry_warning');

// ------------------------------------------------------------------------------------------------------------
// Current licensing
// ------------------------------------------------------------------------------------------------------------
Expand Down
42 changes: 33 additions & 9 deletions includes/shortcode-various.php
Expand Up @@ -114,7 +114,7 @@ function ws_ls_weight_difference_target($user_id = false){

return $display_string;
}
function ws_ls_weight_difference_previous($user_id = false){
function ws_ls_weight_difference_previous( $user_id = false ){
// If not logged in then return no value
if(!is_user_logged_in()) {
return '';
Expand Down Expand Up @@ -188,31 +188,55 @@ function ws_ls_get_weight_extreme($user_id, $recent = false, $unit = "weight_wei
return false;

}
function ws_ls_get_weight_previous($user_id) {
global $wpdb;

$cache_key = $user_id . '-' . WE_LS_CACHE_KEY_WEIGHT_PREVIOUS;

function ws_ls_get_weight_previous( $user_id ) {

$user_id = $user_id ?: get_current_user_id();

global $wpdb;

// Return cache if found!
if ($cache = ws_ls_get_cache($cache_key)) {
if ( $cache = ws_ls_cache_user_get( $user_id, WE_LS_CACHE_KEY_WEIGHT_PREVIOUS ) ) {
return $cache;
}

$table_name = $wpdb->prefix . WE_LS_TABLENAME;
$sql = $wpdb->prepare("SELECT weight_weight FROM $table_name where weight_user_id = %d order by weight_date desc limit 1, 1", $user_id);
$sql = $wpdb->prepare( "SELECT weight_weight FROM $table_name where weight_user_id = %d order by weight_date desc limit 1, 1", $user_id );

$result = $wpdb->get_var($sql);
$result = $wpdb->get_var( $sql );

if ( false === empty( $result ) ) {

$result = floatval($result);
$result = floatval( $result );

ws_ls_cache_user_set( $user_id, WE_LS_CACHE_KEY_WEIGHT_PREVIOUS, $result );

ws_ls_set_cache($cache_key, $result);
return $result;
}

return NULL;
}

/**
*
* Render the shortcode for previos weight [wlt-weight-previous]
*
* @return string
*
*/
function ws_ls_shortcode_previous_weight() {

if ( false === WS_LS_IS_PRO ) {
return '';
}

$kg = ws_ls_get_weight_previous( NULL );

return ( false === empty( $kg ) ) ? we_ls_format_weight_into_correct_string_format( $kg ) : __( 'No previous weight', WE_LS_SLUG );
}
add_shortcode('wlt-weight-previous', 'ws_ls_shortcode_previous_weight');

function ws_ls_get_target_weight_in_kg($user_id = false){

$user_id = (true === empty($user_id)) ? get_current_user_id() : $user_id;
Expand Down
9 changes: 6 additions & 3 deletions pro-features/db.php
Expand Up @@ -186,11 +186,14 @@ function ws_ls_stats_insert_missing_user_ids_into_stats() {
function ws_ls_stats_remove_deleted_user_ids_from_stats() {

global $wpdb;

$stats_table_name = $wpdb->prefix . WE_LS_USER_STATS_TABLENAME;
$data_table_name = $wpdb->prefix . WE_LS_TABLENAME;
$sql = "Delete from $stats_table_name Where user_id not in (Select distinct weight_user_id from $data_table_name)";
$data_table_name = $wpdb->prefix . 'users';

$sql = "Delete from $stats_table_name Where user_id not in ( Select ID from $data_table_name )";

$wpdb->query( $sql );

$wpdb->query($sql);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion pro-features/plus/awards/activate.php
Expand Up @@ -20,7 +20,7 @@ function ws_ls_awards_create_mysql_tables() {

$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
title varchar(40) NOT NULL,
title varchar(200) NOT NULL,
category varchar(20) NOT NULL,
gain_loss varchar(5) NULL DEFAULT NULL,
compare varchar(10) NULL DEFAULT NULL,
Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Expand Up @@ -3,7 +3,7 @@ Contributors: aliakro
Tags: weight, loss, lose, helper, bmi, body, mass, index, graph, track, stones, kg, table, data, plot, target, history, pounds, responsive, chart, measurements, cm, centimeters, inches, hip, waist, bicep, thigh
Requires at least: 4.4.0
Tested up to: 5.0.2
Stable tag: 7.0.5
Stable tag: 7.0.6

License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -155,6 +155,14 @@ Yes. Only recommended if you first installed the plugin at version 1.6 or greate

== Changelog ==

= 7.0.6 =

* Improvement: Added shortcode for user's previous weight [wlt-weight-previous]
* Improvement: Issue 179. Optimised deletion of redundant stats entries.
* Improvement: Issue 195. Increased award title length to 200 characters.
* Improvement: Issue 188. Display an admin warning if the Weight Tracker license expires within 14 days!
* Improvement: Issue 177. Updated Chart.js library.

= 7.0.5 =

* Improvement: Added additional Dutch translations.
Expand Down
8 changes: 4 additions & 4 deletions weight-loss-tracker.php
Expand Up @@ -5,13 +5,13 @@
/**
* Plugin Name: Weight Tracker
* Description: Allow your users to track their weight, measurements and other pieces of custom data. Display in charts, tables, shortcodes and widgets. Manage their data, issue awards, email notifications, etc! Provide advanced data on Body Mass Index (BMI), Basal Metabolic Rate (BMR), Calorie intake, Harris Benedict Formula, Macronutrients Calculator and more.
* Version: 7.0.4
* Version: 7.0.6
* Author: YeKen
* Author URI: https://www.YeKen.uk
* License: GPL2
* Text Domain: weight-loss-tracker
*/
/* Copyright 2018 YeKen.uk
/* Copyright 2019 YeKen.uk
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
Expand All @@ -28,8 +28,8 @@
*/

define('WS_LS_ABSPATH', plugin_dir_path( __FILE__ ));
define('WE_LS_CURRENT_VERSION', '7.0.5');
define('WE_LS_DB_VERSION', '7.0.5');
define('WE_LS_CURRENT_VERSION', '7.0.6');
define('WE_LS_DB_VERSION', '7.0.6');

// -----------------------------------------------------------------------------------------
// AC: Activate / Deactivate / Uninstall Hooks
Expand Down

0 comments on commit 6e042ba

Please sign in to comment.