humanmade/propose-draft-date

块编辑插件,允许贡献用户设置提案发布日期

安装次数: 26,098

依赖项: 0

建议者: 0

安全性: 0

星标: 4

关注者: 17

分支: 1

开放问题: 14

类型:wordpress-plugin


README

Build Status

这是一个WordPress插件,它为贡献作者(以及其他无法安排或发布文章的角色)提供在块编辑器中选择提案日期的界面。该提案日期将通过过滤“浮动”发布日期显示在文章预览中,并在发布文章时生效。

过滤器

以下过滤器可用于修改此插件的行为。

proposed_date.supported_post_types (PHP过滤器)

服务器端PHP过滤器,用于修改可以接受提案日期的发布类型。

示例:为自定义发布类型添加提案日期支持,并从核心页面中移除。

/**
 * Customize the post types which support the proposed date feature.
 *
 * @param array $post_types Array of supported post types.
 *                          Defaults to "post" and "page".
 *
 * @return array Filtered post types array.
 */
function filter_types_with_proposed_dates( array $post_types ) : array {
    $post_types = array_diff( $post_types, [ 'page' ] );
    $post_types[] = 'my_custom_post_type';
    return $post_types;
}
add_filter( 'proposed_date.supported_post_types', 'filter_types_with_proposed_dates', 10, 1 );

proposed_date.should_accept_proposal (PHP过滤器)

服务器端PHP过滤器,根据旧的和新的文章状态以及在这些状态之间转换的文章对象,确定是否检查提案日期并应用它。

示例:在转换为自定义状态时接受提案日期。

/**
 * Always accept any available proposed date when transitioning to the
 * `my-scheduled` custom post status.
 *
 * @param bool    $accept_proposal Whether a proposal should be accepted.
 * @param string  $new_status      New post status.
 * @param string  $old_status      Previous post status.
 * @param WP_Post $post            The post being updated, before changes are applied.
 *
 * @return bool Whether a proposed date should be applied at this time.
 */
function accept_date_proposals_in_custom_status(
    bool $accept_proposal,
    string $new_status,
    string $old_status,
    WP_Post $post
) : bool {
    if ( $new_status === 'my_custom_status' ) {
        return true;
    }
    return $accept_proposal;
}
add_filter( 'proposed_date.should_accept_proposal', 'accept_date_proposals_in_custom_status', 10, 4 );

示例:始终接受存在的提案日期,无论其他情况如何。(如果您这样做,还应使用JS侧的proposed_date.date_label过滤器以确保您向贡献者显示正确的日期值。)

add_filter( 'proposed_date.should_accept_proposal', '__return_true' );

proposed_date.date_label (JS过滤器)

前端JS过滤器,用于确定在文档侧边栏中渲染提案日期时应显示哪个日期值。

示例:始终显示存在的提案日期。

function overrideProposedDateLabel( label, proposedDate, date ) {
    if ( proposedDate ) {
        return proposedDate;
    }
    return label;
}
wp.hooks.addFilter( 'proposed_date.date_label', 'my-plugin', overrideProposedDateLabel );

proposed_date.is_floating (JS过滤器)

覆盖是否将文章日期视为“浮动”(也就是说,如果文章打算立即发布)。

示例:强制“浮动”日期状态,即使存在实际的安排日期值,提案日期也将在前端显示。

function forceIsFloating( isFloating ) {
    return true;
}
wp.hooks.addFilter( 'proposed_date.is_floating', 'my-plugin', forceIsFloating );

proposed_date.supported_statuses (JS过滤器)

自定义支持提案日期值的文章状态列表。

function filterSupportedStatuses( statuses ) {
    return [ ...statuses, 'my_custom_status' ];
}
wp.hooks.addFilter( 'proposed_date.supported_statuses', 'my-plugin', filterSupportedStatuses );

发布流程

给定一个干净的main分支,其中在plugin.php中更新了版本号,按照以下步骤构建并标记版本:

git checkout release
git merge main
npm run build
git add -f build
git commit -m 'Tag v{ YOUR VERSION NUMBER HERE }'
git tag v{ YOUR VERSION NUMBER HERE }
git push origin release
git push origin tags