Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcodes should not echo output #1614

Closed
felixarntz opened this issue Apr 11, 2017 · 2 comments
Closed

Shortcodes should not echo output #1614

felixarntz opened this issue Apr 11, 2017 · 2 comments
Assignees
Milestone

Comments

@felixarntz
Copy link

Issue Overview

Currently the give_donation_history() function for the shortcode may print output directly (see https://github.com/WordImpress/Give/blob/master/includes/shortcodes.php#L62), however shortcodes should never do that, they must always return their output.

Expected Behavior

The output should be returned instead of echoed.

Current Behavior

The output is echoed, causing several problems. This is especially a major issue for the REST API as it breaks entire responses, since HTML is printed out before the actual JSON response.

Possible Solution

In the above linked area, the two lines should not echo the information, but instead append it to a variable and then return it.

Steps to Reproduce (for bugs)

To see how that bug breaks the REST API, access the wp/v2/pages endpoint for the page that is currently set to host the donation history.

@DevinWalker
Copy link
Member

Do you suggest rather to output using ob_start() and returning via ob_get_clean()?
Like so: https://github.com/WordImpress/Give/blob/master/includes/shortcodes.php#L49-L52

@felixarntz
Copy link
Author

That would be a possibility, but I think not using echo and instead appending to a variable and returning that is more efficient. Such as:

$output = apply_filters( 'give_donation_history_nonuser_message', give_output_error( __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ), false ) );
$output .= do_shortcode( '[give_login]' );
return $output;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants