【转载】Wordpress源代码分析之settings.php之三

[url]http://hi.baidu.com/wordpressing/blog/item/64b8f538163069f53a87cec7.html[/url]

/**
* timer_start() - PHP 4 standard microtime start capture
*
* @access private
* @since 0.71
* @global int $timestart Seconds and Microseconds added together from when function is called
* @return bool Always returns true
*/
function timer_start() {
global $timestart;
$mtime = explode(' ', microtime() );
$mtime = $mtime[1] + $mtime[0];
$timestart = $mtime;
return true;
}

microtime -- 返回当前 Unix 时间戳和微秒数。

如果调用时不带可选参数,本函数以 "msec sec" 的格式返回一个字符串,其中 sec 是自 Unix 纪元(0:00:00 January 1, 1970 GMT)起到现在的秒数,msec 是微秒部分。字符串的两部分都是以秒为单位返回的。


/**
* timer_stop() - Return and/or display the time from the page start to when function is called.
*
* You can get the results and print them by doing:
* <code>
* $nTimePageTookToExecute = timer_stop();
* echo $nTimePageTookToExecute;
* </code>
*
* Or instead, you can do:
* <code>
* timer_stop(1);
* </code>
* which will do what the above does. If you need the result, you can assign it to a variable, but
* most cases, you only need to echo it.
*
* @since 0.71
* @global int $timestart Seconds and Microseconds added together from when timer_start() is called
* @global int $timeend Seconds and Microseconds added together from when function is called
*
* @param int $display Use '0' or null to not echo anything and 1 to echo the total time
* @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
* @return float The "second.microsecond" finished time calculation
*/
function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
global $timestart, $timeend;
$mtime = microtime();
$mtime = explode(' ',$mtime);
$mtime = $mtime[1] + $mtime[0];
$timeend = $mtime;
$timetotal = $timeend-$timestart;
$r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
if ( $display )
echo $r;
return $r;
}
timer_start();

时间函数,开始记录时间,结束时间是timer_stop


// Add define('WP_DEBUG',true); to wp-config.php to enable display of notices during development.
/*在 WordPress 2.3.1 版本中,又增加了新的参数,调试参数(WP_DEBUG)。这是一个逻辑参数,也就是只有是(true)和否(false)两个选项。如果设置为是,则 WordPress 发生错误是,会将错误报告给用户。如果你没有在 wp-config.php 中设置此参数,默认参数为否,即不发送错误报告。*/
if (defined('WP_DEBUG') and WP_DEBUG == true) {
error_reporting(E_ALL);
} else {
error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
}

// For an advanced caching plugin to use, static because you would only want one
if ( defined('WP_CACHE') )
@include ABSPATH . 'wp-content/advanced-cache.php';

/**
* Stores the location of the WordPress directory of functions, classes, and core content.
*
* @since 1.0.0
*/
define('WPINC', 'wp-includes');

if ( !defined('LANGDIR') ) {
/**
* Stores the location of the language directory. First looks for language folder in wp-content
* and uses that folder if it exists. Or it uses the "languages" folder in WPINC.
*
* @since 2.1.0
*/
if ( file_exists(ABSPATH . 'wp-content/languages') && @is_dir(ABSPATH . 'wp-content/languages') )
define('LANGDIR', 'wp-content/languages'); // no leading slash, no trailing slash
else
define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
}

关于语言的操作。如果存在wp-content/languages文件夹,就定义常量LANGDIR为wp-content/languages

否则就是wp-includes/languages

/**
* Allows for the plugins directory to be moved from the default location.
*
* This isn't used everywhere. Constant is not used in plugin_basename()
* which might cause conflicts with changing this.
*
* @since 2.1
*/
if ( !defined('PLUGINDIR') )
define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash

require (ABSPATH . WPINC . '/compat.php');
require (ABSPATH . WPINC . '/functions.php');
require (ABSPATH . WPINC . '/classes.php');

require_wp_db();

if ( !empty($wpdb->error) )
dead_db();

$prefix = $wpdb->set_prefix($table_prefix);

if ( is_wp_error($prefix) )
wp_die('<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.');

if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
require_once (ABSPATH . 'wp-content/object-cache.php');
else
require_once (ABSPATH . WPINC . '/cache.php');

wp_cache_init();

require (ABSPATH . WPINC . '/plugin.php');
require (ABSPATH . WPINC . '/default-filters.php');
include_once(ABSPATH . WPINC . '/streams.php');
include_once(ABSPATH . WPINC . '/gettext.php');
require_once (ABSPATH . WPINC . '/l10n.php');

