Plugin Directory

Changeset 3202134


Ignore:
Timestamp:
12/04/2024 08:10:52 AM (16 months ago)
Author:
fapi
Message:

Automatic redirect back after login

Location:
fapi-member
Files:
414 added
4 edited

Legend:

Unmodified
Added
Removed
  • fapi-member/trunk/fapi-member.php

    r3200871 r3202134  
    1515 * Plugin URI:        https://fapi.cz/
    1616 * Description:       Plugin FAPI pro jednoduchou správu členských sekcí na webu.
    17  * Version:           2.2.9
     17 * Version:           2.2.10
    1818 * Requires at least: 5.9
    1919 * Requires PHP:      8.1
     
    3030require __DIR__ . '/src/Utils/functions.php';
    3131
    32 define('FAPI_MEMBER_PLUGIN_VERSION', '2.2.9');
     32define('FAPI_MEMBER_PLUGIN_VERSION', '2.2.10');
    3333
    3434$FapiPlugin = new FapiMemberPlugin();
  • fapi-member/trunk/readme.txt

    r3200871 r3202134  
    66Requires PHP: 8.1
    77License: GPLv2 or later
    8 Stable tag: 2.2.9
     8Stable tag: 2.2.10
    99
    1010Plugin FAPI pro jednoduchou správu členských sekcí na webu.
     
    2626
    2727== Changelog ==
     28
     29= 2.2.10 =
     30* When user is redirected to a 'no access page' and then logs in, they are now redirected back to the page that they were intending to access (if they have access to it)
    2831
    2932= 2.2.9 =
  • fapi-member/trunk/src/Bootstrap.php

    r3189049 r3202134  
    7474    public function initialize(): void
    7575    {
     76        session_start();
     77
    7678        $this->addHooks();
    7779        $this->generateTokenIfNeeded();
  • fapi-member/trunk/src/Service/RedirectService.php

    r3200871 r3202134  
    55use FapiMember\Container\Container;
    66use FapiMember\Model\Enums\Keys\OptionKey;
     7use FapiMember\Model\Enums\Keys\SessionKey;
    78use FapiMember\Model\Enums\Types\LevelUnlockType;
    89use FapiMember\Model\Enums\UserPermission;
     
    112113    public function redirectToNoAccessPage($levelId): void
    113114    {
     115        global $wp_query;
     116
     117        $_SESSION[SessionKey::LAST_PAGE_ID] = $wp_query->post->ID;
     118
    114119        $level = $this->levelRepository->getLevelById($levelId);
    115120
     
    143148
    144149        $memberships = $this->membershipService->getActiveByUserIdAndUpdate($userId);
     150
     151        $allowedPages = [];
     152
     153        foreach ($memberships as $membership) {
     154            $allowedPages = array_merge(
     155                $this->pageRepository->getPageIdsByLevelId($membership->getLevelId()),
     156                $allowedPages,
     157            );
     158        }
     159
     160        $allowedPages = array_unique(array_filter($allowedPages));
     161
     162        if (
     163            isset($_SESSION[SessionKey::LAST_PAGE_ID]) &&
     164            $_SESSION[SessionKey::LAST_PAGE_ID] !== null &&
     165            in_array($_SESSION[SessionKey::LAST_PAGE_ID], $allowedPages)
     166        ) {
     167            $this->redirectToPage($_SESSION[SessionKey::LAST_PAGE_ID]);
     168            $_SESSION[SessionKey::LAST_PAGE_ID] = null;
     169        }
     170
     171        $_SESSION[SessionKey::LAST_PAGE_ID] = null;
    145172
    146173        $pages = array_map(
Note: See TracChangeset for help on using the changeset viewer.