Trouble running python script in WordPress
Question
I followed all the directions in this post Running a python script within wordpress and I still cannot get a result to display.
<?php # -*- coding: utf-8 -*-
/* Plugin Name: Python embedded */
add_shortcode( 'python', 'embed_python' );
function embed_python( $attributes )
{
$data = shortcode_atts(
[
'file' => 'hello.py'
],
$attributes
);
$handle = popen( __DIR__ . '/' . $data['file'], 'r' );
$read = '';
while ( ! feof( $handle ) )
{
$read .= fread( $handle, 2096 );
}
pclose( $handle );
return $read;
}
I uploaded hello.py and Python.php to the plugins folder and made sure the plugin was properly activated.
0
plugins
3 years
2019-12-05T01:54:40-05:00
2019-12-05T01:54:40-05:00 0 Answers
90 views
0
Leave an answer