Skip to content

Commit

Permalink
Feature: Implement shortcode, block redirects (#6860)
Browse files Browse the repository at this point in the history
* Add shortcode redirects

* Add ignore comments
  • Loading branch information
kjohnson authored Aug 2, 2023
1 parent a5e9f2e commit 9d5adb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function give_donation_history( $atts, $content = false ) {
*
* @since 2.30.0 Add short-circuit filter to allow for custom output.
* @since 1.0
* @param array $atts Shortcode attributes
*
* @return string
Expand All @@ -149,6 +149,8 @@ function give_form_shortcode( $atts ) {
$atts['id'] = $atts['id'] ?: FrontendFormTemplateUtils::getFormId();
$formId = absint( $atts['id'] );

give_redirect_form_id($formId, $atts['id']);

// Short-circuit the shortcode output if the filter returns a non-empty string.
$output = apply_filters('givewp_form_shortcode_output', '', $atts);

Expand Down Expand Up @@ -212,6 +214,8 @@ function give_goal_shortcode( $atts ) {
Give_Notices::print_frontend_notice( __( 'The shortcode is missing Donation Form ID attribute.', 'give' ), true );
}

give_redirect_form_id($atts['id']);

// Sanity check 2: Check the form even has Goals enabled.
if ( ! give_is_setting_enabled( give_get_meta( $atts['id'], '_give_goal_option', true ) ) ) {

Expand Down Expand Up @@ -607,6 +611,8 @@ function give_totals_shortcode( $atts ) {
'give_totals'
);

give_redirect_form_id($atts['ids']);

// Total Goal.
$total_goal = give_maybe_sanitize_amount( $atts['total_goal'] );

Expand Down Expand Up @@ -846,6 +852,8 @@ function give_form_grid_shortcode( $atts ) {
$atts
);

give_redirect_form_id($atts['ids']);

// Validate integer attributes.
$atts['forms_per_page'] = intval( $atts['forms_per_page'] );
$atts['excerpt_length'] = intval( $atts['excerpt_length'] );
Expand Down
4 changes: 2 additions & 2 deletions src/DonationForms/V2/Endpoints/ListDonationForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function handleRequest(WP_REST_Request $request): WP_REST_Response

foreach ($items as &$item) {
$v2form = defined('GIVE_NEXT_GEN_VERSION') && ! get_post_meta($item['id'], 'formBuilderFields');
$canMigrate = $v2form && ! give_is_form_migrated($item['id']);
$canTransfer = $v2form && ! $canMigrate && ! give_is_form_donations_transferred($item['id']);
$canMigrate = $v2form && ! give_is_form_migrated($item['id']); // @phpstan-ignore-line
$canTransfer = $v2form && ! $canMigrate && ! give_is_form_donations_transferred($item['id']); // @phpstan-ignore-line

$item['name'] = get_the_title($item['id']);
$item['edit'] = get_edit_post_link($item['id'], 'edit');
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/DonationForms/Endpoints/TestListDonationForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public function getMockColumns(array $donationForms, string $sortDirection = 'de
$expectedItem[$column::getId()] = $column->getCellValue($donationForm);
}
$v2form = defined('GIVE_NEXT_GEN_VERSION') && ! get_post_meta($donationForm->id, 'formBuilderFields');
$canMigrate = $v2form && ! give_is_form_migrated($donationForm->id);
$canTransfer = $v2form && ! $canMigrate && ! give_is_form_donations_transferred($donationForm->id);
$canMigrate = $v2form && ! give_is_form_migrated($donationForm->id); // @phpstan-ignore
$canTransfer = $v2form && ! $canMigrate && ! give_is_form_donations_transferred($donationForm->id); // @phpstan-ignore

$expectedItem['name'] = $donationForm->title;
$expectedItem['edit'] = get_edit_post_link($donationForm->id, 'edit');
Expand Down

0 comments on commit 9d5adb4

Please sign in to comment.