第一次发布 WordPress 插件

前段时间写了个 移除 WordPress 文章评论的网站地址 的插件,想尝试下能否提交成功。

向 WordPress 社区提交插件是一个漫长的过程,我记得提交时队列中有接近 300 个插件等待审核,预计等待时间需要 60 多天🙃。

我在插件提交成功后回去看了下,截至这篇文章发布时的结果是:

Currently there are 257 plugins awaiting review.

The review queue is currently longer than normal, we apologize for the delays and ask for patience.

The current wait for an initial review is at least 16 days.

我是在 2024年01月15日 提交的第一版插件,起初是担心,频繁查看邮件,慢慢就忘记了这个事情。

直到在 2024年01月27日 收到邮件,插件被驳回。符合我的预期,只是原因比较意外。

不是因为插件过于简单,而是因为不符合插件编写规范,理由充分且完整。

节选以下邮件吧:

There are issues with your plugin code preventing it from being approved immediately. We have pended your submission in order to help you correct all issues so that it may be approved and published.
We ask you read this email in its entirety, address all listed issues, and reply to this email with your corrected code attached (or linked). You have three (3) months to make all corrections, before your plugin will be rejected. Even so, as long as you reply to this email, we will be able to continue with your review and eventually publish your code.

Incorrect Stable Tag
In your readme, your ‘Stable Tag’ does not match the Plugin Version as indicated in your main plugin file.

No GPL-compatible license declared
It is necessary to declare the license of this plugin. You can do this using the fields available both in the plugin readme and in the plugin headers.

Generic function/class/define/namespace/option names
All plugins must have unique function names, namespaces, defines, class and option names. This prevents your plugin from conflicting with other plugins or themes. We need you to update your plugin to use more unique and distinct names.

Allowing Direct File Access to plugin files
Direct file access is when someone directly queries your file. This can be done by simply entering the complete path to the file in the URL bar of the browser but can also be done by doing a POST request directly to the file. For files that only contain a PHP class the risk of something funky happening when directly accessed is pretty small. For files that contain procedural code, functions and function calls, the chance of security risks is a lot bigger.

  • readme.txt 里的版本号是 1.0,而代码里是 1.0.0
  • 没有声明 GPL 许可,实际上我在 readme.txt 写了,不过看起来 PHP 里也要写
  • 插件的 PHP 文件可以直接通过 URL 访问

他们在邮件里附上了详细的说明和处理建议,邮件里还附加了插件有关的文档。

当然,最重要的是 Generic function/class/define/namespace/option names 这条

这个在邮件里描述的比较有意思:

不要再尝试使用两 (2) 或三 (3) 个字母前缀。 仅在 WordPress.org 上我们就托管了近 10 万个插件。 我们的服务器之外还有数万个。 相信我们,你会遇到冲突。

虽然说 function 容易重名建议修改添加 function_exists,不过我把代码放在了 namespace myluoluo 里,最终逃过了一劫,哈哈🤣

修改前代码是这样的:

<?php
/**
 * Plugin Name:         Remove comment website
 * Plugin URI:          http://wordpress.org/extend/plugins/remove-comment-website/
 * Description:         Remove website from comments.
 * Version:             1.0.0
 * Requires at least:   5.0
 * Author:              myluoluo
 * Author URI:          https://www.myluoluo.com
 */
// Remove website from comment form.
public function website_remove_hook($fields) {
    if(isset($fields['url']))
    unset($fields['url']);
    return $fields;
}

// Remove website from comments list.
public function remove_comment_author_url_hook($comments) {
    foreach ($comments as $comment) {
        $comment->comment_author_url = '';
    }
    return $comments;
}


add_filter('comment_form_default_fields', array(__CLASS__, 'website_remove_hook'));
add_filter('comments_array', array(__CLASS__, 'remove_comment_author_url_hook'));

修改后是这样的:

<?php
/**
 * Plugin Name:         Remove comment website
 * Plugin URI:          http://wordpress.org/extend/plugins/remove-comment-website/
 * Description:         Remove website from comments.
 * Version:             1.0.1
 * Requires PHP:        7.2
 * Requires at least:   5.0
 * Author:              myluoluo
 * Author URI:          https://www.myluoluo.com
 * License:             GPLv2 or later
 * License URI:         https://www.gnu.org/licenses/gpl-2.0.html
 */
namespace myluoluo;
defined('ABSPATH') or die();

class Remove_Comment_Website {
    // Remove website from comment form.
    public static function website_remove_hook($fields) {
        if(isset($fields['url']))
        unset($fields['url']);
        return $fields;
    }

    // Remove website from comments list.
    public static function remove_comment_author_url_hook($comments) {
        foreach ($comments as $comment) {
            $comment->comment_author_url = '';
        }
        return $comments;
    }

    public static function add_hooks() {
        add_filter('comment_form_default_fields', array(__CLASS__, 'website_remove_hook'));
        add_filter('comments_array', array(__CLASS__, 'remove_comment_author_url_hook'));
    }
}

Remove_Comment_Website::add_hooks();

我在 2024年01月28日 提交了修改后的插件,最终,我在 2024年02月04日 收到了插件审核通过的邮件。

审核通过后给我开通了 SVN 仓库权限,需要把代码推送到 SVN 仓库才算正式发布。

不过根据邮件里的文档,发布超级简单,我本来以为 SVN 操作会挺困难的😆。

我知道,这么简单的插件是一个注定要淹没在众多插件里的沙子,不过我还是很开心😁。

插件地址:https://wordpress.org/plugins/remove-comment-website/

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据