Prohibited Terms Scanner
The Prohibited Terms Scanner plugin has many useful hooks for developers to use to further enhance its functionality, from adding your own scan locations to changing who can run scans.
- ptscanner_location_types
- ptscanner_query_args
- ptscanner_is_public_post
- ptscanner_deadbolt_url_param_is_public
- ptscanner_excluded_post_types
- ptscanner_integration_managed_post_types
- ptscanner_file_content_mimes
- ptscanner_file_text_replacements
- ptscanner_source_title
- ptscanner_cron_max_batches_per_type
- ptscanner_can_view
- ptscanner_can_scan
- ptscanner_assignable_roles
- ptscanner_current_settings
- ptscanner_export_data
- ptscanner_resettable_options
- ptscanner_admin_tabs
- ptscanner_help_links
- ptscanner_header_logo
- ptscanner_script_data
- ptscanner_admin_script_data
- ptscanner_theme_colors
- ptscanner_dynamic_css
- ptscanner_test_mode
- ptscanner_loaded
- ptscanner_admin_enqueue
- ptscanner_subheader_left
- ptscanner_subheader_right
- ptscanner_settings_saved
- ptscanner_settings_imported
- ptscanner_settings_reset
- ptscanner_reschedule_cron
- ptscanner_cron_scan_complete
ptscanner_location_types
TYPE ⇢ Filter
Registers additional places to scan, or changes the built-in ones. Each location type appears as a checkbox on the Scanner tab and in Settings > Search Locations, and is included in scheduled scans when enabled there.
Each entry is keyed by a unique slug and has these properties:
label: Checkbox label and the name shown in the Location column.group: Group heading for the checkbox:content,media,files, or any name of your own.source_callback: Required. Callable that scans one batch. Receives$terms,$offsetand$limit, and returns[ 'rows' => array, 'done' => bool ]. Entries without a callable source_callback are removed.link_callback: Callable that receives the source ID and returns the URL used for View Source. If it returns an empty string, the row'ssource_urlis used.default_enabled: Whether the location is checked by default before Settings are saved.
Each row returned by your source callback needs term, location_type, source_type, an integer source_id, source_url, context_snippet and match_hash. The public match_terms(), build_match_hash() and should_skip_post() methods on \PluginRx\ProhibitedTermsScanner\Scanner do the matching, hashing, omit and public-page checks for you, using each term's Case Sensitive and Strict options and the Snippet Padding setting. Set done to true when there are no more items to scan.
Using post as the source type gives your results the post's title, the highlight-and-blink View Source link, and the Omit Source action. For any other source type, supply the title with ptscanner_source_title.
Example Usage
/** * Scan Yoast SEO meta descriptions as their own location. */ add_filter( 'ptscanner_location_types', function( $types ) { $types[ 'seo_description' ] = [ 'label' => __( 'SEO Meta Description', 'my-textdomain' ), 'group' => 'content', 'source_callback' => 'myprefix_scan_seo_descriptions', 'link_callback' => 'get_permalink', 'default_enabled' => false, ]; return $types; } ); /** * Scan one batch of SEO meta descriptions. * * @param array $terms → [ 'term', 'case_sensitive', 'strict' ] for each saved term. * @param int $offset → Number of items already scanned. * @param int $limit → Batch size from Settings. * * @return array → [ 'rows' => array, 'done' => bool ] */ function myprefix_scan_seo_descriptions( $terms, $offset, $limit ) { $scanner = \PluginRx\ProhibitedTermsScanner\Scanner::instance(); $post_ids = get_posts( [ 'post_type' => \PluginRx\ProhibitedTermsScanner\Settings::instance()->get_enabled_post_types(), 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'ID', 'order' => 'ASC', 'fields' => 'ids', ] ); $rows = []; foreach ( $post_ids as $post_id ) { if ( $scanner->should_skip_post( $post_id ) ) { continue; } $description = (string) get_post_meta( $post_id, '_yoast_wpseo_metadesc', true ); foreach ( $scanner->match_terms( $description, $terms, false ) as $match ) { $rows[] = [ 'term' => $match[ 'term' ], 'location_type' => 'seo_description', 'source_type' => 'post', 'source_id' => $post_id, 'source_url' => get_permalink( $post_id ), 'context_snippet' => $match[ 'snippet' ], 'match_hash' => $scanner->build_match_hash( $match[ 'term' ], 'seo_description', $post_id, $match[ 'snippet' ] ), ]; } } return [ 'rows' => $rows, 'done' => count( $post_ids ) < $limit, ]; }ptscanner_query_args
TYPE ⇢ Filter
Filters the WP_Query arguments the scanners use to find items. The second parameter tells you which query is running:
posts: Posts scanned for titles, content and excerpts.attachments: Media scanned for filenames, alt text and file content.external_links: Posts scanned on the External Links tab.eri_files: ERI File Library files, when that plugin is active.
The built-in Deadbolt integration uses this filter so scans can still see pages Deadbolt hides from other queries.
Example Usage
/** * Skip posts in the "Archive" category (ID 12) during content and external link scans. * * @param array $args → WP_Query arguments. * @param string $context → posts, attachments, external_links or eri_files. * * @return array → The modified arguments. */ add_filter( 'ptscanner_query_args', function( $args, $context ) { if ( in_array( $context, [ 'posts', 'external_links' ], true ) ) { $args[ 'category__not_in' ] = [ 12 ]; } return $args; }, 10, 2 );ptscanner_is_public_post
TYPE ⇢ Filter
Decides whether a post counts as public. When Only Scan Public Pages is on, posts that return false are skipped in scans. It also decides which pages are listed in the shortcode's Omit Public Pages panel. Every published post is public unless an integration, such as Deadbolt, or your code says otherwise.
Example Usage
/** * Treat members-only posts as not public. * * @param bool $is_public → Whether the post is public so far. * @param int $post_id → The post being checked. * * @return bool */ add_filter( 'ptscanner_is_public_post', function( $is_public, $post_id ) { if ( get_post_meta( $post_id, '_myprefix_members_only', true ) ) { return false; } return $is_public; }, 10, 2 );ptscanner_deadbolt_url_param_is_public
TYPE ⇢ Filter
Only applies when Deadbolt is active. Pages Deadbolt unlocks with a URL parameter count as public by default, since anyone with the link can open them. Return false to treat them as restricted. Also receives the post ID as a second parameter.
Example Usage
/** * Treat Deadbolt URL-parameter pages as restricted. */ add_filter( 'ptscanner_deadbolt_url_param_is_public', '__return_false' );ptscanner_excluded_post_types
TYPE ⇢ Filter
Post types that are never scanned, never listed in Settings, and never get the Omit action. The defaults are help-doc-imports, help-docs, x-portfolio and mailpoet_page.
Example Usage
/** * Never scan an internal post type. * * @param array $excluded → Post type slugs to exclude. * * @return array */ add_filter( 'ptscanner_excluded_post_types', function( $excluded ) { $excluded[] = 'myprefix_internal'; return $excluded; } );ptscanner_integration_managed_post_types
TYPE ⇢ Filter
Post types that are scanned by their own location types instead of the standard title, content and excerpt scans. They are hidden from the Post Types setting so the same item is not scanned twice. The defaults are the ERI File Library post types, erifl-files and eri-files.
Example Usage
/** * Leave the "record" post type to a custom location type. * * @param array $post_types → Post type slugs handled by an integration. * * @return array */ add_filter( 'ptscanner_integration_managed_post_types', function( $post_types ) { $post_types[] = 'myprefix_record'; return $post_types; } );ptscanner_file_content_mimes
TYPE ⇢ Filter
The MIME types read by the File Content location. The defaults are text/plain, text/csv, application/pdf and the Word .docx type. PDF and .docx files have their own text extraction; any other type you add is read as plain text, so only add text-based formats. The file type must also be allowed for upload on your site.
For binary formats such as legacy .doc files, register your own location type with ptscanner_location_types and extract the text there.
Example Usage
/** * Also scan tab-separated files and WebVTT caption files. * * @param array $mimes → MIME types to scan. * * @return array */ add_filter( 'ptscanner_file_content_mimes', function( $mimes ) { $mimes[] = 'text/tab-separated-values'; $mimes[] = 'text/vtt'; return $mimes; } );ptscanner_file_text_replacements
TYPE ⇢ Filter
Character replacements applied to text extracted from files before matching. By default, ligatures (such as "fi") are expanded, curly quotes become straight quotes, and soft hyphens and zero-width characters are removed. Runs of whitespace, including special spaces, are collapsed afterwards.
Example Usage
/** * Treat en and em dashes in files as regular hyphens. * * @param array $replacements → Search => replace. * * @return array */ add_filter( 'ptscanner_file_text_replacements', function( $replacements ) { $replacements[ "\u{2013}" ] = '-'; $replacements[ "\u{2014}" ] = '-'; return $replacements; } );ptscanner_source_title
TYPE ⇢ Filter
Supplies the Source title for results whose source type the plugin does not recognize. Built-in types (posts, comments, terms, attachments and ERI files) resolve their own titles, so this is for custom location types. Receives an empty string and the full result row, which includes source_type, source_id, location_type, term and source_url.
Example Usage
/** * Title results from a custom "record" source type. * * @param string $title → An empty string. * @param array $row → The result row. * * @return string */ add_filter( 'ptscanner_source_title', function( $title, $row ) { if ( 'myprefix_record' === $row[ 'source_type' ] ) { $title = myprefix_get_record_name( $row[ 'source_id' ] ); } return $title; }, 10, 2 );ptscanner_cron_max_batches_per_type
TYPE ⇢ Filter
A safety limit on how many batches a scheduled scan runs for each location, so a bad callback can never loop forever. The default is 500, which covers 10,000 items per location at the default batch size of 20.
Example Usage
/** * Allow scheduled scans to cover more items per location. */ add_filter( 'ptscanner_cron_max_batches_per_type', function() { return 2000; } );ptscanner_can_view
TYPE ⇢ Filter
Overrides whether a user can view results (the Results and External Links tabs). Anyone who can scan can also view. Also receives the user ID.
Example Usage
/** * Let users with a custom capability view results. * * @param bool $can → Whether the user can view results. * @param int $user_id → The current user's ID. * * @return bool */ add_filter( 'ptscanner_can_view', function( $can, $user_id ) { return $can || user_can( $user_id, 'myprefix_review_content' ); }, 10, 2 );ptscanner_can_scan
TYPE ⇢ Filter
Overrides whether a user can run scans and act on results, including through the front-end shortcode. Administrators always can. The Errors and Settings tabs always require manage_options regardless of this filter.
Example Usage
/** * Let anyone who can edit other people's pages run scans. * * @param bool $can → Whether the user can scan. * @param int $user_id → The current user's ID. * * @return bool */ add_filter( 'ptscanner_can_scan', function( $can, $user_id ) { return $can || user_can( $user_id, 'edit_others_pages' ); }, 10, 2 );ptscanner_assignable_roles
TYPE ⇢ Filter
The roles offered in the Roles That Can View Results and Roles That Can Scan settings, as slug => name. Administrators are never listed because they always have full access.
Example Usage
/** * Don't offer the Subscriber role. * * @param array $roles → Role slug => translated name. * * @return array */ add_filter( 'ptscanner_assignable_roles', function( $roles ) { unset( $roles[ 'subscriber' ] ); return $roles; } );ptscanner_current_settings
TYPE ⇢ Filter
The current settings, used for the settings export and as the starting point when an import is merged. Keys the plugin does not recognize are included in exports but ignored on import.
Example Usage
/** * Never export the uninstall option. * * @param array $settings → Settings keyed as the Settings tab saves them. * * @return array */ add_filter( 'ptscanner_current_settings', function( $settings ) { unset( $settings[ 'clear_data_on_uninstall' ] ); return $settings; } );ptscanner_export_data
TYPE ⇢ Filter
The full payload written to the downloaded JSON file: metadata, terms and settings.
Example Usage
/** * Record who made the export. * * @param array $export → The export payload. * * @return array */ add_filter( 'ptscanner_export_data', function( $export ) { $export[ 'metadata' ][ 'exported_by' ] = wp_get_current_user()->user_login; return $export; } );ptscanner_resettable_options
TYPE ⇢ Filter
The option names deleted when an administrator clicks Reset Settings. Terms, results, notes and omitted sources are never in this list. Add your own options so your add-on resets along with the plugin.
Example Usage
/** * Reset an add-on option along with the plugin's settings. * * @param array $options → Option names to delete. * * @return array */ add_filter( 'ptscanner_resettable_options', function( $options ) { $options[] = 'myprefix_ptscanner_addon_settings'; return $options; } );ptscanner_admin_tabs
TYPE ⇢ Filter
The tabs in the plugin header, keyed by admin page slug. Each tab has a label, an access level (view, scan or manage) and a callback that outputs the tab's content. Tabs without a label or a callable callback are removed. Optionally set count to true to show the flagged results count on the tab.
Added tabs get the plugin's header, subheader and styles automatically.
Example Usage
/** * Add a Reports tab. * * @param array $tabs → Page slug => [ label, access, callback ]. * * @return array */ add_filter( 'ptscanner_admin_tabs', function( $tabs ) { $tabs[ 'prohibited-terms-scanner_reports' ] = [ 'label' => __( 'Reports', 'my-textdomain' ), 'access' => 'view', 'callback' => 'myprefix_render_reports_tab', ]; return $tabs; } ); /** * Output the Reports tab. */ function myprefix_render_reports_tab() { echo '<div class="wrap ptscanner-wrap ptscanner-content-wrap">'; echo '<div class="ptscanner-box"><div class="ptscanner-box-body">'; echo '<p>' . esc_html__( 'Your report goes here.', 'my-textdomain' ) . '</p>'; echo '</div></div></div>'; }ptscanner_help_links
TYPE ⇢ Filter
The How-To Guide, Developer Docs and Support links shown on the Settings tab and on the Plugins page. Each link has a label and a url.
Example Usage
/** * Send support requests to your own help desk. * * @param array $links → Key => [ label, url ]. * * @return array */ add_filter( 'ptscanner_help_links', function( $links ) { $links[ 'support' ][ 'url' ] = 'https://example.com/help-desk/'; return $links; } );ptscanner_header_logo
TYPE ⇢ Filter
The URL of the logo shown in the plugin header.
Example Usage
/** * Use your own logo in the plugin header. */ add_filter( 'ptscanner_header_logo', function() { return get_stylesheet_directory_uri() . '/images/logo.png'; } );ptscanner_script_data
TYPE ⇢ Filter
The data passed to every plugin script as the ptscanner_data JavaScript object, on the admin tabs and on pages using the shortcode. It includes the AJAX URL, nonce, saved terms, location types and translated strings.
Example Usage
/** * Pass an extra value to the plugin's scripts. * * @param array $data → Script data. * * @return array */ add_filter( 'ptscanner_script_data', function( $data ) { $data[ 'myprefixAddonEnabled' ] = true; return $data; } );ptscanner_admin_script_data
TYPE ⇢ Filter
Admin-only data merged into ptscanner_data on the plugin's admin tabs. On the Settings tab it includes the settings nonce and messages.
Example Usage
/** * Pass the current admin color scheme to the plugin's admin scripts. * * @param array $data → Admin script data. * * @return array */ add_filter( 'ptscanner_admin_script_data', function( $data ) { $data[ 'myprefixColorScheme' ] = get_user_option( 'admin_color' ); return $data; } );ptscanner_theme_colors
TYPE ⇢ Filter
The colors used by the admin screens and the shortcode. When Admin Help Docs is active, its colors are applied through this filter at the default priority, so use a later priority to override them. Supported keys are header-bg, header-font, header-tab, header-tab-link, accent, button, button-font and button-hover. Values must be hex colors.
Example Usage
/** * Use brand colors for the header and buttons. * * @param array $colors → Key => hex color. * * @return array */ add_filter( 'ptscanner_theme_colors', function( $colors ) { $colors[ 'header-bg' ] = '#0B3D5C'; $colors[ 'accent' ] = '#E07A1F'; $colors[ 'button' ] = '#0B3D5C'; $colors[ 'button-hover' ] = '#145A85'; return $colors; }, 20 );ptscanner_dynamic_css
TYPE ⇢ Filter
The generated CSS that sets the color variables. The second parameter is admin for the admin tabs or frontend for the shortcode. Append your own CSS to adjust the plugin's styles.
Example Usage
/** * Round the boxes on the front-end scanner. * * @param string $css → The generated CSS. * @param string $type → admin or frontend. * * @return string */ add_filter( 'ptscanner_dynamic_css', function( $css, $type ) { if ( 'frontend' === $type ) { $css .= '.ptscanner-shortcode-scanner .ptscanner-box{border-radius:8px;}'; } return $css; }, 10, 2 );ptscanner_test_mode
TYPE ⇢ Filter
When true, the plugin's scripts and styles are versioned with the current time so browsers never use a cached copy. By default it follows the test mode setting of the Developer Debug Tools plugin.
Example Usage
/** * Always load fresh plugin assets on a staging site. */ if ( 'staging' === wp_get_environment_type() ) { add_filter( 'ptscanner_test_mode', '__return_true' ); }ptscanner_loaded
TYPE ⇢ Action
Fires after all of the plugin's files are loaded. Use it to start an add-on only when the plugin is active.
Example Usage
/** * Start an add-on once Prohibited Terms Scanner is loaded. */ add_action( 'ptscanner_loaded', 'myprefix_ptscanner_addon_init' );ptscanner_admin_enqueue
TYPE ⇢ Action
Fires after the plugin enqueues its assets on one of its admin tabs. Receives the current page slug.
Example Usage
/** * Load a script on the Results tab only. * * @param string $page → The current tab's page slug. */ add_action( 'ptscanner_admin_enqueue', function( $page ) { if ( 'prohibited-terms-scanner_results' !== $page ) { return; } wp_enqueue_script( 'myprefix-results', plugins_url( 'js/results.js', __FILE__ ), [ 'jquery' ], '1.0.0', true ); } );ptscanner_subheader_left
TYPE ⇢ Action
Fires inside the subheader bar, after the tab title. Receives the current page slug. The plugin uses it for the Save button on the Settings tab. Escape anything you output.
Example Usage
/** * Show a short note next to the Results title. * * @param string $page → The current tab's page slug. */ add_action( 'ptscanner_subheader_left', function( $page ) { if ( 'prohibited-terms-scanner_results' === $page ) { echo '<span class="description">' . esc_html__( 'Fix flagged items within 5 business days.', 'my-textdomain' ) . '</span>'; } } );ptscanner_subheader_right
TYPE ⇢ Action
Fires on the right side of the subheader bar. Receives the current page slug. The plugin uses it for the version number and help links on the Settings tab. Escape anything you output.
Example Usage
/** * Add a link to your content policy on every tab. * * @param string $page → The current tab's page slug. */ add_action( 'ptscanner_subheader_right', function( $page ) { echo '<a href="' . esc_url( home_url( '/content-policy/' ) ) . '" class="ptscanner-button" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Content Policy', 'my-textdomain' ) . '</a>'; } );ptscanner_settings_saved
TYPE ⇢ Action
Fires after settings are saved from the Settings tab and after an import is applied. Receives the sanitized settings, which may include location_types, post_types, taxonomies, public_only, batch_size, snippet_padding, default_case_sensitive, default_strict, warning_enabled, warning_terms, view_roles, scan_roles, pdf_page_lookup, cron_enabled, cron_frequency and clear_data_on_uninstall.
Example Usage
/** * Log when scheduled scanning is turned off. * * @param array $settings → The sanitized settings. */ add_action( 'ptscanner_settings_saved', function( $settings ) { if ( isset( $settings[ 'cron_enabled' ] ) && ! $settings[ 'cron_enabled' ] ) { error_log( 'Prohibited Terms Scanner: scheduled scanning was turned off.' ); } } );ptscanner_settings_imported
TYPE ⇢ Action
Fires after a settings file is imported. Receives the sanitized import as [ 'terms' => array, 'settings' => array ].
Example Usage
/** * Log how many terms were imported. * * @param array $data → [ 'terms' => array, 'settings' => array ] */ add_action( 'ptscanner_settings_imported', function( $data ) { error_log( sprintf( 'Prohibited Terms Scanner: imported %d term(s).', count( $data[ 'terms' ] ) ) ); } );ptscanner_settings_reset
TYPE ⇢ Action
Fires after an administrator clicks Reset Settings and the options are deleted.
Example Usage
/** * Clear an add-on cache when settings are reset. */ add_action( 'ptscanner_settings_reset', function() { delete_transient( 'myprefix_ptscanner_addon_cache' ); } );ptscanner_reschedule_cron
TYPE ⇢ Action
The plugin listens to this action to schedule, reschedule or unschedule the scheduled scan based on the current settings. It fires after settings are saved or reset. Fire it yourself after changing the scheduled scanning options in code.
Example Usage
/** * Switch scheduled scans to weekly from code. */ update_option( 'ptscanner_cron_frequency', 'weekly' ); do_action( 'ptscanner_reschedule_cron' );ptscanner_cron_scan_complete
TYPE ⇢ Action
Fires after a scheduled scan finishes. Receives the number of new flagged results it found.
Example Usage
/** * Email the site admin when a scheduled scan finds something. * * @param int $total_inserted → Number of new flagged results. */ add_action( 'ptscanner_cron_scan_complete', function( $total_inserted ) { if ( $total_inserted > 0 ) { wp_mail( get_option( 'admin_email' ), 'Prohibited terms found', sprintf( 'The scheduled scan found %d new result(s). Review them here: %s', $total_inserted, admin_url( 'admin.php?page=prohibited-terms-scanner_results' ) ) ); } } );