Skip to content

Commit

Permalink
Merge pull request #565 from alicolville/bmi-warnings
Browse files Browse the repository at this point in the history
10.6
  • Loading branch information
alicolville committed Aug 25, 2023
2 parents f89f74c + 6ca0521 commit 83748a5
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/shortcodes/wt-kiosk.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The shortcode supports the following arguments:
| Argument | Description | Options | Example |
|--|--|--|--|
| bmi-format | Specify the format that BMI should be displayed in. |'label' (default), 'both' or 'index' | [wt-kiosk bmi-format='both'] |
| bmi-alert-if-below | If specified, show an alert if the user's BMI is below this value|false (default) or numeric | [wt bmi-alert-if-below='17'] |
| bmi-alert-if-above | If specified, show an alert if the user's BMI is above this value|false (default) or numeric | [wt bmi-alert-if-above='30'] |
|kiosk-barcode-scanner|If set to true, a barcode scanner shall appear at the top when in Kiosk mode. Please note, the barcode/QR code must contain a WordPress user ID e.g. 233. Upon a successful scan, the relevant user record shall be loaded.|True or False (default)|[wt-kiosk kiosk-mode=true kiosk-barcode-scanner=true]
|kiosk-barcode-scanner-camera|If set to true, a barcode/QR scanner that uses the device's cameras shall be displayed|True (true) or False|[wt-kiosk kiosk-mode=true kiosk-barcode-scanner=true kiosk-barcode-scanner-camera=true ]
|kiosk-barcode-scanner-lazer|If set to true, support for an external barcode scanner shall be displayed|True (true) or False|[wt-kiosk kiosk-mode=true kiosk-barcode-scanner=true kiosk-barcode-scanner-lazer=true ]
Expand Down
2 changes: 2 additions & 0 deletions docs/shortcodes/wt.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ The shortcode supports the following arguments:
| Argument | Description | Options | Example |
|--|--|--|--|
| bmi-format | Specify the format that BMI should be displayed in. |'label' (default), 'both' or 'index' | [wt bmi-format='both'] |
| bmi-alert-if-below | If specified, show an alert if the user's BMI is below this value|false (default) or numeric | [wt bmi-alert-if-below='17'] |
| bmi-alert-if-above | If specified, show an alert if the user's BMI is above this value|false (default) or numeric | [wt bmi-alert-if-above='30'] |
| custom-field-groups | Specify one or more custom field group slugs. Specifying groups will ensure that only custom fields within those groups are displayed on the control. | An individual slug or multiple slugs comma delimited. | [wt custom-field-groups='measurements'] [wt custom-field-groups='measurements,fitness-test'] |
| custom-field-slugs | Specify one or more custom field slugs. Specifying slugs will ensure only the fields specified are displayed on the control. | An individual slug or multiple slugs comma delimited. | [wt custom-field-slugs='waist'] [wt custom-field-slugs='waist,bicep,distance-run'] |
|disable-main-font|If set to true will disable the main font used in the shortcode|True or False (default)|[wt disable-main-font=true]
Expand Down
2 changes: 1 addition & 1 deletion includes/admin-pages/settings/page-settings-generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function ws_ls_settings_page_generic() {
<option value="yes" <?php selected( $awards_enabled, 'yes' ); ?>><?php echo __( 'Yes', WE_LS_SLUG ); ?></option>
<option value="no" <?php selected( $awards_enabled, 'no' ); ?>><?php echo __( 'No', WE_LS_SLUG ); ?></option>
</select>
<p> <?php echo __( 'If set to yes, when a weight entry is deleted (for awards given in versions 10.5 and above) any awards that were given at that time are also deleted. Please note, awards will automatically be re-added when a new entry is added if the entry meets the award criteria. ', WE_LS_SLUG ); ?> "></p>
<p> <?php echo __( 'If set to yes, when a weight entry is deleted (for awards given in versions 10.5 and above) any awards that were given at that time are also deleted. Please note, awards will automatically be re-added when a new entry is added if the entry meets the award criteria. ', WE_LS_SLUG ); ?></p>
</td>
</tr>
</table>
Expand Down
39 changes: 38 additions & 1 deletion includes/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,43 @@ function ws_ls_component_bmi( $args = [] ) {
);
}

