Docs/Hooks & Filters

Hooks & Filters

This reference is for developers who want to extend ReadNinja programmatically. All hooks and filters are stable and available in both Free and Pro.

PHP filters

FilterParametersDescription
rpb_is_proboolReturns true if the Pro license is active
rpb_should_displaybool $display, int $post_idProgrammatically control whether the bar is rendered
rpb_bar_configarray $configModify the JS config array before it's output to the page
rpb_settings_tabsarray $tabsAdd or remove tabs on the settings page

rpb_is_pro

Lets other plugins check whether Pro is active without hard-coding class names or constants.

add_action( 'init', function () {
    if ( apply_filters( 'rpb_is_pro', false ) ) {
        // Pro-only logic here
    }
} );

rpb_should_display

Runs just before ReadNinja decides whether to render the bar on the current request. Return false to hide it, true to force it. Use it to hide the bar on very short posts:

add_filter( 'rpb_should_display', function ( $display, $post_id ) {
    $content   = get_post_field( 'post_content', $post_id );
    $word_count = str_word_count( wp_strip_all_tags( $content ) );

    if ( $word_count < 300 ) {
        return false;
    }
    return $display;
}, 10, 2 );

rpb_bar_config

Gives you the full JS config array right before it's passed to the front-end. Use it to inject custom values, override colors based on post meta, or add extra data for your own scripts.

add_filter( 'rpb_bar_config', function ( $config ) {
    if ( is_singular( 'podcast' ) ) {
        $config['color']  = '#ff6b35';
        $config['height'] = 6;
    }
    return $config;
} );

rpb_settings_tabs

Adds a custom tab to the settings page. Combine with the rpb_render_tab_{tab} action to fill its content.

add_filter( 'rpb_settings_tabs', function ( $tabs ) {
    $tabs['custom'] = __( 'Custom', 'my-plugin' );
    return $tabs;
} );

PHP actions

ActionParametersDescription
rpb_after_bar_renderint $post_idFires after the bar HTML is output
rpb_render_tab_{tab}Inject content into any settings page tab

Example — add an extra <div> right after the progress bar on singular posts:

add_action( 'rpb_after_bar_render', function ( $post_id ) {
    echo '<div class="my-custom-ribbon" data-post="' . esc_attr( $post_id ) . '"></div>';
} );

Example — fill the content of the custom tab registered above:

add_action( 'rpb_render_tab_custom', function () {
    echo '<h2>My custom tab</h2>';
    echo '<p>Any settings markup goes here.</p>';
} );

Browser events

ReadNinja dispatches a single DOM event you can listen for on the front-end.

EventTargetDetail
rpb:threshold-reacheddocument{ percent: number }

This event fires once per page load, exactly when the reader crosses the configured threshold (Pro feature — see Threshold trigger).

document.addEventListener('rpb:threshold-reached', (e) => {
  console.log('Reader reached', e.detail.percent, '%')
  // show popup, fire analytics event, etc.
})