引导式安装

$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. Golden Pyramid

    Golden Pyramid Our Robo-Trio need to train for future journeys and treasure hunts. Stephan has built ...

  2. 移植strace调试工具到arm平台

    strace工具是一个非常强大的工具,是调试程序的好工具.要移植到arm平台,就需要使用交叉编译工具编译生成静态链接的可执行文件.具体步骤如下:1.下载 strace-4.5.16     移植str ...

  3. Subsets II 解答

    Question Given a collection of integers that might contain duplicates, nums, return all possible sub ...

  4. 直接使用ip访问google搜索

    173.194.127.148 173.194.127.51 173.194.36.48 (亲测,个人在用,有的ip有时候应该不能访问); 173.194.72.101 173.194.72.103 ...

  5. android滑动基础篇 - 触屏显示信息

    效果图: 代码部分: activity类代码: package com.TouchView; /* * android滑动基础篇 * */ import android.app.Activity; i ...

  6. PHP设计模式笔记一:准备工作 -- Rango韩老师 http://www.imooc.com/learn/236

    一.编程字体选择 1.选择等宽字体 包括Courier New ,Consolas,Source Code Pro(推荐) 2.环境搭建(建议easyPHP) 二.开发符合PSR规范的基础框架 PSR ...

  7. UVa 10256 The Great Divide,推断两个凸包是否相离

    先从给出的两个点集中分别计算出两个凸包, 然后推断两个凸包是否相离. #include<cstdio> #include<vector> #include<cmath&g ...

  8. [Elasticsearch] 部分匹配 (三) - 查询期间的即时搜索

    本章翻译自Elasticsearch官方指南的Partial Matching一章. 查询期间的即时搜索(Query-time Search-as-you-type) 如今让我们来看看前缀匹配可以怎样 ...

  9. VB中DateDiff 函数解释

    VB中DateDiff 函数使用方法 DateDiff (interval, Date1 , Date2[,firstweekofyear[,firstweekofyear]])  返回一个Varia ...

  10. zabbix PHP databases support off Fail

    zabbix初始化检查安装环境不通过: PHP databases support off   Fail     --未找到所支持的数据库 处理方法:安装Mysqli模块 ############## ...