Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter fblanco

    (@fblanco)

    This has been very helpful! Thanks to you both!

    Thread Starter fblanco

    (@fblanco)

    Thanks for answering!

    Just using jQuery.post instead of ajax apparently worked. I have no idea why hahaha. Would you happen to know what difference it makes?

    • This reply was modified 5 years, 8 months ago by fblanco.
    Thread Starter fblanco

    (@fblanco)

    I’ll mark this as resolved, since I accidentally double posted.

    Thread Starter fblanco

    (@fblanco)

    Small update. I’va managed to add this to a snippet:

    function testphprun(){
      if( isset($_GET['testphprun']) ) {
        set_time_limit(0);
        $user_id = get_current_user_id(); 
      	$user_info = get_userdata($user_id);
      	$mailadress = $user_info->user_email;
    	$path = file_get_contents('./wp-content/emails/'.$mailadress.'.txt'); 
    	$result = "";
    	exec('py ./wp-content/script.py '.$mailadress.' '.basename($path).'', $result, $return_var);
    	foreach ($result as $line) {
           echo $line;
      	}
      } 
    }	
    
    add_action('init', 'testphprun');

    So now, whenever I click this button:

    <form method="post" action="http://localhost/wordpress/pdfPython/?testphprun">
        <input type="submit" value="RunScript">
    </form>

    I get redirected to /localhost/wordpress/pdfPython/?testphprun and the php script runs. I’m sure it’s not the best solution, but it works.

    Now I’d like to modify the snippet so that when the page loads, a certain file is downloaded. I tried adding the appropiate headers and a “readfile()” call to this same snippet (after the current code, of course) but that apparently prevents the script from running. It just downloads the file.

    • This reply was modified 5 years, 8 months ago by fblanco.
    Thread Starter fblanco

    (@fblanco)

    Hello! Yes, it does!

    In the end I managed to use full paths and then moved on to relative paths once I figured what the root directory was.

    Thanks for your reply!

    Thread Starter fblanco

    (@fblanco)

    Small Update.

    I managed to get the user’s email using wordpress functions, so that’s done.

Viewing 6 replies - 1 through 6 (of 6 total)