/**
* Display warning notifications for BMI if they fall above or below a certain value
* @param $args
*
* @return string
*/
function ws_ls_component_bmi_warning_notifications( $args ) {

$args = wp_parse_args( $args, [
'bmi-alert-if-above' => null,
'bmi-alert-if-below' => null,
'user-id' => get_current_user_id()
] );

$bmi = ws_ls_get_bmi_for_user( $args[ 'user-id' ] );

if ( true === empty( $bmi ) ) {
return '';
}

$html = '';
$prefix = ( false === empty( $args[ 'kiosk-mode'] ) ) ? __( 'User\'s ', WE_LS_SLUG ) : __( 'Your ', WE_LS_SLUG );

if ( false === empty( $args[ 'bmi-alert-if-above' ] ) &&
(float) $bmi > (float) $args[ 'bmi-alert-if-above' ] ) {
$html .= ws_ls_component_alert( [ 'message' => $prefix . sprintf( __( 'BMI is above %s.', WE_LS_SLUG ), $args[ 'bmi-alert-if-above' ] ), 'type' => 'danger' ] );
}

if ( false === empty( $args[ 'bmi-alert-if-below' ] ) &&
$bmi < (float) $args[ 'bmi-alert-if-below' ] ) {
$html .= ws_ls_component_alert( [ 'message' => $prefix . sprintf( __( 'BMI is below %s.', WE_LS_SLUG ), $args[ 'bmi-alert-if-below' ] ), 'type' => 'danger' ] );
}

return $html;

}

/**
* BMR component
* @param array $args
Expand Down Expand Up @@ -1110,7 +1147,7 @@ function ws_ls_component_user_search( $arguments ) {

wp_enqueue_style( 'wt-selectize', plugins_url( '../assets/css/libraries/selectize.default.min.css', __FILE__ ), [], WE_LS_CURRENT_VERSION );
wp_enqueue_script( 'wt-selectize', plugins_url( '../assets/js/libraries/selectize.min.js', __FILE__ ), [ 'yk-uikit' ], WE_LS_CURRENT_VERSION, true );
wp_enqueue_script( 'wt-user-search', plugins_url( '../assets/js/user-search.' . ws_ls_use_minified() . 'js', __FILE__ ), [ 'wt-selectize' ], WE_LS_CURRENT_VERSION, true );
wp_enqueue_script( 'wt-user-search', plugins_url( '../assets/js/user-search.' . ws_ls_use_minified() . 'js', __FILE__ ), [ 'jquery', 'wt-selectize' ], WE_LS_CURRENT_VERSION, true );

$data_stats = ws_ls_db_entries_count();

Expand Down
8 changes: 4 additions & 4 deletions includes/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function ws_ls_enqueue_files(){

wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'ws-ls-js', plugins_url( '../assets/js/ws-ls' . $minified . '.js', __FILE__ ), [], WE_LS_CURRENT_VERSION, true );
wp_enqueue_script( 'ws-ls-js-form', plugins_url( '../assets/js/ws-ls-entry-form' . $minified . '.js', __FILE__ ), [], WE_LS_CURRENT_VERSION, true );
wp_enqueue_script( 'ws-ls-js-form', plugins_url( '../assets/js/ws-ls-entry-form' . $minified . '.js', __FILE__ ), [ 'jquery' ], WE_LS_CURRENT_VERSION, true );

// Add localization data for JS
wp_localize_script('ws-ls-js', 'ws_ls_config', ws_ls_config_js() );
Expand Down Expand Up @@ -139,7 +139,7 @@ function ws_ls_enqueue_uikit( $include_theme = true, $include_font = true, $load
$uikit_js_enqueued = true;

if ( false === empty( $load_ui_script ) ) {
wp_enqueue_script( 'yk-uikit-' . $load_ui_script, plugins_url( '../assets/js/' . $load_ui_script . $minified . '.js', __FILE__ ), [] , WE_LS_CURRENT_VERSION );
wp_enqueue_script( 'yk-uikit-' . $load_ui_script, plugins_url( '../assets/js/' . $load_ui_script . $minified . '.js', __FILE__ ), [ 'jquery' ] , WE_LS_CURRENT_VERSION, true );
}

}
Expand All @@ -160,7 +160,7 @@ function ws_ls_enqueue_files_ws_ls_only() {

$minified = ws_ls_use_minified();

wp_enqueue_script( 'ws-ls-js', plugins_url( '../assets/js/ws-ls' . $minified . '.js', __FILE__ ), [], WE_LS_CURRENT_VERSION, true );
wp_enqueue_script( 'ws-ls-js', plugins_url( '../assets/js/ws-ls' . $minified . '.js', __FILE__ ), [ 'jquery' ], WE_LS_CURRENT_VERSION, true );

// Add localization data for JS
wp_localize_script('ws-ls-js', 'ws_ls_config', ws_ls_config_js() );
Expand Down Expand Up @@ -226,7 +226,7 @@ function ws_ls_enqueue_form_dependencies() {
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-validate',plugins_url( '../assets/js/libraries/jquery.validate.min.js', __FILE__ ), [ 'jquery' ], WE_LS_CURRENT_VERSION );
wp_enqueue_script( 'jquery-validate-additional',plugins_url( '../assets/js/libraries/additional-methods.min.js', __FILE__ ), [ 'jquery', 'jquery-validate' ], WE_LS_CURRENT_VERSION );
wp_enqueue_script( 'ws-ls-js', plugins_url( '../assets/js/ws-ls-entry-form' . $minified . '.js', __FILE__ ), [], WE_LS_CURRENT_VERSION, true );
wp_enqueue_script( 'ws-ls-js', plugins_url( '../assets/js/ws-ls-entry-form' . $minified . '.js', __FILE__ ), [ 'jquery' ], WE_LS_CURRENT_VERSION, true );
wp_localize_script( 'ws-ls-js', 'ws_ls_config', ws_ls_config_js() );
}

Expand Down
4 changes: 4 additions & 0 deletions includes/shortcode-wt.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function ws_ls_shortcode_wt( $user_defined_arguments ) {
'custom-field-groups' => '', // If specified, only show custom fields that are within these groups
'custom-field-slugs' => '', // If specified, only show the custom fields that are specified
'bmi-format' => 'both', // Format for display BMI
'bmi-alert-if-below' => false, // If specified, show an alert if BMI is below this value
'bmi-alert-if-above' => false, // If specified, show an alert if BMI is above this value
'disable-main-font' => false, // If set to true, don't include the main font
'disable-theme-css' => false, // If set to true, don't include the additional theme CSS used
'enable-week-ranges' => false, // Enable Week Ranges?
Expand Down Expand Up @@ -162,6 +164,8 @@ function ws_ls_shortcode_wt( $user_defined_arguments ) {
$html .= ws_ls_notifications_shortcode( $shortcode_arguments, true );
}

$html .= ws_ls_component_bmi_warning_notifications( $shortcode_arguments );

// Tab menu
$html .= ws_ls_wt_tab_menu( $shortcode_arguments );

Expand Down
32 changes: 32 additions & 0 deletions pro-features/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

defined('ABSPATH') or die("Jog on!");

/**
* Fetch BMI value for user
*
* @param $user_id
*
* @return float|null
*/
function ws_ls_get_bmi_for_user( $user_id ) {

if ( $cache = ws_ls_cache_user_get($user_id, 'bmi-raw' ) ) {
return $cache;
}

$height = ws_ls_user_preferences_get( 'height', $user_id );

if ( true === empty( $height ) ) {
return NULL;
}

$weight = ws_ls_entry_get_latest_kg( $user_id );

if ( true === empty( $weight ) ) {
return NULL;
}

$bmi = ws_ls_calculate_bmi( $height, $weight );

ws_ls_cache_user_set( $user_id, 'bmi-raw', $bmi );

return $bmi;
}

