Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Shortcodes should return not echo #79

Merged
merged 2 commits into from

2 participants

@rinatkhaziev
Collaborator

Shortcodes should return and not echo. acm-tag shortcode callback is just a wrapper for action_acm_tag, which did echo.

Added a second arg for action_acm_tag $echo - defaults to true. If echo is true, the function prints ad code, otherwise it returns it. Shortcode is now also returning value.

@rinatkhaziev rinatkhaziev merged commit f69dad6 into from
@rinatkhaziev rinatkhaziev deleted the branch
@danielbachhuber danielbachhuber commented on the diff
ad-code-manager.php
@@ -1067,7 +1071,7 @@ function shortcode( $atts ) {
if ( empty( $id ) )
return;
- $this->action_acm_tag( $id );
+ return $this->action_acm_tag( $id, false );
@danielbachhuber Owner

Why not just output buffer? Whether or not to echo seems like a hacky argument...

@rinatkhaziev Collaborator

Just in case somebody would like to mess around with the output. You're right, ob will do as well. Feel free to commit ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 18, 2013
  1. @rinatkhaziev
  2. @rinatkhaziev
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 5 deletions.
  1. +8 −4 ad-code-manager.php
  2. +1 −1  readme.txt
View
12 ad-code-manager.php
@@ -834,8 +834,9 @@ function register_ad_codes( $ad_codes = array() ) {
* @uses do_action( 'acm_tag, 'your_tag_id' )
*
* @param string $tag_id Unique ID for the ad tag
+ * @param bool $echo whether to echo or return ( defaults to echo )
*/
- function action_acm_tag( $tag_id ) {
+ function action_acm_tag( $tag_id, $echo = true ) {
/**
* See http://adcodemanager.wordpress.com/2013/04/10/hi-all-on-a-dotcom-site-that-uses/
*
@@ -876,8 +877,11 @@ function action_acm_tag( $tag_id ) {
*/
$output_html = apply_filters( 'acm_output_html_after_tokens_processed', $output_html, $tag_id );
- // Print the ad code
- echo $output_html;
+ if ( $echo )
+ // Print the ad code
+ echo $output_html;
+ else
+ return $output_html;
}
/**
@@ -1067,7 +1071,7 @@ function shortcode( $atts ) {
if ( empty( $id ) )
return;
- $this->action_acm_tag( $id );
+ return $this->action_acm_tag( $id, false );
@danielbachhuber Owner

Why not just output buffer? Whether or not to echo seems like a hacky argument...

@rinatkhaziev Collaborator

Just in case somebody would like to mess around with the output. You're right, ob will do as well. Feel free to commit ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
}
View
2  readme.txt
@@ -2,7 +2,7 @@
Contributors: rinatkhaziev, jeremyfelt, danielbachhuber, carldanley, zztimur, automattic, doejo
Tags: advertising, ad codes, ads, adsense, dfp, doubleclick for publishers
Requires at least: 3.1
-Tested up to: 3.6-beta1
+Tested up to: 3.6-beta3
Stable tag: 0.4.2
Manage your ad codes through the WordPress admin in a safe and easy way.
Something went wrong with that request. Please try again.