WordPress 的 wp() 函数

wp() 函数位于 wp-includes/functions.php 中

/**
 * Set up the WordPress query.
 *
 * @since 2.0.0
 *
 * @global WP       $wp_locale
 * @global WP_Query $wp_query
 * @global WP_Query $wp_the_query
 *
 * @param string|array $query_vars Default WP_Query arguments.
 */
function wp( $query_vars = '' ) {
   global $wp, $wp_query, $wp_the_query;
   $wp->main( $query_vars );

   if ( !isset($wp_the_query) )
      $wp_the_query = $wp_query;
}

这个函数用来设置 WordPress 查询,参数是 $query_vars,可选,默认的 WP_Query 参数。

该函数不返回任何值,它定义了三个全局变量:

  • 使用全局变量:(对象)$wp
  • 使用全局变量:(对象)$$wp_query
  • 使用全局变量:(对象)$wp_the_query

wp() 函数执行了 WP 类的成员方法 main(),WP 类位于 wp-includes/classes.php 中。

main()的内容:

/**
    * Sets up all of the variables required by the WordPress environment.
    *
    * The action {@see 'wp'} has one parameter that references the WP object. It
    * allows for accessing the properties and methods to further manipulate the
    * object.
    *
    * @since 2.0.0
    * @access public
    *
    * @param string|array $query_args Passed to parse_request().
    */
   public function main($query_args = '') {
      $this->init();// 初始化,获取当前用户信息
      $this->parse_request($query_args);// 解析请求
      $this->send_headers();// 发送头信息
      $this->query_posts();// 查询日志
      $this->handle_404();// 操作404(URL地址不存在)
      $this->register_globals();// 注册全局变量

      /**
       * Fires once the WordPress environment has been set up.
       *
       * @since 2.1.0
       *
       * @param WP &$this Current WordPress environment instance (passed by reference).
       */
      do_action_ref_array( 'wp', array( &$this ) );
   }
}

做完这些操作还是会回到 wp-blog-header.php,

包含 wp-includes/template-loader.php 来加载模板并显示,

日志显示日志,页面显示页面,404显示404

这里还不明白,需要继续学习QAQ

转载于:https://my.oschina.net/LinDMET/blog/786394

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值