if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
if ( defined('WP_SITEURL') )
$link = WP_SITEURL . '/wp-admin/install.php';
elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
$link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
else
$link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
require_once(ABSPATH . WPINC . '/kses.php');
require_once(ABSPATH . WPINC . '/pluggable.php');
wp_redirect($link);
die(); // have to die here ~ Mark
}

require (ABSPATH . WPINC . '/formatting.php');
require (ABSPATH . WPINC . '/capabilities.php');
require (ABSPATH . WPINC . '/query.php');
require (ABSPATH . WPINC . '/theme.php');
require (ABSPATH . WPINC . '/user.php');
require (ABSPATH . WPINC . '/general-template.php');
require (ABSPATH . WPINC . '/link-template.php');
require (ABSPATH . WPINC . '/author-template.php');
require (ABSPATH . WPINC . '/post.php');
require (ABSPATH . WPINC . '/post-template.php');
require (ABSPATH . WPINC . '/category.php');
require (ABSPATH . WPINC . '/category-template.php');
require (ABSPATH . WPINC . '/comment.php');
require (ABSPATH . WPINC . '/comment-template.php');
require (ABSPATH . WPINC . '/rewrite.php');
require (ABSPATH . WPINC . '/feed.php');
require (ABSPATH . WPINC . '/bookmark.php');
require (ABSPATH . WPINC . '/bookmark-template.php');
require (ABSPATH . WPINC . '/kses.php');
require (ABSPATH . WPINC . '/cron.php');
require (ABSPATH . WPINC . '/version.php');
require (ABSPATH . WPINC . '/deprecated.php');
require (ABSPATH . WPINC . '/script-loader.php');
require (ABSPATH . WPINC . '/taxonomy.php');
require (ABSPATH . WPINC . '/update.php');
require (ABSPATH . WPINC . '/canonical.php');
require (ABSPATH . WPINC . '/shortcodes.php');
require (ABSPATH . WPINC . '/media.php');

if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) {
// Used to guarantee unique hash cookies
$cookiehash = md5(get_option('siteurl'));
/**
* Used to guarantee unique hash cookies
* @since 1.5
*/
define('COOKIEHASH', $cookiehash);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 WordPress 网站中实现网站雪花飘落效果,可以在 footer.php 文件中添加以下代码: ```php <script type="text/javascript"> var snowmax=35 // 数量 var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD") // 颜色 var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS") // 字体 var snowletter="*" // 雪花形状 var sinkspeed=0.6 // 速度 var snowmaxsize=22 // 最大尺寸 var snowminsize=8 // 最小尺寸 var snowingzone=1 // 雪花类别,不需要修改 var snow=new Array() var marginbottom var marginright var timer var i_snow=0 var x_mv=new Array(); var crds=new Array(); var lftrght=new Array(); var browserinfos=navigator.userAgent var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/) var ns6=document.getElementById&&!document.all var opera=browserinfos.match(/Opera/) var browserok=ie5||ns6||opera function randommaker(range) { rand=Math.floor(range*Math.random()) return rand } function initsnow() { if (ie5 || opera) { marginbottom = document.body.clientHeight marginright = document.body.clientWidth } else if (ns6) { marginbottom = window.innerHeight marginright = window.innerWidth } var snowsizerange=snowmaxsize-snowminsize for (i=0;i<=snowmax;i++) { crds[i] = 0; lftrght[i] = Math.random()*15; x_mv[i] = 0.03 + Math.random()/10; snow[i]=document.getElementById("s"+i) snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)] snow[i].size=randommaker(snowsizerange)+snowminsize snow[i].style.fontSize=snow[i].size+'px'; snow[i].style.color=snowcolor[randommaker(snowcolor.length)] snow[i].sink=sinkspeed*snow[i].size/5 if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)} if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)} if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4} snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size) snow[i].style.left=snow[i].posx+'px'; snow[i].style.top=snow[i].posy+'px'; } movesnow() } function movesnow() { for (i=0;i<=snowmax;i++) { crds[i] += x_mv[i]; snow[i].posy+=snow[i].sink snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i])+'px'; snow[i].style.top=snow[i].posy+'px'; if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])) { if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)} if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)} if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4} snow[i].posy=0 } } var timer=setTimeout("movesnow()",50) } for (i=0;i<=snowmax;i++) { document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>") } initsnow(); </script> ``` 这段代码使用 JavaScript 实现了网站雪花飘落效果,可以根据需要进行修改。在 WordPress 的 footer.php 文件中添加方法是在主题文件夹下找到 footer.php 文件,在其中添加以上代码即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值