0

I'm trying to show an alert to the screen when a form is submitted showing the current logged in user's name. I know I need to include the wp-load.php file but whenever I do that like this:

<?php
    include('../../../wp-load.php');

    global $current_user;
    $current_user = wp_get_current_user();

    echo "<script type='text/javascript'>alert('$current_user');</script>";
?>

Upon my form submission I get the whole:

This page isn't working example.com is currently unable to handle this request. HTTP ERROR 500

How am I supposed to resolve this?

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
  • It is all about errors. Try enabling [error reporting](https://stackoverflow.com/q/845021/5914775) and look in your log files for more information about why it couldn't fulfil your request. – Tom Udding Jun 01 '17 at 15:44
  • Theme files should already have WordPress fully loaded - they execute within its framework. Chances are you're double-including the WP framework as a result and causing conflicts. Just echoing out a raw ` – ceejayoz Jun 01 '17 at 15:44
  • how do you submit your form? ajax or reload? if the first, you should be able to do an alert on submit. If the second, you should land on a page where WP framework is loaded, an can just check for POST var and trigger your alert – Kaddath Jun 01 '17 at 15:47

0 Answers0