2016-04-22 12 views
0

私は意図したとおりに動作しているプラ​​グインを書きました。ショートコードリスナーを追加し、HTMLを出力します。問題は私がwp-admin/に再ログインしたときに、私は死の白い画面しか見ることができない。私のプラグインを削除すると、Wordpressはうまく動作します。ショートコードを含むWordpressプラグインは、死の白いスクリーンを引き起こします。

<?php 
/* 
Plugin Name: Widgets 
Plugin URI: http://dshatz.com 
Description: A plugin for generating some website widgets 
Version: 1.0 
Author: Me 
Author URI: http://dshatz.com 
*/?> 

<?php 
function checkout_button_create(){ 
    $ec = @$_GET['ec']; 
    $userId = @$_GET['id']; 

    $c = mysqli_connect("localhost", "user", "pwd", "db"); 
    $stmt = $c->prepare("..."); 
    $stmt->bind_param("is", $userId, $ec); 
    $stmt->execute(); 
    $payment_id = $c->insert_id; 
    $stmt->close(); 

    $stmt = $c->prepare("..."); 
    $stmt->bind_param("i", $payment_id); 
    $stmt->execute(); 
    $stmt->bind_result($name, $price); 
    $stmt->fetch(); 
    $stmt->close(); 

$html = <<<EOD 
<h1>$name</h1> 
<form id="purchase_form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" type="hidden" value="_xclick" /> 
<input name="business" type="hidden" value="..." /> 
<input name="item_name" type="hidden" value="..." /> 
<input name="currency_code" type="hidden" value="EUR" /> 
<input name="amount" type="hidden" value="$price" /> 
<input name="custom" type="hidden" value="$payment_id"></input> 
<input name="lc" type="hidden" value="EN_US" /> 
<input name="no_note" type="hidden" value="" /> 
<input name="paymentaction" type="hidden" value="sale" /> 
<input name="return" type="hidden" value="/licenses/purchased/" /> 
<input name="bn" type="hidden" value="WPPlugin_SP" /> 
<input name="cancel_return" type="hidden" value="/" /> 
<input class="paypalbuttonimage" style="border: none;" alt="Make your payments with PayPal. It is free, secure, effective." name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" /> 
<img style="border: none; display: none;" src="http://i2.wp.com/www.paypal.com/EN_US/i/scr/pixel.gif?resize=1%2C1&ssl=1" alt="" width="1" height="1" border="0" /></form> 
EOD; 
return $html; 
} 

function register_form_create(){ 
    $email = @$_GET['email']; 
    if(!isset($email)) $email=""; 
    $ec = @$_GET['ec']; 

    $html = <<<EOD 
     <style> 
      input{ 
       float: right; 
      } 
      form div{ 
       padding-bottom: 10px; 
      } 
      .error_indicator{ 
       color: red; 
      } 
     </style> 
     <script type="text/javascript"> 
      function validateEmail(email) { 
       var re = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 
       return re.test(email); 
      } 
      jQuery(document).ready(function(){ 
       jQuery("form.register_form").submit(function(e){ 
        var fieldsOk = true; 
        var mailOk = false; 
        var mail = jQuery("input[type='email']", jQuery(this)); 
        mailOk = validateEmail(jQuery(mail).val()); 

        jQuery("input", jQuery(this)).each(function(index){ 
         if(jQuery(this).val().length == 0) { 
          fieldsOk = false; 
          return; 
         } 
        }); 
        if(fieldsOk) jQuery(".fill_in_pls").css("display", "none"); 
        else { 
         jQuery(".fill_in_pls").css("display", "inline"); 
         jQuery(".invalid_email").css("display", "none"); 
         e.preventDefault(); 
         return false; 
        } 

        if(!mailOk){ 
         e.preventDefault(); 
         jQuery(".invalid_email", jQuery(this)).css("display", "inline"); 
         return false; 
        } 
        jQuery(".invalid_email", jQuery(this)).css("display: none;"); 
        return ; 
       }); 
      }); 
     </script> 
     <form class="register_form" method="POST" action="/license/register.php" style="width: 50%;"> 
      <div> 
       <label for="email_input">Email</label><input id="email_input" type="email" name="email" value="$email"/> 
      </div> 
      <div> 
       <label for="fname_input">First name</label><input id="fname_input" type="text" name="fname"/> 
      </div> 
      <div> 
       <label for="lname_input">Last name</label><input id="lname_input" type="text" name="lname"/> 
      </div> 
      <input type="hidden" name="ec" value="$ec"/> 
      <div> 
       <input type="submit" value="Checkout"/> 
      </div> 
       <div class="error_indicator invalid_email" style="display: none;">Please enter a valid email</div> 
       <div class="error_indicator fill_in_pls" style="display: none;">Please fill in all fields</div> 
     </form> 
EOD; 
    return $html; 
} 

add_shortcode('register', 'register_form_create'); 
add_shortcode('checkout', 'checkout_button_create'); 
?> 

私はページ上のショートを挿入すると、コードは完璧で実行されます。ここでは

はコードです。このひどい白いスクリーンを引き起こす原因は何ですか?

+0

あなたはエラーログへのアクセス権を持っているのですか? –

+0

どちらですか? 'php_errorlog'には何もありません。 –

+0

2番目のクエリは接続を閉じた後に実行されます。 – RST

答えて

1

これは動作するかもしれません。

