/** * This function removes core page associations and access rights from posts when they're deleted */ public function deletePostHandler($post_id) { // remove access rights, if any $protected_content = new MM_ProtectedContentEngine(); $protected_content->removeAllRights($post_id); // remove core page associations, if any $corepage = new MM_CorePageEngine(); $corepage->removeCorePageById($post_id); }
function loginRedirect($redirectTo, $request, $user) { // clear login form session parameters MM_Session::clear(MM_Session::$KEY_LOGIN_FORM_USER_ID); MM_Session::clear(MM_Session::$KEY_LOGIN_FORM_USERNAME); $newRedirectTo = ""; $allowUserOverride = true; if (class_exists("MM_CorePageEngine")) { if ($user instanceof WP_User && isset($user->data->ID) && intval($user->data->ID) > 0) { // check if this is an employee $employee = MM_Employee::findByUserId($user->data->ID); if ($employee->isValid()) { MM_Preview::clearPreviewMode(); MM_Preview::getData(); $newRedirectTo = $employee->getHomepage(); } if (empty($newRedirectTo)) { $mmUser = new MM_User($user->data->ID); if ($mmUser->getStatus() == MM_Status::$EXPIRED) { $allowUserOverride = false; $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_EXPIRED, $mmUser); wp_logout(); } else { if ($mmUser->getStatus() == MM_Status::$CANCELED) { $allowUserOverride = false; $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_CANCELED, $mmUser); wp_logout(); } else { if ($mmUser->getStatus() == MM_Status::$LOCKED) { $allowUserOverride = false; $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_LOCKED, $mmUser); wp_logout(); } else { if ($mmUser->getStatus() == MM_Status::$OVERDUE) { $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$MY_ACCOUNT, "", $mmUser); } else { MM_Preview::clearPreviewMode(); $setting = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_ON_LOGIN_USE_WP_FRONTPAGE); if ($setting == "1") { $newRedirectTo = MM_OptionUtils::getOption("siteurl"); } else { $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$MEMBER_HOME_PAGE, "", $mmUser); } $lastAccessDeniedPageID = MM_Session::value(MM_OptionUtils::$OPTION_KEY_LAST_PAGE_DENIED); // check if current member has access to the last access denied page $pce = new MM_ProtectedContentEngine(); if (intval($lastAccessDeniedPageID) > 0 && $pce->canAccessPost($lastAccessDeniedPageID, $mmUser->getId())) { $corePageEngine = new MM_CorePageEngine(); if (!$corePageEngine->arePermalinksUsed()) { $newRedirectTo = get_page_link($lastAccessDeniedPageID); } else { $newRedirectTo = get_permalink($lastAccessDeniedPageID); } } MM_Session::clear(MM_OptionUtils::$OPTION_KEY_LAST_PAGE_DENIED); MM_ActivityLog::log($mmUser, MM_ActivityLog::$EVENT_TYPE_LOGIN); if ($mmUser->hasReachedMaxIPCount()) { global $current_user, $user; $mmUser->setStatus(MM_Status::$LOCKED); $mmUser->commitData(); $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_LOCKED, $mmUser); wp_logout(); } } } } } if (empty($newRedirectTo)) { $newRedirectTo = MM_OptionUtils::getOption("siteurl"); } } } // give customer an opportunity to redirect the user if ($allowUserOverride) { $currentUrl = !empty($newRedirectTo) ? $newRedirectTo : $redirectTo; $infoObj = new stdClass(); $infoObj->currentUrl = $currentUrl; $infoObj->user = $user; $redirectOverride = apply_filters(MM_Filters::$LOGIN_REDIRECT, $infoObj); if (is_string($redirectOverride) && !empty($redirectOverride) && $redirectOverride != $currentUrl) { if (!defined("DOING_AJAX") || !DOING_AJAX) { wp_redirect($redirectOverride); exit; } else { return $redirectOverride; } } } if (!empty($newRedirectTo)) { return $newRedirectTo; } return $redirectTo; } }
public function filterContent($content) { global $wp_query; if (!is_feed() && !is_search() && !is_archive()) { return $content; } $protectedContent = new MM_ProtectedContentEngine(); $postId = $wp_query->query_vars["page_id"]; if ($protectedContent->protectContent($postId)) { $wpPost = get_post($postId); setup_postdata($wpPost); if ($wpPost && ($wpPost->post_status == "publish" || $wpPost->post_status == "inherit") && ($wpPost->post_type == "post" || $wpPost->post_type == "page" || MM_Utils::isCustomPostType($wpPost->post_type))) { $hasExcerpt = strpos($wpPost->post_content, "<!--more-->"); if ($hasExcerpt) { return substr($wpPost->post_content, 0, $hasExcerpt) . " <a href=\"" . get_permalink($postId) . "\">Read More</a>"; } return $content; } else { return $content; } } $post = get_post($postId); setup_postdata($post); $hasExcerpt = strpos($post->post_content, "<!--more-->"); if ($hasExcerpt) { return substr($post->post_content, 0, $hasExcerpt) . " <a href=\"" . get_permalink($postId) . "\">Read More</a>"; } return "This content is for members only"; }