Skip to content

Hooks and Filters

SnipShare overviewPremiumGet SnipShare →

SnipShare provides 2 filters, 11 lifecycle action hooks, and 21 template hooks so you can customise paste behaviour, react to events, and inject content anywhere in the front-end templates - without editing core files.


Fires immediately before a new paste is inserted into the database. Use this to validate, modify, or augment paste data.

Signature:

$data = apply_filters( 'snipshare_before_create_paste', $data );

Parameters:

Param Type Description
$data array Paste data array before INSERT. Keys: user_id, title, description, visibility, status, password_hash, burn_after_read, expires_at, share_hash, file_count

Return: Modified $data array.

Example - force all new pastes to be unlisted:

add_filter( 'snipshare_before_create_paste', function( $data ) {
$data['visibility'] = 'unlisted';
return $data;
} );

Fires inside SnipShare_Paste::query() before the SQL query is built. Use this to modify query arguments - add custom filters, override defaults, or restrict results.

Signature:

$args = apply_filters( 'snipshare_paste_query_args', $args );

Parameters:

Param Type Description
$args array Query args array. Keys: user_id, visibility, status, language, tag, search, per_page, page, orderby, order

Return: Modified $args array.

Example - exclude a specific user’s pastes from all public queries:

add_filter( 'snipshare_paste_query_args', function( $args ) {
// Exclude user ID 5 from all queries
if ( empty( $args['user_id'] ) ) {
$args['exclude_user'] = 5; // you'd also need to handle this in a custom query
}
return $args;
} );

Fires after a new paste is successfully inserted.

do_action( 'snipshare_paste_created', $paste_id, $data );
Param Type Description
$paste_id int ID of the newly created paste
$data array The raw data array passed to SnipShare_Paste::create()

Use case: Send notifications, update external indexes, trigger webhooks.


Fires after a paste is successfully updated.

do_action( 'snipshare_paste_updated', $paste_id, $data );
Param Type Description
$paste_id int ID of the updated paste
$data array The data array passed to the update call

Fires after a paste’s status is set to trashed.

do_action( 'snipshare_paste_trashed', $paste_id );

Fires after a paste is permanently deleted from the database.

do_action( 'snipshare_paste_deleted', $paste_id );

Note: At this point the paste row and all related records (files, revisions, tags, stars) have already been deleted.


Fires after a paste is forked.

do_action( 'snipshare_paste_forked', $fork_id, $original_paste_id, $user_id );
Param Type Description
$fork_id int ID of the newly created fork
$original_paste_id int ID of the paste that was forked
$user_id int ID of the user who performed the fork

Use case: BuddyPress fork notification (built-in). Updating fork counts on external systems.


Fires after a user stars a paste (toggle on).

do_action( 'snipshare_paste_starred', $paste_id, $user_id );

Use case: BuddyPress star notification (built-in). Gamification points.


Fires after a user removes their star from a paste (toggle off).

do_action( 'snipshare_paste_unstarred', $paste_id, $user_id );

Fires after a user submits a report.

do_action( 'snipshare_paste_reported', $report_id, $paste_id, $reporter_id );
Param Type Description
$report_id int ID of the new report record
$paste_id int ID of the reported paste
$reporter_id int WP user ID of the reporter

Use case: Email notification to admins when a new report is filed.

add_action( 'snipshare_paste_reported', function( $report_id, $paste_id, $reporter_id ) {
wp_mail(
get_option( 'admin_email' ),
'New paste reported',
"Paste ID {$paste_id} was reported. View it at: " . admin_url( 'admin.php?page=snipshare-moderation' )
);
}, 10, 3 );

Fires after an admin reviews a report.

do_action( 'snipshare_report_reviewed', $report_id, $action );
Param Type Description
$report_id int ID of the reviewed report
$action string reviewed or dismissed

Fires after a new collection is created.

do_action( 'snipshare_collection_created', $collection_id, $data );

Fires after a paste is added to a collection.

do_action( 'snipshare_paste_added_to_collection', $collection_id, $paste_id );

SnipShare also fires template hooks in all front-end templates for injecting custom content:

Hook Location
snipshare_before_archive Before paste archive content
snipshare_after_archive After paste archive content
snipshare_before_paste_loop Before paste loop in archive
snipshare_after_paste_loop After paste loop in archive
snipshare_before_paste_card Before each paste card (receives $paste)
snipshare_after_paste_card After each paste card (receives $paste)
snipshare_before_single_paste Before single paste view (receives $paste)
snipshare_after_single_paste After single paste view (receives $paste)
snipshare_before_paste_files Before file tabs on single view (receives $paste)
snipshare_after_paste_files After file tabs on single view (receives $paste)
snipshare_before_paste_form Before create/edit form
snipshare_after_paste_form After create/edit form
snipshare_paste_form_fields Inside form - add custom fields
snipshare_before_user_profile Before user profile content (receives $profile_user)
snipshare_after_user_profile After user profile content (receives $profile_user)
snipshare_before_collection Before collection view (receives $collection)
snipshare_after_collection After collection view (receives $collection)
snipshare_before_diff Before diff view (receives $paste)
snipshare_after_diff After diff view (receives $paste)
snipshare_before_embed Before embed view (receives $paste)
snipshare_after_embed After embed view (receives $paste)