开源欣赏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作为主题,个人对这个无爱,因为他 ...
随机推荐
- HighCharts去掉水印链接
找到highcharts-all.js文件,将credits:{enabled:!0}改为credits:{enabled:0}即可
- 【转】ubuntu设置PATH----不错
原文网址:http://no001.blog.51cto.com/1142339/554927 试了好多遍,多无效.. 最后在/etc/enviroment下设置才有效. 不过让有一些未解问题 我使用 ...
- 使用WCF实现SOA面向服务编程—— 架构设计
原文地址:http://www.cnblogs.com/leslies2/archive/2011/03/29/1997889.html SOA本身就是一种面向企业级服务的系统架构,简单来说,SOA就 ...
- 《Algorithms 4th Edition》读书笔记——3.1 符号表(Elementary Symbol Tables)-Ⅱ
3.1.2 有序的符号表 典型的应用程序中,键都是Comparable的对象,因此可以使用a.compare(b)来比较a和b两个键.许多符号表的实现都利用Comparable接口带来的键的有序性来更 ...
- python海明距离 - 5IVI4I_I_60Y的日志 - 网易博客
python海明距离 - 5IVI4I_I_60Y的日志 - 网易博客 python海明距离 2009-10-01 09:50:41| 分类: Python | 标签: |举报 |字号大中小 ...
- Android 之 Eclipse 导入 Android 源码
很多人都下载过下图中的 Sources for Android SDK,但是很少人知道怎么用 下载完毕后可以再 Android SDK 根目录下看到 sources 文件夹内 有 andr ...
- python之路-模块安装 paramiko
paramiko介绍(全是洋文,看不懂啊,赶紧有道翻译吧,等有朝一日,我去报个华尔街): "Paramiko" is a combination of the esperanto ...
- 写PPT的方法
这个方法是今天同事的方法,看到他的PPT简洁高效,明了,记下了他的方法: 写文字:写框架,这个框架或者内容可以是word形式的,目的是展示内容 找模板:在搜集到的各种ppt模板中选几个适合自己文字的页 ...
- LDA-线性判别分析(三)
本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...
- Error creating bean with name 'memcachedClient'...java.lang.OutOfMemoryError
1,Tomcat启动报错例如以下: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating ...