删除 TranslatePress 挂钩

如果您需要进一步自定义工作,可以使用此代码示例停用所有必要的钩子。由于钩子的优先级,代码需要放在插件中,而不是主题中的 functions.php 文件中。钩子在 plugins_loaded 操作上很早就执行了。

<?php

add_action( ‘trp_before_running_hooks’, ‘trpc_remove_hooks_to_disable_gettext_translation’, 10, 1);
function trpc_remove_hooks_to_disable_gettext_translation( $trp_loader ){
$trp_loader->remove_hook( ‘init’, ‘create_gettext_translated_global’ );
$trp_loader->remove_hook( ‘shutdown’, ‘machine_translate_gettext’ );
}

如果项目要求您将代码放在 functions.php 中,则必须使用不同的方法来删除钩子。以下是如何获取所需组件对象的示例:

/* This particular code example refers to removing the TranslatePress search capability in secondary languages. */
// Use a different hook if ‘init’ is not executed early enough
add_action(‘init’, ‘trpc_remove_search_hook’);
function trpc_remove_search_hook(){
$trp = TRP_Translate_Press::get_trp_instance();

// fetch the component needed by replacing 'search' with the name of the component. Name of all components are found in class-translatepress.php
$trp_search = $trp->get_component('search');

// Use default WordPress function remove_filter or remove_action. Make sure to specifiy priority too.
remove_filter('pre_get_posts', array($trp_search,'trp_search_filter'), 99999999 );

}

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
相关推荐
评论 抢沙发

请登录后发表评论

    暂无评论内容