开源欣赏wordpress之intall.php
引导式安装
$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 ! " ? $ % ^ & ).'); ?></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的更多相关文章
- 开源欣赏wordpress之文章新增页面如何实现。
本地网址http://localhost/wordpress/wp-admin/post-new.php 进而找到post-new.php页面. 进入之后, require_once( dirname ...
- 开源欣赏wordpress之用户新增user-new.php
require_once( dirname( __FILE__ ) . '/admin.php' ); 引入根文件. if ( is_multisite() ) { if ( ! current_us ...
- 开源欣赏wordpress之post.php
switch($action) { case 'postajaxpost': case 'post': case 'post-quickpress-publish': case 'post-quick ...
- 开源免费的WordPress个人博客主题推荐
二次元动漫类个人主题 Sakura 功能强大,美观大气,二次元动漫专属 演示地址:https://2heng.xin/theme-sakura/ 开源地址:https://github.com/mas ...
- WordPress版微信小程序开发系列(一):WordPress REST API
自动我发布开源程序WordPress版微信小程序以来,很多WordPress站长在搭建微信小程序的过程中会碰到各种问题来咨询我,有些问题其实很简单,只要仔细看看我写的文章,就可以自己解决.不过这些文章 ...
- wordpress 主题开发
https://yusi123.com/3205.html https://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tut ...
- Wordpress对接小程序配置过程
最近发现一个很棒的开源项目-WordPress版微信小程序 https://github.com/iamxjb/winxin-app-watch-life.net,详细看了下介绍非常棒,不仅支持的功 ...
- 什么是WordPress
首先,假设您没有WordPress的经验: 我将从基础开始. 在本教程中,我将回答问题:"什么是WordPress?" 在这篇文章中,我将说明您可以在哪里获得WordPress以及 ...
- 个人对joomla3.2x和joomla2.5X浅薄看法
很久没有写joomla文章了,发现想写的东西还是挺多的,后面抽时间补回来,其实更多还是php的一些东西.joomla3.0以后系统改变挺大,后台都是用bootstrap作为主题,个人对这个无爱,因为他 ...
随机推荐
- logstash 内置匹配IP
10.252.142.174 - - [06/Sep/2016:08:41:36 +0800] "GET /api/validate/code/send?mobilePhone=186522 ...
- 深入浅出Node.js (5) - 内存控制
5.1 V8的垃圾回收机制与内存限制 5.1.1 Node与V8 5.1.2 V8的内存限制 5.1.3 V8的对象分配 5.1.4 V8的垃圾回收机制 5.1.5 查看垃圾回收日志 5.2 高效使用 ...
- 【转】使用adb命令对手机进行截屏(截图)保存到电脑,SDCard
原文网址:http://blog.csdn.net/huangyabin001/article/details/29198367 adb shell /system/bin/screencap -p ...
- hdu 4504 威威猫系列故事——篮球梦_简单dp
题目链接 题意:你现在分数为a,对方分数为b,你比赛还有n分钟,每次进攻需要15分钟,现在你先进攻,每次进攻可以得1或2或3,对方每次进攻得一分,问超过对方分数有多少种打法 思路:因为情况太多要用__ ...
- postGreSQL数据库部署及简单使用
1,deployByRuiyIns rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.no ...
- WEB程序会话管理--HttpSession和Cookie
WEB应用的会话管理的原理: 由于WEB应用的请求和响应是基于HTTP的,而HTTP由属于无状态的通信协议,只能记录本次请求的信息,因此服务器不会记住这一次的请求和下一次请求的关系.所以会话管理的原理 ...
- SQL生成随机字符串
1.SQLserve生成随机字符串 SELECT replace(newid(), '-', '')
- hdu 4007 Dave(线性探查+枚举)
Problem Description Recently, Dave is boring, so he often walks around. He finds that some places ar ...
- 2个2D向量计算交点的夹角和补角
2维向量如何计算与某一个交点之间的夹角,假设A,B是向量,C是他们共同连接的一个点计算出A-C-B形成的角度 我们先了解几个简单的计算: 2D向量的乘积计算 (A.x * B.x + A.y * ...
- C#~使用FileSystemWatcher来监视文件系统的变化
对于一个文件夹的改变,C#这边有自己的类来实现,我们不需要关心它的内部实现机制,不需要关心它底层调用哪些API,我们只需要关心如何去调用它,如何让它帮助我们记录文件夹的修改情况即可. #region ...