WordPress插件激活触发致命错误

时间:2018-11-26 01:51:33

标签: php wordpress

我知道有很多这样的问题,但是我找不到与我的案子相关的细节。要么,要么他们没有答案。

我编写了一个非常简单的PHP脚本,并上传到了zip文件夹中的wordPress网站,当我尝试激活该插件时,WordPress给了我一条消息:“插件无法激活,因为它触发了致命错误”。它实际上并没有给我任何错误消息。我已经将WP_DEBUG,WP_DEBUG_LOG和WP_DEBUG_DISPLAY都设置为true,但是根据假定的错误,这些都没有更新。看来我无法找出致命错误到底是什么。

我对如何解决此问题感到困惑。任何帮助都会有用。

<?php

/*
Plugin Name: Denrile's Plogger
Plugin URI: http://my-awesomeness-emporium.com
description: >- a plugin to that takes the user to the Pruvan website,
after using CURL to log them in so that the redirect doesn't hit a user authentication wall.
Version: 1.0
Author: John Mauran
Author URI: http://github.com/jmauran91
License: GPL2
*/

  $j_username = "Denrile";
  $j_password = "*************";
  $login_url ="https://titlereporter.direct.pruvan.com/v2/login";
  $last_url = "https://titlereporter.direct.pruvan.com/v2/pmgr";


  function loginToJulian($url, $username, $password){
    $curl = curl_init();
    $header[0]= "Accept: application/json, text/javascript, */*; q=0.01";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Content-Type: application/x-www-form-urlencoded";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $verbose = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_STDERR, $verbose);
    // Make the errors visible in a new file

    $payload_username = '"'.$username.'"';
    $payload_password = '"'.$password.'"';
    $payloadtext=urlencode('{"username":'.$payload_username.',"password":'.$payload_password.'}');
    $payload = "payload=".$payloadtext;
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $store = curl_exec($curl);
    curl_close($store);
  }

  if(isset($_GET['prvn_login'])){
    loginToJulian($login_url, $j_username, $j_password);
    header("Location: https://titlereporter.direct.pruvan.com/v2/pmgr");
    exit();
  }
  else{

    exit();
  }

?>

此插件的一般想法是,它将挂接到wordPress网站上由javascript生成的A标签,CURL发布到另一个网站进行登录,然后重定向到该网站,希望绕过用户身份验证,因为由于使用了CURL,该用户已经登录。

1 个答案:

答案 0 :(得分:1)

此代码对我有用。 但是有一个问题,为什么要添加exit();在else条件内,它破坏了插件的激活过程。

请检查并告知我。

<?php

/*
Plugin Name: Denrile's Plogger
Plugin URI: http://my-awesomeness-emporium.com
description: >- a plugin to that takes the user to the Pruvan website,
after using CURL to log them in so that the redirect doesn't hit a user authentication wall.
Version: 1.0
Author: John Mauran
Author URI: http://github.com/jmauran91
License: GPL2
*/

  $j_username = "Denrile";
  $j_password = "*************";
  $login_url ="https://titlereporter.direct.pruvan.com/v2/login";
  $last_url = "https://titlereporter.direct.pruvan.com/v2/pmgr";


  function loginToJulian($url, $username, $password){
    $curl = curl_init();
    $header[0]= "Accept: application/json, text/javascript, */*; q=0.01";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Content-Type: application/x-www-form-urlencoded";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $verbose = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_STDERR, $verbose);
    // Make the errors visible in a new file

    $payload_username = '"'.$username.'"';
    $payload_password = '"'.$password.'"';
    $payloadtext=urlencode('{"username":'.$payload_username.',"password":'.$payload_password.'}');
    $payload = "payload=".$payloadtext;
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $store = curl_exec($curl);
    curl_close($store);
  }


  function default_wordpress_hook(){
    if(isset($_GET['prvn_login'])){
      loginToJulian($login_url, $j_username, $j_password);
      header("Location: https://titlereporter.direct.pruvan.com/v2/pmgr");
      exit();
    } else {

    }  
  }
  add_action("init","default_wordpress_hook");

?>