require_once( dirname( __FILE__ ) . '/admin.php' );

引入根文件。

if ( is_multisite() ) {
    if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) )
        wp_die( __( 'Cheatin’ uh?' ) );
} elseif ( ! current_user_can( 'create_users' ) ) {
    wp_die( __( 'Cheatin’ uh?' ) );
}

用户权限验证,封装在方法当中了。

用户信息输入完后,跳转到列表。是这么个流程。

用户列表有批量操作的多选按钮。同时有新增用户,等管理。

同时可以根据多个条件进行搜索。搜索过程中子页面是跳转的。结果信息直接在头部提示。

我们继续看代码。

$user_details = null;
    if ( false !== strpos($_REQUEST[ 'email' ], '@') ) {
        $user_details = get_user_by('email', $_REQUEST[ 'email' ]);
    } else {
        if ( is_super_admin() ) {
            $user_details = get_user_by('login', $_REQUEST[ 'email' ]);
        } else {
            wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
            die();
        }
    }

一些逻辑验证,方法封装,很多可以具有通用性。比如wp_redirect()就特别具有通用性,一个项目中离不开页面跳转。

这种简洁的页面设计就特别有意思。背景变红,边框变红。

这次的错误提示是提交后,后台反馈的。

很有意思。前后端同时验证。

<div class="error below-h2">
        <p><strong>错误</strong>:请填写用户名。</p><p><strong>错误</strong>:此用户名包含无效字符,请输入有效的用户名。</p><p><strong>错误</strong>:电子邮件地址不正确。</p>    </div>

这就是html的内容,是在div层中展示出来的。

// Adding an existing user to this blog
    $new_user_email = $user_details->user_email;
    $redirect = 'user-new.php';
    $username = $user_details->user_login;
    $user_id = $user_details->ID;
    if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
        $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
    }

进行用户已存在验证。

$newuser_key = substr( md5( $user_id ), ,  );
            add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );

            $roles = get_editable_roles();
            $role = $roles[ $_REQUEST['role'] ];
            /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
            $message = __( 'Hi,

You\'ve been invited to join \'%1$s\' at
%$s with the role of %$s.

Please click the following link to confirm the invite:
%$s' );
            wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf( $message, get_option( 'blogname' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ), home_url( "/newbloguser/$newuser_key/" ) ) );
            $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );

通过验证,各种欢迎。

if ( isset($_GET['update']) ) {
    $messages = array();
    if ( is_multisite() ) {
        switch ( $_GET['update'] ) {
            case "newuserconfirmation":
                $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
                break;
            case "add":
                $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
                break;
            case "addnoconfirmation":
                $messages[] = __('User has been added to your site.');
                break;
            case "addexisting":
                $messages[] = __('That user is already a member of this site.');
                break;
            case "does_not_exist":
                $messages[] = __('The requested user does not exist.');
                break;
            case "enter_email":
                $messages[] = __('Please enter a valid email address.');
                break;
        }
    } else {
        if ( 'add' == $_GET['update'] )
            $messages[] = __('User added.');
    }
}

消息提示,分类提示,很有意思。貌似这个也是封装好的内容。

<?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
    <div class="error">
        <ul>
        <?php
            foreach ( $errors->get_error_messages() as $err )
                echo "<li>$err</li>\n";
        ?>
        </ul>
    </div>
<?php endif;

if ( ! empty( $messages ) ) {
    foreach ( $messages as $msg )
        echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
} ?>

<?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?>
    <div class="error">
        <?php
            foreach ( $add_user_errors->get_error_messages() as $message )
                echo "<p>$message</p>";
        ?>
    </div>
<?php endif; ?>

错误信息展示,如果有的话,将div展示出来。这就是前端的逻辑,可以卸载tpl中。

<table class="form-table">
    <tr class="form-field form-required">
        <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
        <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td>
    </tr>
    <tr class="form-field form-required">
        <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
        <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td>
    </tr>
<?php if ( !is_multisite() ) { ?>
    <tr class="form-field">
        <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
        <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
    </tr>
    <tr class="form-field">
        <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
        <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
    </tr>
    <tr class="form-field">
        <th scope="row"><label for="url"><?php _e('Website') ?></label></th>
        <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td>
    </tr>
<?php
/**
 * Filter the display of the password fields.
 *
 * @since 1.5.1
 *
 * @param bool True or false, based on if you want to show the password fields. Default is true.
 */
if ( apply_filters( 'show_password_fields', true ) ) : ?>
    <tr class="form-field form-required">
        <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
        <td>
            <input  workaround -->
            <input name="pass1" type="password" id="pass1" autocomplete="off" />
        </td>
    </tr>
    <tr class="form-field form-required">
        <th scope="row"><label for="pass2"><?php _e('Repeat Password'); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
        <td>
        <input name="pass2" type="password" id="pass2" autocomplete="off" />
        <br />
        <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
        <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
        </td>
    </tr>
    <tr>
        <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th>
        <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
    </tr>
<?php endif; ?>
<?php } // !is_multisite ?>
    <tr class="form-field">
        <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
        <td><select name="role" id="role">
            <?php
            if ( !$new_user_role )
                $new_user_role = !empty($current_role) ? $current_role : get_option('default_role');
            wp_dropdown_roles($new_user_role);
            ?>
            </select>
        </td>
    </tr>
    <?php if ( is_multisite() && is_super_admin() ) { ?>
    <tr>
        <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
        <td><label " <?php checked( $new_user_ignore_pass ); ?> /> <?php _e( 'Add the user without sending them a confirmation email.' ); ?></label></td>
    </tr>
    <?php } ?>
