/** * This function returns a user object based on if a member is logged in or an admin. If an * admin is logged in, a user object will be returned based on the current preview bar settings */ public static function getCurrentUser() { global $user, $current_user; $user_obj = null; if (MM_Employee::isEmployee()) { $previewObj = MM_Preview::getData(); if ($previewObj !== false) { return $previewObj->getUser(); } } if (isset($user->ID) && intval($user->ID) > 0) { $user_obj = MM_User::create($user->ID); } else { if (isset($user->data->ID) && intval($user->data->ID) > 0) { $user_obj = MM_User::create($user->data->ID); } else { if (isset($current_user->ID) && intval($current_user->ID) > 0) { $user_obj = MM_User::create($current_user->ID); } } } return $user_obj; }
public function handlePageAccess() { global $wp_query, $current_user; if (class_exists("MM_CorePageEngine")) { if (isset($wp_query->post) && isset($wp_query->post->ID)) { if (!isset($_POST["log"])) { if (!MM_CorePageEngine::isMyAccountCorePage($wp_query->post->ID) && !MM_CorePageEngine::isLoginCorePage($wp_query->post->ID) && !MM_CorePageEngine::isErrorCorePage($wp_query->post->ID)) { MM_Session::clear(MM_OptionUtils::$OPTION_KEY_LAST_PAGE_DENIED); } } } if (MM_CorePageEngine::isFrontPage()) { MM_CorePageEngine::redirectToSiteHomePage(true); } else { if (isset($wp_query->post) && isset($wp_query->post->ID) && intval($wp_query->post->ID) > 0) { $isAdmin = false; if (isset($current_user->ID)) { if (MM_Employee::isEmployee()) { $isAdmin = true; } } if ($isAdmin) { $preview = MM_Preview::getData(); if ($preview !== false) { if (MM_CorePageEngine::isMemberHomePage($wp_query->post->ID) || MM_CorePageEngine::isSaveTheSalePage($wp_query->post->ID) || MM_CorePageEngine::isMyAccountCorePage($wp_query->post->ID)) { // if preview settings is set to non-members, redirect to the error page if ($preview->getMembershipId() <= 0) { $url = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCESS_DENIED); $currentUrl = MM_Utils::constructPageUrl(); $compareUrl = preg_replace("/https?/", "", $url); $compareUrl = preg_replace("/\\/\\?/", "?", $compareUrl); $currentUrl = preg_replace("/https?/", "", $currentUrl); $currentUrl = preg_replace("/\\/\\?/", "?", $currentUrl); if (strpos($currentUrl, $compareUrl) !== 0) { header("Location: {$url}"); exit; } } } } } else { // check user account status $userObj = new MM_User($current_user->ID); if ($userObj->getStatus() == MM_Status::$CANCELED || $userObj->getStatus() == MM_Status::$LOCKED) { wp_logout(); if ($userObj->getStatus() == MM_Status::$LOCKED) { $url = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_LOCKED); wp_redirect($url); exit; } else { if ($userObj->getStatus() == MM_Status::$CANCELED && !MM_CorePageEngine::isSaveTheSalePage($wp_query->post->ID)) { $url = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_CANCELED); wp_redirect($url); exit; } } } } // don't allow access to member homepages, save-the-sale pages or the // my account page if the user is not logged in if (MM_CorePageEngine::isMemberHomePage($wp_query->post->ID) || MM_CorePageEngine::isSaveTheSalePage($wp_query->post->ID) || MM_CorePageEngine::isMyAccountCorePage($wp_query->post->ID)) { if (!is_user_logged_in()) { // if user is not logged in, redirect them to the login page, but first saved // the attempted access page incase they log in succesfully afterwards MM_Session::value(MM_OptionUtils::$OPTION_KEY_LAST_PAGE_DENIED, $wp_query->post->ID); header("Location: " . MM_CorePageEngine::getUrl(MM_CorePageType::$LOGIN_PAGE)); exit; } else { if (MM_CorePageEngine::isMemberHomePage($wp_query->post->ID)) { // check if there's a specific member homepage for this user MM_CorePageEngine::redirectToMemberHomePage($wp_query->post->ID); } else { if (MM_CorePageEngine::isSaveTheSalePage($wp_query->post->ID)) { // check if there's a specific save-the-sale page for this user MM_CorePageEngine::redirectToSaveTheSalePage($wp_query->post->ID); } } } } } } if (!is_admin()) { $protectedContent = new MM_ProtectedContentEngine(); $postId = $wp_query->query_vars["page_id"]; if (isset($wp_query->post) && isset($wp_query->post->ID) && intval($wp_query->post->ID) > 0) { $postId = $wp_query->post->ID; } if (intval($postId) > 0) { if (!is_feed()) { $protectedContent->protectContent($postId, is_home()); } } } } }
public function customizeAdminBar() { if (MM_Employee::isEmployee()) { global $wp_admin_bar; $wp_admin_bar->add_menu(array('id' => 'mm-menu', 'title' => '<img src="' . MM_Utils::getImageUrl('mm-logo-svg') . '" style="width:22px; margin-bottom:2px;" />', 'href' => MM_ModuleUtils::getUrl(MM_MODULE_DASHBOARD), 'meta' => array('title' => __('MemberMouse')))); $wp_admin_bar->add_menu(array("id" => "mm-manage-members", "title" => "Manage Members", "href" => MM_ModuleUtils::getUrl(MM_MODULE_MANAGE_MEMBERS), "parent" => "mm-menu")); $wp_admin_bar->add_menu(array("id" => "mm-browse-transactions", "title" => "Browse Transactions", "href" => MM_ModuleUtils::getUrl(MM_MODULE_MANAGE_TRANSACTIONS), "parent" => "mm-menu")); $wp_admin_bar->add_menu(array("id" => "mm-reporting-suite", "title" => "Reporting Suite", "href" => MM_ModuleUtils::getUrl(MM_MODULE_REPORTING), "parent" => "mm-menu")); $wp_admin_bar->add_menu(array("id" => "mm-product-settings", "title" => "Product Settings", "href" => MM_ModuleUtils::getUrl(MM_MODULE_PRODUCT_SETTINGS), "parent" => "mm-menu")); $wp_admin_bar->add_menu(array("id" => "mm-support-center", "title" => "Support Center", "href" => "http://membermouse.uservoice.com", "parent" => "mm-menu", "meta" => array("target" => "blank"))); } if (!is_admin() && MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_SHOW_PREVIEW_BAR) == "1" && MM_Employee::isEmployee()) { ?> <style> #wpadminbar { background: linear-gradient(to top, #373737 0px, #464646 0px) repeat scroll 0 0 #464646; background-image: -webkit-linear-gradient(bottom,#373737 0,#464646 1px); border-bottom: 1px #555555 solid; } #wpadminbar .ab-top-secondary { background: linear-gradient(to top, #373737 0px, #464646 0px) repeat scroll 0 0 #464646; background-image: -webkit-linear-gradient(bottom,#373737 0,#464646 1px); border-bottom: 1px #555555 solid; } body { margin-top: 34px; } </style> <script type='text/javascript'> jQuery(document).ready(function() { mmPreviewJs.hideNonMemberItems(); }); </script> <?php } }