Hooks & Filters
LW Plugins provide WordPress hooks and filters for third-party integration and customization.
LW SEO
Filters
lw_seo_markdown_output
Filter the final markdown output for a post, page, or term.
| Parameter | Type | Description |
|---|---|---|
$output | string | The generated markdown string |
$object | WP_Post|WP_Term | The source object |
add_filter( 'lw_seo_markdown_output', function ( string $output, $object ): string {
// Append custom footer to markdown output
return $output . "\n\n---\nPowered by My Site";
}, 10, 2 );lw_seo_markdown_is_supported
Filter whether the markdown endpoint is supported for the current request.
| Parameter | Type | Description |
|---|---|---|
$supported | bool | Whether markdown is supported (default: true) |
$wp_query | WP_Query | The current query object |
add_filter( 'lw_seo_markdown_is_supported', function ( bool $supported, WP_Query $query ): bool {
// Disable markdown for a specific post type
if ( $query->is_singular( 'secret_post_type' ) ) {
return false;
}
return $supported;
}, 10, 2 );lw_seo_markdown_frontmatter
Filter the frontmatter data array before it is rendered in markdown output.
| Parameter | Type | Description |
|---|---|---|
$data | array | Frontmatter key-value pairs |
$object | WP_Post|WP_Term | The source object |
add_filter( 'lw_seo_markdown_frontmatter', function ( array $data, WP_Post $post ): array {
$data['custom_field'] = get_post_meta( $post->ID, 'my_field', true );
return $data;
}, 10, 2 );lw_seo_markdown_body
Filter the markdown body content (after HTML-to-markdown conversion).
| Parameter | Type | Description |
|---|---|---|
$body | string | The markdown body content |
$object | WP_Post|WP_Term | The source object |
add_filter( 'lw_seo_markdown_body', function ( string $body, WP_Post $post ): string {
// Add a disclaimer to all markdown bodies
return $body . "\n\n> This content is copyrighted.";
}, 10, 2 );lw_seo_content_signals
Filter the resolved content signals (ai-train, ai-input, search) for a post or global context.
| Parameter | Type | Description |
|---|---|---|
$signals | array | Content signal values |
$object | WP_Post|null | The post object (null for global) |
add_filter( 'lw_seo_content_signals', function ( array $signals, ?WP_Post $post ): array {
// Override AI training signal for specific category
if ( $post && has_category( 'private', $post ) ) {
$signals['ai-train'] = 'disallow';
}
return $signals;
}, 10, 2 );lw_seo_meta_box_post_types
Filter which post types show the SEO meta box.
| Parameter | Type | Description |
|---|---|---|
$post_types | array | Array of post type slugs |
add_filter( 'lw_seo_meta_box_post_types', function ( array $types ): array {
// Remove meta box from a custom post type
return array_diff( $types, [ 'my_custom_type' ] );
} );LW Cookie
Filters
lw_cookie_consent_categories
Get the current user’s consent categories and their states.
| Parameter | Type | Description |
|---|---|---|
$default | array | Default value (pass empty array) |
Returns: array<string, bool> - Category names mapped to consent state.
$categories = apply_filters( 'lw_cookie_consent_categories', [] );
if ( ! empty( $categories['marketing'] ) ) {
// User consented to marketing - load tracking scripts
}lw_cookie_has_consent
Check if the user has given any cookie consent.
| Parameter | Type | Description |
|---|---|---|
$default | bool | Default value (pass false) |
$has_consent = apply_filters( 'lw_cookie_has_consent', false );
if ( $has_consent ) {
// User has interacted with the cookie banner
}lw_cookie_is_category_allowed
Check if a specific cookie category is allowed.
| Parameter | Type | Description |
|---|---|---|
$default | bool | Default value (pass false) |
$category | string | Category to check: necessary, functional, analytics, marketing |
$analytics_allowed = apply_filters( 'lw_cookie_is_category_allowed', false, 'analytics' );
if ( $analytics_allowed ) {
// Load analytics scripts
}lw_cookie_consent_id
Get the current consent ID (unique identifier for the consent record).
| Parameter | Type | Description |
|---|---|---|
$default | string|null | Default value (pass null) |
$consent_id = apply_filters( 'lw_cookie_consent_id', null );lw_cookie_should_block_script
Override whether a specific script should be blocked before consent.
| Parameter | Type | Description |
|---|---|---|
$should_block | bool | Whether the script should be blocked |
$handle | string | Script handle |
$src | string | Script source URL |
$category | string | Detected category |
add_filter( 'lw_cookie_should_block_script', function ( $should_block, $handle, $src, $category ) {
// Don't block my plugin's pixel - I handle consent myself
if ( $handle === 'my-plugin-pixel' ) {
return false;
}
return $should_block;
}, 10, 4 );LW LMS
Filters
lw_lms_has_course_access
Filter whether a user has access to a course.
| Parameter | Type | Description |
|---|---|---|
$has_access | bool | Whether the user has access |
$course_id | int | Course ID |
$user_id | int | User ID |
add_filter( 'lw_lms_has_course_access', function ( bool $has_access, int $course_id, int $user_id ): bool {
// Grant access to all courses for admins
if ( user_can( $user_id, 'manage_options' ) ) {
return true;
}
return $has_access;
}, 10, 3 );lw_lms_has_lesson_access
Filter whether a user has access to a specific lesson.
| Parameter | Type | Description |
|---|---|---|
$has_access | bool | Whether the user has access |
$lesson_id | int | Lesson ID |
$user_id | int | User ID |
add_filter( 'lw_lms_has_lesson_access', function ( bool $has_access, int $lesson_id, int $user_id ): bool {
// Custom access logic
return $has_access;
}, 10, 3 );Actions
lw_lms_lesson_completed
Fires when a user marks a lesson as completed.
| Parameter | Type | Description |
|---|---|---|
$lesson_id | int | Lesson ID |
$user_id | int | User ID |
add_action( 'lw_lms_lesson_completed', function ( int $lesson_id, int $user_id ): void {
// Send notification or award points
}, 10, 2 );lw_lms_course_completed
Fires when a user completes all lessons in a course.
| Parameter | Type | Description |
|---|---|---|
$course_id | int | Course ID |
$user_id | int | User ID |
add_action( 'lw_lms_course_completed', function ( int $course_id, int $user_id ): void {
// Issue certificate or grant achievement
}, 10, 2 );lw_lms_attachment_downloaded
Fires when a user downloads a protected course/lesson attachment.
| Parameter | Type | Description |
|---|---|---|
$attachment_id | int | Attachment ID |
$user_id | int | User ID |
add_action( 'lw_lms_attachment_downloaded', function ( int $attachment_id, int $user_id ): void {
// Log download activity
}, 10, 2 );LW Memberships
Filters
lw_mship_supported_post_types
Filter which post types support content restriction.
| Parameter | Type | Description |
|---|---|---|
$types | array | Array of post type slugs |
add_filter( 'lw_mship_supported_post_types', function ( array $types ): array {
$types[] = 'my_custom_type';
return $types;
} );lw_mship_my_account_template
Filter the WooCommerce My Account memberships tab template.
| Parameter | Type | Description |
|---|---|---|
$template | string | Template HTML content |
lw_mship_member_discount
Filter the calculated member discount amount.
| Parameter | Type | Description |
|---|---|---|
$discount | float | Discount amount |
$product | WC_Product | WooCommerce product |
$user_id | int | User ID |
Actions
lw_mship_membership_granted
Fires when a membership is granted to a user.
| Parameter | Type | Description |
|---|---|---|
$membership_id | int | Membership record ID |
$user_id | int | User ID |
$plan_id | int | Plan ID |
add_action( 'lw_mship_membership_granted', function ( int $membership_id, int $user_id, int $plan_id ): void {
// Send welcome email or trigger onboarding
}, 10, 3 );lw_mship_membership_revoked
Fires when a membership is cancelled/revoked.
| Parameter | Type | Description |
|---|---|---|
$membership_id | int | Membership record ID |
$user_id | int | User ID |
$plan_id | int | Plan ID |
add_action( 'lw_mship_membership_revoked', function ( int $membership_id, int $user_id, int $plan_id ): void {
// Clean up user access or send notification
}, 10, 3 );lw_mship_membership_expired
Fires when a membership expires (via cron check).
| Parameter | Type | Description |
|---|---|---|
$membership_id | int | Membership record ID |
$user_id | int | User ID |
$plan_id | int | Plan ID |
add_action( 'lw_mship_membership_expired', function ( int $membership_id, int $user_id, int $plan_id ): void {
// Send renewal reminder or downgrade access
}, 10, 3 );lw_mship_check_ending_soon
Fires during cron to check for memberships ending soon (used internally for email notifications).
Shared Hook
lw_plugins_overview_cards
Action hook fired on the LW Plugins overview admin page. Used internally by each plugin to render its card. Third-party plugins can use this to add custom cards to the LW Plugins dashboard.
add_action( 'lw_plugins_overview_cards', function (): void {
echo '<div class="lw-plugin-card">My Custom Card</div>';
} );