LLMS_Template_Loader::maybe_restrict_post_content( WP_Post $post, WP_Query $query )
Maybe restrict the post content in the REST loop
Parameters Parameters
- $post
-
(WP_Post) (Required) Post Object.
- $query
-
(WP_Query) (Required) Query object.
Return Return
(void)
Source Source
File: includes/class.llms.template.loader.php
* @return void
*/
public function maybe_restrict_post_content( $post, $query ) {
/**
* Filters the post types that must be skipped.
*
* The LifterLMS post types content restriction should be handled by the LifterLMS rest-api.
*
* @since 3.41.1
*
* @param string[] $post_types The array of post types to skip.
*/
$skip = apply_filters(
'llms_in_rest_restrict_content_skip_post_types',
array(
'course',
'lesson',
'llms_quiz',
'llms_membership',
'llms_question',
'llms_certificate',
'llms_my_certificate',
)
);
if ( in_array( get_post_type( $post ), $skip, true ) ) {
return;
}
// Needed by `llms_page_restricted()` to work as expected.
$is_singular = $query->is_singular;
$query->is_singular = true;
$page_restricted = llms_page_restricted( get_the_ID() );
if ( $page_restricted['is_restricted'] ) {
$msg = __( 'This content is restricted', 'lifterlms' );
$reason = $page_restricted['reason'];
if ( in_array( $reason, array( 'membership', 'sitewide_membership' ), true ) ) {
$membership_id = $page_restricted['restriction_id'];
if ( ! empty( $membership_id ) && is_numeric( $membership_id ) ) {
$membership = new LLMS_Membership( $membership_id );
if ( 'yes' === $membership->get( 'restriction_add_notice' ) ) {
$msg = $membership->get( 'restriction_notice' );
}
}
}
/**
* Filters the restriction message.
*
* The dynamic portion of the hook name, `$reason`, refers to the restriction reason.
*
* @since 3.41.1
*
* @param string $message Restriction message.
* @param array $restriction Array of restriction info from `llms_page_restricted()`.
*/
$msg = apply_filters( "llms_in_rest_restricted_by_{$reason}_message", $msg, $page_restricted );
$post->post_content = $msg;
$post->post_excerpt = $msg;
}
$query->is_singular = $is_singular;
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.10.1 | Fixed incorrect position of true in in_array(). |
| 4.0.0 | Don't pass by reference because it's unnecessary. |
| 3.41.1 | Introduced. |