[英]Updating failed. The response is not a valid JSON response. when add plugin shortcode
I'm trying to add a new wordpress plugin.我正在尝试添加一个新的 wordpress 插件。 This is my plugin php file,这是我的插件 php 文件,
<?php
/**
* Plugin Name: User Info
**/
function create_the_custom_table()
{
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'students';
$sql = "CREATE TABLE " . $table_name . " (
id int(11) NOT NULL AUTO_INCREMENT,
fname VARCHAR(255),
lname VARCHAR(255),
PRIMARY KEY (id),
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
register_activation_hook(__FILE__, 'create_the_custom_table');
$path = preg_replace( '/wp-content.*$/', '', __DIR__ );
require_once( $path . 'wp-load.php' );
function userinf()
{
if(isset($_POST['submit'])){
print $fname = $_POST['fname'];
print $lname = $_POST['lname'];
}
?>
<form>
<label>First Name</label><input type="text" name="fname"/>
<br/>
<label>Last Name</label><input type="text" name="lname"/>
<br/>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
}
add_shortcode('userinfo', 'userinf');
But when I try to add shortcode like this,但是当我尝试像这样添加简码时,
Getting this error,收到此错误,
Updating failed.更新失败。 The response is not a valid JSON response.响应不是有效的 JSON 响应。
Replace your userinf() by as you are not returing data to the shortcode.将您的userinf()替换为,因为您没有将数据返回到简码。
function userinf()
{
ob_start();
if(isset($_POST['submit'])){
print $fname = $_POST['fname'];
print $lname = $_POST['lname'];
}
?>
<form>
<label>First Name</label><input type="text" name="fname"/>
<br/>
<label>Last Name</label><input type="text" name="lname"/>
<br/>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
return ob_get_clean();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.