From 01d5739d85f0cd75f825a59ee50f1114cd01899c Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Fri, 8 Sep 2023 12:03:18 +0100 Subject: [PATCH 01/31] Strip out various old shortcodes and legacy docs. --- docs/shortcodes.md | 1 - docs/shortcodes/wt-legacy.md | 77 -------------------------------- includes/shortcode-wt-legacy.php | 2 - includes/shortcode-wt.php | 3 +- readme.txt | 6 +++ 5 files changed, 7 insertions(+), 82 deletions(-) delete mode 100644 docs/shortcodes/wt-legacy.md diff --git a/docs/shortcodes.md b/docs/shortcodes.md index 5fc4b4e6..37bdb8c6 100644 --- a/docs/shortcodes.md +++ b/docs/shortcodes.md @@ -33,7 +33,6 @@ The majority of the public facing functionality are implemented using [WordPress |[[wt-group-view-as-table]]({{ site.baseurl }}/shortcodes/wt-group-view-as-table.html)|Display a table of summary information for users within a given [group]({{ site.baseurl }}/groups.html). |[[wt-waist-to-hip-ratio-calculator]]({{ site.baseurl }}/shortcodes/wt-waist-to-hip-ratio-calculator.html)|Displays a Waist-to-Hip ratio calculator for your users to use.| |[[wt-if]]({{ site.baseurl }}/shortcodes/wt-if.html)|Add conditional display logic based on whether WT data has been completed or not.| -|[[wt-legacy]]({{ site.baseurl }}/shortcodes/wt-legacy.html) |A legacy version of [[wt]]({{ site.baseurl }}/shortcodes/wt.html).| |[[wt-league-table]]({{ site.baseurl }}/shortcodes/wt-league-table.html)|Display a league table of Weight Tracker users.| |[[wt-macronutrients]]({{ site.baseurl }}/shortcodes/wt-macronutrients.html)|Displays a macronutrient figure from the macronutrient intake calculations.| |[[wt-macronutrients-table]]({{ site.baseurl }}/shortcodes/wt-macronutrients-table.html)|Displays recommendations on the best way to split your calorie intake.| diff --git a/docs/shortcodes/wt-legacy.md b/docs/shortcodes/wt-legacy.md deleted file mode 100644 index 39668415..00000000 --- a/docs/shortcodes/wt-legacy.md +++ /dev/null @@ -1,77 +0,0 @@ -## [wt-legacy] - -### DEPRECATED. Soon to be removed from the plugin and has been replaced with [[wt]]({{ site.baseurl }}/shortcodes/wt.html). - -This is the most popular shortcode for the Weight Tracker plugin and displays upto four sections / tabs when a user is logged into WordPress. - -> The following shortcode is available in both the free and [Pro/Pro Plus]({{ site.baseurl }}/features.html) version of the plugin. The Pro version has the following additional features: -> * Support for measurements and [custom fields]({{ site.baseurl }}/custom-fields.html). -> * Advanced data table for viewing weight entries. Supporting sorting, paging, editing and deleting. -> * Support for BMI, BMR, suggested calorie intake and Macronutrients. -> * A settings page to allow the user to tailor the plugin to their needs. -> * User Settings - -*Note: Please only place this shortcode once per page. If placed more than once you may experience unstable results.* - -**Overview** - -![Main image](http://yeken.uk/wp-content/uploads/2021/03/wt-e1615930590182.png) - -Displays a chart of the user's weight and custom field ([Pro feature]({{ site.baseurl }}/upgrade.html)) entries in either imperial or metric. The appearance of chart can be customised within the admin settings to change its appearance, type, maximum number of points, etc. - -Below the chart is a target form and weight / custom field entry form. If enabled, the target form allows the user to enter their desired target weight. This target is then displayed on the chart and used by other shortcodes / widgets. - -The main feature of the Overview screen is the ability to enter a weight for the given day or overwrite a previous entry. These entries are then stored against the user's record in chronological order and displayed on the chart and “In Detail” tab. - -[Pro]({{ site.baseurl }}/upgrade.html) users that have enabled measurements will be presented with additional fields that allow your user's to enter measurements for various parts of their body. Measurement entries are displayed alongside the weight entries - -**In detail** - - “The in Detail” tab has another target form for ease of use but its primary function is to display all of the user's weight and custom field entries in tabular format. The [Pro]({{ site.baseurl }}/upgrade.html) version has an improved data table with features such as sortable, expandable and contains links to edit / delete each weight entry. The weight entries can also be filtered by the drop down to show all entries or select them by a week by week basis. This filtering is reflected in the table and the chart. - -**Advanced** - -![Advanced tab](https://yeken.uk/wp-content/uploads/2021/03/advanced-tab-e1616003559458.png) - -With a [Pro Plus](https://shop.yeken.uk/product/weight-tracker-pro-plus/) license an additional tab is present with "Advanced" data. This tab contains the following information; - -- BMI (Body Mass Index) -- BMR (Basal Metabolic Rate) -- Suggested Calorie Intake -- Macronutrients - -For more information on these values, please read our guide on [Weight Tracker calculations]({{ site.baseurl }}/calculations.html). - -**Settings** - - If enabled and you have [Pro]({{ site.baseurl }}/upgrade.html), the last tab presents the logged in user with a settings page. This allows users to specify their height (if BMI enabled), select their preferred measurement units and date format. - -They also have the option to delete their existing data. - -**Shortcode arguments** - -The shortcode supports the following arguments: - -| Argument | Description | Options | Example | -|--|--|--|--| -| allow-delete-data | If set to false (default is true), the section allowing users to delete their own data is hidden. | True (default) or false | [wt-legacy allow-delete-data="false"] | -| bmi-format | Specify the format that BMI should be displayed in. |'label' (default), 'both' or 'index' | [wt-legacy bmi-format='both'] | -| custom-field-groups (8.4+) | 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-legacy custom-field-groups='measurements'] [wt-legacy custom-field-groups='measurements,fitness-test'] | -| custom-field-slugs (8.4+) | 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-legacy custom-field-slugs='waist'] [wt-legacy custom-field-slugs='waist,bicep,distance-run'] | -| disable-advanced-tables |If set to true, disable advanced data tables (responsive with delete and add / edit options). | True or false (default). | [wt-legacy disable-advanced-tables=true] | -| disable-second-check | Disables the check to see if the [wt-legacy] shortcode has already been placed on the page. Some themes and plugins may throw an error when this check is enabled. | True or false (default). | [wt-legacy disable-second-check=true] | -| disable-tabs | If set to true, disable tabs and display all content on one "page" | True or false (default). | [wt-legacy disable-tabs=true] | | -| enable-week-ranges | If enabled, a drop down of weeks shall be displayed above the "Weight History" table. When a week is selected, the table will be filtered to only show entries within that week. | True or false (default). | [wt-legacy enable-week-ranges=true] | -| hide-advanced-narrative | If set to true (default is false) hide the text on the Advanced tab which explains each section. | True or false (default). | [wt-legacy hide-advanced-narrative=true] | -| hide-chart-overview (8.4+) | Hide the chart from the "Overview" tab. | True or false (default). | [wt-legacy hide-chart-overview=true] | -| hide-first-target-form | Hide the target form from the Overview tab. | True or false (default). | [wt-legacy hide-first-target-form=true] | -| hide-notes | If set to true (default is false) hide the "notes" section of the form. | True or false (default). | [wt-legacy hide-notes=true] | -| hide-photos | If set to true (default is false) hide the photo upload section of the form. | True or false (default). | [wt-legacy hide-photos=true] | -| hide-tab-advanced | If set to true (default is false) hide the Advanced tab. | True or false (default). | [wt-legacy hide-tab-advanced=true] | -| hide-tab-descriptions | If set to true (default is false) hide the descriptions under the tab title. | True or false (default). | [wt-legacy hide-tab-descriptions=true] | -| hide-tab-photos | If set to true (default is false) hide the Photos tab. | True or false (default). | [wt-legacy hide-tab-photos=true] | -| hide-second-target-form | Hide the target form from the "In Detail" tab. | True or false (default). |[wt-legacy hide-second-target-form=true] | -| min-chart-points|Specifies how many weight entries must be present before the chart is displayed. By default, it is set to 2.|A numeric value. Default 2.|[wt-legacy min-chart-points=0]| -| show-add-button | If true, an "Add Entry" button is displayed above the chart. Clicking this button jumps the user to the weight entry form. | True or false (default). | [wl show-add-button=true] | -| show-chart-history (8.4+) | If true, display a chart on the "History" tab. | True or false (default). | [wt-legacy show-chart-history=true] | -|weight-mandatory|By default, for a weight form, it is mandatory for a weight to be entered. If setting this argument to false, the form can be submitted with out.|true or false (default)|[wt-legacy weight-mandatory='true'] \ No newline at end of file diff --git a/includes/shortcode-wt-legacy.php b/includes/shortcode-wt-legacy.php index 5ff51863..84abf2e1 100755 --- a/includes/shortcode-wt-legacy.php +++ b/includes/shortcode-wt-legacy.php @@ -282,8 +282,6 @@ function ws_ls_shortcode_wt_legacy( $user_defined_arguments ) { return $html_output; } -add_shortcode( 'wlt', 'ws_ls_shortcode_wt_legacy' ); -add_shortcode( 'wt-legacy', 'ws_ls_shortcode_wt_legacy' ); /** * Embed Chart diff --git a/includes/shortcode-wt.php b/includes/shortcode-wt.php index 02c16f6b..6628415b 100644 --- a/includes/shortcode-wt.php +++ b/includes/shortcode-wt.php @@ -186,8 +186,7 @@ function ws_ls_shortcode_wt( $user_defined_arguments ) { return $html . ''; } -add_shortcode( 'wt', 'ws_ls_shortcode_wt' ); -add_shortcode( 'wt-beta', 'ws_ls_shortcode_wt' ); +add_shortcode( 'wt', 'ws_ls_shortcode_wt' );; /** * Wrapper for [wt] to enable shortcode mode diff --git a/readme.txt b/readme.txt index 769ae23a..1f9cd483 100644 --- a/readme.txt +++ b/readme.txt @@ -152,6 +152,12 @@ Measurements are created using Custom Fields. You can therefore specify the unit == Changelog == += 10.7 = + +* Maintenance: Removed support for the shortcode [wt-beta], you must use [wt] instead. +* Maintenance: Removed support for the shortcode [wlt], you must use [wt] instead. +* Maintenance: Removed support for the shortcode [wt-legacy], you must use [wt] instead. + = 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. From 2fc5e036a3863c192ff2342b49b0af94ca122917 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Fri, 8 Sep 2023 12:05:45 +0100 Subject: [PATCH 02/31] Move to wt file --- includes/shortcode-wt-legacy.php | 60 ------------------------------- includes/shortcode-wt.php | 61 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/includes/shortcode-wt-legacy.php b/includes/shortcode-wt-legacy.php index 84abf2e1..e47adedb 100755 --- a/includes/shortcode-wt-legacy.php +++ b/includes/shortcode-wt-legacy.php @@ -283,66 +283,6 @@ function ws_ls_shortcode_wt_legacy( $user_defined_arguments ) { } -/** - * Embed Chart - * - * @param $weight_data - * @param $shortcode_arguments - * - * @return string - */ -function ws_ls_shortcode_embed_chart( $weight_data, $shortcode_arguments ) { - - $shortcode_arguments = wp_parse_args( $shortcode_arguments, [ 'custom-field-groups' => [], - 'custom-field-slugs' => [], - 'hide-title' => false, - 'legend-position' => 'top', - 'uikit' => false, - 'hide-custom-fields' => false, - 'user-id' => get_current_user_id() - - ] ); - - $html_output = ''; - - // Do we have enough data points to display a chart? - if ( ( false === empty( $weight_data ) && count( $weight_data ) >= $shortcode_arguments[ 'min-chart-points' ] ) || - ( true === empty( $weight_data ) && 0 === $shortcode_arguments[ 'min-chart-points' ] ) ) { - - // Display "Add Weight" button? - if( false === empty( $shortcode_arguments[ 'show-add-button' ] ) && - true === ws_ls_to_bool( $shortcode_arguments[ 'show-add-button' ] ) ) { - $html_output .= sprintf('
- -
', - __( 'Add a weight entry', WE_LS_SLUG ) - ); - } - - if ( false === $shortcode_arguments[ 'hide-title'] ) { - $html_output .= ws_ls_title( __( 'In a chart', WE_LS_SLUG ) ); - } - - $html_output .= ws_ls_display_chart( $weight_data, [ 'custom-field-groups' => $shortcode_arguments[ 'custom-field-groups' ], - 'custom-field-slugs' => $shortcode_arguments[ 'custom-field-slugs' ], - 'legend-position' => $shortcode_arguments[ 'legend-position' ], - 'user-id' => $shortcode_arguments[ 'user-id' ], - 'show-meta-fields' => ! $shortcode_arguments[ 'hide-custom-fields' ] - ] ); - - } else { - - $message = sprintf( __( 'A graph shall appear when %d or more weight entries have been entered.', WE_LS_SLUG ), - $shortcode_arguments[ 'min-chart-points' ] ); - - $html_output .= ( true === empty( $shortcode_arguments[ 'uikit' ] ) ) ? - ws_ls_display_blockquote( $message ) : - ws_ls_component_alert( [ 'message' => $message, 'type' => 'warning', 'closable' => false ] ); - - } - - return $html_output; -} /** * HTML for opening tab diff --git a/includes/shortcode-wt.php b/includes/shortcode-wt.php index 6628415b..b4528795 100644 --- a/includes/shortcode-wt.php +++ b/includes/shortcode-wt.php @@ -651,3 +651,64 @@ function ws_ls_wt_link_goto_tab( $tab ) { return esc_url( add_query_arg( 'tab', $tab, $link ) ); } + +/** + * Embed Chart + * + * @param $weight_data + * @param $shortcode_arguments + * + * @return string + */ +function ws_ls_shortcode_embed_chart( $weight_data, $shortcode_arguments ) { + + $shortcode_arguments = wp_parse_args( $shortcode_arguments, [ 'custom-field-groups' => [], + 'custom-field-slugs' => [], + 'hide-title' => false, + 'legend-position' => 'top', + 'uikit' => false, + 'hide-custom-fields' => false, + 'user-id' => get_current_user_id() + + ] ); + + $html_output = ''; + + // Do we have enough data points to display a chart? + if ( ( false === empty( $weight_data ) && count( $weight_data ) >= $shortcode_arguments[ 'min-chart-points' ] ) || + ( true === empty( $weight_data ) && 0 === $shortcode_arguments[ 'min-chart-points' ] ) ) { + + // Display "Add Weight" button? + if( false === empty( $shortcode_arguments[ 'show-add-button' ] ) && + true === ws_ls_to_bool( $shortcode_arguments[ 'show-add-button' ] ) ) { + $html_output .= sprintf('
+ +
', + __( 'Add a weight entry', WE_LS_SLUG ) + ); + } + + if ( false === $shortcode_arguments[ 'hide-title'] ) { + $html_output .= ws_ls_title( __( 'In a chart', WE_LS_SLUG ) ); + } + + $html_output .= ws_ls_display_chart( $weight_data, [ 'custom-field-groups' => $shortcode_arguments[ 'custom-field-groups' ], + 'custom-field-slugs' => $shortcode_arguments[ 'custom-field-slugs' ], + 'legend-position' => $shortcode_arguments[ 'legend-position' ], + 'user-id' => $shortcode_arguments[ 'user-id' ], + 'show-meta-fields' => ! $shortcode_arguments[ 'hide-custom-fields' ] + ] ); + + } else { + + $message = sprintf( __( 'A graph shall appear when %d or more weight entries have been entered.', WE_LS_SLUG ), + $shortcode_arguments[ 'min-chart-points' ] ); + + $html_output .= ( true === empty( $shortcode_arguments[ 'uikit' ] ) ) ? + ws_ls_display_blockquote( $message ) : + ws_ls_component_alert( [ 'message' => $message, 'type' => 'warning', 'closable' => false ] ); + + } + + return $html_output; +} \ No newline at end of file From af1d8d3444537bde12600532f7cdd17555b2c6e8 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Fri, 8 Sep 2023 12:09:57 +0100 Subject: [PATCH 03/31] Dropped legacy code and moved code where needed. --- includes/functions.php | 9 + includes/shortcode-wt-legacy.php | 338 ------------------------------- weight-loss-tracker.php | 1 - 3 files changed, 9 insertions(+), 339 deletions(-) delete mode 100755 includes/shortcode-wt-legacy.php diff --git a/includes/functions.php b/includes/functions.php index 42221234..426b6b63 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1033,6 +1033,15 @@ function ws_ls_blockquote_login_prompt( ) { return ws_ls_display_blockquote( __( 'You must be logged in to view or edit your data.' , WE_LS_SLUG ) , '', false, true ); } +/** + * @param $title_text + * + * @return string + */ +function ws_ls_title( $title_text ) { + return sprintf( '

%s

', esc_html( $title_text ) ); +} + /** * Calculate max upload size (taken from Drupal) * @return float|int diff --git a/includes/shortcode-wt-legacy.php b/includes/shortcode-wt-legacy.php deleted file mode 100755 index e47adedb..00000000 --- a/includes/shortcode-wt-legacy.php +++ /dev/null @@ -1,338 +0,0 @@ - 2, // Minimum number of data entries before chart is shown - 'hide-first-target-form' => false, // Hide first Target form - 'hide-second-target-form' => false, // Hide second Target form - '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' => 'label', // Format for display BMI - 'show-add-button' => false, // Display a "Add weight" button above the chart. - 'show-chart-history' => false, // Display a chart on the History tab. - 'allow-delete-data' => true, // Show "Delete your data" section - 'hide-notes' => ws_ls_setting_hide_notes(), // Hide notes field - 'hide-photos' => false, // Hide photos part of form - 'hide-chart-overview' => false, // Hide chart on the overview tab - 'hide-tab-photos' => false, // Hide Photos tab - 'hide-tab-advanced' => false, // Hide Advanced tab (macroN, calories, etc) - 'hide-tab-descriptions' => ws_ls_option_to_bool( 'ws-ls-tab-hide-descriptions', 'yes' ), // Hide tab descriptions - 'hide-advanced-narrative' => false, // Hide text describing BMR, MarcoN, etc - 'disable-advanced-tables' => false, // Disable advanced data tables. - 'disable-tabs' => false, // Disable using tabs. - 'disable-second-check' => false, // Disable check to see if [wlt] placed more than once - 'enable-week-ranges' => false, // Enable Week Ranges? - 'user-id' => get_current_user_id(), - 'weight-mandatory' => true, // Is weight mandatory? - ], $user_defined_arguments ); - - if ( true === $ws_ls_wlt_already_placed && false === ws_ls_to_bool( $shortcode_arguments['disable-second-check'] ) ) { - return sprintf('

%s

', __( 'This shortcode can only be placed once on a page / post. To disable this check, try: [wt disable-second-check=true]', WE_LS_SLUG ) ); - } - - ws_ls_enqueue_files(); - - // Display error if user not logged in - if ( false === is_user_logged_in() ) { - return ws_ls_display_blockquote( __( 'You need to be logged in to record your weight.', WE_LS_SLUG ) , '', false, true ); - } - - $user_id = (int) $shortcode_arguments[ 'user-id' ]; - $use_tabs = ( false === ws_ls_to_bool( $shortcode_arguments[ 'disable-tabs' ] ) ); - $show_advanced_tab = ( false === ws_ls_to_bool( $shortcode_arguments[ 'hide-tab-advanced' ] ) && true === WS_LS_IS_PRO_PLUS ); - $show_photos_tab = ( false === ws_ls_to_bool( $shortcode_arguments[ 'hide-tab-photos' ] ) && true === ws_ls_meta_fields_photo_any_enabled( true ) ); - $week_ranges_enabled = ws_ls_to_bool( $shortcode_arguments[ 'enable-week-ranges' ] ); - $shortcode_arguments[ 'min-chart-points' ] = (int) $shortcode_arguments[ 'min-chart-points' ]; - $html_output = ''; - - $html_output .= ws_ls_wt_legacy_notice(); - - // If a form was previously submitted then display resulting message! - if ( false === empty( $save_response[ 'message' ] ) ){ - $html_output .= $save_response[ 'message' ]; - } - - if( 'true' === ws_ls_querystring_value( 'user-preference-saved', 'true' ) ) { - $html_output .= ws_ls_blockquote_success( __( 'Your settings have been successfully saved!', WE_LS_SLUG ) ); - } elseif( 'true' === ws_ls_querystring_value( 'user-delete-all', 'true' ) ) { - $html_output .= ws_ls_blockquote_success( __( 'Your data has successfully been deleted.', WE_LS_SLUG ) ); - } - - $selected_week_number = ( true === $week_ranges_enabled ) ? ws_ls_post_value_numeric( 'week-number' ) : NULL; - $weight_data = ws_ls_entries_get( [ 'week' => $selected_week_number, - 'prep' => true, - 'week' => $selected_week_number, - 'reverse' => true, - 'sort' => 'desc' ] ); - - // If enabled, render tab header - if ( $use_tabs ) { - - $hide_tab_descriptions = ws_ls_to_bool( $shortcode_arguments[ 'hide-tab-descriptions' ] ); - - $html_output .= '
-
-
    '; - - $tabs = [ - [ - 'icon' => 'fa-line-chart', - 'title' => __( 'Overview', WE_LS_SLUG ), - 'description' => __( 'Chart and add a new entry', WE_LS_SLUG ) - ], - [ - 'icon' => 'fa-table', - 'title' => __( 'History', WE_LS_SLUG ), - 'description' => ( true === WS_LS_IS_PRO ) ? __( 'View all of your entries', WE_LS_SLUG ) : __( 'View your latest entries', WE_LS_SLUG ) - ] - - ]; - - // Show Photos Tab? - if ( true === $show_photos_tab ) { - - $tabs[] = [ - 'icon' => 'fa-picture-o', - 'title' => __( 'Photos', WE_LS_SLUG ), - 'description' => __( 'View a gallery of your photos', WE_LS_SLUG ) - ]; - } - - // Show Advanced Tab? - if ( true === $show_advanced_tab ) { - - $tabs[] = [ - 'icon' => 'fa-university', - 'title' => __( 'Advanced', WE_LS_SLUG ), - 'description' => __( 'BMI, BMR, Calories and Macronutrients', WE_LS_SLUG ) - ]; - } - - // If enabled, have a third tab to allow users to manage their own settings! - if ( true === ws_ls_user_preferences_is_enabled() ) { - - $tabs[] = [ - 'icon' => 'fa-cog', - 'title' => __( 'Preferences', WE_LS_SLUG ), - 'description' => __( 'Customise this tool for you', WE_LS_SLUG ) - ]; - } - - foreach ( $tabs as $tab ) { - - $html_output .= sprintf( '
  • - %2$s%3$s -
  • ', - $tab[ 'icon' ], - $tab[ 'title' ], - ( false === $hide_tab_descriptions ) ? sprintf( '%s', $tab[ 'description' ] ) : '' ); - } - - $html_output .= '
-
'; - } - - // Start Chart Tab - $html_output .= ws_ls_start_tab("wlt-chart", $use_tabs); - - // Display chart? - if ( false === ws_ls_to_bool( $shortcode_arguments[ 'hide-chart-overview' ] ) ) { - $html_output .= ws_ls_shortcode_embed_chart( $weight_data, $shortcode_arguments ); - } - - // Include target form? - if ( true === ws_ls_targets_enabled() && false === ws_ls_to_bool( $shortcode_arguments[ 'hide-first-target-form' ] ) ) { - $html_output .= ws_ls_form_weight( [ 'type' => 'target', 'css-class-form' => 'ws-ls-target-form', 'user-id' => $user_id, 'hide-confirmation' => true ] ) . '
'; - } - - // Display "Add Weight" anchor? - if(true == $shortcode_arguments['show-add-button']) { - $html_output .= ''; - } - - $entry_id = ws_ls_querystring_value('ws-edit-entry', true); - - // Are we in front end and editing enabled, and of course we want to edit, then do so! - if( false === empty( $entry_id ) ) { - - //If we have a Redirect URL, base decode. - $redirect_url = ws_ls_querystring_value( 'redirect' ); - - if ( false === empty( $redirect_url ) ) { - $redirect_url = base64_decode( $redirect_url ); - } - - $html_output .= ws_ls_form_weight( [ 'css-class-form' => 'ws-ls-main-weight-form', - 'user-id' => $user_id, - 'entry-id' => $entry_id, - 'hide-fields-photos' => ws_ls_to_bool( $shortcode_arguments[ 'hide-photos' ] ), - 'redirect-url' => $redirect_url, - 'hide-notes' => ws_ls_to_bool( $shortcode_arguments[ 'hide-notes' ] ), - 'hide-confirmation' => true, - 'custom-field-groups' => $shortcode_arguments[ 'custom-field-groups' ], - 'custom-field-slugs' => $shortcode_arguments[ 'custom-field-slugs' ], - 'weight-mandatory' => $shortcode_arguments[ 'weight-mandatory' ] - ] ); - - } else { - - $html_output .= ws_ls_form_weight( [ 'css-class-form' => 'ws-ls-main-weight-form', - 'user-id' => $user_id, - 'hide-fields-photos' => ws_ls_to_bool( $shortcode_arguments[ 'hide-photos' ] ), - 'hide-notes' => ws_ls_to_bool( $shortcode_arguments[ 'hide-notes' ] ), - 'hide-confirmation' => true, - 'custom-field-groups' => $shortcode_arguments[ 'custom-field-groups' ], - 'custom-field-slugs' => $shortcode_arguments[ 'custom-field-slugs' ], - 'weight-mandatory' => $shortcode_arguments[ 'weight-mandatory' ] - ] ); - } - - // Close first tab - $html_output .= ws_ls_end_tab( $use_tabs ); - - // Start data table tab? - if ( true === $use_tabs ) { - $html_output .= ws_ls_start_tab( 'wlt-weight-history', $use_tabs ); - } - - $week_ranges = ( true === $week_ranges_enabled ) ? ws_ls_week_ranges_get( $user_id ) : NULL; - - // If we have data, display data table - if ( false === empty( $weight_data ) ) { - - if ( true === ws_ls_to_bool( $shortcode_arguments[ 'show-chart-history' ] ) ) { - $html_output .= ws_ls_shortcode_embed_chart( $weight_data, $shortcode_arguments ); - } - - if ( true === ws_ls_targets_enabled() && $use_tabs && - false === ws_ls_to_bool( $shortcode_arguments[ 'hide-second-target-form' ] ) ) { - $html_output .= ws_ls_form_weight( [ 'type' => 'target', 'css-class-form' => 'ws-ls-target-form', 'user-id' => $user_id, 'hide-confirmation' => true ] ) . '
'; - } - - // Display week filters and data tab - $html_output .= ws_ls_title( __( 'Weight History', WE_LS_SLUG ) ); - - if( true === $week_ranges_enabled ) { - $html_output .= ws_ls_week_ranges_display( $week_ranges, $selected_week_number ); - } - - if ( true === WS_LS_IS_PRO && false === ws_ls_to_bool( $shortcode_arguments[ 'disable-advanced-tables' ] ) ){ - $html_output .= ws_ls_shortcode_table( [ 'user-id' => $user_id, 'enable-add-edit' => true, 'enable-meta-fields' => true, - 'week' => $selected_week_number, 'bmi-format' => $shortcode_arguments[ 'bmi-format' ], - 'custom-field-groups' => $shortcode_arguments[ 'custom-field-groups' ], - 'custom-field-slugs' => $shortcode_arguments[ 'custom-field-slugs' ] - ] ); - } else { - $html_output .= ws_ls_display_table( $user_id, $weight_data ); - } - } - elseif ( $use_tabs && false === empty( $selected_week_number ) ) { - $html_output .= __( 'No data could be found for this week, please try selecting another:', WE_LS_SLUG ); - if( true === $week_ranges_enabled ) { - $html_output .= ws_ls_week_ranges_display( $week_ranges, $selected_week_number ); - } - } - elseif ( $use_tabs ) { - $html_output .= __('You haven\'t entered any weight data yet.', WE_LS_SLUG); - } - - $html_output .= ws_ls_end_tab($use_tabs); - - // Photos tab? - if ( true === $show_photos_tab ){ - $html_output .= ws_ls_start_tab( 'wlt-user-photos', $use_tabs ); - $html_output .= ws_ls_shortcode_wlt_display_photos_tab( $user_id ); - $html_output .= ws_ls_end_tab( $use_tabs ); - } - - // Advanced Data? MacroN etc? - if ( true === $show_advanced_tab ){ - $html_output .= ws_ls_start_tab( 'wlt-user-advanced', $use_tabs ); - $html_output .= ws_ls_shortcode_wlt_display_advanced_tab( $shortcode_arguments ); - $html_output .= ws_ls_end_tab( $use_tabs ); - } - - // If enabled, have a third tab to allow users to manage their own settings! - if( true === ws_ls_user_preferences_is_enabled() ){ - $html_output .= ws_ls_start_tab( 'wlt-user-preferences', $use_tabs ); - $html_output .= ws_ls_user_preferences_form( [ 'user-id' => $user_id, 'allow-delete-data' => ws_ls_to_bool( $shortcode_arguments[ 'allow-delete-data' ] ) ] ); - $html_output .= ws_ls_end_tab( $use_tabs ); - } - - $html_output .= ws_ls_end_tab( $use_tabs ); - $html_output .= ws_ls_end_tab( $use_tabs ); - - $ws_ls_wlt_already_placed = true; - - return $html_output; - -} - - -/** -* HTML for opening tab -* @param $tab_name -* @param $use_tabs -* -* @return string -*/ -function ws_ls_start_tab( $tab_name, $use_tabs ) { - return ( true === $use_tabs ) ? sprintf( '
', $tab_name ) : ''; -} - -/** -* HTML for closing tab -* @param $use_tabs -* -* @return string -*/ -function ws_ls_end_tab( $use_tabs ) { - return ( true === $use_tabs ) ? '
' : ''; -} - -/** -* @param $title_text -* -* @return string -*/ -function ws_ls_title( $title_text ) { - return sprintf( '

