Forum Moderators: coopster
I also have a custom plugin that I use to insert data into posts.
For example, the shortcode [BasePrice] may contain 27. The shortcode is used in a Wordpress post as $[BasePrice] to insert the 27 into the post, and $$[BasePrice] to insert $27.
I suspect that these shortcodes retrieve the data as strings, but I did not code the plugin, as I am not a coder.
I have another plugin called "Raw HTML" which keeps WordPress from breaking some HTML. Using this plugin, I been able to dynamically price my PayPal button code by inserting the $[BasePrice] shortcode from the custom plugin.
However, I do not seem to be able to use the shortcode to insert a variable into a PHP calculation.
This works ...
<?php
$firstnum = 32;
$secnum = 27;
echo $firstnum - $secnum;
?>
... and displays 5.
This breaks ...
<?php
$firstnum = $[BasePrice];
$secnum = $[LowPrice];
echo $firstnum - $secnum;
?>
As does this (using the "Raw HTML" plugin) ...
<!--start_raw--><?php
$firstnum = <!--end_raw-->$[BasePrice]<!--start_raw-->;
$secnum = <!--end_raw-->$[LowPrice]<!--start_raw-->;
echo ($firstnum-$secnum);
?><!--end_raw-->
Can anyone identify my problem (other than I shouldn't be allowed on a computer at my age) and a solution?
Thanks,
Kirk Ward
Here is a link to download the full code.
<snip>
Thanks for your interest.
Kirk
[edited by: eelixduppy at 4:34 am (utc) on Jan. 25, 2010]
[edit reason] Please post relevant code to thread [/edit]
This breaks ...<?php
$firstnum = $[BasePrice];
$secnum = $[LowPrice];
echo $firstnum - $secnum;
?>
When you say "this breaks" ... what do you mean, what error message do you receive? At first pass I would guess that BasePrice is a constant [php.net], as is LowPrice. But then the braces syntax doesn't make sense so these are more likely template variables that need to be parsed by WP instead.
Understanding PHP string [php.net] syntax will help clarify and perhaps point you in the right direction. I believe it's going to be the WP plug-in documentation.
The brackets are standard WordPress formatting for "shortcode" variables which are parsed by various plugins. I had previously pasted a link to the zipped, but unencrypted plugin code, but it appears to have been deleted (I presume by an admin or moderator- see the <snip> in the prior post).
I do not know how to code, so me examining it is useless, which is why I tried to provide access to the code as a previous poster had suggested I paste it here. It seemed a bit long for that.
Any suggestions?
Kirk