WordPress 使用 wp 命令创建 .opt 文件用以支持多语言 作者: Shine 时间: 2021-07-20 分类: PHP 评论 ## 前言 > 个人所理解,如有错误请指正 首先需要明白一件事情,创建 `.opt` 文件前,首先在你的插件注释里添加以下关键注释(**Text Domain** 和 **Domain Path** 字段): - **Text Domain**:文本域(个人理解),这个比较关键 - **Domain Path**:翻译文件存放的路径 ``` /** * Plugin Name: 插件的名字 * Plugin URI: https://nowtime.cc/ * Description: 插件简介 * Version: 0.0.1 * Author: Chuwen * Author URI: https://nowtime.cc * Text Domain: chuwen * Domain Path: /i18n/languages/ * Requires at least: 5.5 * Requires PHP: 7.0 * * @package Chuwen * @date 2021/7/20 14:50 */ ``` 以上工作完成后,就可以接着往下看了 ## 安装 wp 命令 > WP-CLI 是一款用于管理 WordPress 的命令行交互界面,无需浏览器即可完成插件更新,多站点设置等许多操作。 官网地址:https://wp-cli.org/zh-cn/ [官方]安装文档:[https://wp-cli.org/zh-cn/#安装](https://wp-cli.org/zh-cn/#安装 "https://wp-cli.org/zh-cn/#安装") ### 本文主要介绍 macOS 以及 Linux 系统安装 #### Linux 安装教程 ```shell cd ~ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # 检查 Phar 文件确保其正常运行: php wp-cli.phar --info # 要使用 wp 执行 WP-CLI 命令,必须有执行权限并且 PATH 已在环境变量中注册,例如: chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp # 最后再次验证 wp --info ``` #### macOS 可以借助 Homebrew 进行安装 > Homebrew 官方安装文档:https://docs.brew.sh/Installation > 其安装教程可参照:https://zhuanlan.zhihu.com/p/111014448 Homebrew 安装完成后,执行 `brew install wp-cli` 即可 #### Windows 安装教程 > 自行网上搜索,因为**某些功能在 Windows 中将受到限制**,所以我推荐在 Windows 10 以及以上的系统,安装 WSL(Windows 子系统),然后参照 Linux 系统安装 `wp` 命令即可 ### 验证安装 wp 命令 输入 `wp --info` 即可验证  ```shell chuwen@MiBook# wp --info OS: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64 Shell: /bin/zsh PHP binary: /usr/local/Cellar/php@7.3/7.3.28/bin/php PHP version: 7.3.28 php.ini used: /usr/local/etc/php/7.3/php.ini MySQL binary: MySQL version: SQL modes: 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: /Users/chuwen WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.5.0 ``` ## 生成 `.pot` 文件 - 假设你的 WordPress 根目录是:`/www/wwwroot/wordpress.com` - 假设你的 WordPress 插件目录:`/www/wwwroot/wordpress.com/wp-content/plugins/chuwen` 首先进入的你的**插件目录** ```shell cd /www/wwwroot/wordpress.com/wp-content/plugins/chuwen ``` 然后生成 `.opt` 文件 ```shell # 如果你是按照最开头的做法做的,那么会自动将生成的 `.opt` 文件放到 `Domain Path` 文件夹下 wp i18n make-pot . # 如果你想指定文件存放路径、文件名 wp i18n make-pot . i18n/languages/chuwen.pot ``` 最后生成结果查看你插件目录下的 `i18n/languages/` 里面的文件即可 ### 生成多语言 将生成的比如 `chuwen.pot` 复制一份,将其命名为 `en_US.pot`,然后使用工具进行翻译即可
WordPress 使用 CloudFlare 后,后台无法进入、重定向次数过多、提示 Sorry, you are not allowed to access this page. 作者: Shine 时间: 2021-07-10 分类: PHP 评论 ## 具体原因 1. CloudFlare 那边 SSL 配置的是“灵活”  2. WordPress 后台配置的又是 https  最终就会导致浏览器一直报“重定向次数过多”,或者 WordPress 直接报 `Sorry, you are not allowed to access this page.` CloudFlare SSL 配置“灵活”,指的是 **源站**(也就是你的 WordPress)博客不支持 https,然后 CloudFlare 可以实现: 浏览器 --https--> CloudFlare --http--> 你的服务器(WordPress) **但是**,你在 WordPress 后台配置的了你的 WordPress 地址是 `https` 地址开头的,所以当 CloudFlare 访问你的 WordPress 时,你的 WordPress 告诉 CloudFlare 你只能通过 https 访问,CloudFlare 又告诉你的浏览器你只能访问 https 这样就造成了循环.... ## 解决办法 将 CloudFlare 的 SSL 配置改为“完全”或“完全(严格)”,**推荐选择完全**具体看: 
目录/时间线 Typecho 自定义模板 作者: Shine 时间: 2021-07-04 分类: PHP 1 条评论 ## 使用说明 如果你使用的是 Typecho 默认主题,那么你可以在你博客目录下 `/www/wwwroot/nowtime.cc/usr/themes/default` 新建一个文件名为 `time-line.php` 然后将下述**模板源码**粘贴进去保存 > 其它主题可以参照着你主题目录下的 `page.php` 源码来修改我下面写的**模板源码** 然后去博客后台 -> 管理 -> 独立页面 -> 新增,选择模板  然后“发布页面即可” ### 效果预览 https://nowtime.cc/time-line.html  ## 模板源码 ```php need('header.php'); ?> title() ?> content(); ?> need('comments.php'); ?> widget("Widget_Contents_Post_Recent", "pageSize=100000000000000")->to($post); $recentPost = array(); while ($post->next()) { $recentPost[] = array( "title" => $post->title, "link" => $post->permalink, "time" => $post->created, ); } ?> need('sidebar.php'); ?> need('footer.php'); ?> ```
Hyperf 使用 @date、@datetime 注释启动都报错 作者: Shine 时间: 2021-07-03 分类: PHP 评论 Hyperf 使用 @date、@datetime 注释启动都报错 ### 使用 @date 注释 代码如下: ```php * @date: 2021/7/3 12:28 */ public function index(RequestInterface $request, ResponseInterface $response): \Psr\Http\Message\ResponseInterface { return $response->raw($this->help()); } } ``` 报错: ```log #4 /www/wwwroot/NowTool/vendor/hyperf/d in /www/wwwroot/NowTool/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 39 Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@date" in method App\Controller\V1\Video\DouyinController::index() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /www/wwwroot/NowTool/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:39 Stack trace: ``` ### 使用 @datetime 注释 又报以下错误: ```log Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The class "datetime" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "datetime". If it is indeed no annotation, then you need to add @IgnoreAnnotation("datetime") to the _class_ doc comment of method App\Controller\V1\Video\DouyinController::index(). in /www/wwwroot/NowTool/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:39 Stack trace: ``` > The class "datetime" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "datetime". ### 看到以上错误大概需要怎么做了 参照文档的“注解”部分:https://hyperf.wiki/2.1/#/zh-cn/annotation 解决办法就是,添加需要忽略“注解”,配置文件位置 `/config/autoload/annotations.php`:  然后就可以正常启动了 
Laravel 添加模型方法注释,使 PHPStorm 有语法提示 作者: Shine 时间: 2021-06-30 分类: Laravel,PHP 评论 ## 安装 1. 在 PHPStorm 上装 `Laravel` 插件  2. 在项目中添加 `barryvdh/laravel-ide-helper` 包 ```shell composer require barryvdh/laravel-ide-helper ``` ## 使用 1.为**所有模型**添加注释 ```shell php artisan ide-helper:models ``` 2.为**指定模型**添加注释 > 以下展示的是为 `App\Models\Admin` 模型添加注释,*\App\Models\Admin* 是模型的命名空间名字 ```shell php artisan ide-helper:models \App\Models\Admin ``` 3.为 Facades 生成注释 ```shell php artisan ide-helper:generate ``` 4.生成 PHPstorm Meta file ```shell php artisan ide-helper:meta ``` ## 运行为“模型添加注释”后的截图 