%s

', esc_html( $title_text ) ); -} - - -/** - * Display a notice about it being beta - * @return string - */ -function ws_ls_wt_legacy_notice() { - - if ( !current_user_can( 'manage_options' ) ) { - return ''; - } - - $message = '

- - Note: Only administrators can see this message. - -

-

This shortcode, [wt-legacy] will soon be deprecated and removed from the plugin. Please switch to [wt]. Read more:

-

https://docs.yeken.uk/shortcodes/wt.html.

-'; - - return ws_ls_blockquote_error( $message ); -} diff --git a/weight-loss-tracker.php b/weight-loss-tracker.php index d18eb0f2..ed86d8d8 100755 --- a/weight-loss-tracker.php +++ b/weight-loss-tracker.php @@ -82,7 +82,6 @@ require_once( WS_LS_ABSPATH . 'includes/ajax.php' ); require_once( WS_LS_ABSPATH . 'includes/setup-wizard.php' ); require_once( WS_LS_ABSPATH . 'includes/components.php' ); -require_once( WS_LS_ABSPATH . 'includes/shortcode-wt-legacy.php' ); require_once( WS_LS_ABSPATH . 'includes/shortcode-wt.php' ); require_once( WS_LS_ABSPATH . 'includes/shortcode-various.php' ); require_once( WS_LS_ABSPATH . 'includes/form-handler.php' ); From 83751aa3797878897bfc07e9fc5da2f9b6e2d6f8 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Sat, 9 Sep 2023 14:52:48 +0100 Subject: [PATCH 04/31] Removed redundant setting "Hide tab descriptions" --- .../settings/page-settings-generic.php | 15 +-------------- readme.txt | 1 + 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/includes/admin-pages/settings/page-settings-generic.php b/includes/admin-pages/settings/page-settings-generic.php index 48ed6dcc..5a94e850 100755 --- a/includes/admin-pages/settings/page-settings-generic.php +++ b/includes/admin-pages/settings/page-settings-generic.php @@ -232,19 +232,7 @@ function ws_ls_settings_page_generic() {

- - - - +
- - -

.

