如何调试 PHP 脚本无法执行


How to debug PHP script not executing?

我正在处理这里的WordPress页面 http://beta.fray.it/invite 并单击Twitter图标,我在列表元素上设置了此onclick属性

onclick="window.location.href = '<?php echo get_template_directory_uri(); ?>/components/invite/twitter/redirect.php';">

这将我带到PHP文件,该文件应将用户重定向到Twitter进行身份验证。我在用于测试的另一台服务器上得到了这个工作,但不是在这里。发生的情况是,我看到主页上的内容 http://beta.fray.it 但没有重定向。这是什么原因呢?

wp-config 中启用 WP_DEBUG 和 WP_DEBUG_LOG 后.php(默认情况下禁用WP_DEBUG,因为WP_DEBUG设置为 false)。

debug.log 在出现错误、警告、通知或日志调用时在/wp-content/目录中生成。

您还可以利用包装器函数来集中日志调用

if(!function_exists('_log')){
  function _log( $message ) {
    if( WP_DEBUG === true ){
      if( is_array( $message ) || is_object( $message ) ){
        error_log( print_r( $message, true ) );
      } else {
        error_log( $message );
      }
    }
  }
}

你可以在这里阅读更多关于它的信息

还要查看手抄本: http://codex.wordpress.org/Debugging_in_WordPress

尝试更改链接href

 onclick='window.location.href =' + "<?php echo get_template_directory_uri(); ?>" + '/components/invite/twitter/redirect.php';