引导式安装

$weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
    $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
    $admin_password = isset($_POST['admin_password']) ? trim( wp_unslash( $_POST['admin_password'] ) ) : '';
    $admin_email  = isset( $_POST['admin_email']  ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';

点评:这是获取值,并处理的代码,简洁清晰。

<form id="setup" method="post" action="install.php?step=2">
    <table class="form-table">
        <tr>
            <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th>
            <td><input name=" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
        </tr>
        <tr>
            <th scope="row"><label for="user_login"><?php _e('Username'); ?></label></th>
            <td>
            <?php
            if ( $user_table ) {
                _e('User(s) already exists.');
            } else {
                ?><input name=" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
                <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods and the @ symbol.' ); ?></p>
            <?php
            } ?>
            </td>
        </tr>
        <?php if ( ! $user_table ) : ?>
        <tr>
            <th scope="row">
                <label for="admin_password"><?php _e('Password, twice'); ?></label>
                <p><?php _e('A password will be automatically generated for you if you leave this blank.'); ?></p>
            </th>
            <td>
                <input name=" value="" />
                <p><input name=" value="" /></p>
                <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
                <p><?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>
        <?php endif; ?>
        <tr>
            <th scope="row"><label for="admin_email"><?php _e( 'Your E-mail' ); ?></label></th>
            <td><input name=" value="<?php echo esc_attr( $admin_email ); ?>" />
            <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
        </tr>
        <tr>
            <th scope="row"><label for="blog_public"><?php _e( 'Privacy' ); ?></label></th>
            <td colspan=" <?php checked( $blog_public ); ?> /> <?php _e( 'Allow search engines to index this site.' ); ?></label></td>
        </tr>
    </table>
    <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p>
</form>

点评:这是form表单的内容。逻辑也非常清晰。思维严谨。

// Let's check to make sure WP isn't already installed.
if ( is_blog_installed() ) {
    display_header();
    die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p><p class="step"><a href="../wp-login.php" class="button button-large">' . __( 'Log In' ) . '</a></p></body></html>' );
}

判断是否已安装代码。
各种提示语,人性化。

if ( ! empty( $wpdb->error ) )
            wp_die( $wpdb->error->get_error_message() );

        display_header();
        // Fill in the data we gathered
        $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
        $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
        $admin_password = isset($_POST['admin_password']) ? wp_unslash( $_POST['admin_password'] ) : '';
        $admin_password_check = isset($_POST['admin_password2']) ? wp_unslash( $_POST['admin_password2'] ) : '';
        $admin_email  = isset( $_POST['admin_email']  ) ?trim( wp_unslash( $_POST['admin_email'] ) ) : '';
        $;
        // check e-mail address
        $error = false;
        if ( empty( $user_name ) ) {
            // TODO: poka-yoke
            display_setup_form( __( 'Please provide a valid username.' ) );
            $error = true;
        } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
            display_setup_form( __( 'The username you provided has invalid characters.' ) );
            $error = true;
        } elseif ( $admin_password != $admin_password_check ) {
            // TODO: poka-yoke
            display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
            $error = true;
        } else if ( empty( $admin_email ) ) {
            // TODO: poka-yoke
            display_setup_form( __( 'You must provide an email address.' ) );
            $error = true;
        } elseif ( ! is_email( $admin_email ) ) {
            // TODO: poka-yoke
            display_setup_form( __( 'Sorry, that isn’t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
            $error = true;
        }

        if ( $error === false ) {
            $wpdb->show_errors();
            $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password);
            extract( $result, EXTR_SKIP );

点评:注册登录验证,先验证前端的提交是否有错误。碉堡了。

开源欣赏wordpress之intall.php的更多相关文章

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

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

  2. 开源欣赏wordpress之用户新增user-new.php

    require_once( dirname( __FILE__ ) . '/admin.php' ); 引入根文件. if ( is_multisite() ) { if ( ! current_us ...

  3. 开源欣赏wordpress之post.php

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

  4. 开源免费的WordPress个人博客主题推荐

    二次元动漫类个人主题 Sakura 功能强大,美观大气,二次元动漫专属 演示地址:https://2heng.xin/theme-sakura/ 开源地址:https://github.com/mas ...

  5. WordPress版微信小程序开发系列(一):WordPress REST API

    自动我发布开源程序WordPress版微信小程序以来,很多WordPress站长在搭建微信小程序的过程中会碰到各种问题来咨询我,有些问题其实很简单,只要仔细看看我写的文章,就可以自己解决.不过这些文章 ...

  6. wordpress 主题开发

    https://yusi123.com/3205.html https://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tut ...

  7. Wordpress对接小程序配置过程

    最近发现一个很棒的开源项目-WordPress版微信小程序  https://github.com/iamxjb/winxin-app-watch-life.net,详细看了下介绍非常棒,不仅支持的功 ...

  8. 什么是WordPress

    首先,假设您没有WordPress的经验: 我将从基础开始. 在本教程中,我将回答问题:"什么是WordPress?" 在这篇文章中,我将说明您可以在哪里获得WordPress以及 ...

  9. 个人对joomla3.2x和joomla2.5X浅薄看法

    很久没有写joomla文章了,发现想写的东西还是挺多的,后面抽时间补回来,其实更多还是php的一些东西.joomla3.0以后系统改变挺大,后台都是用bootstrap作为主题,个人对这个无爱,因为他 ...

随机推荐

  1. [置顶] Android学习系列-Android中解析xml(7)

    Android学习系列-Android中解析xml(7) 一,概述 1,一个是DOM,它是生成一个树,有了树以后你搜索.查找都可以做. 2,另一种是基于流的,就是解析器从头到尾解析一遍xml文件.   ...

  2. logstash 中的贪婪匹配

    logstash 中的贪婪匹配: 10.252.142.174 - - [06/Sep/2016:08:41:36 +0800] "GET /api/validate/code/send?m ...

  3. C3P0连接池详细配置

    C3P0连接池详细配置 转自http://msq.javaeye.com/blog/60387 <c3p0-config> <default-config> <!--当连 ...

  4. Uva 1342 - That Nice Euler Circuit

    Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...

  5. Shell下通过echo+telnet在远端执行命令

    创建脚本cmd.sh,用于输入telnet的用户与密码,以及生成远端需要执行的命令   执行命令 MY_SIGN=/tmp/sign; (sh cmd.sh ) | (telnet localhost ...

  6. ora-28056 (Writing audit records to Windows Event Log failed)

    系统:windows xp oracle 版本 SQL> select * from v$version; BANNER ------------------------------------ ...

  7. jquery 鼠标图片经过效果

    <script> //鼠标图片经过效果 $(function(){ $(".jione_box ").css("background-color", ...

  8. iOS-网络编程(一)HTTP协议

    一. 网络编程基础 在移动互联网时代,几乎所有应用都需要用到网络,只有通过网络跟外界进行数据交互.数据更新,应用才能保持新鲜.活力.一个好的移动网络应用不仅要有良好的UI和良好的用户体验也要具备实时更 ...

  9. JUnit基础及第一个单元测试实例(JUnit3.8)

    单元测试 单元测试(unit testing) ,是指对软件中的最小可测试单元进行检查和验证. 单元测试不是为了证明您是对的,而是为了证明您没有错误. 单元测试主要是用来判断程序的执行结果与自己期望的 ...

  10. Java单元测试:@BeforeClass,@Before,@Test,@After,@AfterClass中的问题详解

    在Junit4中还有的测试注解有:  @BeforeClass ,@Before,@Test,@After,@AfterClass 1.其中:@BeforeClass,@AfterClass是Juni ...