Add your own code to the plugin through its hooks
TermsFeed AutoTerms fires 5 actions and applies 6 legacy filters of its own, and triggers 1 jQuery event after the Update Notices render. Add every PHP callback in a plugin or in the theme functions.php, and pass the number of arguments for a hook with more than 1, such as 2 for wpautoterms_container.
| Hook | Kind | Arguments | Fires |
|---|---|---|---|
wpautoterms_container |
Action | $where, $type |
While the plugin builds each of the 4 kit containers on a website page |
wpautoterms_registered_cpt |
Action | None | On init, right after the post type wpautoterms_page registers |
wpautoterms_dismissed_admin_notice |
Action | $class, $id, $removed |
On each wpautoterms_notices_action request that carries c and id |
wpautoterms_pre_editor |
Action | $option |
Before each rich-text message editor on a kit screen |
wpautoterms_post_editor |
Action | $option |
After each rich-text message editor on a kit screen |
atospp_tos_before_heading, atospp_tos_after_heading, atospp_tos_after_end |
Filter | $html (an empty string) |
Around the Terms of Service of the legacy shortcodes |
atospp_pp_before_heading, atospp_pp_after_heading, atospp_pp_after_end |
Filter | $html (an empty string) |
Around the Privacy Policy of the legacy shortcodes |
the_content |
Core filter | $content |
On the content of a legal page that [wpautoterms page="..."] embeds |
widget_title |
Core filter | $title, $instance, $id_base |
On the title of the Legal Pages widget |
post-load |
jQuery event | None | On document.body, after the Update Notices render |
The plugin has no filter of its own on the legal page text, the kit settings, or what the Cookie Consent kit prints.
Print your own markup in a kit container with wpautoterms_container
The wpautoterms_container action lets you echo markup into the 4 containers that hold the notices and what the Cookie Consent kit prints. It passes $where (top or bottom) and $type (static or fixed), and the plugin wraps what you echo in <div id="wpautoterms-<where>-<type>-container">. It fires on every page, whether or not a kit is on, except wp-login.php and wp-register.php, at these points.
- Top static and top fixed, normal mode. The plugin builds them on the
wpaction at priority 20 and inserts them right after the<body>tag. - Top static and top fixed, compatibility mode. "Caching plugins compatibility mode" moves them to the footer, on
wp_footerat priority 100002. - Bottom fixed and bottom static. Both print in the footer on
wp_footerat priority 100002, bottom fixed first. - Kit output inside each container. The kits listen at priority 10, in the order Update Notices, Cookie Notice, then the Cookie Consent kit. A callback at priority 5 prints before the kit output, and a callback at priority 20 prints after it.
The main query is ready on wp, so conditional tags such as is_front_page() and is_singular() work inside the callback. The example prints a shipping message in the bottom fixed container of the front page, after any kit output.
add_action( 'wpautoterms_container', 'mytheme_autoterms_shipping_bar', 20, 2 );
/**
* Prints a message in the bottom fixed container of TermsFeed AutoTerms on the front page.
*
* @param string $where top or bottom.
* @param string $type static or fixed.
*/
function mytheme_autoterms_shipping_bar( $where, $type ) {
if ( 'bottom' !== $where || 'fixed' !== $type || ! is_front_page() ) {
return;
}
echo '<div class="mytheme-shipping-bar">' . esc_html__( 'Free shipping on orders over $50.', 'mytheme' ) . '</div>';
}
On the front page, the <div id="wpautoterms-bottom-fixed-container"> element then holds the mytheme-shipping-bar element, after any kit output.
Fixed containers cover the content beneath them. A page cache stores the bottom containers with the page, and the top containers under WP Super Cache, Cache Enabler, or compatibility mode. Clear the cache after you change a callback. Look up the container IDs and selectors in TermsFeed AutoTerms CSS Classes and Containers, and set up page caching for the kits with WordPress Caching Plugins.
Run code after the post type registers with wpautoterms_registered_cpt
The wpautoterms_registered_cpt action fires on init at priority -999998, right after the post type wpautoterms_page registers, with no argument. Use it to add post type support or attach a taxonomy before any other init callback reads the post type. The example adds thumbnail support, which shows the Featured image box in a theme that declares post-thumbnails support.
add_action(
'wpautoterms_registered_cpt',
function () {
add_post_type_support( 'wpautoterms_page', 'thumbnail' );
}
);
React to a dismissed admin notice with wpautoterms_dismissed_admin_notice
The wpautoterms_dismissed_admin_notice action fires on each request to the AJAX action wpautoterms_notices_action that carries the c and id parameters. It passes $class, the notice class (error, updated, or notice-info), $id, the notice id, and $removed, which is true when a stored notice was removed. Only a user with edit_wpautoterms_pages reaches it.
No plugin screen sends that request, so the action fires only for requests other code sends. The example logs the dismissals that removed a stored notice.
add_action(
'wpautoterms_dismissed_admin_notice',
function ( $class, $id, $removed ) {
if ( ! $removed ) {
return;
}
error_log(
sprintf(
'TermsFeed AutoTerms notice "%s" (%s) dismissed by user %d',
$id,
$class,
get_current_user_id()
)
);
},
10,
3
);
Add content around the rich-text message editors with wpautoterms_pre_editor and wpautoterms_post_editor
The wpautoterms_pre_editor and wpautoterms_post_editor actions fire in the admin before and after each rich-text message editor of the notice and Endorsements kits. Both pass $option, whose name() method returns the editor ID.
| Editor ID | Field |
|---|---|
wpautoterms_cookies_notice_message |
"Message" on the Cookie Notice screen |
wpautoterms_update_notice_message |
"Message" on the Update Notices of Legal Pages screen |
wpautoterms_update_notice_message_multiple |
"Message for multiple updated pages" on the Update Notices of Legal Pages screen |
wpautoterms_endorsements_message |
"Disclaimer message" on the Endorsements screen |
The plugin prints the "Insert shortcode:" links from wpautoterms_post_editor at priority 10, so hook at priority 20 to print after them.
add_action(
'wpautoterms_post_editor',
function ( $option ) {
if ( 'wpautoterms_cookies_notice_message' !== $option->name() ) {
return;
}
echo '<p class="description">' . esc_html__( 'Keep the message to 2 sentences and link the Cookies Policy.', 'mytheme' ) . '</p>';
},
20
);
Change the legacy shortcode output with the atospp filters
6 filters add HTML around each document that the legacy Auto Terms of Service and Privacy Policy 1.x shortcodes print. Each receives an empty string, and the plugin prints the value you return without escaping it, so escape every value you add.
| Filter | Where the returned HTML prints | Shortcodes that print it |
|---|---|---|
atospp_tos_before_heading |
Before the Terms of Service heading, h2#atospp-terms |
[my_terms_of_service], [my_terms_of_service_and_privacy_policy] |
atospp_tos_after_heading |
After the Terms of Service heading | [my_terms_of_service], [my_terms_of_service_and_privacy_policy] |
atospp_tos_after_end |
After the end of the Terms of Service, its closing numbered list | [my_terms_of_service], [my_terms_of_service_and_privacy_policy] |
atospp_pp_before_heading |
Before the Privacy Policy heading, h2#atospp-privacy |
[my_privacy_policy], [my_terms_of_service_and_privacy_policy] |
atospp_pp_after_heading |
After the Privacy Policy heading | [my_privacy_policy], [my_terms_of_service_and_privacy_policy] |
atospp_pp_after_end |
After the last paragraph of the Privacy Policy | [my_privacy_policy], [my_terms_of_service_and_privacy_policy] |
The filters run only while the legacy text shows, with every required field filled and "On / Displaying" saved on the Legacy Auto TOS & PP screen.
add_filter(
'atospp_pp_after_heading',
function ( $html ) {
return $html . '<p class="mytheme-legacy-note">' . esc_html__( 'This policy applies to example.com and its subdomains.', 'mytheme' ) . '</p>';
}
);
add_filter(
'atospp_tos_after_end',
function ( $html ) {
return $html . '<p><a href="' . esc_url( home_url( '/contact/' ) ) . '">' . esc_html__( 'Contact us about these terms', 'mytheme' ) . '</a></p>';
}
);
The legacy text shows only on sites upgraded from 1.x, and other sites get a placeholder. Find the legacy shortcodes and their settings in Legal Page Shortcodes for WordPress.
Core filters the plugin applies
The plugin applies the core filters the_content and widget_title with their core arguments, so callbacks you already hook to them run on its output.
the_content on an embedded legal page
The [wpautoterms page="<slug>"] shortcode runs the embedded legal page through the_content, so your callbacks run twice on a post that embeds one: once for the legal page, once for the host post. During the pass for the legal page, get_post() still returns the host post, and the global $wpautoterms_post holds the legal page. The example adds a share line to post content and leaves embedded legal pages untouched.
add_filter(
'the_content',
function ( $content ) {
global $wpautoterms_post;
if ( ! empty( $wpautoterms_post ) && 'wpautoterms_page' === get_post_type( $wpautoterms_post ) ) {
return $content;
}
if ( ! is_singular( 'post' ) || ! in_the_loop() ) {
return $content;
}
return $content . '<p class="mytheme-share">' . esc_html__( 'Share this post', 'mytheme' ) . '</p>';
}
);
widget_title on the "Legal Pages" widget
The Legal Pages widget passes its title through widget_title, with the id base wpautoterms_widget. The title arrives HTML-escaped, the widget prints the returned value as it is, and an empty saved title arrives as "TermsFeed AutoTerms Plugin Legal Pages". The example replaces that default title only.
add_filter(
'widget_title',
function ( $title, $instance = array(), $id_base = '' ) {
if ( 'wpautoterms_widget' !== $id_base || ! empty( $instance['title'] ) ) {
return $title;
}
return esc_html__( 'Legal', 'mytheme' );
},
10,
3
);
Run code after the Update Notices render with the post-load event
The plugin triggers the jQuery event post-load on document.body each time it renders the Update Notices, with or without a notice. Other scripts, such as infinite scroll, trigger post-load too, so check for the notice markup in your handler. Attach it at load time, in a footer script. This one gives each notice the ARIA role status.
jQuery( document.body ).on( 'post-load', function () {
var notices = document.querySelectorAll( '#wpautoterms-update-notice-placeholder .wpautoterms-update-notice' );
for ( var i = 0; i < notices.length; i++ ) {
notices[ i ].setAttribute( 'role', 'status' );
}
} );
Enqueue it from js/update-notice.js in a child theme, in the footer, with a dependency on jquery.
add_action(
'wp_enqueue_scripts',
function () {
wp_enqueue_script(
'mytheme-update-notice',
get_stylesheet_directory_uri() . '/js/update-notice.js',
array( 'jquery' ),
'1.0.0',
true
);
}
);
The notices script defines other globals. Find them in TermsFeed AutoTerms Script and Style Handles.