admin管理员组文章数量:1122832
I have the following code:
function auto_link_post_titles( $content, $post_id, $field ) {
$excluded_ids = array(); // Put the IDs of the pages you want to exclude here
$excluded_field_names = array(); // Put the names of the fields you want to exclude here
if(!in_array($post_id, $excluded_ids) && !in_array($field['name'], $excluded_field_names)) {
// Sets the post type(s) we'll retrieve.
$desired_post_types = array( 'my_post_type', 'my_other_post_type' );
// This is to get all published posts from all post types.
$args = array(
'post_type' => $desired_post_types,
'post_status' => 'publish',
'posts_per_page' => -1, // this is to retrieve all posts
);
$posts = get_posts( $args );
// Here are looping through each post and replace the title in the content with a link.
foreach ( $posts as $post ) {
$post_title = esc_html( $post->post_title ); // Here we are getting the post title.
$post_link = esc_url( get_permalink( $post->ID ) ); // Here we are getting the post link.
// Create a link element
$link = '<a href="' . $post_link . '" target="_blank">' . $post_title . '</a>';
// Here we are replacing the plain text title with the link.
$content = str_replace( $post_title, $link, $content );
}
}
return $content;
}
// We have apply the function to the content of posts.
// Note the number of parameters is set to 3 here
add_filter( 'acf/load_value', 'auto_link_post_titles', 10, 3 );
Unfortunately, this code breaks it "Ninja Tables" and "Ninja Tables Pro" plugin.
Question, my problem: Is it possible to exclude this function for specific plugin? And if yes, how? (Plugin loads ACF values.)
I have the following code:
function auto_link_post_titles( $content, $post_id, $field ) {
$excluded_ids = array(); // Put the IDs of the pages you want to exclude here
$excluded_field_names = array(); // Put the names of the fields you want to exclude here
if(!in_array($post_id, $excluded_ids) && !in_array($field['name'], $excluded_field_names)) {
// Sets the post type(s) we'll retrieve.
$desired_post_types = array( 'my_post_type', 'my_other_post_type' );
// This is to get all published posts from all post types.
$args = array(
'post_type' => $desired_post_types,
'post_status' => 'publish',
'posts_per_page' => -1, // this is to retrieve all posts
);
$posts = get_posts( $args );
// Here are looping through each post and replace the title in the content with a link.
foreach ( $posts as $post ) {
$post_title = esc_html( $post->post_title ); // Here we are getting the post title.
$post_link = esc_url( get_permalink( $post->ID ) ); // Here we are getting the post link.
// Create a link element
$link = '<a href="' . $post_link . '" target="_blank">' . $post_title . '</a>';
// Here we are replacing the plain text title with the link.
$content = str_replace( $post_title, $link, $content );
}
}
return $content;
}
// We have apply the function to the content of posts.
// Note the number of parameters is set to 3 here
add_filter( 'acf/load_value', 'auto_link_post_titles', 10, 3 );
Unfortunately, this code breaks it "Ninja Tables" and "Ninja Tables Pro" plugin.
Question, my problem: Is it possible to exclude this function for specific plugin? And if yes, how? (Plugin loads ACF values.)
Share Improve this question asked Sep 25, 2024 at 5:32 MapaMapa 194 bronze badges1 Answer
Reset to default 0With the help of given line you should be able to check if the request is related to Ninja Tables. Also you can modify this if you have another condition to detect the plugin's context.
In this case we have used did_action('ninja_tables_loaded')
to checks if the action ninja_tables_loaded
has been fired, which might be specific to Ninja Tables.
The given code needs to be added below $excluded_field_names = array();
This code will check the context for Ninja Table and if it's true then it will return from here without further processing.
// Check for Ninja Tables context
if ( isset( $_GET['ntb'] ) || did_action( 'ninja_tables_loaded' ) ) {
return $content;
}
本文标签: phpFunction exclusion for a plugin
版权声明:本文标题:php - Function exclusion for a plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288724a1928154.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论