admin管理员组文章数量:1122846
I am working with a third party API for events, the results of the GET request I've written are rendered/displayed at this URL (inside the SDK folder):
.php
I need to embed these results into specific pages dynamically, so I've used a PHP shortcode embed plugin to allow me to echo the file contents onto the page. I have tested this using:
<?php
echo "hello world";
?>
And this displays correctly when using the shortcode. So I have the results of the GET request in the results.php file and the ability to embed PHP directly in the page using a shortcode (rather than creating/editing templates in multiple places).
I am now trying to use: echo file_get_contents
or include
to render the results.php file onto the page using the following code:
<?php
echo file_get_contents("/skiddle-php-sdk-master/demo/result.php");
?>
But I get a file path warning:
Warning: file_get_contents(/skiddle-php-sdk-master/demo/result.php): failed to open stream: No such file or directory in /home/customer/www/example/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(97) : eval()'d code on line 2
I believe this indicates that for some reason the shortcode plugin is expecting the results.php file to be inside the subdirectory of the plugin which it isn't and shouldn't be for obvious reasons.
I've tried things like this:
/../../skiddle-php-sdk-master/demo/result.php
to no avail. Can anyone help me to understand how I can return the content of results.php using this process?
I am working with a third party API for events, the results of the GET request I've written are rendered/displayed at this URL (inside the SDK folder):
https://example.com/skiddle-php-sdk-master/demo/result.php
I need to embed these results into specific pages dynamically, so I've used a PHP shortcode embed plugin to allow me to echo the file contents onto the page. I have tested this using:
<?php
echo "hello world";
?>
And this displays correctly when using the shortcode. So I have the results of the GET request in the results.php file and the ability to embed PHP directly in the page using a shortcode (rather than creating/editing templates in multiple places).
I am now trying to use: echo file_get_contents
or include
to render the results.php file onto the page using the following code:
<?php
echo file_get_contents("/skiddle-php-sdk-master/demo/result.php");
?>
But I get a file path warning:
Warning: file_get_contents(/skiddle-php-sdk-master/demo/result.php): failed to open stream: No such file or directory in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(97) : eval()'d code on line 2
I believe this indicates that for some reason the shortcode plugin is expecting the results.php file to be inside the subdirectory of the plugin which it isn't and shouldn't be for obvious reasons.
I've tried things like this:
/../../skiddle-php-sdk-master/demo/result.php
to no avail. Can anyone help me to understand how I can return the content of results.php using this process?
Share Improve this question asked Jan 8, 2022 at 22:33 vanvan 11 bronze badge 1- 2 That plugin should be considered dangerous and a dead end, anything that lets you enter and store PHP via WP Admin into the database or write to arbitrary files is a major security risk. Instead you should register shortcodes the normal way and upload the PHP file, either by modifying your themes functions.php or by turning it into a plugin ( aka put a comment at the top of the file with the plugin name and drop it in the plugins folder) – Tom J Nowell ♦ Commented Jan 9, 2022 at 3:39
2 Answers
Reset to default 0Apparently single quotes are a thing in this scenario, this now returns the results.php file contents:
<?php
echo include('skiddle-php-sdk-master/demo/result.php');
?>
I can't respond to that answer directly (not enough reputation apparently) but if you echo the result of that include like that, you'll get a "1" output as well which is the success result from the include(). Just do the include() without the echo statement to get the contents of the file:
<?php include('skiddle-php-sdk-master/demo/result.php'); ?>
本文标签: pluginsHow do I display PHP file contents on front end of Wordpress
版权声明:本文标题:plugins - How do I display PHP file contents on front end of Wordpress? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295042a1929486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论