[英]PHP WordPress - Advanced Custom Fields - Applying Filters in Pro version
我正在構建WP插件,並已按照其網站上的文檔集成了ACF(免費版本): https : //www.advancedcustomfields.com/resources/includes-acf-in-a-plugin-theme/
我還使用一系列過濾器根據位置設置加載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 );
該代碼基於以下簡單插件: https : //github.com/lukechapman/custom-post-template-support-for-acf/blob/master/acf-custom-post-template-support.php
一切都絕對完美,但是自從我升級到ACF pro以來,這已經完全停止了工作。
我似乎找不到特定於為ACF pro添加過濾器的任何資源,只有基本版本。 我已經對其進行調試,並且可以確認路徑正確,日志中沒有錯誤,並且還向第一個回調函數acf_location_rules_types()
添加了一些調試代碼,而根本沒有調用它。
加載篩選器的腳本正在運行,但是就像ACF Pro中不再存在篩選器選項一樣。
我在哪里錯呢?
編輯
我也嘗試過這樣一個非常簡單的實現,也沒有被稱為:
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.