From 93c549bf0931ef37bb00116e2e559d5826a2e934 Mon Sep 17 00:00:00 2001 From: Ali Colville Date: Sat, 19 Oct 2024 13:55:50 +0100 Subject: [PATCH] Added ability to fire entries to web hooks --- .../user-data/data-add-edit-entry.php | 27 ++++++++++++++++++- includes/functions.php | 2 +- pro-features/web-hooks.php | 18 +++++++++++++ readme.txt | 6 ++++- weight-loss-tracker.php | 4 +-- 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/includes/admin-pages/user-data/data-add-edit-entry.php b/includes/admin-pages/user-data/data-add-edit-entry.php index 2dc53837..462a08aa 100755 --- a/includes/admin-pages/user-data/data-add-edit-entry.php +++ b/includes/admin-pages/user-data/data-add-edit-entry.php @@ -40,7 +40,7 @@ function ws_ls_admin_page_data_add_edit() {

- $user_id, @@ -50,6 +50,31 @@ function ws_ls_admin_page_data_add_edit() { 'weight-mandatory' => false ] ); + // Allow to manually fire web hook again + if ( true === ws_ls_webhooks_enabled() ) { + + $link = ws_ls_get_url(); + + $link = add_query_arg( [ 'webhook-entry-id' => $entry_id, 'webhook-user-id' => $user_id ] ); + + printf( '
+
+

%1$s

+ %3$s', + esc_html__( 'Web Hooks', WE_LS_SLUG ), + esc_url( $link ), + esc_html__( 'Re-send to endpoint(s)', WE_LS_SLUG ) ); + + $entry_id = ws_ls_querystring_value( 'webhook-entry-id' ); + $user_id = ws_ls_querystring_value( 'webhook-user-id' ); + + if ( false === empty( $user_id ) && + false === empty( $entry_id ) ) { + ws_ls_webhooks_manually_fire_weight( $user_id, $entry_id ); + printf( '

%s

', esc_html__( 'Sent!', WE_LS_SLUG ) ); + } + } + } else { echo sprintf( '

%s

', esc_html__('A Pro license is required to add / edit a weight entry.', WE_LS_SLUG) ); } diff --git a/includes/functions.php b/includes/functions.php index 2a554b0b..1a2bb40f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -873,7 +873,7 @@ function ws_ls_get_url( $base_64_encode = false ) { $current_url = sanitize_url( $current_url ); - $current_url = remove_query_arg( [ 'group-id', 'removedata', 'removed' ] , $current_url ); + $current_url = remove_query_arg( [ 'group-id', 'removedata', 'removed', 'webhook-entry-id', 'webhook-user-id' ] , $current_url ); return ( true === $base_64_encode ) ? base64_encode( $current_url ) : $current_url; } diff --git a/pro-features/web-hooks.php b/pro-features/web-hooks.php index d3b9ce0e..20d624de 100644 --- a/pro-features/web-hooks.php +++ b/pro-features/web-hooks.php @@ -144,6 +144,24 @@ function ws_ls_webhooks_weight_target( $type, $entry ) { } add_action( 'wlt-hook-data-added-edited', 'ws_ls_webhooks_weight_target', 10, 2 ); +/** + * Manually fire an a web hook for this weight entry + */ +function ws_ls_webhooks_manually_fire_weight( $user_id, $entry_id ) { + + if ( true === empty( $user_id ) ) { + return; + } + + if ( true === empty( $entry_id ) ) { + return; + } + + $entry = ws_ls_entry_get( [ 'user-id' => $user_id, 'id' => $entry_id, 'meta' => true ] ); + + ws_ls_webhooks_weight_target( [ 'type' => 'weight', 'mode' => 'resend' ], $entry ); +} + /** * Listen out for new note hooks * @param $note diff --git a/readme.txt b/readme.txt index 7a64c247..48cb7929 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: aliakro Tags: weight,tracker,chart,history,macronutrient Requires at least: 6.0 Tested up to: 6.5 -Stable tag: 10.17 +Stable tag: 10.18 Requires PHP: 7.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -170,6 +170,10 @@ Measurements are created using Custom Fields. You can therefore specify the unit == Changelog == += 10.18 = + +* New feature: Added "Re-send to Endpoint(s)" button to "Edit Entry" screen within WP Dashboard. When pressed, the entry as currently seen, is re-fired to all webhook endpoints. + = 10.17 = * New feature: Expanded [wt-if] shortcodes to include comparison modes: 'equals', 'greater-than','greater-than-or-equal-to', 'less-than' or 'less-than-or-equal-to'. Read more: https://docs.yeken.uk/shortcodes/wt-if.html diff --git a/weight-loss-tracker.php b/weight-loss-tracker.php index f67b383a..0d325d56 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.17 + * Version: 10.18 * Requires at least: 6.0 * Tested up to: 6.5 * Requires PHP: 7.4 @@ -17,7 +17,7 @@ * Domain Path: /includes/languages */ -define( 'WE_LS_CURRENT_VERSION', '10.17' ); +define( 'WE_LS_CURRENT_VERSION', '10.18' ); define( 'WS_LS_ABSPATH', plugin_dir_path( __FILE__ ) ); define( 'WS_LS_BASE_URL', plugin_dir_url( __FILE__ ) ); define( 'WE_LS_TITLE', 'Weight Tracker' );