Skip Navigation

[Closed] Types shortcode inside third party shortcode inside view

This support ticket is created 7 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 25 replies, has 2 voices.

Last updated by Shane 7 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#464753

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christian,

I did some debugging and I conclude that this amazon shortcode doesn't accept as an attribute or data another shortcode.

I test it with a minimal shortcode I created

// Add Shortcode
function post_field( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'post_id' => '',
			'field' => '',
		),
		$atts
	);
        $meta = get_post_meta($atts['post_id'],$atts[field]);
	return $meta[0];

}
add_shortcode( 'post_field', 'post_field' );

This uses the default get post meta function from wordpress in order to retrieve the values. As you can see nothing fancy has been added and it still doesn't work.

So it doesn't seem to be an issue on our end 🙁

Could you explain to the plugin developers this new issue and see how best they can get it resolved?

Please let me know.
Thanks,
Shane

#466033

Hi again Shane,
Timo is the Amazon Simple Affiliate plugin developer, I would like to invite him to this tread to disccuss about the problem, I think this is going to be most efficient way to solve this problem.

Could you please give me access (loggin and password) to him?

#466038

Hi Shane, Timo here (from ASA 2 support),

thanks for your code example, but I must admit, I do not understand the relation to the issue. Could you explain what you were trying to tell us with the shortcode function?

We got this shortcode working successfully in standard posts and custom posts created by your Types plugin:
[asa2 value="OffersMainPriceAmount"][types field="asin-amazon"][/types][/asa2]

But when rendered by the Types Views extension, the content between the asa2 tags get prepended with the string "###SPACE###". I do not say that the Types plugin creates this string, but it must come from somewhere other than ASA 2. Maybe even another plugin which interferes in replacing shortcode contents.

#466517

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christian,

I wrote the custom shortcode to pull the value from the database to try within the ASA shortcode but that still does not work.

I even tried through a regular page and this still does not work and this is using all the defaults so no interaction from views.
hidden link

As you can see it still does not work.

Is the ASA shortcode allow other shortcodes to provide the value it needs ? Not sure where the ##SPACE## is coming from .

Could you try disabling all your non-toolset plugins leaving on the ASA plugin active with our toolset ?

Please let me know the results of this.

Thanks,
Shane

#467169

After some hours of debugging, I found the explanation.

The problem with the mysterious ###SPACE### string comes from your plugin's function "wpv_do_shortcode". Check the script wp-views/embedded/inc/wpv-shortcodes.php on line 5741:

function wpv_do_shortcode($content) {

  $content = apply_filters('wpv-pre-do-shortcode', $content);

  // HACK HACK HACK
  // fix up a problem where shortcodes are not handled
  // correctly by WP when there a next to each other

  $content = str_replace('][', ']###SPACE###[', $content);
  $content = str_replace(']###SPACE###[/', '][/', $content);
  $content = do_shortcode($content);
  $content = str_replace('###SPACE###', '', $content);

  return $content;
}

This is a step by step walkthrough what it does with our use case:

The original $content is:
[asa2 value="OffersMainPriceAmount"][post_field post_id='3603' field='wpcf-asin-amazon'][/asa2]

Step 1:

$content = str_replace('][', ']###SPACE###[', $content);

Now $content is:
[asa2 value="OffersMainPriceAmount"]###SPACE###[post_field post_id='3603' field='wpcf-asin-amazon']###SPACE###[/asa2]

Step 2:

$content = str_replace(']###SPACE###[/', '][/', $content);

Now $content is:
[asa2 value="OffersMainPriceAmount"]###SPACE###[post_field post_id='3603' field='wpcf-asin-amazon'][/asa2]

Step 3:

$content = do_shortcode($content);

-> This runs into an error inside the asa2 shortcode because there still is ###SPACE### in the content.

Step 4:

$content = str_replace('###SPACE###', '', $content);

Now all ###SPACE### get removed but this is too late! This should be done before step 3 where do_shortcode gets executed. I am not sure what the hack in that function initially was all about, but you can not rely on that every shortcode will ignore some of your internal placeholder strings. In case of ASA 2 (hidden link), it expects a valid Amazon ASIN and if ###SPACE### gets prepended, it obviously is not a valid ASIN anymore and the result will be an empty output and a logged error.

So I think your function should look like this:

function wpv_do_shortcode($content) {

  $content = apply_filters('wpv-pre-do-shortcode', $content);

  // HACK HACK HACK
  // fix up a problem where shortcodes are not handled
  // correctly by WP when there a next to each other

  $content = str_replace('][', ']###SPACE###[', $content);
  $content = str_replace(']###SPACE###[/', '][/', $content);
  $content = str_replace('###SPACE###', '', $content);
  $content = do_shortcode($content);
  

  return $content;
}

This way, our use case is working as expected. Can you provide an update with the function changed that way?

And by the way, your plugin produces many PHP Notices which makes it kind of hard to debug.

#467539

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christian,

Thank you for sharing this with me.

I'll pass this onto our development team so they can have a look at it. I'll update you with any information that they provide.

Thanks,
Shane

#467552

Ok Shane I will be waiting for that news. Hopefuly soon

#468531

Hi Shane, this is Cristian, do you have news??? I still need to solve the problem in my "real instalation" Remeber that Timo solve this problem in the test site. If you agree with Timo I would appreciate an update of the plugin

#469773

Hi Shane, this is Cristian, do you have news??? I still need to solve the problem in my "real instalation" Remeber that Timo solve this problem in the test site. If you agree with Timo I would appreciate an update of the plugin

#474296

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christian,

Just an update on this .

Our developers have recognise this and will be checking if this is needed anymore. They mentioned that it was added to prevent wordpress from missmanaging shortcodes that were placed too closed together.

Thanks,
Shane

#483730

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Cristian,

Another update on this issue as it is still in review.

Currently no ETA has been set for this.

Thanks,
Shane

The topic ‘[Closed] Types shortcode inside third party shortcode inside view’ is closed to new replies.