Hooks and Filters
SnipShare fires actions at each stage of a paste’s lifecycle and provides filters for altering data before it is stored or queried. Template action hooks let you inject markup into the front-end views.
Filters
Section titled “Filters”| Filter | Argument | Purpose |
|---|---|---|
snipshare_before_create_paste |
$data (array) |
Modify the paste data array before it is inserted. |
snipshare_paste_query_args |
$args (array) |
Modify query arguments before SnipShare_Paste::query() runs. |
Lifecycle actions
Section titled “Lifecycle actions”| Action | Arguments | Fires when |
|---|---|---|
snipshare_paste_created |
$paste_id, $data |
A new paste is inserted. |
snipshare_paste_updated |
$paste_id, $data |
A paste is updated. |
snipshare_paste_trashed |
$paste_id |
A paste is moved to trash. |
snipshare_paste_deleted |
$paste_id |
A paste is permanently deleted. |
snipshare_paste_forked |
$fork_id, $original_id, $user_id |
A paste is forked. |
snipshare_paste_starred |
$paste_id, $user_id |
A paste is starred. |
snipshare_paste_unstarred |
$paste_id, $user_id |
A paste is unstarred. |
snipshare_paste_reported |
$report_id, $paste_id, $reporter_id |
A report is submitted. |
snipshare_report_reviewed |
$report_id, $action |
A report is reviewed or dismissed by an admin. |
snipshare_collection_created |
$collection_id, $data |
A collection is created. |
snipshare_paste_added_to_collection |
$collection_id, $paste_id |
A paste is added to a collection. |
Template actions
Section titled “Template actions”These fire inside the front-end templates and take no arguments. Use them to add markup around SnipShare views:
snipshare_before_archive, snipshare_after_archive,
snipshare_before_paste_loop, snipshare_after_paste_loop,
snipshare_before_paste_card, snipshare_after_paste_card,
snipshare_before_single_paste, snipshare_after_single_paste,
snipshare_before_paste_files, snipshare_after_paste_files,
snipshare_before_paste_form, snipshare_after_paste_form,
snipshare_paste_form_fields,
snipshare_before_user_profile, snipshare_after_user_profile,
snipshare_before_collection, snipshare_after_collection,
snipshare_before_diff, snipshare_after_diff,
snipshare_before_embed, snipshare_after_embed.
Example
Section titled “Example”// Force every new paste to be unlisted by default.add_filter( 'snipshare_before_create_paste', function ( $data ) { if ( empty( $data['visibility'] ) ) { $data['visibility'] = 'unlisted'; } return $data;} );
// Log when a paste is forked.add_action( 'snipshare_paste_forked', function ( $fork_id, $original_id, $user_id ) { error_log( "Paste {$original_id} forked to {$fork_id} by user {$user_id}" );}, 10, 3 );
