{"id":6318,"date":"2009-08-04T21:58:10","date_gmt":"2009-08-04T21:58:10","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/php-shortcode\/"},"modified":"2009-08-04T22:29:09","modified_gmt":"2009-08-04T22:29:09","slug":"php-shortcode","status":"closed","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/php-shortcode\/","author":3410801,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"1.3","stable_tag":"1.3","tested":"2.8.3","requires":"2.5","requires_php":"","requires_plugins":"","header_name":"PHP Shortcode","header_author":"Godfrey Chan","header_description":"","assets_banners_color":"","last_updated":"2009-08-04 22:29:09","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"http:\/\/www.chancancode.com\/","rating":0,"author_block_rating":0,"active_installs":100,"downloads":8553,"num_ratings":0,"support_threads":1,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":0},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.3"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[1214,243,662,86,166],"plugin_category":[],"plugin_contributors":[80711],"plugin_business_model":[],"class_list":["post-6318","plugin","type-plugin","status-closed","hentry","plugin_tags-code","plugin_tags-pages","plugin_tags-php","plugin_tags-post","plugin_tags-posts","plugin_contributors-godfreykfc","plugin_committers-godfreykfc"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/php-shortcode.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>Based on kukukuan's <a href=\"http:\/\/wordpress.org\/extend\/plugins\/inline-php\/\">Inline PHP<\/a>, this plugin allows you to embed and run PHP code in posts, pages or widgets* with a WordPress shortcode.<\/p>\n\n<p>(* Requires a shortcode enabled widget plugin, such as <a href=\"http:\/\/wordpress.org\/extend\/plugins\/section-widget\/\">Section Widget<\/a>.)<\/p>\n\n<h4>Usage<\/h4>\n\n<p>The plugin provides two pairs of shortcodes - <code>[php]code[\/php]<\/code> and <code>[echo]code[\/echo]<\/code>. these two pairs of shortcodes resembles the functionality of the <code>&lt;?php code ?&gt;<\/code> and <code>&lt;?= code ?&gt;<\/code> tags in a normal PHP script, respectively.<\/p>\n\n<p>For example:<\/p>\n\n<pre><code>The answer to the &lt;em&gt;ultimate&lt;\/em&gt; math challenge, &lt;strong&gt;1+2&lt;\/strong&gt;, is...\n[php]\n  $a = 1;\n  $b = 2;\n\n  echo $a + $b;\n[\/php]\n<\/code><\/pre>\n\n<p>Will become:<\/p>\n\n<pre><code>The answer to the &lt;em&gt;ultimate&lt;\/em&gt; math challenge, &lt;strong&gt;1+2&lt;\/strong&gt;, is...\n3\n<\/code><\/pre>\n\n<p>The <code>[echo]<\/code> tag will automatically print the returned value of the first expression. Therefore, <code>[echo]some_function()[\/echo]<\/code> is essentially equivalent to <code>[php]echo some_function()[\/php]<\/code>.<\/p>\n\n<h4>Some Important Notes<\/h4>\n\n<p>** This plugin will change the priority of the <code>do_shortcode<\/code> filter. If you are experiencing any conflict with other shortcode plugins, please disable the plugin and report the problem in the forums. **<\/p>\n\n<p>Although I said the shortcode pairs resembles a <code>&lt;?php code ?&gt;<\/code> tag pair, there is an important difference. The PHP code in the shortcodes are executed in a \"throw-away\" local namespace, instead of the global one. All variables defined in a <code>[php] code [\/php]<\/code> block <strong>cannot<\/strong> be accessed outside the block. Therefore, this will not work:<\/p>\n\n<pre><code>[php]\n  $a = 1;\n  $b = 2;\n[\/php]\n\nThe answer to the &lt;em&gt;ultimate&lt;\/em&gt; math challenge, &lt;strong&gt;1+2&lt;\/strong&gt;, is... [echo]$a+$b[\/echo]\n<\/code><\/pre>\n\n<p>And neither would this:<\/p>\n\n<pre><code>[php]\n  $my_array = array('apple','orange');\n\n  foreach($my_array as $fruit):\n[\/php]\n\nI like [echo]$fruit[\/echo]\n\n[php]endforeach;[\/php]\n<\/code><\/pre>\n\n<p>To work around the first problem, you may use the <code>global<\/code> keyword:<\/p>\n\n<pre><code>[php]\n  global $a, $b;\n  $a = 1;\n  $b = 2;\n[\/php]\n\nThe answer to the &lt;em&gt;ultimate&lt;\/em&gt; math challenge, &lt;strong&gt;1+2&lt;\/strong&gt;, is... [php]global $a, $b; echo $a+$b[\/php]\n<\/code><\/pre>\n\n<p>And to work around the second problem, you may use \"real\" PHP closing tags within your <code>[php] code [\/php]<\/code> block to switch between PHP and HTML mode:<\/p>\n\n<pre><code>[php]\n  $my_array = array('apple','orange');\n\n  foreach($my_array as $fruit):\n?&gt;\n\nI like &lt;?php echo $fruit; ?&gt;\n\n&lt;?php\n  endforeach;\n[\/php]\n<\/code><\/pre>\n\n<p>(Yes, it is a bit weird... you'd probably want to avoid doing that if possible.)<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Extract the zip file and drop the contents in the wp-content\/plugins\/ directory of your WordPress installation<\/li>\n<li>Activate the Plugin from Plugins page<\/li>\n<\/ol>","raw_excerpt":"Based on kukukuan&#039;s Inline PHP plugin, this plugin allows you to embed and run PHP code in posts, pages or widgets with a WordPress shortcode.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/6318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=6318"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/godfreykfc"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=6318"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=6318"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=6318"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=6318"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=6318"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=6318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}