</table>

验证页面的表单设计。

<?php
/** This action is documented in wp-admin/user-new.php */
do_action( 'user_new_form', 'add-new-user' );
?>

<?php submit_button( __( 'Add New User '), 'primary', 'createuser', true, array( 'id' => 'createusersub' ) ); ?>

</form>
<?php } // current_user_can('create_users') ?>
</div>
<?php
include( ABSPATH . 'wp-admin/admin-footer.php' );

一些尾文件的引入。

很有意思。php还可以这么玩。

开源欣赏wordpress之用户新增user-new.php的更多相关文章

  1. 开源欣赏wordpress之文章新增页面如何实现。

    本地网址http://localhost/wordpress/wp-admin/post-new.php 进而找到post-new.php页面. 进入之后, require_once( dirname ...

  2. 开源欣赏wordpress之intall.php

    引导式安装 $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) ...

  3. 开源欣赏wordpress之post.php

    switch($action) { case 'postajaxpost': case 'post': case 'post-quickpress-publish': case 'post-quick ...

  4. WordPress 前端用户投稿插件 Frontend Publishing

    WordPress添加投稿功能(无需注册/可邮件通知站长和投稿人) WordPress匿名投稿插件:DX-Contribute (有朋友反馈不能用) WordPress投稿插件:User Submit ...

  5. WordPress的用户系统总结

    原文发表自我的个人主页,欢迎大家訪问~转载请保留本段,或注明原文链接:http://www.hainter.com/wordpress-user-module keyword:WordPress,用户 ...

  6. 【php增删改查实例】第十六节 - 用户新增

    6.1工具栏 <div id="toolbar"> <a href="javascript:openDialog()" class=" ...

  7. 【Java框架型项目从入门到装逼】第十三节 用户新增功能完结篇

    这一节,我们把用户新增的功能继续做一个完善.首先,新增成功后,需要给前台返回一个信息,就是告诉浏览器,这次用户新增的操作到底是成功了呢,还是失败了呢?为此,我们需要专门引入一个结果类,里面只有两个属性 ...

  8. 【Java框架型项目从入门到装逼】第十一节 用户新增之把数据传递到后台

    让我们继续来做"主线任务",这一节,我们来做具体的用户新增功能.首先,为了简单起见,我把主页面改了一些,改的是列表那一块.删去了一些字段,和数据库表对应一致: 现在,我们要实现一个 ...

  9. Adminimize 插件:WordPress根据用户角色显示/隐藏某些后台功能

    倡萌刚才分享了 WordPress根据用户角色隐藏文章/页面的功能模块(Meta Boxes),如果你还想根据不同用户角色显示或隐藏后台的某些功能,比如 顶部工具条.左边导航菜单.小工具.仪表盘.菜单 ...

随机推荐

  1. Php模板引擎Smarty安装和配置

    Smarty 是PHP的一个模板引擎,是由Monte Ohrt 和 Andrei Zmievski 使用PHP语言开发的,发展至今已成为一个非常流行的模板引擎,Smarty 提供了一种易于管理和使用的 ...

  2. perl 对象 通过bless实现

    对象只是一种特殊的引用,它知道自己是和哪个类关联在一起的,而构造器知道如何创建那种关联关系. 这些构造器是通过使用bless操作符,将一个普通的引用物转换成一个对象实现的,

  3. IO-APIC

    MP-BIOS bug :8254 timer not connected to IO-APIC解决办法 云计算中在基于一个template image instance vmServer时出现上述的 ...

  4. Uboot与Linux之间的参数传递

    U-boot会给Linux Kernel传递很多参数,如:串口,RAM,videofb等.而Linux kernel也会读取和处理这些参数.两者之间通过struct tag来传递参数. U-boot把 ...

  5. JavaScript获取某年某月的最后一天

    JavaScript获取某年某月的最后一天 1.实现源代码 <!DOCTYPE html> <!-- To change this license header, choose Li ...

  6. 涂抹Oracle笔记2:数据库的连接-启动-关闭

    一.数据库的连接sqlplus <username>[/<password>][@<connect_idertifier>]|/[as sysdba| as sys ...

  7. 《JavaScript 闯关记》之垃圾回收和内存管理

    JavaScript 具有自动垃圾收集机制(GC:Garbage Collecation),也就是说,执行环境会负责管理代码执行过程中使用的内存.而在 C 和 C++ 之类的语言中,开发人员的一项基本 ...

  8. COM口,串行通讯端口,RS-232接口 基础知识

    COM口即串行通讯端口. COM口的接口标准规范和总线标准规范是RS-232,有时候也叫做RS-232口.电脑上的com口多为9针,最大速率115200bps.通常用于连接鼠标(串口)及通讯设备(如连 ...

  9. [转]CENTOS6 VNCSERVER安装

    标签:vncservercentos6.0 ssh隧道 vncviewer centos 休闲 职场 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律 ...

  10. iOS开发 ~应用程序设计理念:视图控制器(UIViewController)、视图(UIView)

    应用程序设计理念:视图控制器(UIViewController).视图(UIView) 利用视图控制器(底层)管理视图(外观),一对一 1.视图的作用:负责显示的外观 2.视图控制器的作用:创建界面. ...