/** * Return true is the post/page is protected for premium users * * @param obj $post Post Object. * @return boolean */ function moove_is_premium(&$post) { $post_level = moove_post_protection_level($post); return moove_protection_level_diff($post_level) === 'premium'; }
/** * Content protection, returns the trimmed content if is protected. * * @param string $content Content string. */ function moove_protect_content($content) { $moove_user = new Moove_User(); $u = $moove_user->moove_check(); $post = $GLOBALS['post']; $protection_selected = get_post_meta($post->ID, 'moove_post_protect_data', true); if (empty($protection_selected)) { $post_type = $post->post_type; $options = get_option('moove_post_protect'); if (isset($options[$post_type])) { $protection_selected = $options[$post_type]; } } if (!$u['wp_admin'] || !$u['editor']) { if (!is_admin() && !current_user_can('edit_posts')) { $post_level = moove_post_protection_level($post); if (!is_user_logged_in() && !moove_is_public($post) && !moove_is_premium($post)) { $trimmed = wp_trim_words($post->post_content, $num_words = 55, $more = null); $content = $trimmed; $content .= Moove_View::load('moove.protected.truncated.free_membership_restriction'); } if (moove_is_premium($post)) { $trimmed = wp_trim_words($post->post_content, $num_words = 55, $more = null); $content = $trimmed; $content .= Moove_View::load('moove.protected.truncated.premium_membership_restriction'); } } } return $content; }