Skip to content

Commit

Permalink
Merge pull request #621 from alicolville/webhook-refire
Browse files Browse the repository at this point in the history
10.18
  • Loading branch information
alicolville authored Oct 19, 2024
2 parents 02b9a61 + 93c549b commit 9feba64
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
27 changes: 26 additions & 1 deletion includes/admin-pages/user-data/data-add-edit-entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function ws_ls_admin_page_data_add_edit() {
<div class="postbox">
<h2><span><?php echo esc_html__('Add / Edit an entry', WE_LS_SLUG); ?></span></h2>
<div class="inside">
<?php
<?php
if ( true === WS_LS_IS_PRO ) {

echo ws_ls_form_weight( [ 'user-id' => $user_id,
Expand All @@ -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( ' <br />
<hr />
<h3>%1$s<h3>
<a class="button-secondary" href="%2$s"><i class="fa fa-arrow-right"></i> %3$s</a>',
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( '<p>%s</p>', esc_html__( 'Sent!', WE_LS_SLUG ) );
}
}

} else {
echo sprintf( '<p>%s</p>', esc_html__('A Pro license is required to add / edit a weight entry.', WE_LS_SLUG) );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions pro-features/web-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: aliakro
Tags: weight,tracker,chart,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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions weight-loss-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Plugin Name: Weight Tracker
* Description: Allow your users to track their weight, body measurements, photos and other pieces of custom data. Display in charts, tables, shortcodes and widgets. Manage their data, issue awards, email notifications, etc! Provide advanced data on Body Mass Index (BMI), Basal Metabolic Rate (BMR), Calorie intake, Harris Benedict Formula, Macronutrients Calculator and more.
* Version: 10.17
* Version: 10.18
* Requires at least: 6.0
* Tested up to: 6.5
* Requires PHP: 7.4
Expand All @@ -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' );
Expand Down

0 comments on commit 9feba64

Please sign in to comment.