繁体   English   中英

带有短代码的Wordpress插件导致白屏死机

[英]Wordpress Plugin with shortcodes causes The White Screen Of Death

我编写了一个插件,该插件可以正常工作。 它添加了一个简码侦听器并输出一些HTML。 问题是当我重新登录到wp-admin/ ,我只看到死亡的白屏。 如果删除插件,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 = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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');
?>

当我在页面上插入简码时,代码运行得非常完美。 是什么原因导致此可怕的白屏?

试试这可能是可行的。

只需更换

var mail = jQuery(“ input [type ='email']”,jQuery(this));

var mail = jQuery(“ input [type = \\'email \\']”,jQuery(this));

我添加了反斜杠。

完整的插件代码:

<?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 = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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');
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM