Skip to main content Skip to navigation Skip to footer

Hooks & Filters

Updated

Do you need a Developer?

If you need help with customising code, using the below hooks and filters, or customising email templates, including changing text or adding new information, you may need to hire a developer to help you.

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


Function: Get User Subscriptions

cn_get_user_subscriptions( $key )

Purpose: Retrieve all subscriptions for a given user ID or email address.

Example:
if ( class_exists( 'Content_Notify' ) ) {
if ( is_user_logged_in() ) {
echo "<p>You have: " . count( cn_get_user_subscriptions( get_current_user_id() ) ) . " subscriptions</p>"; }
}


Function: Check Single Subscription

cn_subscription_single_check( $key, $post_id )

Purpose: Check if a user already has a subscription to this post/page/custom post type.

Example:
if ( class_exists( 'Content_Notify' ) ) {
if ( is_user_logged_in() && cn_subscription_single_check( get_current_user_id(), get_the_ID() ) ) {
echo "<p>You can only have one subscription for this post.</p>";
}
}


Filter: Alert Subject – Publish

cn\alert\subject\publish

Purpose: Filter for the subject field when a publish status is used on any post type.
The $post object and $entry (details of the user’s subscription) are available to use.

Example:
function cn_filter_subject_publish( $subject, $post, $entry ) {
$subject = __( 'Alert: New ' . $post_type_name[0]['single'] . ' Published', 'content-notify' );
return $subject;
}
add_filter( 'cn\alert\subject\publish', 'cn_filter_subject_publish', 10, 3 );


Filter: Alert Subject – Update

cn\alert\subject\update

Purpose: Filter for the subject field when an update status is used on any post type.
The $post object and $entry (details of the user’s subscription) are available to use.

Example:
function cn_filter_subject_update( $subject, $post, $entry ) {
$subject = __( 'Alert: ' . $post_type_name[0]['single'] . ' Updated', 'cn\alert\user\message' );
return $subject;
}
add_filter( 'cn\alert\subject\update', 'cn_filter_subject_update', 10, 3 );


Filter: Digest Alert Subject

cn\alert\digest\subject

Purpose: Filter for the subject field when a digest alert is sent.
The $post object and $entry (details of the user’s subscription) are available to use.

Example:
function cn_filter_subject_digest( $subject, $post_ids, $entry, $frequency ) {
$subject = sprintf(
// translators: digest frequency
__( 'Here\'s what you missed this %s', 'content-notify' )
, $frequency );
if ( $frequency == 'daily' ) {
$subject = __( 'Here\'s what you missed today', 'content-notify' );
}
if ( $frequency == 'weekly' ) {
$subject = __( 'Here\'s what you missed this week', 'content-notify' );
}
if ( $frequency == 'monthly' ) {
$subject = __( 'Here\'s what you missed this month', 'content-notify' );
}
return $subject;
}
add_filter( 'cn\alert\digest\subject', 'cn_filter_subject_digest', 10, 3 );


Filter: Email HTML

cn\alert\html

Purpose: Filter the HTML that Content Notify sends in an email.
Note: You can also customise the HTML email using a template file. Details of this can be found here.

Example:
function cn_filter_html( $email_html, $subject, $featured, $title, $message, $links, $sender_details ) {
$email_html = 'INSERT CONTENTS OF THE wp-content/plugins/content-notify/templates/alert-email.php FILE HERE';
return $email_html;
}
add_filter( 'cn\alert\html', 'cn_filter_html' );


Filter: User Alert Message

cn\alert\user\message

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

Example:
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:
function cn_filter_admin_message( $message ) {
$message = "
<p>" . __( "Here's what they signed up for: ", 'content-notify' ) . "</p>
" . $message_name . "
" . $mesage_post_type . "
" . $message_status . "
" . $message_author . "
" . $message_terms . "
" . $message_keywords . "
<p class='btn-container'><a href='" . get_edit_post_link( $subscription['ID'], false ) . "' class='btn btn-primary'>" . __( 'View Subscription', 'content-notify' ) . "</a></p>
";
return $message;
}
add_filter( 'cn\alert\admin\message', 'cn_filter_admin_message' );


Filter: Digest Alert Message

cn\alert\digest\user\message

Purpose: Filter for each message in the digest.

Example:
function cn_filter_digest_message( $message ) {
$messages[] = $featured . $title . $message;
}
add_filter( 'cn\alert\digest\user\message', 'cn_filter_digest_message' );


Get started

Start using it today

Ready to transform your communications for your
visitors, members, subscribers, and users?

View Pricing

14-DAY MONEY BACK GUARANTEE
ON NEW PURCHASES

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Services provided by our payment processor, Stripe, require that Strictly Necessary Cookies are enabled in order to protect against fraudulent purchases and to allow purchases to be made.
Stripe's cookie policy can be found here: https://stripe.com/gb/legal/cookies-policy

This website uses YouTube to host and view videos relating to the operation of this plugin and forms part of the documentation. Use of cookies from YouTube is required in order to fully document or explain elements of the plugin.
Google's cookie policy can be found here: https://policies.google.com/privacy

This website uses the following additional cookies which can't be initially disabled but can be safely deleted:

  • PHPSESSID - This cookie is created upon logging in and is used by PHP to keep track of sessions. It can be deleted at any time but will be recreated the next time a login occurs.
  • moove_gdpr_popup - This cookie is created upon accepting/dismissing the cookie banner. It stores this state so that it doens't show repeatedly.