だけのjQuery( "入力[タイプ= 'メール']"、jQueryの(この))=

VARメールを交換してください。

TO VARメール= jQueryの( "入力[タイプ= \ 'のメール\']"、jQueryの(この));

私はバックスラッシュを追加しました。

のフルプラグインコード:

<?php 
/** 
* Plugin Name: Widgets 
* Plugin URI: http://danielpataki.com 
* Description: This plugin adds some Facebook Open Graph tags to our single posts. 
* Version: 1.0.0 
* Author: Daniel Pataki 
* Author URI: http://danielpataki.com 
* License: GPL2 
*/ 
function checkout_button_create(){ 
    $ec = @$_GET['ec']; 
    $userId = @$_GET['id']; 

    $c = mysqli_connect("localhost", "user", "pwd", "db"); 
    $stmt = $c->prepare("..."); 
    $stmt->bind_param("is", $userId, $ec); 
    $stmt->execute(); 
    $payment_id = $c->insert_id; 
    $stmt->close(); 

    $stmt = $c->prepare("..."); 
    $stmt->bind_param("i", $payment_id); 
    $stmt->execute(); 
    $stmt->bind_result($name, $price); 
    $stmt->fetch(); 
    $stmt->close(); 

$html = '<h1>$name</h1> 
<form id="purchase_form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" type="hidden" value="_xclick" /> 
<input name="business" type="hidden" value="..." /> 
<input name="item_name" type="hidden" value="..." /> 
<input name="currency_code" type="hidden" value="EUR" /> 
<input name="amount" type="hidden" value="$price" /> 
<input name="custom" type="hidden" value="$payment_id"></input> 
<input name="lc" type="hidden" value="EN_US" /> 
<input name="no_note" type="hidden" value="" /> 
<input name="paymentaction" type="hidden" value="sale" /> 
<input name="return" type="hidden" value="/licenses/purchased/" /> 
<input name="bn" type="hidden" value="WPPlugin_SP" /> 
<input name="cancel_return" type="hidden" value="/" /> 
<input class="paypalbuttonimage" style="border: none;" alt="Make your payments with PayPal. It is free, secure, effective." name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" /> 
<img style="border: none; display: none;" src="http://i2.wp.com/www.paypal.com/EN_US/i/scr/pixel.gif?resize=1%2C1&ssl=1" alt="" width="1" height="1" border="0" /></form>'; 
return $html; 
} 

function register_form_create(){ 
    $email = @$_GET['email']; 
    if(!isset($email)) $email=""; 
    $ec = @$_GET['ec']; 

    $html = '<style> 
      input{ 
       float: right; 
      } 
      form div{ 
       padding-bottom: 10px; 
      } 
      .error_indicator{ 
       color: red; 
      } 
     </style> 
     <script type="text/javascript"> 
      function validateEmail(email) { 
       var re = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 
       return re.test(email); 
      } 
      jQuery(document).ready(function(){ 
       jQuery("form.register_form").submit(function(e){ 
        var fieldsOk = true; 
        var mailOk = false; 
        var mail = jQuery("input[type=\'email\']", jQuery(this)); 
        mailOk = validateEmail(jQuery(mail).val()); 

        jQuery("input", jQuery(this)).each(function(index){ 
         if(jQuery(this).val().length == 0) { 
          fieldsOk = false; 
          return; 
         } 
        }); 
        if(fieldsOk) jQuery(".fill_in_pls").css("display", "none"); 
        else { 
         jQuery(".fill_in_pls").css("display", "inline"); 
         jQuery(".invalid_email").css("display", "none"); 
         e.preventDefault(); 
         return false; 
        } 

        if(!mailOk){ 
         e.preventDefault(); 
         jQuery(".invalid_email", jQuery(this)).css("display", "inline"); 
         return false; 
        } 
        jQuery(".invalid_email", jQuery(this)).css("display: none;"); 
        return ; 
       }); 
      }); 
     </script> 
     <form class="register_form" method="POST" action="/license/register.php" style="width: 50%;"> 
      <div> 
       <label for="email_input">Email</label><input id="email_input" type="email" name="email" value="$email"/> 
      </div> 
      <div> 
       <label for="fname_input">First name</label><input id="fname_input" type="text" name="fname"/> 
      </div> 
      <div> 
       <label for="lname_input">Last name</label><input id="lname_input" type="text" name="lname"/> 
      </div> 
      <input type="hidden" name="ec" value="$ec"/> 
      <div> 
       <input type="submit" value="Checkout"/> 
      </div> 
       <div class="error_indicator invalid_email" style="display: none;">Please enter a valid email</div> 
       <div class="error_indicator fill_in_pls" style="display: none;">Please fill in all fields</div> 
     </form>'; 
    return $html; 
} 

add_shortcode('register', 'register_form_create'); 
add_shortcode('checkout', 'checkout_button_create'); 
?> 
+0

残念ながら、まだ白い画面。シングルクォータがWordPressで嫌になる可能性はありますか? –

+0

@DanielShatz私の更新は私の答えを更新しました。完全にプラグインされたコードを追加しました。これはlocalhostで動作しています。 thx – vrajesh

+0

再度テストしました。 PHP Heredoc構文がWordPressプラグインで完全にサポートされていないように見えます。どうもありがとうございました。私はしばらく時間を節約しました。あまりにも奇妙なことに、これに関する情報はGoogleにありません。 –

関連する問題