错误是:
警告:无法修改标题信息-标题已由C:\\wamp64444\\www\\demoplugin\\wp includes\\class.wp style.php:237)中的C:\\wamp64444\\www\\demoplugin\\wp includes\\pluggable发送。php在线914
创建注册表单和表单登录表单的插件代码
<?php
/*
Plugin Name: Form test
Plugin URI: http://co.com
Description: a plugin to create a form
Version: 1.2
Author: Ghn
Author URI: http://co.com
License: GPL2
*/
function registration_form($username, $password, $email)
{
echo\'<form method="post" action="\' . $_SERVER[\'REQUEST_URI\'] . \'" >
UserName: <input type="text" name="username" value="\' . ( isset( $_POST[\'username\'] ) ? $username : null ) . \'"><br>
Email: <input type="email" name="email" value="\' . ( isset( $_POST[\'email\']) ? $email : null ) . \'"><br>
Password: <input type="password" name="password" value="\' . ( isset( $_POST[\'password\'] ) ? $password : null ) . \'"><br>
<input type="submit" name="submit" value="Register">
</form>\';
}
function registration_validation( $username, $password, $email )
{
global $reg_errors;
$reg_errors = new WP_Error;
if ( empty( $username ) || empty( $password ) || empty( $email ) )
{
$reg_errors->add(\'field\', \'Required form field is missing\');
}
if ( 4 > strlen( $username ) )
{
$reg_errors->add( \'username_length\', \'Username too short. At least 4 characters is required\' );
}
if ( username_exists( $username ) )
$reg_errors->add(\'user_name\', \'Sorry, that username already exists!\');
if ( ! validate_username( $username ) )
{
$reg_errors->add( \'username_invalid\', \'Sorry, the username you entered is not valid\' );
}
if ( 5 > strlen( $password ) )
{
$reg_errors->add( \'password\', \'Password length must be greater than 5\' );
}
if ( !is_email( $email ) )
{
$reg_errors->add( \'email_invalid\', \'Email is not valid\' );
}
if ( email_exists( $email ) )
{
$reg_errors->add( \'email\', \'Email Already in use\' );
}
if ( is_wp_error( $reg_errors ) )
{
foreach ( $reg_errors->get_error_messages() as $error )
{
echo \'<div>\';
echo \'<strong>ERROR</strong>:\';
echo $error . \'<br/>\';
echo \'</div>\';
}
}
}
function complete_registration()
{
global $reg_errors, $username, $password, $email;
if ( 1 > count( $reg_errors->get_error_messages() ) )
{
$userdata = array(
\'user_login\' => $username,
\'user_email\' => $email,
\'user_pass\' => $password,
);
$user = wp_insert_user( $userdata );
echo \'Registration complete. \';
}
}
function custom_registration_function()
{
if ( isset($_POST[\'submit\'] ) )
{
registration_validation(
$_POST[\'username\'],
$_POST[\'password\'],
$_POST[\'email\']
);
// sanitize user form input
global $username, $password, $email;
$username = sanitize_user( $_POST[\'username\'] );
$password = esc_attr( $_POST[\'password\'] );
$email = sanitize_email( $_POST[\'email\'] );
// call @function complete_registration to create the user
// only when no WP_error is found
complete_registration(
$username,
$password,
$email
);
}
registration_form(
$username,
$password,
$email
);
}
add_shortcode(\'test\', \'form_creation\');
// The callback function that will replace [book]
function form_creation() {
ob_start();
custom_registration_function();
return ob_get_clean();
}
function login_form()
{
echo\'<form method="post" action="\' . $_SERVER[\'REQUEST_URI\'] . \'" >
Email: <input type="email" name="email" value="\' . ( isset( $_POST[\'email\']) ? $email : null ) . \'"><br>
Password: <input type="password" name="password" value="\' . ( isset( $_POST[\'password\'] ) ? $password : null ) . \'"><br>
<input type="submit" name="submit" value="Register">
</form>\';
}
function dlf_auth( $username, $password )
{
global $user;
$creds = array();
$creds[\'user_login\'] = $username;
$creds[\'user_password\'] = $password;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
{
echo $user->get_error_message();
}
if ( !is_wp_error($user) )
{
echo \'login success\';
}
}
function dlf_process()
{
if (isset($_POST[\'submit\']))
{
dlf_auth($_POST[\'email\'], $_POST[\'password\']);
}
login_form();
}
add_shortcode(\'testlogin\', \'login_test\');
// The callback function that will replace [book]
function login_test() {
ob_start();
dlf_process();
return ob_get_clean();
}
?>