-
@@ -1214,7 +1202,6 @@ function ws_ls_register_settings(){ // Tabs register_setting( 'we-ls-options-group', 'ws-ls-tab-window-resize' ); - register_setting( 'we-ls-options-group', 'ws-ls-tab-hide-descriptions' ); register_setting( 'we-ls-options-group', 'ws-ls-tab-theme' ); // Pro only open diff --git a/readme.txt b/readme.txt index 1f9cd483..dbc29bb0 100644 --- a/readme.txt +++ b/readme.txt @@ -157,6 +157,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed support for the shortcode [wt-beta], you must use [wt] instead. * Maintenance: Removed support for the shortcode [wlt], you must use [wt] instead. * Maintenance: Removed support for the shortcode [wt-legacy], you must use [wt] instead. +* Maintenance: Removed redundant setting "Hide tab descriptions" from the "User Experience" settings page. = 10.6 = From 8881a28631b9dd8cd7fcdbdb206d028603a1e7be Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Sat, 9 Sep 2023 14:59:39 +0100 Subject: [PATCH 05/31] Removed JS references / config in front end --- assets/js/ws-ls.js | 18 ------------------ assets/js/ws-ls.min.js | 2 +- includes/core.php | 20 +------------------- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/assets/js/ws-ls.js b/assets/js/ws-ls.js index 3d1fe41b..48c6e23c 100755 --- a/assets/js/ws-ls.js +++ b/assets/js/ws-ls.js @@ -24,24 +24,6 @@ jQuery( document ).ready( function ( $ ) { function() { window.location.replace( ws_ls_config[ 'current-url' ] + '?target-cleared=true&wt-user-id=' + user_id ) } ); }); - // ----------------------------------------------------------------------- - // Tabs (ZoZo) - // ----------------------------------------------------------------------- - - // Just saved data or cancelled? If so, set default Tab to be "In Detail" - let default_tab = ( ws_ls_querystring_value( 'ws-edit-saved' ) || ws_ls_querystring_value( 'ws-edit-cancel' ) ) ? 'tab2' : 'tab1'; - - let tabs_are_ready = function( event, item ) { - $( '#ws-ls-tabs-loading' ).addClass( 'ws-ls-hide' ); - $( '#' + item.id ).addClass( 'ws-ls-force-show' ); - $( '#' + item.id ).removeClass( 'ws-ls-hide' ); - }; - - ws_ls_config[ 'tab-config' ][ 'defaultTab' ] = default_tab; - ws_ls_config[ 'tab-config' ][ 'ready' ] = tabs_are_ready; - - tabs_global = $( '#ws-ls-tabs' ).zozoTabs( ws_ls_config[ 'tab-config' ] ); - // ----------------------------------------------------------------------- // Progress Bar // ----------------------------------------------------------------------- diff --git a/assets/js/ws-ls.min.js b/assets/js/ws-ls.min.js index e913dca6..5db95603 100644 --- a/assets/js/ws-ls.min.js +++ b/assets/js/ws-ls.min.js @@ -1 +1 @@ -let tabs_global=!1;jQuery(document).ready(function(a){a(".ws-ls-clear-target").click(function(b){if(b.preventDefault(),!1===confirm(ws_ls_config["clear-target"]))return;let c=a(this).data("user-id");ws_ls_post("ws_ls_clear_target",{"user-id":c},function(){window.location.replace(ws_ls_config["current-url"]+"?target-cleared=true&wt-user-id="+c)})});let b=ws_ls_querystring_value("ws-edit-saved")||ws_ls_querystring_value("ws-edit-cancel")?"tab2":"tab1";if(ws_ls_config["tab-config"].defaultTab=b,ws_ls_config["tab-config"].ready=function(b,c){a("#ws-ls-tabs-loading").addClass("ws-ls-hide"),a("#"+c.id).addClass("ws-ls-force-show"),a("#"+c.id).removeClass("ws-ls-hide")},tabs_global=a("#ws-ls-tabs").zozoTabs(ws_ls_config["tab-config"]),a(".ws-ls-progress").each(function(){let b="#"+a(this).attr("id"),c=a(this).data("progress"),d=a(this).data("percentage-text"),e={strokeWidth:a(this).data("stroke-width"),easing:"easeInOut",duration:a(this).data("animation-duration"),color:a(this).data("stroke-colour"),trailColor:a(this).data("trail-colour"),trailWidth:a(this).data("trail-width"),svgStyle:{width:a(this).data("width"),height:a(this).data("height")},text:{style:{color:a(this).data("text-colour")},value:Math.round(100*c)+"% "+d},step:function(a,b){b.setText(Math.round(100*b.value())+"% "+d)}},f=!1;f="circle"===a(this).data("type")?new ProgressBar.Circle(b,e):new ProgressBar.Line(b,e),f.animate(c)}),"true"===ws_ls_config["photos-enabled"]){let a=document.querySelectorAll(".ws-ls-input-file");Array.prototype.forEach.call(a,function(a){let b=a.nextElementSibling,c=b.innerHTML;a.addEventListener("change",function(a){let d=a.target.value.split("\\").pop();d?b.querySelector("span").innerHTML=d:b.innerHTML=c}),a.addEventListener("focus",function(){a.classList.add("has-focus")}),a.addEventListener("blur",function(){a.classList.remove("has-focus")})})}if("true"===ws_ls_config["is-pro"]){function b(){let b={"user-id":a("#ws-ls-user-id").val()};a(".ws-ls-user-pref-form select, .ws-ls-user-pref-form .custom-field").each(function(){b[a(this).attr("id")]=a(this).val()}),b["ws-ls-dob"]=a("#ws-ls-dob").val(),ws_ls_post("ws_ls_save_preferences",b,ws_ls_user_preference_callback)}a(".ws-ls-user-delete-all").validate({errorClass:"ws-ls-invalid",validClass:"ws-ls-valid",errorContainer:".ws-ls-user-delete-all .ws-ls-error-summary",errorLabelContainer:".ws-ls-user-delete-all .ws-ls-error-summary ul",wrapper:"li",messages:{"ws-ls-delete-all":ws_ls_config["validation-we-ls-history"]},submitHandler:function(a){a.submit()}}),a(".ws-ls-user-pref-form").submit(function(a){a.preventDefault(),"true"!==ws_ls_config["validation-about-you-mandatory"]&&b()});let c=!1;"true"===ws_ls_config["validation-about-you-mandatory"]&&(c=a(".ws-ls-user-pref-form").validate({errorClass:"ws-ls-invalid",validClass:"ws-ls-valid",errorContainer:".ws-ls-user-pref-form .ws-ls-error-summary",errorLabelContainer:".ws-ls-user-pref-form .ws-ls-error-summary ul",wrapper:"li",rules:ws_ls_config["validation-user-pref-rules"],messages:ws_ls_config["validation-user-pref-messages"],submitHandler:function(){b()}}),a.extend(jQuery.validator.messages,{required:ws_ls_config["validation-required"]}),a(".ws-ls-user-pref-form .we-ls-datepicker").length&&("true"===ws_ls_config["us-date"]?a(".ws-ls-user-pref-form .we-ls-datepicker").rules("add",{required:!0,date:!0}):a(".ws-ls-user-pref-form .we-ls-datepicker").rules("add",{required:!0,dateITA:!0})))}});function ws_ls_post(a,b,c){b.action=a,b.security=ws_ls_config["ajax-security-nonce"],jQuery.post(ws_ls_config["ajax-url"],b,function(a){c(b,a)})}function ws_ls_user_preference_callback(a,b){if(1==b){let a=jQuery(".ws-ls-user-pref-form").data("redirect-url");a?window.location.replace(a):window.location.replace(ws_ls_config["current-url"]+"?user-preference-saved=true")}}function ws_ls_querystring_value(a){let b=window.location.search.substring(1),c=b.split("&");for(let b,d=0;d ws_ls_config_js_datapicker_locale(), 'in-admin' => ( is_admin() ) ? 'true' : 'false', 'max-photo-upload' => ws_ls_photo_max_upload_size(), - 'tab-config' => ws_ls_config_js_tab_config(), 'form-load-previous' => false === is_admin() && WS_LS_IS_PRO && ws_ls_option_to_bool( 'ws-ls-populate-form-with-values-on-date', 'yes' ), 'focus' => ws_ls_querystring_value( 'focus' ), 'load-entry-url' => apply_filters( 'wlt_current_url', get_permalink() ), @@ -89,21 +88,4 @@ function ws_ls_config_js_datapicker_locale() { 'firstDay' => get_option( 'start_of_week' ), 'entry-found' => __( 'An entry has been found for this date. Would you like to load the existing entry?', WE_LS_SLUG ) . PHP_EOL . PHP_EOL . __( 'Note: Any unsaved data shall be lost!', WE_LS_SLUG ) ]; -} - -/** - * JS Config for Tabs - * @return array - */ -function ws_ls_config_js_tab_config() { - - return [ 'rounded' => false, - 'multiline' => true, - 'theme' => get_option( 'ws-ls-tab-theme', 'silver' ), // white, crystal, silver, gray, black, orange, red, green, blue, deepblue - 'size' => 'small', - 'minWindowWidth' => (int) get_option( 'ws-ls-tab-window-resize', '1200' ), - 'mobileNav' => true, - 'responsive' => true, - 'animation' => [ 'effects' => 'slideH', 'easing' => 'easeInOutCirc', 'type' => 'jquery' ] - ]; -} +} \ No newline at end of file From b28cbd9862a824456b62f76ba15e28336bd189d4 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Sat, 9 Sep 2023 15:01:03 +0100 Subject: [PATCH 06/31] Removed redundant setting "Tab appearance" --- .../settings/page-settings-generic.php | 21 +------------------ readme.txt | 1 + 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/includes/admin-pages/settings/page-settings-generic.php b/includes/admin-pages/settings/page-settings-generic.php index 5a94e850..2abbcdc0 100755 --- a/includes/admin-pages/settings/page-settings-generic.php +++ b/includes/admin-pages/settings/page-settings-generic.php @@ -233,25 +233,7 @@ function ws_ls_settings_page_generic() {

- - - - + Date: Sat, 9 Sep 2023 15:02:48 +0100 Subject: [PATCH 07/31] Removed redundant setting "Switching to a drop down" --- .../settings/page-settings-generic.php | 18 ------------------ readme.txt | 1 + 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/includes/admin-pages/settings/page-settings-generic.php b/includes/admin-pages/settings/page-settings-generic.php index 2abbcdc0..aa7e6ff9 100755 --- a/includes/admin-pages/settings/page-settings-generic.php +++ b/includes/admin-pages/settings/page-settings-generic.php @@ -230,21 +230,6 @@ function ws_ls_settings_page_generic() {
- - -
-

- - - - - - - - -
- -

.

-

@@ -1182,9 +1167,6 @@ function ws_ls_register_settings(){ register_setting( 'we-ls-options-group', 'ws-ls-number-formatting-separator' ); register_setting( 'we-ls-options-group', 'ws-ls-default-aim' ); - // Tabs - register_setting( 'we-ls-options-group', 'ws-ls-tab-window-resize' ); - // Pro only open if( WS_LS_IS_PRO ){ diff --git a/readme.txt b/readme.txt index d40f4a7e..e518def5 100644 --- a/readme.txt +++ b/readme.txt @@ -159,6 +159,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed support for the shortcode [wt-legacy], you must use [wt] instead. * Maintenance: Removed redundant setting "Hide tab descriptions" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Tab appearance" from the "User Experience" settings page. +* Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. = 10.6 = From efc0729c7ef2e1380c0d5a83444ab40263587c93 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Sat, 9 Sep 2023 15:11:05 +0100 Subject: [PATCH 08/31] Removed setting "Include thousand separator?" --- .../settings/page-settings-generic.php | 17 ----------------- includes/functions.php | 5 +---- readme.txt | 1 + 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/includes/admin-pages/settings/page-settings-generic.php b/includes/admin-pages/settings/page-settings-generic.php index aa7e6ff9..cba68ccd 100755 --- a/includes/admin-pages/settings/page-settings-generic.php +++ b/includes/admin-pages/settings/page-settings-generic.php @@ -295,22 +295,6 @@ function ws_ls_settings_page_generic() {
-

- - - - - -
- - -

.

-

@@ -1164,7 +1148,6 @@ function ws_ls_register_settings(){ register_setting( 'we-ls-options-group', 'ws-ls-fill-under-weight-line' ); register_setting( 'we-ls-options-group', 'ws-ls-fill-under-weight-line-opacity' ); register_setting( 'we-ls-options-group', 'ws-ls-fill-under-weight-line-colour' ); - register_setting( 'we-ls-options-group', 'ws-ls-number-formatting-separator' ); register_setting( 'we-ls-options-group', 'ws-ls-default-aim' ); // Pro only open diff --git a/includes/functions.php b/includes/functions.php index 426b6b63..173c265a 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1413,10 +1413,7 @@ function ws_ls_round_number( $number, $decimal_places = 0 ) { var_dump($number); } - - $seperator = ( 'yes' === get_option( 'ws-ls-number-formatting-separator', 'yes' ) ) ? ',' : ''; - - return number_format( $number, $decimal_places, '.', $seperator ); + return number_format( $number, $decimal_places, '.', ',' ); } /** diff --git a/readme.txt b/readme.txt index e518def5..10dd4e11 100644 --- a/readme.txt +++ b/readme.txt @@ -160,6 +160,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Hide tab descriptions" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Tab appearance" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. +* Maintenance: Removed setting "Include thousand separator?" from the "User Experience" settings page. A comma shall be used by default. = 10.6 = From 419b9be110b8fa8be44da5b975a62e5f5c600f22 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Sat, 9 Sep 2023 15:15:39 +0100 Subject: [PATCH 09/31] Challenges are enabled by default --- .../settings/page-settings-generic.php | 19 +------------------ includes/functions.php | 11 +---------- includes/hooks.php | 6 +----- readme.txt | 3 ++- weight-loss-tracker.php | 6 +----- 5 files changed, 6 insertions(+), 39 deletions(-) diff --git a/includes/admin-pages/settings/page-settings-generic.php b/includes/admin-pages/settings/page-settings-generic.php index cba68ccd..38e08848 100755 --- a/includes/admin-pages/settings/page-settings-generic.php +++ b/includes/admin-pages/settings/page-settings-generic.php @@ -230,22 +230,6 @@ function ws_ls_settings_page_generic() {
-

- - - - - -
- - -

-

@@ -1216,8 +1200,7 @@ function ws_ls_register_settings(){ register_setting( 'we-ls-options-group', 'ws-ls-cal-show-gain' ); register_setting( 'we-ls-options-group', 'ws-ls-cal-add-unit' ); register_setting( 'we-ls-options-group', 'ws-ls-cal-lose-unit' ); - register_setting( 'we-ls-options-group', 'ws-ls-challenges-enabled' ); - register_setting( 'we-ls-options-group', 'ws-ls-awards-delete-when-entry-deleted-enabled' ); + register_setting( 'we-ls-options-group', 'ws-ls-awards-delete-when-entry-deleted-enabled' ); register_setting( 'we-ls-options-group', 'ws-ls-macro-proteins-maintain' ); register_setting( 'we-ls-options-group', 'ws-ls-macro-carbs-maintain' ); diff --git a/includes/functions.php b/includes/functions.php index 173c265a..a634258d 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1397,8 +1397,7 @@ function ws_ls_user_display_name( $user_id ) { * @return bool */ function ws_ls_challenges_is_enabled() { - return ( WS_LS_IS_PRO_PLUS && - true === ws_ls_settings_challenges_enabled() ); + return WS_LS_IS_PRO_PLUS; } /** @@ -1453,14 +1452,6 @@ function ws_ls_targets_enabled() { return ( 'yes' === get_option( 'ws-ls-allow-targets', 'yes' ) ); } -/** - * Challenges enabled? - * @return bool - */ -function ws_ls_settings_challenges_enabled() { - return ( 'yes' === get_option( 'ws-ls-challenges-enabled', 'yes' ) ); -} - /** * Fetch weight unit as readable text * @param $key diff --git a/includes/hooks.php b/includes/hooks.php index 8fa85748..f9a259e0 100755 --- a/includes/hooks.php +++ b/includes/hooks.php @@ -16,14 +16,10 @@ function ws_ls_build_admin_menu() { add_submenu_page( 'ws-ls-data-home', __( 'User Groups', WE_LS_SLUG ), __( 'User Groups', WE_LS_SLUG ), 'manage_options', 'ws-ls-user-groups', 'ws_ls_settings_page_group' ); add_submenu_page( 'ws-ls-data-home', __( 'Custom Fields', WE_LS_SLUG ), __('Custom Fields', WE_LS_SLUG), 'manage_options', 'ws-ls-meta-fields', 'ws_ls_meta_fields_page' ); add_submenu_page( 'ws-ls-data-home', __( 'Awards', WE_LS_SLUG ), __('Awards', WE_LS_SLUG), 'manage_options', 'ws-ls-awards', 'ws_ls_awards_page' ); - - if ( true === ws_ls_settings_challenges_enabled() ) { - add_submenu_page( 'ws-ls-data-home', __( 'Challenges', WE_LS_SLUG ), __('Challenges', WE_LS_SLUG), 'manage_options', 'ws-ls-challenges', 'ws_ls_challenges_admin_page' ); - } + add_submenu_page( 'ws-ls-data-home', __( 'Challenges', WE_LS_SLUG ), __('Challenges', WE_LS_SLUG), 'manage_options', 'ws-ls-challenges', 'ws_ls_challenges_admin_page' ); $menu_text = ( false === WS_LS_IS_PRO && false === WS_LS_IS_PRO_PLUS ) ? __('Upgrade', WE_LS_SLUG) : __('Your License', WE_LS_SLUG); - add_submenu_page( 'ws-ls-data-home', __('Settings', WE_LS_SLUG), __('Settings', WE_LS_SLUG), 'manage_options', 'ws-ls-settings', 'ws_ls_settings_page'); add_submenu_page( 'ws-ls-data-home', $menu_text, $menu_text, 'manage_options', 'ws-ls-license', 'ws_ls_advertise_pro'); diff --git a/readme.txt b/readme.txt index 10dd4e11..4de556f4 100644 --- a/readme.txt +++ b/readme.txt @@ -160,7 +160,8 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Hide tab descriptions" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Tab appearance" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. -* Maintenance: Removed setting "Include thousand separator?" from the "User Experience" settings page. A comma shall be used by default. +* Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. +* Maintenance: Challenges functionality is now enabled by default. = 10.6 = diff --git a/weight-loss-tracker.php b/weight-loss-tracker.php index ed86d8d8..74e2acd4 100755 --- a/weight-loss-tracker.php +++ b/weight-loss-tracker.php @@ -158,11 +158,7 @@ require_once( WS_LS_ABSPATH . 'pro-features/plus/awards/hooks.php' ); require_once( WS_LS_ABSPATH . 'pro-features/email-notifications.php' ); require_once( WS_LS_ABSPATH . 'pro-features/web-hooks.php' ); - -if ( true === ws_ls_settings_challenges_enabled() ) { - require_once( WS_LS_ABSPATH . 'pro-features/plus/challenge/inc.php' ); -} - +require_once( WS_LS_ABSPATH . 'pro-features/plus/challenge/inc.php' ); require_once( WS_LS_ABSPATH . 'pro-features/plus/messaging/inc.php' ); require_once( WS_LS_ABSPATH . 'pro-features/plus/bmr.php' ); From d31383bc4749cd3ab38d498fdf9c0af70e0b7e18 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:35:17 +0100 Subject: [PATCH 10/31] Typo --- includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/functions.php b/includes/functions.php index a634258d..203d864b 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1437,7 +1437,7 @@ function ws_ls_user_preferences_is_enabled() { } /** - * Hass CSS been disabled? + * Has CSS been disabled? * @return bool */ function ws_ls_css_is_disabled() { From 9599d5ed883e5a60c6b79c601f3ce0edf06892be Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:41:25 +0100 Subject: [PATCH 11/31] Removed references to array_push() and replaced with []. --- pro-features/footable.php | 9 +++++---- readme.txt | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pro-features/footable.php b/pro-features/footable.php index 687c9b22..84bfef59 100755 --- a/pro-features/footable.php +++ b/pro-features/footable.php @@ -329,7 +329,7 @@ function ws_ls_datatable_rows( $arguments ) { $row[ 'options' ][ 'classes' ] = 'ws-ls-has-note'; } - array_push( $rows, $row ); + $rows[] = $row; } ws_ls_cache_user_set( $arguments[ 'user-id' ], $cache_key, $rows ); @@ -419,7 +419,8 @@ function ws_ls_datatable_columns( $arguments = [] ) { // Add BMI? if( true === $arguments[ 'enable-bmi' ] && true === ws_ls_bmi_in_tables() ) { - array_push($columns, [ 'name' => 'bmi', 'title' => ws_ls_tooltip( __( 'BMI', WE_LS_SLUG ), __( 'Body Mass Index', WE_LS_SLUG ) ), 'breakpoints'=> 'xs', 'type' => 'text' ] ); + + $columns[] = [ 'name' => 'bmi', 'title' => ws_ls_tooltip( __( 'BMI', WE_LS_SLUG ), __( 'Body Mass Index', WE_LS_SLUG ) ), 'breakpoints'=> 'xs', 'type' => 'text' ]; } if ( true === $arguments[ 'enable-meta' ] && @@ -450,13 +451,13 @@ function ws_ls_datatable_columns( $arguments = [] ) { continue; } - array_push($columns, [ 'name' => 'meta-' . $field['id'], 'title' => stripslashes( $field['field_name'] ), 'breakpoints'=> $column_size, 'type' => 'text' ] ); + $columns[] = [ 'name' => 'meta-' . $field['id'], 'title' => stripslashes( $field['field_name'] ), 'breakpoints'=> $column_size, 'type' => 'text' ]; } } } if ( true === $arguments[ 'enable-notes' ] ) { - array_push($columns, [ 'name' => 'notes', 'title' => __( 'Notes', WE_LS_SLUG ), 'breakpoints'=> 'lg', 'type' => 'text' ] ); + $columns[] = [ 'name' => 'notes', 'title' => __( 'Notes', WE_LS_SLUG ), 'breakpoints'=> 'lg', 'type' => 'text' ]; } return apply_filters( 'wlt-filter-front-end-data-table-columns', $columns, $arguments[ 'front-end' ] ); diff --git a/readme.txt b/readme.txt index 4de556f4..e71c8efd 100644 --- a/readme.txt +++ b/readme.txt @@ -162,6 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. +$ Maintenance: Removed references to array_push() and replaced with []. = 10.6 = From e16543fbe4fdfd2df005f10da32a82135f49e298 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:43:55 +0100 Subject: [PATCH 12/31] Code tidy --- includes/components.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/components.php b/includes/components.php index ddcea9d6..50245579 100644 --- a/includes/components.php +++ b/includes/components.php @@ -31,7 +31,7 @@ function ws_ls_uikit_summary_boxes( $arguments, $boxes = [] ) { $arguments = wp_parse_args( $arguments, [ 'user-id' => get_current_user_id(), 'breakpoint_s' => 2 ] ); $no_boxes = count( $boxes ); - $breakpoint_m = $no_boxes < 4 ? $no_boxes : 4; + $breakpoint_m = min( $no_boxes, 4 ); $breakpoint_s = $no_boxes < 3 ? $no_boxes : (int) $arguments[ 'breakpoint_s' ]; $divider_count = 0; From 4a43d7691220d065e2264a78444584e73e28c268 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:47:31 +0100 Subject: [PATCH 13/31] Minor tweaks --- includes/db.php | 1 + pro-features/plus/messaging/functions-notes.php | 4 +--- pro-features/shortcode-if.php | 2 +- readme.txt | 3 ++- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/db.php b/includes/db.php index 10c71dfb..7b6d8bcd 100755 --- a/includes/db.php +++ b/includes/db.php @@ -448,6 +448,7 @@ function ws_ls_db_entry_delete_all() { $wpdb->query('TRUNCATE TABLE ' . $wpdb->prefix . WE_LS_TARGETS_TABLENAME ); $wpdb->query('TRUNCATE TABLE ' . $wpdb->prefix . WE_LS_TABLENAME ); $wpdb->query('TRUNCATE TABLE ' . $wpdb->prefix . WE_LS_USER_STATS_TABLENAME ); + } /** diff --git a/pro-features/plus/messaging/functions-notes.php b/pro-features/plus/messaging/functions-notes.php index 43f7003a..3614adab 100644 --- a/pro-features/plus/messaging/functions-notes.php +++ b/pro-features/plus/messaging/functions-notes.php @@ -140,7 +140,5 @@ function ws_ls_notes_sanitise( $content ) { $content = stripslashes( $content ); $content = wp_kses_post( $content ); - $content = str_replace( PHP_EOL, '
', $content ); - - return $content; + return str_replace( PHP_EOL, '
', $content ); } diff --git a/pro-features/shortcode-if.php b/pro-features/shortcode-if.php index b056d710..597dd020 100755 --- a/pro-features/shortcode-if.php +++ b/pro-features/shortcode-if.php @@ -38,7 +38,7 @@ function ws_ls_shortcode_if( $user_defined_arguments, $content = null, $level = } // Remove Pro Plus fields if they don't have a license - if( false === WS_LS_IS_PRO_PLUS && true === in_array( $arguments[ 'field' ], [ 'bmr' ] ) ) { + if( false === WS_LS_IS_PRO_PLUS && true === ( $arguments['field'] == 'bmr' ) ) { return sprintf( '

%s

', __( 'Unfortunately the field you specified is for Pro Plus licenses only.', WE_LS_SLUG ) ); } diff --git a/readme.txt b/readme.txt index e71c8efd..b293b775 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,8 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -$ Maintenance: Removed references to array_push() and replaced with []. +* Maintenance: Based on PHPStorm inspect made 4+ changes to code for optimisation. + = 10.6 = From fcb0affeb3aa4b40b9b5a314854ea49c3f170484 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:49:24 +0100 Subject: [PATCH 14/31] Added default returns --- includes/functions.php | 2 +- pro-features/plus/messaging/functions-notes.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/functions.php b/includes/functions.php index 203d864b..6208857a 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -990,7 +990,7 @@ function ws_ls_display_blockquote( $text, $class = '', $just_echo = false, $incl if ( true === $just_echo ) { echo $html_output; - return; + return ''; } return $html_output; diff --git a/pro-features/plus/messaging/functions-notes.php b/pro-features/plus/messaging/functions-notes.php index 3614adab..deb6d43c 100644 --- a/pro-features/plus/messaging/functions-notes.php +++ b/pro-features/plus/messaging/functions-notes.php @@ -124,6 +124,8 @@ function ws_ls_notes_render( $note, $echo = true, $uikit = false, $alternate = f } echo $html; + + return ''; } /** From 5e9bb08844ca5eea92b06e027aa24293957457aa Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:50:00 +0100 Subject: [PATCH 15/31] Call the right function --- pro-features/export/admin.page.php | 4 ++-- readme.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pro-features/export/admin.page.php b/pro-features/export/admin.page.php index ad4dd6f4..c03936a0 100644 --- a/pro-features/export/admin.page.php +++ b/pro-features/export/admin.page.php @@ -266,7 +266,7 @@ function ws_ls_export_admin_page_new() {
-

+

-

+

diff --git a/readme.txt b/readme.txt index b293b775..bf3ee878 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspect made 4+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspect made 6+ changes to code for optimisation. = 10.6 = From f643ed79e8bd17abf4c241b865cb1560f5a6b342 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:51:07 +0100 Subject: [PATCH 16/31] Incorrect function usuage --- pro-features/export/db.php | 4 ++-- readme.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pro-features/export/db.php b/pro-features/export/db.php index 6c11b0ae..ed54ab0e 100644 --- a/pro-features/export/db.php +++ b/pro-features/export/db.php @@ -275,7 +275,7 @@ function ws_ls_db_export_criteria_step( $export_id, $step = 0 ) { [ '%d' ], [ '%d' ] ); - ws_ls_cache_user_delete( 'exports', (int) $export_id ); + ws_ls_cache_user_delete( 'exports' ); return $result; } @@ -296,7 +296,7 @@ function ws_ls_db_export_criteria_count( $export_id, $count = 0 ) { [ '%d' ], [ '%d' ] ); - ws_ls_cache_user_delete( 'exports', (int) $export_id ); + ws_ls_cache_user_delete( 'exports' ); return $result; } diff --git a/readme.txt b/readme.txt index bf3ee878..5931cc1b 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspect made 6+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspect made 8+ changes to code for optimisation. = 10.6 = From 8ed77f42c2af984ad887953621a77d243f514459 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:57:58 +0100 Subject: [PATCH 17/31] Simplified IFs --- includes/ajax.php | 4 ++-- includes/db.php | 6 ++---- includes/email-manager.php | 2 +- includes/functions.php | 2 +- includes/hooks.php | 2 +- includes/license.php | 2 +- pro-features/db.php | 4 ++-- pro-features/footable.php | 2 +- pro-features/functions-stats.php | 2 +- pro-features/plus/harris-benedict.php | 8 ++------ pro-features/plus/meta-fields/functions-photos.php | 2 +- pro-features/shortcode-progress-bar.php | 2 +- pro-features/shortcode-stats.php | 8 ++++---- readme.txt | 2 +- 14 files changed, 21 insertions(+), 27 deletions(-) diff --git a/includes/ajax.php b/includes/ajax.php index f9d5cfd7..49ecd6cb 100644 --- a/includes/ajax.php +++ b/includes/ajax.php @@ -13,7 +13,7 @@ function ws_ls_clear_target_callback() { $user_id = ws_ls_post_value('user-id'); - if( true == ws_ls_db_target_delete( $user_id ) ){ + if( ws_ls_db_target_delete( $user_id ) ){ wp_send_json(1); } @@ -70,7 +70,7 @@ function ws_ls_save_preferences_callback() { do_action( 'ws-ls-hook-user-preference-save', (int) $fields['user_id'], $in_admin_area, $fields ); - if( false == ws_ls_set_user_preferences( $in_admin_area, $fields ) ){ + if( ! ws_ls_set_user_preferences( $in_admin_area, $fields ) ){ wp_send_json (0 ); } diff --git a/includes/db.php b/includes/db.php index 7b6d8bcd..c656339c 100755 --- a/includes/db.php +++ b/includes/db.php @@ -739,8 +739,7 @@ function ws_ls_db_user_preferences( $user_id = NULL, $use_cache = true ) { $cache = ws_ls_cache_user_get( $user_id, 'user-preferences' ); - if ( true == $use_cache && - false === empty( $cache ) ) { + if ( $use_cache && ! empty( $cache ) ) { return $cache; } @@ -768,8 +767,7 @@ function ws_ls_db_entries_count( $user_id = NULL, $use_cache = true ) { $cache = ws_ls_cache_user_get( $user_id, 'entry-counts' ); - if ( true == $use_cache && - false === empty( $cache ) ) { + if ( $use_cache && ! empty( $cache ) ) { return $cache; } diff --git a/includes/email-manager.php b/includes/email-manager.php index 5cb9571f..03141a18 100755 --- a/includes/email-manager.php +++ b/includes/email-manager.php @@ -484,7 +484,7 @@ function ws_ls_emailer_get_all( $only_editable = true ) { $sql = 'Select * from ' . $wpdb->prefix . WE_LS_EMAIL_TABLENAME; - if ( true == $only_editable ) { + if ( $only_editable ) { $sql .= ' where editable = 1'; } diff --git a/includes/functions.php b/includes/functions.php index 6208857a..2cb7a488 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1161,7 +1161,7 @@ function ws_ls_photo_display_max_upload_size() { $upload_size = ws_ls_photo_get_sizes($max_size); - return ( true == is_array($upload_size) ) ? ws_ls_display_max_server_upload_size() : $upload_size; + return is_array( $upload_size ) ? ws_ls_display_max_server_upload_size() : $upload_size; } /** diff --git a/includes/hooks.php b/includes/hooks.php index f9a259e0..c1f01b2d 100755 --- a/includes/hooks.php +++ b/includes/hooks.php @@ -231,7 +231,7 @@ function ws_ls_enqueue_form_dependencies() { * @return string */ function ws_ls_use_minified() { - return ( defined('SCRIPT_DEBUG' ) && false == SCRIPT_DEBUG ) ? '.min' : ''; + return ( defined('SCRIPT_DEBUG' ) && ! SCRIPT_DEBUG ) ? '.min' : ''; } function ws_ls_admin_config() { diff --git a/includes/license.php b/includes/license.php index e4956567..b14e6d7b 100755 --- a/includes/license.php +++ b/includes/license.php @@ -365,7 +365,7 @@ function ws_ls_has_a_valid_old_pro_license() { $valid_license = get_option(WS_LS_LICENSE_VALID); - if(true == $valid_license) { + if( $valid_license ) { return true; } diff --git a/pro-features/db.php b/pro-features/db.php index 4f4f90cf..e6c5c25c 100755 --- a/pro-features/db.php +++ b/pro-features/db.php @@ -24,7 +24,7 @@ function ws_ls_db_stats_sum_weight_difference() { global $wpdb; $result = $wpdb->get_var( 'SELECT sum( weight_difference ) FROM ' . $wpdb->prefix . WE_LS_USER_STATS_TABLENAME ); - return ( false == empty( $result ) ) ? floatval( $result ) : false; + return ! empty( $result ) ? floatval( $result ) : false; } /** @@ -90,7 +90,7 @@ function ws_ls_db_stats_league_table_fetch( $ignore_cache = false, $limit = 10, $where = []; // Select only users that have lost weight? - if( true == ws_ls_force_bool_argument( $losers_only ) ) { + if( ws_ls_force_bool_argument( $losers_only ) ) { $where[] = 'weight_difference <= 0'; } diff --git a/pro-features/footable.php b/pro-features/footable.php index 84bfef59..4e9c285c 100755 --- a/pro-features/footable.php +++ b/pro-features/footable.php @@ -514,7 +514,7 @@ function ws_ls_data_js_config() { } else { $config[ 'current-url-base64' ] = ws_ls_get_url( true ); - $config[ 'us-date' ] = ( true == ws_ls_settings_date_is_us() ) ? 'true' : 'false'; + $config[ 'us-date' ] = ws_ls_settings_date_is_us() ? 'true' : 'false'; // Have we detected were in Admin, on a user profile? if ( true === ws_ls_datatable_is_user_profile() ) { diff --git a/pro-features/functions-stats.php b/pro-features/functions-stats.php index 424bb309..82310681 100644 --- a/pro-features/functions-stats.php +++ b/pro-features/functions-stats.php @@ -35,7 +35,7 @@ function ws_ls_stats_run_cron() { */ function ws_ls_stats_run_cron_for_first_time() { - if( false == get_option('ws-ls-stats-run-for-first-time')) { + if( ! get_option( 'ws-ls-stats-run-for-first-time' ) ) { ws_ls_stats_run_cron(); update_option('ws-ls-stats-run-for-first-time', true); } diff --git a/pro-features/plus/harris-benedict.php b/pro-features/plus/harris-benedict.php index d05ebc19..37d595a9 100644 --- a/pro-features/plus/harris-benedict.php +++ b/pro-features/plus/harris-benedict.php @@ -92,9 +92,7 @@ function ws_ls_harris_benedict_calculate_calories_raw( $bmr, $gender, $activity_ $calories_to_lose = ( $calorie_intake['maintain']['total'] > $calories_to_lose ) ? $calorie_intake['maintain']['total'] - $calories_to_lose : $calorie_intake['maintain']['total']; $is_female = ws_ls_is_female_raw( $gender ); - $calorie_cap = ( true == $is_female ) ? - ws_ls_harris_benedict_setting( 'ws-ls-female-cal-cap' ) - : ws_ls_harris_benedict_setting( 'ws-ls-male-cal-cap' ); + $calorie_cap = $is_female ? ws_ls_harris_benedict_setting( 'ws-ls-female-cal-cap' ) : ws_ls_harris_benedict_setting( 'ws-ls-male-cal-cap' ); // If suggested calorie intake to lose weight is above the cap, then set to cap. if ( $calories_to_lose > $calorie_cap ) { @@ -458,9 +456,7 @@ function ws_ls_display_calorie_cap( $user_id = false ) { function ws_ls_display_calorie_cap_raw( $gender ) { $is_female = ws_ls_is_female_raw( $gender ); - $calorie_cap = ( true == $is_female ) ? - ws_ls_harris_benedict_setting( 'ws-ls-female-cal-cap' ) : - ws_ls_harris_benedict_setting( 'ws-ls-male-cal-cap' ); + $calorie_cap = $is_female ? ws_ls_harris_benedict_setting( 'ws-ls-female-cal-cap' ) : ws_ls_harris_benedict_setting( 'ws-ls-male-cal-cap' ); return sprintf('%s %s %s. %s %s.', ($is_female) ? __('Female', WE_LS_SLUG ) : __('Male', WE_LS_SLUG ), diff --git a/pro-features/plus/meta-fields/functions-photos.php b/pro-features/plus/meta-fields/functions-photos.php index edad6de5..9a4e031b 100644 --- a/pro-features/plus/meta-fields/functions-photos.php +++ b/pro-features/plus/meta-fields/functions-photos.php @@ -115,7 +115,7 @@ function ws_ls_meta_fields_photos_process_upload( $field_name, $date_text = NULL // The wp_insert_attachment function needs the literal system path, which was passed back from wp_handle_upload $file_name_and_location = $uploaded_file['file']; - if( true == empty( $user_id ) ){ + if( empty( $user_id ) ){ $user_id = get_current_user_id(); } diff --git a/pro-features/shortcode-progress-bar.php b/pro-features/shortcode-progress-bar.php index f7d164a0..35dfd52d 100755 --- a/pro-features/shortcode-progress-bar.php +++ b/pro-features/shortcode-progress-bar.php @@ -61,7 +61,7 @@ function ws_ls_shortcode_progress_bar( $user_defined_arguments ) { $arguments['animation-duration'] = ws_ls_force_numeric_argument( $arguments[ 'animation-duration' ], 1400 ); // If no width or height specified by user, then set circle to a better default size. - if('circle' == $arguments['type'] && false == $arguments['width-height-specified']) { + if( 'circle' == $arguments['type'] && ! $arguments['width-height-specified'] ) { $arguments['width'] = '150px'; $arguments['height'] = '150px'; } diff --git a/pro-features/shortcode-stats.php b/pro-features/shortcode-stats.php index 52d492f0..b80824ea 100755 --- a/pro-features/shortcode-stats.php +++ b/pro-features/shortcode-stats.php @@ -38,7 +38,7 @@ function ws_ls_shortcode_stats_league_total( $user_defined_arguments ) {
'; - if(true == $arguments['show_percentage']) { + if( $arguments['show_percentage'] ) { $html .= ''; } @@ -67,7 +67,7 @@ function ws_ls_shortcode_stats_league_total( $user_defined_arguments ) { $percentage = ''; // Calculate % - if( true == $arguments[ 'show_percentage' ] && 0 !== (int) $row[ 'start_weight' ] ) { + if( $arguments['show_percentage'] && 0 !== (int) $row[ 'start_weight' ] ) { $percentage = ( ( $row[ 'recent_weight' ] - $row[ 'start_weight' ]) / $row[ 'start_weight' ] ) * 100; $percentage = ( false === ws_ls_to_bool( $arguments[ 'invert' ] ) ) ? $percentage : -$percentage ; $percentage = round( $percentage ) . '%'; @@ -89,7 +89,7 @@ function ws_ls_shortcode_stats_league_total( $user_defined_arguments ) { ws_ls_blur(), $display_name, ws_ls_blur_text( $stats[ 'display-value' ] ), - ( true == $arguments[ 'show_percentage' ] ) ? '' : '', + $arguments['show_percentage'] ? '' : '', ws_ls_blur_text( $row[ 'no_entries' ] ) ); @@ -157,7 +157,7 @@ function ws_ls_shortcode_stats_display_value( $stats, $arguments ) { } // Ignore global and user settings and force display to Kg? - if( true == ws_ls_to_bool( $arguments[ 'force-to-kg' ] ) ) { + if( ws_ls_to_bool( $arguments['force-to-kg'] ) ) { $stats[ 'display-unit' ] = 'kg'; } diff --git a/readme.txt b/readme.txt index 5931cc1b..4f65e264 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspect made 8+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 26+ changes to code for optimisation. = 10.6 = From d4b2af9263f84fb92c6532231a0a010464e4b577 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 09:58:23 +0100 Subject: [PATCH 18/31] Simplified IF --- pro-features/plus/meta-fields/shortcodes.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pro-features/plus/meta-fields/shortcodes.php b/pro-features/plus/meta-fields/shortcodes.php index 1d6ba92d..2b6071ea 100644 --- a/pro-features/plus/meta-fields/shortcodes.php +++ b/pro-features/plus/meta-fields/shortcodes.php @@ -95,8 +95,7 @@ function ws_ls_meta_fields_shortcode_accumulator( $user_defined_arguments ) { $increments = explode( ',', $shortcode_arguments[ 'increment-values' ] ); - if ( true == empty( $shortcode_arguments[ 'increment-values' ] ) || - true === empty( $increments ) ) { + if ( empty( $shortcode_arguments['increment-values'] ) || empty( $increments ) ) { return __( 'Please ensure you have a valid list of increment values e.g. [wt-custom-fields-accumulator increment-values="1,5,10"]', WE_LS_SLUG ); } From 9a245d012bc662c04114b475d7481e4f2c8467d8 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:36:31 +0100 Subject: [PATCH 19/31] Dropped default values that were not needed --- includes/admin-pages/awards/page-awards-add-update.php | 4 ++-- includes/admin-pages/user-data/data-search-results.php | 4 ++-- includes/caching.php | 2 +- includes/core-forms.php | 4 ++-- includes/core.php | 2 +- includes/form-handler.php | 6 +++--- includes/functions.php | 4 ++-- pro-features/plus/challenge/functions.php | 2 +- pro-features/plus/harris-benedict.php | 4 ++-- pro-features/plus/macronutrient-calculator.php | 2 +- pro-features/plus/shortcode.calculator.php | 2 +- pro-features/shortcode-stats.php | 4 ++-- pro-features/user-groups.php | 4 ++-- pro-features/user-preferences.php | 2 +- pro-features/web-hooks.php | 2 +- readme.txt | 2 +- 16 files changed, 25 insertions(+), 25 deletions(-) diff --git a/includes/admin-pages/awards/page-awards-add-update.php b/includes/admin-pages/awards/page-awards-add-update.php index 972f71dd..8206850d 100755 --- a/includes/admin-pages/awards/page-awards-add-update.php +++ b/includes/admin-pages/awards/page-awards-add-update.php @@ -23,7 +23,7 @@ function ws_ls_awards_add_update_page() { $mandatory_fields = array_merge( $mandatory_fields, [ 'weight_percentage' ] ); } else if ( 'weight' === $award['category'] ) { if( ws_ls_setting( 'use-imperial' ) ) { - if ( 'stones_pounds' === ws_ls_setting( 'weight-unit' ) ) { + if ( 'stones_pounds' === ws_ls_setting() ) { $mandatory_fields = array_merge( $mandatory_fields, [ 'stones', 'pounds' ] ); $award['value'] = ws_ls_convert_stones_pounds_to_kg( $award['stones'], $award['pounds'] ); } else { @@ -159,7 +159,7 @@ function ws_ls_awards_add_update_page() { if( ws_ls_setting( 'use-imperial' ) ) { - if ( 'stones_pounds' === ws_ls_setting( 'weight-unit' ) ) { + if ( 'stones_pounds' === ws_ls_setting() ) { if ( true === $validation_fail ) { $weight['stones'] = $award['stones']; diff --git a/includes/admin-pages/user-data/data-search-results.php b/includes/admin-pages/user-data/data-search-results.php index 3f845882..89ce7bc1 100755 --- a/includes/admin-pages/user-data/data-search-results.php +++ b/includes/admin-pages/user-data/data-search-results.php @@ -23,11 +23,11 @@ function ws_ls_admin_page_search_results() { ws_ls_display_pro_upgrade_notice(); } - $search_term = ws_ls_querystring_value( 'search', false ); + $search_term = ws_ls_querystring_value( 'search' ); if( true === WS_LS_IS_PRO && false === empty( $search_term ) ) { - $search_results = ws_ls_user_search( $search_term,true ); + $search_results = ws_ls_user_search( $search_term ); if( false === empty( $search_results ) ) { diff --git a/includes/caching.php b/includes/caching.php index 4d5b0130..ff7755a7 100755 --- a/includes/caching.php +++ b/includes/caching.php @@ -56,7 +56,7 @@ function ws_ls_cache_user_get( $user_id, $key ) { // If no data is found at this key, presume the cache entry has expired, so remove from lookup. if ( false === $data_value ) { unset( $user_lookup_table[ $key ] ); - ws_ls_cache_set( $user_id, $user_lookup_table, WE_LS_CACHE_TIME ); + ws_ls_cache_set( $user_id, $user_lookup_table ); } return $data_value; diff --git a/includes/core-forms.php b/includes/core-forms.php index e835a835..c62a87ba 100644 --- a/includes/core-forms.php +++ b/includes/core-forms.php @@ -96,7 +96,7 @@ function ws_ls_form_weight( $arguments = [] ) { if ( true === in_array( $arguments[ 'type' ], [ 'custom-fields', 'weight' ] ) && ( true === empty( $arguments[ 'entry-id' ] ) && empty( $arguments[ 'entry' ] ) ) - && WS_LS_IS_PRO && ws_ls_option_to_bool( 'ws-ls-populate-form-with-values-on-date', 'yes' ) + && WS_LS_IS_PRO && ws_ls_option_to_bool( 'ws-ls-populate-form-with-values-on-date' ) ) { $date = ws_ls_convert_date_to_iso( $arguments[ 'todays-date' ]); @@ -330,7 +330,7 @@ function ws_ls_form_init( $arguments = [] ) { // Are photo fields enabled for this form? $arguments[ 'photos-enabled' ] = ( false === $arguments[ 'hide-fields-photos' ] && true === $arguments[ 'meta-enabled' ] && - true === ws_ls_meta_fields_photo_any_enabled( false ) ); + true === ws_ls_meta_fields_photo_any_enabled() ); // Custom field filtering? $arguments[ 'custom-field-groups' ] = ws_ls_meta_fields_groups_slugs_to_ids( $arguments[ 'custom-field-groups' ] ); diff --git a/includes/core.php b/includes/core.php index e9aecbf5..93c9807a 100755 --- a/includes/core.php +++ b/includes/core.php @@ -36,7 +36,7 @@ function ws_ls_config_js() { 'date-picker-locale' => ws_ls_config_js_datapicker_locale(), 'in-admin' => ( is_admin() ) ? 'true' : 'false', 'max-photo-upload' => ws_ls_photo_max_upload_size(), - 'form-load-previous' => false === is_admin() && WS_LS_IS_PRO && ws_ls_option_to_bool( 'ws-ls-populate-form-with-values-on-date', 'yes' ), + 'form-load-previous' => false === is_admin() && WS_LS_IS_PRO && ws_ls_option_to_bool( 'ws-ls-populate-form-with-values-on-date' ), 'focus' => ws_ls_querystring_value( 'focus' ), 'load-entry-url' => apply_filters( 'wlt_current_url', get_permalink() ), ]; diff --git a/includes/form-handler.php b/includes/form-handler.php index df9afeea..6cff15c2 100755 --- a/includes/form-handler.php +++ b/includes/form-handler.php @@ -226,7 +226,7 @@ function ws_ls_form_post_handler_extract_weight( $get_or_post = 'post' ) { // Are we lucky? Metric by default? $kg = 'post' === $get_or_post ? ws_ls_post_value( 'ws-ls-weight-kg', NULL, true ) : - ws_ls_querystring_value( 'ws-ls-weight-kg', false, NULL, true ); + ws_ls_querystring_value( 'ws-ls-weight-kg', false, NULL ); if ( NULL !== $kg ) { return $kg; @@ -234,11 +234,11 @@ function ws_ls_form_post_handler_extract_weight( $get_or_post = 'post' ) { $stones = 'post' === $get_or_post ? ws_ls_post_value( 'ws-ls-weight-stones', NULL, true ) : - ws_ls_querystring_value( 'ws-ls-weight-stones', false, NULL, true ); + ws_ls_querystring_value( 'ws-ls-weight-stones', false, NULL ); $pounds = 'post' === $get_or_post ? ws_ls_post_value( 'ws-ls-weight-pounds', NULL, true ) : - ws_ls_querystring_value( 'ws-ls-weight-pounds', false, NULL, true ); + ws_ls_querystring_value( 'ws-ls-weight-pounds', false, NULL ); // Stones and Pounds if ( NULL !== $stones ) { diff --git a/includes/functions.php b/includes/functions.php index 2cb7a488..7cc65159 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1412,7 +1412,7 @@ function ws_ls_round_number( $number, $decimal_places = 0 ) { var_dump($number); } - return number_format( $number, $decimal_places, '.', ',' ); + return number_format( $number, $decimal_places ); } /** @@ -1638,7 +1638,7 @@ function ws_ls_weight_difference_from_start( $user_id, $kg ) { */ function ws_ls_get_unit() { - switch ( ws_ls_setting( 'weight-unit' )) { + switch ( ws_ls_setting() ) { case 'pounds_only': $unit = __("lbs", WE_LS_SLUG); break; diff --git a/pro-features/plus/challenge/functions.php b/pro-features/plus/challenge/functions.php index 9f7af942..77531943 100644 --- a/pro-features/plus/challenge/functions.php +++ b/pro-features/plus/challenge/functions.php @@ -502,7 +502,7 @@ function ws_ls_challenges_show_filters() { */ function ws_ls_challenge_filters_group_select_values() { - $groups = ws_ls_groups( true ); + $groups = ws_ls_groups(); return wp_list_pluck( $groups, 'name', 'id' ); } diff --git a/pro-features/plus/harris-benedict.php b/pro-features/plus/harris-benedict.php index 37d595a9..c696090a 100644 --- a/pro-features/plus/harris-benedict.php +++ b/pro-features/plus/harris-benedict.php @@ -88,7 +88,7 @@ function ws_ls_harris_benedict_calculate_calories_raw( $bmr, $gender, $activity_ // Lose // -------------------------------------------------- - $calories_to_lose = ws_ls_harris_benedict_filter_calories_to_lose( $calorie_intake['maintain']['total'], $gender, false ); + $calories_to_lose = ws_ls_harris_benedict_filter_calories_to_lose( $calorie_intake['maintain']['total'], $gender ); $calories_to_lose = ( $calorie_intake['maintain']['total'] > $calories_to_lose ) ? $calorie_intake['maintain']['total'] - $calories_to_lose : $calorie_intake['maintain']['total']; $is_female = ws_ls_is_female_raw( $gender ); @@ -522,7 +522,7 @@ function ws_ls_harris_benedict_filter_show_hide_gains_loss( $calorie_intake ) { return $calorie_intake; } -add_filter( 'wlt-filter-calories-pre', 'ws_ls_harris_benedict_filter_show_hide_gains_loss', 10, 1 ); +add_filter( 'wlt-filter-calories-pre', 'ws_ls_harris_benedict_filter_show_hide_gains_loss' ); /** * Return the setting for calories to add weight diff --git a/pro-features/plus/macronutrient-calculator.php b/pro-features/plus/macronutrient-calculator.php index 9f8cbe4a..86d8df73 100644 --- a/pro-features/plus/macronutrient-calculator.php +++ b/pro-features/plus/macronutrient-calculator.php @@ -153,7 +153,7 @@ function ws_ls_macro_render_table($user_id, $missing_data_text = false, $additio ', ws_ls_get_macro_name( $key ), - ws_ls_round_number( $macros[$key]['calories'], 0 ), + ws_ls_round_number( $macros[$key]['calories'] ), __('Total', WE_LS_SLUG), __('Breakfast', WE_LS_SLUG), __('Lunch', WE_LS_SLUG), diff --git a/pro-features/plus/shortcode.calculator.php b/pro-features/plus/shortcode.calculator.php index f74b8f04..b6200557 100644 --- a/pro-features/plus/shortcode.calculator.php +++ b/pro-features/plus/shortcode.calculator.php @@ -104,7 +104,7 @@ function ws_ls_shortcode_calculator( $user_defined_arguments ) { $html_output .= sprintf( '

%1$s %2$s.

', esc_html( $arguments[ 'text-bmi' ] ), esc_html( $bmi ) ); } - $calories = ws_ls_harris_benedict_calculate_calories_raw( $bmr, $entry[ 'ws-ls-gender' ], $entry[ 'ws-ls-activity-level' ], false ); + $calories = ws_ls_harris_benedict_calculate_calories_raw( $bmr, $entry[ 'ws-ls-gender' ], $entry[ 'ws-ls-activity-level' ] ); if ( true === ws_ls_to_bool( $arguments[ 'results-show-calories' ] ) ) { diff --git a/pro-features/shortcode-stats.php b/pro-features/shortcode-stats.php index b80824ea..0be0b5dc 100755 --- a/pro-features/shortcode-stats.php +++ b/pro-features/shortcode-stats.php @@ -62,7 +62,7 @@ function ws_ls_shortcode_stats_league_total( $user_defined_arguments ) { } // Get the display value for weight - $stats = ws_ls_shortcode_stats_display_value([ 'kg' => $row['weight_difference'], 'display-unit' => ws_ls_setting( 'weight-unit' ), 'display-value' => '' ], $arguments ); + $stats = ws_ls_shortcode_stats_display_value([ 'kg' => $row['weight_difference'], 'display-unit' => ws_ls_setting(), 'display-value' => '' ], $arguments ); $percentage = ''; @@ -122,7 +122,7 @@ function ws_ls_shortcode_stats_total_lost( $user_defined_arguments ) { $arguments = shortcode_atts( [ 'display' => 'number/text', 'force-to-kg' => 'false', 'invert' => false ], $user_defined_arguments ); $summary_stats = ws_ls_stats_get_summary_stats(); - $stats = ws_ls_shortcode_stats_display_value( [ 'kg' => $summary_stats['difference'], 'display-unit' => ws_ls_setting('weight-unit' ), 'display-value' => '' ], $arguments ); + $stats = ws_ls_shortcode_stats_display_value( [ 'kg' => $summary_stats['difference'], 'display-unit' => ws_ls_setting(), 'display-value' => '' ], $arguments ); return $stats['display-value']; } diff --git a/pro-features/user-groups.php b/pro-features/user-groups.php index 2733e978..5571fb25 100755 --- a/pro-features/user-groups.php +++ b/pro-features/user-groups.php @@ -136,7 +136,7 @@ function ws_ls_groups_hooks_user_preferences_form( $html, $user_id ) { if ( true === ws_ls_groups_enabled() ) { - $groups = ws_ls_groups( true ); + $groups = ws_ls_groups(); if ( false === empty( $groups ) ) { @@ -1030,4 +1030,4 @@ function ws_ls_groups_add_missing_group( $user_id ) { ws_ls_groups_add_to_user( 0, $user_id ); } -add_action( 'wlt-hook-data-attempting-added-edited', 'ws_ls_groups_add_missing_group', 10, 1 ); +add_action( 'wlt-hook-data-attempting-added-edited', 'ws_ls_groups_add_missing_group' ); diff --git a/pro-features/user-preferences.php b/pro-features/user-preferences.php index a07b5002..aa141b34 100755 --- a/pro-features/user-preferences.php +++ b/pro-features/user-preferences.php @@ -98,7 +98,7 @@ function ws_ls_user_preferences_form( $user_defined_arguments ) { '; if ( false === ws_ls_to_bool( $arguments[ 'hide-aim' ] ) ) { - $html_output .= ws_ls_form_field_select( [ 'uikit' => $arguments[ 'uikit' ], 'key' => 'ws-ls-aim', 'label' => $labels['aim'], 'values' => ws_ls_aims(), 'selected' => ws_ls_user_preferences_get( 'aim', $user_id, NULL ), 'css-class' => 'ws-ls-aboutyou-field' ] ); + $html_output .= ws_ls_form_field_select( [ 'uikit' => $arguments[ 'uikit' ], 'key' => 'ws-ls-aim', 'label' => $labels['aim'], 'values' => ws_ls_aims(), 'selected' => ws_ls_user_preferences_get( 'aim', $user_id ), 'css-class' => 'ws-ls-aboutyou-field' ] ); } if ( false === ws_ls_to_bool( $arguments[ 'hide-extras' ] ) ) { diff --git a/pro-features/web-hooks.php b/pro-features/web-hooks.php index 40f1c00c..cb8ecfbb 100644 --- a/pro-features/web-hooks.php +++ b/pro-features/web-hooks.php @@ -208,7 +208,7 @@ function ws_ls_webhooks_data_prep_weight( $entry ) { $data[ 'custom-fields' ] = []; foreach ( $entry[ 'meta' ] as $id => $value ) { - $index = ws_ls_meta_fields_get_column( $id, 'field_key' ); + $index = ws_ls_meta_fields_get_column( $id ); $data[ 'custom-fields' ][ $index ] = ws_ls_fields_display_field_value( $value, $id, true ); } } diff --git a/readme.txt b/readme.txt index 4f65e264..be250bff 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 26+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 36+ changes to code for optimisation. = 10.6 = From bfc66f9117ee99022219b5e752619831b7d57e81 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:41:42 +0100 Subject: [PATCH 20/31] Simplified logic statements --- includes/admin-pages/settings/page-settings-generic.php | 2 +- includes/admin-pages/user-data/data-summary.php | 8 ++++---- includes/admin-pages/user-data/data-view-all.php | 4 ++-- includes/ajax.php | 2 +- includes/db.php | 4 ++-- includes/functions.php | 2 +- pro-features/functions.php | 2 +- pro-features/plus/awards/functions.php | 4 ++-- pro-features/plus/harris-benedict.php | 4 ++-- pro-features/plus/meta-fields/db.php | 2 +- pro-features/user-birthdays.php | 2 +- pro-features/user-groups.php | 2 +- readme.txt | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/includes/admin-pages/settings/page-settings-generic.php b/includes/admin-pages/settings/page-settings-generic.php index 38e08848..66027e29 100755 --- a/includes/admin-pages/settings/page-settings-generic.php +++ b/includes/admin-pages/settings/page-settings-generic.php @@ -11,7 +11,7 @@ function ws_ls_settings_page_generic() { $disable_if_not_pro_class = (WS_LS_IS_PRO) ? '' : 'ws-ls-disabled'; $disable_if_not_pro_plus_class = (WS_LS_IS_PRO_PLUS) ? '' : 'ws-ls-disabled-pro-plus'; - $clear_cache = ( isset($_GET['settings-updated']) && 'true' == $_GET['settings-updated'] ) ? true : false; + $clear_cache = isset( $_GET[ 'settings-updated' ] ) && 'true' == $_GET[ 'settings-updated' ]; if ( true === is_admin() && false === empty( $_GET['recreatetables'] ) ) { diff --git a/includes/admin-pages/user-data/data-summary.php b/includes/admin-pages/user-data/data-summary.php index b507f0b4..f7033e0e 100755 --- a/includes/admin-pages/user-data/data-summary.php +++ b/includes/admin-pages/user-data/data-summary.php @@ -191,12 +191,12 @@ function ws_ls_postbox_league_table() { // If changing gain / loss set options if( false === empty($_GET['show-gain'])) { - $value = ('y' === $_GET['show-gain']) ? true : false; + $value = 'y' === $_GET['show-gain']; update_option('ws-ls-show-gains', $value); } // Are we wanting to see who has lost the most? Or gained? - $show_gain = get_option('ws-ls-show-gains') ? true : false; + $show_gain = (bool) get_option( 'ws-ls-show-gains' ); $title = ( false === $show_gain ) ? __( 'League table for those that have lost the most', WE_LS_SLUG ) : __( 'League Table for those that have gained the most', WE_LS_SLUG ); ws_ls_postbox_header( [ 'title' => $title, 'postbox-id' => 'league-table' ] ); @@ -250,12 +250,12 @@ function ws_ls_postbox_latest_entries() {?> // Show meta data? if( false === empty( $_GET['show-meta'] ) ) { - $value = ( 'y' === $_GET['show-meta'] ) ? true : false; + $value = 'y' === $_GET['show-meta']; update_option('ws-ls-show-meta', $value ); } $entries_limit = (int) get_option( 'ws-ls-entries-limit', 100 ); - $show_meta = get_option( 'ws-ls-show-meta' ) ? true : false; + $show_meta = (bool) get_option( 'ws-ls-show-meta' ); $title = ( false === empty( $entries_limit ) ) ? sprintf( 'Last %d entries', $entries_limit ) : __( 'All entries', WE_LS_SLUG ); diff --git a/includes/admin-pages/user-data/data-view-all.php b/includes/admin-pages/user-data/data-view-all.php index ab4ccb1e..8f7f5f00 100755 --- a/includes/admin-pages/user-data/data-view-all.php +++ b/includes/admin-pages/user-data/data-view-all.php @@ -58,11 +58,11 @@ function ws_ls_admin_page_view_all() { // Show meta data? if ( false === empty( $_GET['show-meta'] ) ) { - $value = ( 'y' === $_GET['show-meta'] ) ? true : false; + $value = 'y' === $_GET['show-meta']; update_option( 'ws-ls-show-meta', $value ); } - $show_meta = get_option( 'ws-ls-show-meta' ) ? true : false; + $show_meta = (bool) get_option( 'ws-ls-show-meta' ); echo ws_ls_data_table_render( [ 'limit' => 5000, 'enable-meta-fields' => $show_meta, 'custom-field-col-size' => 'xs' ] ); diff --git a/includes/ajax.php b/includes/ajax.php index 49ecd6cb..6874b723 100644 --- a/includes/ajax.php +++ b/includes/ajax.php @@ -45,7 +45,7 @@ function ws_ls_save_preferences_callback() { check_ajax_referer( 'ws-ls-nonce', 'security' ); - $in_admin_area = ( NULL !== ws_ls_post_value('we-ls-in-admin' ) ) ? true : false; + $in_admin_area = NULL !== ws_ls_post_value('we-ls-in-admin' ); $fields = []; diff --git a/includes/db.php b/includes/db.php index c656339c..2217e117 100755 --- a/includes/db.php +++ b/includes/db.php @@ -635,7 +635,7 @@ function ws_ls_set_user_preference( $field, $value, $user_id = NULL ) { $db_field_types ); - $result = ($result === false) ? false : true; + $result = ! ( ( $result === false ) ); // Tidy up cache ws_ls_cache_user_delete( $db_fields['user_id'] ); @@ -680,7 +680,7 @@ function ws_ls_set_user_preference_simple( $field, $value, $user_id = NULL ) { [ '%d' ] ); - $result = ($result === false) ? false : true; + $result = ! ( ( $result === false ) ); // If settings are saved correctly, then fire hook for others. if ( true === $result ) { diff --git a/includes/functions.php b/includes/functions.php index 7cc65159..768d371e 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -630,7 +630,7 @@ function ws_ls_force_dimension_argument($value, $default = false) { if ( false === empty($value) ) { // Is this a percentage? - $is_percentage = (false !== stripos($value, '%') ) ? true: false; + $is_percentage = false !== stripos( $value, '%' ); // Strip % sign out if needed $value = ( $is_percentage ) ? ws_ls_remove_non_numeric($value) : $value; diff --git a/pro-features/functions.php b/pro-features/functions.php index 6610ead2..36f41409 100755 --- a/pro-features/functions.php +++ b/pro-features/functions.php @@ -782,7 +782,7 @@ function ws_ls_user_exist( $user_id ) { return false; } - return ( false === get_userdata( $user_id ) ) ? false : true; + return ! ( ( false === get_userdata( $user_id ) ) ); } /** diff --git a/pro-features/plus/awards/functions.php b/pro-features/plus/awards/functions.php index 2ebba2e3..e3fc9e58 100755 --- a/pro-features/plus/awards/functions.php +++ b/pro-features/plus/awards/functions.php @@ -213,7 +213,7 @@ function ws_ls_awards_to_give( $user_id = NULL, $change_type = NULL, $losing_wei // Loop through each award in DB, count it's type and decide whether to consider issuing it. return [ - 'any' => ( count( $awards ) > 0 ) ? true : false, + 'any' => count( $awards ) > 0, 'counts' => $counts, 'awards' => $awards ]; @@ -367,5 +367,5 @@ function ws_ls_awards_render_badges( $user_defined_arguments ) { * @return bool */ function ws_ls_awards_email_notifications_enabled() { - return 'y' === get_option('ws-ls-awards-email-notifications', false ) ? true : false; + return 'y' === get_option('ws-ls-awards-email-notifications', false ); } diff --git a/pro-features/plus/harris-benedict.php b/pro-features/plus/harris-benedict.php index c696090a..7c1febb6 100644 --- a/pro-features/plus/harris-benedict.php +++ b/pro-features/plus/harris-benedict.php @@ -479,7 +479,7 @@ function ws_ls_harris_benedict_show_lose_figures() { return false; } - return 'no' === get_option('ws-ls-cal-show-loss', true ) ? false : true; + return ! ( 'no' === get_option( 'ws-ls-cal-show-loss', true ) ); } /** @@ -493,7 +493,7 @@ function ws_ls_harris_benedict_show_gain_figures() { return false; } - return 'yes' === get_option('ws-ls-cal-show-gain', false ) ? true : false; + return 'yes' === get_option('ws-ls-cal-show-gain', false ); } /** diff --git a/pro-features/plus/meta-fields/db.php b/pro-features/plus/meta-fields/db.php index f4b85c79..25b25650 100755 --- a/pro-features/plus/meta-fields/db.php +++ b/pro-features/plus/meta-fields/db.php @@ -394,7 +394,7 @@ function ws_ls_meta_fields_key_exist( $key ) { $count = $wpdb->get_var( $sql ); - return ( 0 === (int) $count ) ? false : true; + return ! ( ( 0 === (int) $count ) ); } /** diff --git a/pro-features/user-birthdays.php b/pro-features/user-birthdays.php index 0461b481..ee7686d9 100755 --- a/pro-features/user-birthdays.php +++ b/pro-features/user-birthdays.php @@ -13,7 +13,7 @@ function ws_ls_birthdays_enabled() { return false; } - return 'yes' === get_option('ws-ls-enable-birthdays', false ) ? true : false; + return 'yes' === get_option('ws-ls-enable-birthdays', false ); } /** diff --git a/pro-features/user-groups.php b/pro-features/user-groups.php index 5571fb25..1a68d7a8 100755 --- a/pro-features/user-groups.php +++ b/pro-features/user-groups.php @@ -28,7 +28,7 @@ function ws_ls_groups_can_users_edit() { return false; } - return 'yes' === get_option('ws-ls-enable-groups-user-edit', false ) ? true : false; + return 'yes' === get_option('ws-ls-enable-groups-user-edit', false ); } /** diff --git a/readme.txt b/readme.txt index be250bff..2926991e 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 36+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 48+ changes to code for optimisation. = 10.6 = From ad67d36f673d1704ad3c55394ca32ed98c4e9b4d Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:42:43 +0100 Subject: [PATCH 21/31] Removed unneeded returns --- includes/deprecated.php | 2 -- pro-features/db.php | 5 +---- pro-features/email-notifications.php | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/includes/deprecated.php b/includes/deprecated.php index 856c3091..7deacd0e 100644 --- a/includes/deprecated.php +++ b/includes/deprecated.php @@ -18,8 +18,6 @@ function ws_ls_harris_benedict_migrate_old_macro_percentages() { update_option( 'ws-ls-macro-carbs-' . $key, ws_ls_harris_benedict_setting( 'ws-ls-macro-carbs' ) ); update_option( 'ws-ls-macro-fats-' . $key, ws_ls_harris_benedict_setting( 'ws-ls-macro-fats' ) ); } - - return; } } add_action( 'admin_init', 'ws_ls_harris_benedict_migrate_old_macro_percentages' ); diff --git a/pro-features/db.php b/pro-features/db.php index e6c5c25c..0fb251a7 100755 --- a/pro-features/db.php +++ b/pro-features/db.php @@ -42,7 +42,7 @@ function ws_ls_db_stats_insert_missing_user_ids_into_stats() { Select distinct weight_user_id, NULL, NULL, NULL, NOW() - INTERVAL 7 DAY from $data_table_name where weight_weight is not null and weight_user_id not in (Select user_id from $stats_table_name)"; $wpdb->query( $sql ); - return; + } /** @@ -58,8 +58,6 @@ function ws_ls_db_stats_remove_deleted_user_ids_from_stats() { $sql = "Delete from $stats_table_name Where user_id not in ( Select ID from $data_table_name )"; $wpdb->query( $sql ); - - return; } /** @@ -127,5 +125,4 @@ function ws_ls_db_stats_clear_last_updated_date(){ // Note: Set last update to 7 days ago so this record is considered to be out of date and requiring a refresh $wpdb->query( 'Update ' . $wpdb->prefix . WE_LS_USER_STATS_TABLENAME . ' set last_update = NOW() - INTERVAL 7 DAY' ); - return; } diff --git a/pro-features/email-notifications.php b/pro-features/email-notifications.php index 8d8750a7..2c11651c 100644 --- a/pro-features/email-notifications.php +++ b/pro-features/email-notifications.php @@ -123,8 +123,6 @@ function ws_ls_email_notification( $type, $weight_data ) { ws_ls_emailer_send( $email_addresses, $email_data[ 'subject' ], $message[ 'email' ], $email_data ); } } - - return; } add_action( 'wlt-hook-data-added-edited', 'ws_ls_email_notification', 10, 2); From 3359bb9471c51683d8f911a016da381c55cd7d05 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:46:42 +0100 Subject: [PATCH 22/31] Inlined variables --- includes/functions.php | 4 +--- pro-features/footable.php | 4 +--- pro-features/functions.php | 14 +++----------- pro-features/hook-gravity-forms.php | 12 +++--------- pro-features/plus/awards/functions.php | 3 +-- pro-features/plus/challenge/db.php | 3 +-- pro-features/plus/challenge/functions.php | 4 +--- pro-features/plus/harris-benedict.php | 4 +--- pro-features/plus/meta-fields/db.php | 12 +++--------- pro-features/shortcode-stats.php | 4 +--- readme.txt | 2 +- 11 files changed, 17 insertions(+), 49 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 768d371e..21e9b55f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -309,9 +309,7 @@ function ws_ls_entry_get( $arguments = [] ) { } - $entry = ws_ls_weight_prep( $entry ); - - return $entry; + return ws_ls_weight_prep( $entry ); } /** diff --git a/pro-features/footable.php b/pro-features/footable.php index 4e9c285c..cd6a7295 100755 --- a/pro-features/footable.php +++ b/pro-features/footable.php @@ -339,9 +339,7 @@ function ws_ls_datatable_rows( $arguments ) { $rows = array_reverse( $rows ); // Localise the row for the user viewing - $rows = array_map( 'ws_ls_datatable_rows_localise', $rows ); - - return $rows; + return array_map( 'ws_ls_datatable_rows_localise', $rows ); } /** diff --git a/pro-features/functions.php b/pro-features/functions.php index 36f41409..9201245a 100755 --- a/pro-features/functions.php +++ b/pro-features/functions.php @@ -400,9 +400,7 @@ function ws_ls_activity_levels() { '1.9' => __( 'Extra Active (very active & physical job)', WE_LS_SLUG ) ]; - $activity_levels = apply_filters( 'wlt-filter-activity-levels', $activity_levels ); - - return $activity_levels; + return apply_filters( 'wlt-filter-activity-levels', $activity_levels ); } /** @@ -419,13 +417,9 @@ function ws_ls_aims() { 3 => __('Gain weight', WE_LS_SLUG) ]; - $aims = apply_filters( 'wlt-filter-aims', $aims ); - - return $aims; + return apply_filters( 'wlt-filter-aims', $aims ); } - - /** * Return an array of heights * @@ -822,9 +816,7 @@ function ws_ls_get_progress_attribute_from_aim() { $aim_string = 'lose'; } - $aim_string = apply_filters( 'wlt-filter-aim-progress-attribute', $aim_string, $aim_int ); - - return $aim_string; + return apply_filters( 'wlt-filter-aim-progress-attribute', $aim_string, $aim_int ); } /** diff --git a/pro-features/hook-gravity-forms.php b/pro-features/hook-gravity-forms.php index 069e7e8c..3d133ce1 100755 --- a/pro-features/hook-gravity-forms.php +++ b/pro-features/hook-gravity-forms.php @@ -239,9 +239,7 @@ function ws_ls_gravity_forms_keys() { $keys = array_merge( $keys, ws_ls_gravity_forms_weight_keys() ); $keys = array_merge( $keys, ws_ls_gravity_forms_preferences_keys() ); - $keys = array_merge( $keys, ws_ls_gravity_forms_meta_fields_keys() ); - - return $keys; + return array_merge( $keys, ws_ls_gravity_forms_meta_fields_keys() ); } /** @@ -256,9 +254,7 @@ function ws_ls_gravity_forms_weight_keys() { $keys[] = $prefix . 'pounds'; $keys[] = $prefix . 'stones'; - $keys = apply_filters( 'wlt-filters-gf-weight-keys', $keys ); - - return $keys; + return apply_filters( 'wlt-filters-gf-weight-keys', $keys ); } /** @@ -272,9 +268,7 @@ function ws_ls_gravity_forms_preferences_keys() { $keys[] = $prefix . 'body-type'; - $keys = apply_filters( 'wlt-filters-gf-preferences-keys', $keys ); - - return $keys; + return apply_filters( 'wlt-filters-gf-preferences-keys', $keys ); } /** diff --git a/pro-features/plus/awards/functions.php b/pro-features/plus/awards/functions.php index e3fc9e58..b9c3f558 100755 --- a/pro-features/plus/awards/functions.php +++ b/pro-features/plus/awards/functions.php @@ -38,7 +38,7 @@ function ws_ls_awards_categories( $simple = false) { } - $fields = [ + return [ 'bmi' => __('BMI: Change', WE_LS_SLUG ), 'bmi-equals' => __('BMI: Equals', WE_LS_SLUG ), 'weight-target' => __('Weight: Target met (based on user aim)', WE_LS_SLUG ), @@ -47,7 +47,6 @@ function ws_ls_awards_categories( $simple = false) { ]; - return $fields; } /** diff --git a/pro-features/plus/challenge/db.php b/pro-features/plus/challenge/db.php index 96b2b862..5126d1f7 100644 --- a/pro-features/plus/challenge/db.php +++ b/pro-features/plus/challenge/db.php @@ -456,7 +456,6 @@ function ws_ls_challenges_get_meal_tracker_entries( $user_id, $start_date = NULL $result = $wpdb->get_results( $sql, ARRAY_A ); - $result = ( false === empty( $result ) ) ? $result : false; + return ( ! empty( $result ) ) ? $result : false; - return $result; } diff --git a/pro-features/plus/challenge/functions.php b/pro-features/plus/challenge/functions.php index 77531943..e5bb86ea 100644 --- a/pro-features/plus/challenge/functions.php +++ b/pro-features/plus/challenge/functions.php @@ -520,7 +520,5 @@ function ws_ls_challenge_link( $challenge_id, $mode = 'view' ) { $url = sprintf( 'admin.php?page=ws-ls-challenges&mode=%1$s&challenge-id=%2$d', $mode, $challenge_id ); - $url = admin_url( $url ); - - return $url; + return admin_url( $url ); } diff --git a/pro-features/plus/harris-benedict.php b/pro-features/plus/harris-benedict.php index 7c1febb6..05ad34ba 100644 --- a/pro-features/plus/harris-benedict.php +++ b/pro-features/plus/harris-benedict.php @@ -138,9 +138,7 @@ function ws_ls_harris_benedict_calculate_calories_raw( $bmr, $gender, $activity_ $calorie_intake[ $key ] = array_map('ws_ls_round_bmr_harris', $calorie_intake[$key]); } - $calorie_intake = apply_filters( 'wlt-filter-harris-benedict', $calorie_intake, $user_id, $bmr, $activity_level, $calories_to_lose, $calories_to_gain, $gender ); - - return $calorie_intake; + return apply_filters( 'wlt-filter-harris-benedict', $calorie_intake, $user_id, $bmr, $activity_level, $calories_to_lose, $calories_to_gain, $gender ); } /** diff --git a/pro-features/plus/meta-fields/db.php b/pro-features/plus/meta-fields/db.php index 25b25650..0ce305b3 100755 --- a/pro-features/plus/meta-fields/db.php +++ b/pro-features/plus/meta-fields/db.php @@ -15,9 +15,7 @@ function ws_ls_meta( $entry_id ) { $sql = $wpdb->prepare( 'Select * from ' . $wpdb->prefix . WE_LS_MYSQL_META_ENTRY . ' where entry_id = %d', $entry_id ); - $data = $wpdb->get_results( $sql, ARRAY_A ); - - return $data; + return $wpdb->get_results( $sql, ARRAY_A ); } /** @@ -33,9 +31,7 @@ function ws_ls_meta_for_given_meta_field( $meta_field_id ) { $sql = $wpdb->prepare( 'Select * from ' . $wpdb->prefix . WE_LS_MYSQL_META_ENTRY . ' where meta_field_id = %d', $meta_field_id ); - $data = $wpdb->get_results( $sql, ARRAY_A ); - - return $data; + return $wpdb->get_results( $sql, ARRAY_A ); } /** @@ -159,11 +155,9 @@ function ws_ls_meta_fields_enabled() { if ( false === empty( $fields ) ) { // Remove any disabled fields! - $fields = array_filter( $fields, function( $value ) { + return array_filter( $fields, function( $value ) { return ( false === empty( $value['enabled'] ) && 2 === (int) $value['enabled'] ); }); - - return $fields; } return []; diff --git a/pro-features/shortcode-stats.php b/pro-features/shortcode-stats.php index 0be0b5dc..dbe2c210 100755 --- a/pro-features/shortcode-stats.php +++ b/pro-features/shortcode-stats.php @@ -174,9 +174,7 @@ function ws_ls_shortcode_stats_display_value( $stats, $arguments ) { } // Allow theme developer to override stats message - $stats = apply_filters( 'wlt-filter-stats-shortcode', $stats); - - return $stats; + return apply_filters( 'wlt-filter-stats-shortcode', $stats ); } return ''; diff --git a/readme.txt b/readme.txt index 2926991e..f3e9e4a9 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 48+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 70+ changes to code for optimisation. = 10.6 = From e66a4bc5c62f96822aa8a929cf0a2be9cabc5721 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:47:41 +0100 Subject: [PATCH 23/31] Removed stray semi colons --- includes/admin-pages/user-data/data-groups.php | 3 +-- includes/functions.php | 2 +- includes/shortcode-wt.php | 2 +- pro-features/user-preferences.php | 2 +- readme.txt | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/includes/admin-pages/user-data/data-groups.php b/includes/admin-pages/user-data/data-groups.php index bba51461..a65169e4 100755 --- a/includes/admin-pages/user-data/data-groups.php +++ b/includes/admin-pages/user-data/data-groups.php @@ -55,8 +55,7 @@ function ws_ls_admin_page_group_view() { if ( true === (bool) apply_filters( 'wlt-filters-admin-entries-per-group-view-enabled', true ) ) { echo ws_ls_component_group_view_entries( [ 'group-id' => $group_id, 'enable-group-select' => false, 'uikit' => false ]); } - - ;?> + ?>

diff --git a/includes/functions.php b/includes/functions.php index 21e9b55f..9a610551 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -478,7 +478,7 @@ function ws_ls_entry_get_todays( $arguments = [] ) { if ( true === empty( $todays_entry ) ) { return NULL; - }; + } return ( true === $arguments[ 'kg-only'] && false === empty( $todays_entry[ 'kg' ] ) ) ? diff --git a/includes/shortcode-wt.php b/includes/shortcode-wt.php index b4528795..0818cb36 100644 --- a/includes/shortcode-wt.php +++ b/includes/shortcode-wt.php @@ -186,7 +186,7 @@ function ws_ls_shortcode_wt( $user_defined_arguments ) { return $html . ''; } -add_shortcode( 'wt', 'ws_ls_shortcode_wt' );; +add_shortcode( 'wt', 'ws_ls_shortcode_wt' ); /** * Wrapper for [wt] to enable shortcode mode diff --git a/pro-features/user-preferences.php b/pro-features/user-preferences.php index aa141b34..6221ecfb 100755 --- a/pro-features/user-preferences.php +++ b/pro-features/user-preferences.php @@ -40,7 +40,7 @@ function ws_ls_user_preferences_form( $user_defined_arguments ) { // Have user preferences been allowed in Settings? if ( false === ws_ls_user_preferences_is_enabled() && false === is_admin() && false === $arguments[ 'kiosk-mode' ]) { - return ws_ls_display_blockquote( __( 'To use this shortcode, please ensure you have enabled the setting "Allow user settings".', WE_LS_SLUG) );; + return ws_ls_display_blockquote( __( 'To use this shortcode, please ensure you have enabled the setting "Allow user settings".', WE_LS_SLUG) ); } // Delete all the user's data if selected diff --git a/readme.txt b/readme.txt index f3e9e4a9..a779b15f 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 70+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 80+ changes to code for optimisation. = 10.6 = From c8f3d30677a2c5b346867d6dbb46fb19d5382680 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:54:59 +0100 Subject: [PATCH 24/31] Removed unneeded element --- pro-features/footable.php | 2 +- pro-features/user-preferences.php | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pro-features/footable.php b/pro-features/footable.php index cd6a7295..cc91428c 100755 --- a/pro-features/footable.php +++ b/pro-features/footable.php @@ -396,7 +396,7 @@ function ws_ls_datatable_columns( $arguments = [] ) { [ 'name' => 'user_id', 'title' => 'USER ID', 'visible' => false, 'type' => 'number' ] ]; - // If not front end, add nice nice name + // If not front end, add nice name if ( false === $arguments[ 'front-end' ] ) { $columns[] = [ 'name' => 'user_nicename', 'title' => __( 'User', WE_LS_SLUG ), 'breakpoints'=> '', 'type' => 'text' ]; } else { diff --git a/pro-features/user-preferences.php b/pro-features/user-preferences.php index 6221ecfb..3e1d796f 100755 --- a/pro-features/user-preferences.php +++ b/pro-features/user-preferences.php @@ -53,8 +53,7 @@ function ws_ls_user_preferences_form( $user_defined_arguments ) { // Decide which set of labels to render $labels = [ - 'title-about' => __( 'About You:', WE_LS_SLUG ), - 'height' => __( 'Your height:', WE_LS_SLUG ), + 'height' => __( 'Your height:', WE_LS_SLUG ), 'weight' => __( 'In which unit would you like to record your weight:', WE_LS_SLUG ), 'date' => __( 'Display dates in the following formats:', WE_LS_SLUG ), 'gender' => __( 'Your Gender:', WE_LS_SLUG ), @@ -66,9 +65,7 @@ function ws_ls_user_preferences_form( $user_defined_arguments ) { // If admin, add notice and override labels if( is_admin() ) { - $labels = [ - 'title-about' => __( 'About User:', WE_LS_SLUG ), - 'height' => __( 'Height:', WE_LS_SLUG ), + $labels = [ 'height' => __( 'Height:', WE_LS_SLUG ), 'weight' => __( 'Weight unit:', WE_LS_SLUG ), 'date' => __( 'Date format:', WE_LS_SLUG ), 'gender' => __( 'Gender:', WE_LS_SLUG ), From d972a5e7c7d51f9822b2a36ce8293ada3a3b6735 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 10:58:33 +0100 Subject: [PATCH 25/31] Removed unneeded code --- includes/admin-pages/user-data/data-notes.php | 5 +---- includes/components.php | 3 +-- pro-features/footable.php | 4 ---- pro-features/functions-pages.php | 2 -- pro-features/plus/awards/hooks.php | 2 +- pro-features/user-preferences.php | 2 -- readme.txt | 2 +- 7 files changed, 4 insertions(+), 16 deletions(-) diff --git a/includes/admin-pages/user-data/data-notes.php b/includes/admin-pages/user-data/data-notes.php index 6e8ab11a..381ddca1 100644 --- a/includes/admin-pages/user-data/data-notes.php +++ b/includes/admin-pages/user-data/data-notes.php @@ -28,10 +28,7 @@ function ws_ls_admin_page_data_notes_for_user() { $notes = ws_ls_notes_fetch( $user_id, NULL ); if ( false === empty( $notes ) ) { - - if ( false === empty( $notes ) ) { - array_map( 'ws_ls_notes_render', $notes ); - } + array_map( 'ws_ls_notes_render', $notes ); } else { printf( '

diff --git a/includes/components.php b/includes/components.php index 50245579..43430be1 100644 --- a/includes/components.php +++ b/includes/components.php @@ -519,8 +519,7 @@ function ws_ls_component_latest_versus_another( $args = [] ) { $percentage_difference = 0; } else { - $percentage_difference = ( NULL !== $percentage_difference && - true === $percentage_difference[ 'increase' ] ) ? $percentage_difference[ 'percentage' ] : -$percentage_difference[ 'percentage' ]; + $percentage_difference = ( true === $percentage_difference[ 'increase' ] ) ? $percentage_difference[ 'percentage' ] : -$percentage_difference[ 'percentage' ]; $percentage_difference = ws_ls_round_number( $percentage_difference, 1 ); } diff --git a/pro-features/footable.php b/pro-features/footable.php index cc91428c..09acb044 100755 --- a/pro-features/footable.php +++ b/pro-features/footable.php @@ -232,8 +232,6 @@ function ws_ls_datatable_rows( $arguments ) { $gain_loss = $entry[ 'user_profile' ] = sprintf('%s', ws_ls_get_link_to_user_profile( $entry[ 'user_id' ] ), __( 'Check record', WE_LS_SLUG ) ); } elseif ( false === empty( $entry[ 'kg' ] ) ) { $gain_loss = __( 'First weight entry', WE_LS_SLUG ); - } else { - $gain_loss = ''; } if ( false === empty( $entry[ 'kg' ] ) ) { @@ -276,8 +274,6 @@ function ws_ls_datatable_rows( $arguments ) { $gain_loss = $entry[ 'user_profile' ] = sprintf('%s', ws_ls_get_link_to_user_profile( $entry[ 'user_id' ] ), __( 'Check record', WE_LS_SLUG ) ); } elseif ( false === empty( $entry[ 'kg' ] ) ) { $gain_loss = __( 'First weight entry', WE_LS_SLUG ); - } else { - $gain_loss = ''; } if ( true === is_numeric( $gain_loss ) ) { diff --git a/pro-features/functions-pages.php b/pro-features/functions-pages.php index 8bebc5d9..10658fa8 100644 --- a/pro-features/functions-pages.php +++ b/pro-features/functions-pages.php @@ -71,8 +71,6 @@ function ws_ls_user_side_bar( $user_id ) { ws_ls_postbox_sidebar_user_information( $user_id ); } elseif ( 'add-entry' === $postbox ) { ws_ls_postbox_sidebar_add_entry( $user_id ); - } elseif ( 'user-information' === $postbox ) { - ws_ls_postbox_sidebar_user_information( $user_id ); } elseif ( 'export-data' === $postbox ) { ws_ls_postbox_sidebar_export_data( $user_id ); } elseif ( 'settings' === $postbox ) { diff --git a/pro-features/plus/awards/hooks.php b/pro-features/plus/awards/hooks.php index c191c764..e9940da6 100755 --- a/pro-features/plus/awards/hooks.php +++ b/pro-features/plus/awards/hooks.php @@ -179,7 +179,7 @@ function ws_ls_awards_listen( $info, $weight_object ) { // Percentage of body weight lost // --------------------------------------------------------------- - if ( false === empty( $awards['counts']['weight-percentage'] ) && false === empty( $weight_object['difference_from_start_kg'] ) ) { + if ( false === empty( $awards['counts']['weight-percentage'] ) ) { $percentage_difference = ws_ls_calculate_percentage_difference( $start_weight, $weight_object['kg'] ); diff --git a/pro-features/user-preferences.php b/pro-features/user-preferences.php index 3e1d796f..b5543f03 100755 --- a/pro-features/user-preferences.php +++ b/pro-features/user-preferences.php @@ -82,8 +82,6 @@ function ws_ls_user_preferences_form( $user_defined_arguments ) { ws_ls_enqueue_files(); } - $html_output = ''; - // If enabled, show user preferences form if( false === empty( $arguments[ 'show-user-preferences' ] ) ) { diff --git a/readme.txt b/readme.txt index a779b15f..3c6f805e 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 80+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 110+ changes to code for optimisation. = 10.6 = From 04a4f1c49cc184cd741b88e38f0a71a71cc5ec37 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 11:00:26 +0100 Subject: [PATCH 26/31] Tweaks --- includes/functions.php | 2 +- pro-features/plus/challenge/shortcodes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 9a610551..8e79f1d2 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -546,7 +546,7 @@ function ws_ls_entry_get_previous_kg( $user_id = NULL ) { function ws_ls_force_bool_argument( $value ) { return ( 'true' === strtolower( $value ) || - ( true === is_bool( $value ) && true === $value ) ); + ( true === $value ) ); } /** diff --git a/pro-features/plus/challenge/shortcodes.php b/pro-features/plus/challenge/shortcodes.php index e3d857b1..ce1c9445 100644 --- a/pro-features/plus/challenge/shortcodes.php +++ b/pro-features/plus/challenge/shortcodes.php @@ -21,7 +21,7 @@ function ws_ls_challenges_shortcodes_opt_in( $user_defined_arguments ) { $get_optin = ws_ls_querystring_value( 'opt-in' ); // Update user preferences; - if ( false !== $get_optin && true === in_array( $get_optin, [ 'yes', 'no' ] ) ) { + if ( true === in_array( $get_optin, [ 'yes', 'no' ] ) ) { ws_ls_set_user_preference_simple( 'challenge_opt_in', ( 'yes' === $get_optin ) ? 1 : 0 ); return sprintf( '

%1$s %2$s.

', From c3e2aa8fdd1a25c7b79b3d9a1bd4a9cec43ce338 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 11:31:01 +0100 Subject: [PATCH 27/31] Removed unreachable code --- includes/functions.php | 3 --- pro-features/functions.php | 3 --- pro-features/plus/awards/functions.php | 2 -- pro-features/plus/meta-fields/functions.php | 2 -- readme.txt | 2 +- 5 files changed, 1 insertion(+), 11 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 8e79f1d2..254c3bc7 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1569,13 +1569,10 @@ function ws_ls_setting( $key = 'weight-unit', $user_id = NULL, $force_admin = fa case 'weight-unit': return ws_ls_settings_weight_unit(); - break; case 'use-imperial': return ws_ls_settings_weight_is_imperial(); - break; case 'use-us-dates': return ws_ls_settings_date_is_us(); - break; } return NULL; diff --git a/pro-features/functions.php b/pro-features/functions.php index 9201245a..0673510b 100755 --- a/pro-features/functions.php +++ b/pro-features/functions.php @@ -144,13 +144,10 @@ function ws_ls_bmi_display( $bmi, $display = 'index' ) { switch ( $display ) { case 'label': return ws_ls_calculate_bmi_label( $bmi ); - break; case 'both': return sprintf( '%s (%s)', ws_ls_calculate_bmi_label( $bmi ), $bmi ); - break; default: return $bmi; - break; } return ''; diff --git a/pro-features/plus/awards/functions.php b/pro-features/plus/awards/functions.php index b9c3f558..75cbc8b2 100755 --- a/pro-features/plus/awards/functions.php +++ b/pro-features/plus/awards/functions.php @@ -61,10 +61,8 @@ function ws_ls_awards_gain_loss_display( $gain_loss ) { switch ( $gain_loss ) { case 'gain'; return __('Gain', WE_LS_SLUG); - break; case 'loss': return __('Loss', WE_LS_SLUG); - break; default: return ''; } diff --git a/pro-features/plus/meta-fields/functions.php b/pro-features/plus/meta-fields/functions.php index 7c9e0c8a..b8f1bfca 100755 --- a/pro-features/plus/meta-fields/functions.php +++ b/pro-features/plus/meta-fields/functions.php @@ -229,10 +229,8 @@ function ws_ls_fields_display_field_value_yes_no( $value ) { switch ( (int) $value ) { case 1: return __('No', WE_LS_SLUG); - break; case 2: return __('Yes', WE_LS_SLUG); - break; default: return ''; diff --git a/readme.txt b/readme.txt index 3c6f805e..f1a6bf97 100644 --- a/readme.txt +++ b/readme.txt @@ -162,7 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 110+ changes to code for optimisation. +* Maintenance: Based on PHPStorm inspection made 120+ changes to code for optimisation. = 10.6 = From a658217742bb69121f1ce5b2c4b3c48bc9fd0d0c Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 11:32:21 +0100 Subject: [PATCH 28/31] Removed unneeded declartions --- includes/converters.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/converters.php b/includes/converters.php index 35a10c26..998430e6 100755 --- a/includes/converters.php +++ b/includes/converters.php @@ -56,7 +56,7 @@ function ws_ls_convert_pounds_to_stones( $pounds ) { * @return array */ function ws_ls_convert_pounds_to_stone_pounds( $lb ) { - $weight = [ 'stones' => 0, 'pounds' => 0 ]; + $weight[ 'stones' ] = $lb < 0 ? -1 * floor(-1 * $lb / 14 ) : floor($lb / 14 ); $weight[ 'pounds' ] = Round( fmod( $lb, 14 ), 1 ); return $weight; @@ -80,7 +80,7 @@ function ws_ls_convert_kg_to_lb( $kg ) { * @return array */ function ws_ls_convert_kg_to_stone_pounds( $kg ) { - $weight = [ 'stones' => 0, 'pounds' => 0 ]; + $totalPounds = Round($kg * 2.20462, 3 ); $weight[ 'stones' ] = $totalPounds < 0 ? -1 * floor(-1 * $totalPounds / 14 ) : floor($totalPounds / 14 ); $weight[ 'pounds' ] = Round ( fmod( $totalPounds, 14 ), 2 ); From fe600aa0aa2403ca390682aa15caef50603fbf00 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 12:03:42 +0100 Subject: [PATCH 29/31] Removed unneeded declarations. --- includes/converters.php | 2 +- pro-features/plus/challenge/db.php | 4 +--- pro-features/plus/messaging/db.php | 1 - pro-features/user-groups.php | 2 -- readme.txt | 3 +-- 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/includes/converters.php b/includes/converters.php index 998430e6..1c06f5a6 100755 --- a/includes/converters.php +++ b/includes/converters.php @@ -80,7 +80,7 @@ function ws_ls_convert_kg_to_lb( $kg ) { * @return array */ function ws_ls_convert_kg_to_stone_pounds( $kg ) { - + $totalPounds = Round($kg * 2.20462, 3 ); $weight[ 'stones' ] = $totalPounds < 0 ? -1 * floor(-1 * $totalPounds / 14 ) : floor($totalPounds / 14 ); $weight[ 'pounds' ] = Round ( fmod( $totalPounds, 14 ), 2 ); diff --git a/pro-features/plus/challenge/db.php b/pro-features/plus/challenge/db.php index 5126d1f7..7b367769 100644 --- a/pro-features/plus/challenge/db.php +++ b/pro-features/plus/challenge/db.php @@ -367,9 +367,7 @@ function ws_ls_challenges_stats( $challenge_id ) { } global $wpdb; - - $stats = [ 'count' => NULL, 'to-be-processed' => NULL, 'processed' => NULL ]; - + $challenge_id = (int) $challenge_id; $stats[ 'count' ] = $wpdb->get_var( 'SELECT count( user_id ) FROM ' . $wpdb->prefix . WE_LS_MYSQL_CHALLENGES_DATA . ' WHERE challenge_id = ' . $challenge_id ); diff --git a/pro-features/plus/messaging/db.php b/pro-features/plus/messaging/db.php index 6171485c..49189e0e 100644 --- a/pro-features/plus/messaging/db.php +++ b/pro-features/plus/messaging/db.php @@ -236,7 +236,6 @@ function ws_ls_messages_db_stats( $user_id ) { $latest_note_id = $wpdb->get_var( 'SELECT id FROM ' . $wpdb->prefix . WE_LS_MYSQL_MESSAGES . ' WHERE `note` = 1 and `to` = ' . $user_id . ' order by created desc' ); $latest_note = ws_ls_messaging_db_get( $latest_note_id ); - $stats = [ 'notes-count' => NULL, 'notes-count-visible' => NULL ]; $user_id = (int) $user_id; $stats[ 'notes-count' ] = $wpdb->get_var( 'SELECT count( id ) FROM ' . $wpdb->prefix . WE_LS_MYSQL_MESSAGES . ' WHERE `note` = 1 and `to` = ' . $user_id ); $stats[ 'notes-count-visible' ] = $wpdb->get_var( 'SELECT count( id ) FROM ' . $wpdb->prefix . WE_LS_MYSQL_MESSAGES . ' WHERE `note` = 1 and `visible_to_user` = 1 and `to` = ' . $user_id ); diff --git a/pro-features/user-groups.php b/pro-features/user-groups.php index 1a68d7a8..42dfc5cd 100755 --- a/pro-features/user-groups.php +++ b/pro-features/user-groups.php @@ -557,8 +557,6 @@ function ws_ls_groups_export_add( $row ) { return $row; } - $row[ 'group' ] = ''; - $group = ws_ls_groups_user( $row[ 'user_id' ] ); if ( false === empty( $group[ 0 ][ 'name' ] ) ) { diff --git a/readme.txt b/readme.txt index f1a6bf97..5b29bc45 100644 --- a/readme.txt +++ b/readme.txt @@ -162,8 +162,7 @@ Measurements are created using Custom Fields. You can therefore specify the unit * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Removed redundant setting "Switching to a drop down" from the "User Experience" settings page. * Maintenance: Challenges functionality is now enabled by default. -* Maintenance: Based on PHPStorm inspection made 120+ changes to code for optimisation. - +* Maintenance: Based on PHPStorm inspection made 129+ changes to code for optimisation. = 10.6 = From a3d992c49f427b7be8d5b788a5cede23bdebaf9e Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 13:54:56 +0100 Subject: [PATCH 30/31] Removed unneeded assignments --- includes/converters.php | 1 - pro-features/plus/meta-fields/hooks.php | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/includes/converters.php b/includes/converters.php index 1c06f5a6..32b7916f 100755 --- a/includes/converters.php +++ b/includes/converters.php @@ -112,7 +112,6 @@ function ws_ls_weight_display( $kg, $user_id = NULL, $key = false, $force_admin $weight[ 'pounds' ] = ws_ls_convert_kg_to_lb( $kg ); $weight[ 'display' ] = sprintf( '%s%s', $weight[ 'pounds' ], __( 'lbs', WE_LS_SLUG ) ); $weight[ 'graph-value' ] = $weight[ 'pounds' ]; - $weight[ 'pounds' ] = $weight['pounds']; $weight[ 'imperial' ] = true; break; diff --git a/pro-features/plus/meta-fields/hooks.php b/pro-features/plus/meta-fields/hooks.php index 66d4842d..aea51332 100755 --- a/pro-features/plus/meta-fields/hooks.php +++ b/pro-features/plus/meta-fields/hooks.php @@ -145,10 +145,7 @@ function ws_ls_meta_fields_ajax_custom_field_groups_get(){ $rows = ws_ls_meta_fields_groups( false ); foreach ( $rows as &$row ) { - $row[ 'id' ] = $row[ 'id' ]; - $row[ 'slug' ] = $row[ 'slug' ]; - $row[ 'name' ] = $row[ 'name' ]; - $row[ 'count' ] = ws_ls_meta_fields_groups_count( $row[ 'id' ] ); + $row[ 'count' ] = ws_ls_meta_fields_groups_count( $row[ 'id' ] ); } } From 941ea9dbab6e078fc4605763ce745fdf1de35c45 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Mon, 11 Sep 2023 13:58:35 +0100 Subject: [PATCH 31/31] Version bumps --- readme.txt | 2 +- weight-loss-tracker.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.txt b/readme.txt index 5b29bc45..11d16d73 100644 --- a/readme.txt +++ b/readme.txt @@ -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.6 +Stable tag: 10.7 Requires PHP: 7.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html diff --git a/weight-loss-tracker.php b/weight-loss-tracker.php index 74e2acd4..4c3ebe44 100755 --- a/weight-loss-tracker.php +++ b/weight-loss-tracker.php @@ -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.6 + * Version: 10.7 * Requires at least: 5.7 * Tested up to: 6.3 * Requires PHP: 7.2 @@ -18,7 +18,7 @@ */ define( 'WS_LS_ABSPATH', plugin_dir_path( __FILE__ ) ); -define( 'WE_LS_CURRENT_VERSION', '10.6' ); +define( 'WE_LS_CURRENT_VERSION', '10.7' ); 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' ); @@ -28,8 +28,8 @@ define( 'WE_LS_FREE_TRIAL_URL', 'https://shop.yeken.uk/get-a-trial-license/' ); define( 'WE_LS_CDN_CHART_JS', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.2.0/chart.min.js' ); define( 'WE_LS_CDN_FONT_AWESOME_CSS', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' ); -define( 'WE_LS_PRO_PRICE', 50.00 ); -define( 'WE_LS_PRO_PLUS_PRICE', 100.00 ); +define( 'WE_LS_PRO_PRICE', 60.00 ); +define( 'WE_LS_PRO_PLUS_PRICE', 120.00 ); global $form_number; // This is used to keep track of multiple forms on a page allowing us to pass messages to each global $save_response; // This is used to keep track of form posts responses
' . __('Name', WE_LS_SLUG) . ' ' . __('Weight Difference', WE_LS_SLUG) . '+/-' . ws_ls_blur_text( $percentage ) . '' . ws_ls_blur_text( $percentage ) . '