wp全局变量

简介

使用WordPress全局变量有多种原因。几乎所有WordPress产生的数据都可以在全局变量中找到。

请注意,与直接更改全局变量相比,在情况允许的条件下使用恰当的API功能会更好一点,

你需要先使用global $variable;全局化你的变量,以便能够使用全局变量。

"不推荐使用除以下列表之外的全局变量"

Inside the Loop variables

While inside the loop, these globals are set, containing information about the current post being processed.

  • $post The whole post object.

  • $authordata (object) Returns an object with information about the author, set alongside the last $post. Object described in Function_Reference/get_userdata.

  • $currentday Day of the post.

  • $currentmonth Month of the post.

  • $page (int) The page of the post, as specified by the query var page.

  • $pages (array)The content pages within a post, which were separated by <!--nextpage--> elements.

  • $multipage (boolean)Returns true if the post has multiple pages, related to $page and $pages.

  • $more (boolean) Returns true if there are multiple pages in the post, related to $page and $pages.

  • $numpages (int) Returns the number of pages in the post, related to $page and $pages.

Browser Detection Booleans

These globals store data about which browser the user is on.

  • $is_iphone (boolean) iPhone Safari

  • $is_chrome (boolean) Google Chrome

  • $is_safari (boolean) Safari

  • $is_NS4 (boolean) Netscape 4

  • $is_opera (boolean) Opera

  • $is_macIE (boolean) Mac Internet Explorer

  • $is_winIE (boolean) Windows Internet Explorer

  • $is_gecko (boolean) FireFox

  • $is_lynx (boolean)

  • $is_IE (boolean) Internet Explorer


Web Server Detection Booleans

These globals store data about which web server WordPress is running on.

  • $is_apache (boolean) Apache HTTP Server

  • $is_IIS (boolean) Microsoft Internet Information Services (IIS)

  • $is_iis7 (boolean) Microsoft Internet Information Services (IIS) v7.x


Version Variables

  • $wp_version (string) The installed version of WordPress

  • $wp_db_version (int) The version number of the database

  • $tinymce_version (string) The installed version of TinyMCE

  • $manifest_version (string) The cache manifest version

  • $required_php_version (string) The version of PHP this install of WordPress requires

  • $required_mysql_version (string) The version of MySQL this install of WordPress requires


Misc

  • $super_admins (array) An array of user IDs that should be granted super admin privileges (multisite). This global is only set by the site owner (e.g., in wp-config.php), and contains an array of IDs of users who should have super admin privileges. If set it will override the list of super admins in the database.

  • $wp_query (object) The global instance of the Class_Reference/WP_Query class.

  • $wp_rewrite (object) The global instance of the Class_Reference/WP_Rewrite class.

  • $wp (object) The global instance of the Class_Reference/WP class.

  • $wpdb (object) The global instance of the Class_Reference/wpdb class.

  • $wp_locale (object)

  • $wp_admin_bar (WP_Admin_Bar)

  • $wp_roles (WP_Roles)

  • $wp_meta_boxes (object) Object containing all registered metaboxes, including their id's, args, callback functions and title for all post types including custom.

Admin Globals


转载于:https://my.oschina.net/ajian2014/blog/306206

### WP-CLI 安装教程 安装 WP-CLI 是管理 WordPress 站点的重要一步。以下是详细的安装步骤以及注意事项: #### 1. **环境准备** 在开始之前,确保服务器满足以下条件: - 已经通过 SSH 登录到服务器。 - 系统中已安装 PHP(建议版本为 7.0 或更高)。可以通过以下命令检查 PHP 版本: ```bash php --version ``` 输出应类似于以下内容[^3]: ``` PHP binary: /usr/bin/php PHP version: 7.4.25 ``` #### 2. **下载 WP-CLI Phar 文件** 使用 `curl` 或 `wget` 下载最新的 WP-CLI Phar 文件。推荐使用 `curl` 方法: ```bash curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar ``` 验证文件是否可用: ```bash php wp-cli.phar --info ``` 如果一切正常,您将看到有关 PHPWP-CLI 的详细信息输出。 #### 3. **赋予可执行权限** 将下载的 Phar 文件移动到系统的 PATH 中,并赋予其可执行权限: ```bash chmod +x wp-cli.phar mv wp-cli.phar /usr/local/bin/wp ``` 测试 WP-CLI 是否成功安装: ```bash wp --info ``` 输出示例: ``` OS: Linux ... Shell: ... PHP binary: /usr/bin/php PHP version: 7.4.25 php.ini used: /etc/php/7.4/cli/php.ini WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: / WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.6.0 ``` #### 4. **验证安装** 运行以下命令以确认 WP-CLI 功能正常: ```bash wp help ``` 此外,还可以测试一些基本功能,例如列出站点上的所有插件: ```bash wp plugin list ``` #### 5. **常见问题解决** - **PHP 不被识别**:如果系统未正确配置 PHP,请先安装 PHP 并将其路径加入环境变量。 - **权限不足**:在某些环境中可能需要提升权限才能完成安装。可以尝试加上 `sudo` 命令重试: ```bash sudo mv wp-cli.phar /usr/local/bin/wp sudo chmod +x /usr/local/bin/wp ``` --- ### 示例代码块 以下是完整的安装过程脚本化实现: ```bash #!/bin/bash # Step 1: Download the latest WP-CLI Phar file echo "Downloading WP-CLI..." curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # Step 2: Verify the downloaded file if php wp-cli.phar --info; then echo "WP-CLI Phar file verified successfully." else echo "Failed to verify WP-CLI Phar file. Please check your PHP installation." exit 1 fi # Step 3: Move the file to system PATH and make it executable chmod +x wp-cli.phar mv wp-cli.phar /usr/local/bin/wp # Step 4: Test the installation echo "Testing WP-CLI installation..." if wp --info; then echo "WP-CLI installed successfully!" else echo "Installation failed. Check permissions or try with sudo." exit 1 fi ``` 保存以上脚本为 `install-wp-cli.sh`,并通过以下命令运行: ```bash bash install-wp-cli.sh ``` --- ### 注意事项 - 推荐始终使用最新稳定版的 WP-CLI,以获得最佳性能和支持。 - 对于 Windows 用户,需额外配置 PATH 环境变量以便全局访问 `wp` 命令。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值