Hooks & Filters

Updated


Content Notify contains a number of useful filters so that you can customise various aspects of the plugin. These are:

Filter: Load Public CSS

cn\assets\enqueue_css_public

Purpose: Override if Content Notify’s CSS file is loaded. Can be true (load CSS) or false (don’t load CSS). Handy for improving support for themes or plugins.

Example:

1
add_filter( 'cn\assets\enqueue_css_public', '__return_false' );

Filter: Post Types

cn\post_types\exclude

Purpose: Exclude post types from appearing in the select box in both the front-end and admin subscription form.

Example:

1
2
3
4
5
6
7
function cn_filter_post_types( $post_types ) {
$post_types_additional = array( 'post' );
$post_types = array_merge( $post_types, $post_types_additional );

return $post_types;
}
add_filter( 'cn\post_types\exclude', 'cn_filter_post_types' );

Filter: Authors

cn\authors\exclude

Purpose: Exclude authors from appearing in the select box in both the front-end and admin subscription form.

Example:

1
2
3
4
5
6
function cn_filter_authors( $authors ) {
$authors = array( 'admin' );

return $authors;
}
add_filter( 'cn\authors\exclude', 'cn_filter_authors' );

Filter: Taxonomies

cn\taxonomies\exclude

Purpose: Exclude taxonomies from appearing in the select box in both the front-end and admin subscription form.

Example:

1
2
3
4
5
6
7
function cn_filter_taxonomies( $taxonomies ) {
$taxonomies_additional = array( 'category' );
$taxonomies = array_merge( $taxonomies, $taxonomies_additional );

return $taxonomies;
}
add_filter( 'cn\taxonomies\exclude', 'cn_filter_taxonomies' );

Filter: Empty Terms

cn\taxonomies\show_empty

Purpose: Show empty terms in the Taxonomy select box(es) in both the front-end and admin subscription form. Empty terms are normally hidden by default. Can be true (hide empty terms) or false (show empty terms).

Example:

1
add_filter( 'cn\taxonomies\show_empty', '__return_false' );

Filter: Alert Subject – Publish

cn\alert\subject\publish

Purpose: Filter for the subject field when a publish status is used on any post type.

Example:

1
2
3
4
5
6
function cn_filter_subject_publish( $subject ) {
$subject = __( 'Alert: New ' . $post_type_name[0]['single'] . ' Published', 'cn' );

return $subject;
}
add_filter( 'cn\alert\subject\publish', 'cn_filter_subject_publish' );

Filter: Alert Subject – Update

cn\alert\subject\update

Purpose: Filter for the subject field when an update status is used on any post type.

Example:

1
2
3
4
5
6
function cn_filter_subject_update( $subject ) {
$subject = __( 'Alert: ' . $post_type_name[0]['single'] . ' Updated', 'cn' );

return $subject;
}
add_filter( 'cn\alert\subject\update', 'cn_filter_subject_update' );

Filter: User Alert Message

cn\alert\user\message

Purpose: Filter for the message field used on any post type.

Example:

1
2
3
4
5
6
7
8
function cn_filter_user_message( $message ) {
if ( empty( $post->post_password ) ) {
$message = $post->post_content;
}

return $message;
}
add_filter( 'cn\alert\user\message', 'cn_filter_user_message' );

Filter: Admin Alert Message

cn\alert\admin\message

Purpose: Filter for the message in the alert that is sent to the admin when a user verifies their subscription.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function cn_filter_admin_message( $message ) {
$message = "
<p>
"
. __( "Here's what they signed up for: ", 'cn' ) . "
</p>

<p>
"
. $message_name . "
"
. __( '<strong>Notify When:</strong> ', 'cn' ) . $subscription['post_type'] . "<br>
"
. __( '<strong>Are:</strong> ', 'cn' ) . $subscription['status'] . "<br>
"
. __( '<strong>By:</strong> ', 'cn' ) . $subscription['author'] . "
"
. __( '<strong>In:</strong> ', 'cn' ) . $subscription['user_terms'] . "
</p>

<p class='btn-container'><a href='"
. get_edit_post_link( $subscription['ID'] ) . "' class='btn btn-primary'>" . __( 'View Subscription', 'cn' ) . "</a></p>
"
;

return $message;
}
add_filter( 'cn\alert\admin\message', 'cn_filter_admin_message' );