/**
* Fetch BMI value for data table
*
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: aliakro
Tags: weight,tracker,chart,bmi,bmr,macronutrient,measure,awards,custom fields,history,measurements,data
Requires at least: 5.7
Tested up to: 6.3
Stable tag: 10.5
Stable tag: 10.6
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -152,6 +152,12 @@ Measurements are created using Custom Fields. You can therefore specify the unit

== Changelog ==

= 10.6 =

* New feature: Added the arguments "bmi-alert-if-below" and "bmi-alert-if-above" to [wt] to show an alert if the user's BMI is below or above the specified value.
* New feature: Added the arguments "bmi-alert-if-below" and "bmi-alert-if-above" to [wt-kiosk] to show an alert if the user's BMI is below or above the specified value.
* Improvement: Some jQuery scripts are now loaded in the footer rather than the header.

= 10.5 =

* Improvement: Added a new setting "Delete awards when weight entry deleted?". If enabled, any awards that were awarded to a user will be deleted when the weight entry is deleted (only works with awards added in version 10.5 onwards). Read more: https://github.com/alicolville/Weight-Tracker/issues/549
Expand Down
4 changes: 2 additions & 2 deletions weight-loss-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Plugin Name: Weight Tracker
* Description: Allow your users to track their weight, body measurements, photos 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: 10.5
* Version: 10.6
* Requires at least: 5.7
* Tested up to: 6.3
* Requires PHP: 7.2
Expand All @@ -18,7 +18,7 @@
*/

define( 'WS_LS_ABSPATH', plugin_dir_path( __FILE__ ) );
define( 'WE_LS_CURRENT_VERSION', '10.5' );
define( 'WE_LS_CURRENT_VERSION', '10.6' );
define( 'WE_LS_TITLE', 'Weight Tracker' );
define( 'WE_LS_SLUG', 'weight-loss-tracker' );
define( 'WE_LS_LICENSE_TYPES_URL', 'https://docs.yeken.uk/features.html' );
Expand Down

0 comments on commit 83748a5

Please sign in to comment.