我写了一个插件,它按预期工作。它添加了一个短代码监听器并输出一些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');
?>
当我在页面上插入短代码时,代码运行得非常完美。什么会导致这个可怕的白屏?
答案 0 :(得分:1)
尝试这可能是有效的。
只需替换
var mail = jQuery(&#34;输入[type =&#39; email&#39;]&#34;,jQuery(this));
要
var mail = jQuery(&#34;输入[type = \&#39; email \&#39;]&#34;,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');
?>