简体   繁体   English

PHP WordPress-高级自定义字段-在Pro版本中应用过滤器

[英]PHP WordPress - Advanced Custom Fields - Applying Filters in Pro version

I am building a WP plugin and have integrated ACF (free version) as per the documentation on their website: https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/ 我正在构建WP插件,并已按照其网站上的文档集成了ACF(免费版本): https : //www.advancedcustomfields.com/resources/includes-acf-in-a-plugin-theme/

I also use a series of filters to load the ACF fields based on the location setting: 我还使用一系列过滤器根据位置设置加载ACF字段:

$this->loader->add_filter( 'acf/location/rule_types', $plugin_admin, 'acf_location_rules_types' );
$this->loader->add_filter( 'acf/location/rule_values/cpt', $plugin_admin, 'acf_location_rules_values_cpt' );
$this->loader->add_filter( 'acf/location/rule_match/cpt', $plugin_admin, 'acf_location_rules_match_cpt', 10, 3 );

This code is based on this simple plugin: https://github.com/lukechapman/custom-post-template-support-for-acf/blob/master/acf-custom-post-template-support.php 该代码基于以下简单插件: https : //github.com/lukechapman/custom-post-template-support-for-acf/blob/master/acf-custom-post-template-support.php

Everything has worked absolutely perfectly, but since I have upgraded to ACF pro this has completely stopped working. 一切都绝对完美,但是自从我升级到ACF pro以来,这已经完全停止了工作。

I can't seem to find any resources specific to adding filters for ACF pro, only the basic version. 我似乎找不到特定于为ACF pro添加过滤器的任何资源,只有基本版本。 I've debugged it and can confirm paths are correct, no errors in logs, and I also added some debug code to the first callback function acf_location_rules_types() and this is not being called at all. 我已经对其进行调试,并且可以确认路径正确,日志中没有错误,并且还向第一个回调函数acf_location_rules_types()添加了一些调试代码,而根本没有调用它。

The script that loads the filters is working, but it's like the filter options no longer exist in ACF Pro. 加载筛选器的脚本正在运行,但是就像ACF Pro中不再存在筛选器选项一样。

Where am I going wrong with this? 我在哪里错呢?

EDIT 编辑

I've also tried a very simple implementation like this which is also not being called: 我也尝试过这样一个非常简单的实现,也没有被称为:

add_filter('acf/location/rule_types', function ($rules) {
    error_log('acf/location/rule_types debug');
    return false;
});
<?php
// functions.php
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
    $choices['Post']['post-type-has-taxonomy'] = __('Post Type has Taxonomy');
    return $choices;
}
add_filter( 'acf/location/rule_values/post-type-has-taxonomy', 'acf_location_rules_values_has_taxonomy' );
function acf_location_rules_values_has_taxonomy( $choices ) {
    return array_merge($choices, get_taxonomies());
}
add_filter('acf/location/rule_match/post-type-has-taxonomy', 'acf_location_rules_match_has_taxonomy', 10, 3);
function acf_location_rules_match_has_taxonomy( $match, $rule, $options )
{
    if ($rule['operator'] == '==') {
        $match = is_object_in_taxonomy($options['post_type'], $rule['value']);
    } elseif ($rule['operator'] == '!=') {
        $match = !is_object_in_taxonomy($options['post_type'], $rule['value']);
    }
    return $match;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM