alleyinteractive/wp-filter-side-effects 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alleyinteractive/wp-filter-side-effects

最新稳定版本:v2.0.0

Composer 安装命令:

composer require alleyinteractive/wp-filter-side-effects

包简介

Use a WordPress filter like an action.

README 文档

README

add_filter_side_effect() allows attaching a callback function to a WordPress filter without requiring that the callback function return the filtered value or even return any value. It wraps add_filter() and accepts the same arguments with the same defaults.

The callback function can return void or return a value. If the callback function returns a value, that value will be ignored, not passed back to the filter. Filter side effects thus behave like add_action() callbacks and can be used in situations where a call to apply_filters() signals that some behavior needs to occur, but no convenient action exists to run it.

Installation

Install the latest version with:

$ composer require alleyinteractive/wp-filter-side-effects

Basic usage

<?php

use function Alley\WP\add_filter_side_effect;

add_filter_side_effect(
    'rest_pre_insert_post',
    function ( $prepared_post, $request ): void {
        // Do something before the post is saved, like...
        $language_slug    = $request['lang'];
        $default_category = $this->get_custom_default_language_category( $language_slug );

        if ( $default_category ) {
            add_filter( 'pre_option_default_category', fn() => $default_category );
        }
    },
    10,
    2,
);

About

License

GPL-2.0-or-later

Maintainers

Alley Interactive

统计信息

  • 总下载量: 364.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 21
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-06-03