Skip to content

Commit

Permalink
Merge pull request #119 from fapi-cz/FAPI-MEMBER-2.2.10-add-redirects…
Browse files Browse the repository at this point in the history
…-after-login-back-to-the-previous-page

2.2.10 - Added redirects after login back to the previous page
  • Loading branch information
Marek-Klein authored Dec 9, 2024
2 parents ef39f2d + ff02ce0 commit 07aa0e3
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ js-add: ## Add editor dependencies
js-outdated: ## List editor outdated dependencies
docker exec node /bin/sh -c 'yarn outdated'

PLUGIN_FILE=fapi-member.php
README_FILE=readme.txt

update-version:
@if [ -z "$(version)" ]; then \
echo "Error: version parameter is required. Use 'make update-version version=NEW_VERSION'"; \
exit 1; \
fi
sed -i "" -E "s/(Version:[[:space:]]+)[0-9]+(\.[0-9]+)?(\.[0-9]+)?/\1$(version)/" $(PLUGIN_FILE)
sed -i "" -E "s/define\('FAPI_MEMBER_PLUGIN_VERSION', '.*'\);/define('FAPI_MEMBER_PLUGIN_VERSION', '$(version)');/" $(PLUGIN_FILE)
sed -i "" -E "s/(Stable tag:[[:space:]]+)[0-9]+(\.[0-9]+)?(\.[0-9]+)?/\1$(version)/" $(README_FILE)
echo "Version updated to $(version)"

build: ## Builds the plugin source code
[ -d wp-build ] && rm -d -r wp-build
[ -d wp-build-test ] && rm -d -r wp-build-test
Expand Down Expand Up @@ -84,6 +97,7 @@ build: ## Builds the plugin source code
rm -rf wp-build-test/fapi-member

prepare-deploy: isset-version ## Prepares everything for a deploy
make update-version version=$(version)
docker exec node /bin/sh -c 'yarn --cwd multiple-blocks install'
docker exec node /bin/sh -c 'yarn --cwd multiple-blocks build'
make composer-install
Expand Down Expand Up @@ -134,7 +148,7 @@ git-new-branch:
$(eval final_branch_name := FAPI-MEMBER-$(v)-$(first_word)-$(rest_of_commit))

@git checkout -b $(final_branch_name)
make git-commit m="$(m)"
make git-commit m="$(v) - $(m)"

git-rebase-master: ## Fetches data and rebases branch with master
@echo "\033[33mRebasing with master...\033[34m"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ to je možné využít při vývoji na testování např. zakládání uživatel

# Build a nasazení na WP
## POUZE POKUD VÍŠ CO DĚLÁŠ
1. Změnit verzi balíčku
1. změnit verzi v `fapi-member.php`' - všude kde je uvedena verze
2. změnit verzi v `readme.txt` - všude kde je uvedena verze
1. Změnit verzi v souborech `make update-version version=x.x.x`
1. zkontrolovat `fapi-member.php`' - všude kde je uvedena verze
2. zkontrolovat`readme.txt` - všude kde je uvedena verze a napsat changelog
2. Připravit deploy `make prepare-deploy version=x.x.x`
3. Případně otestovat aplikační build na živém webu
1. Po `prepare-deploy` se vytvoří složka `wp-build-test` se zipem produkčního buildu aplikace
Expand Down
4 changes: 2 additions & 2 deletions fapi-member.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Plugin Name: FAPI Member
* Plugin URI: https://fapi.cz/
* Description: Plugin FAPI pro jednoduchou správu členských sekcí na webu.
* Version: 2.2.9
* Version: 2.2.10
* Requires at least: 5.9
* Requires PHP: 8.1
* Author: FAPI Business s.r.o.
Expand All @@ -29,7 +29,7 @@
require __DIR__ . '/src/Elementor/fapi-member.php';
require __DIR__ . '/src/Utils/functions.php';

define('FAPI_MEMBER_PLUGIN_VERSION', '2.2.9');
define('FAPI_MEMBER_PLUGIN_VERSION', '2.2.10');

$FapiPlugin = new FapiMemberPlugin();

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 5.9
Tested up to: 6.4
Requires PHP: 8.1
License: GPLv2 or later
Stable tag: 2.2.9
Stable tag: 2.2.10

Plugin FAPI pro jednoduchou správu členských sekcí na webu.

Expand All @@ -26,6 +26,9 @@ Ohodnotit tento plugin můžete na stránkách [WordPress](https://wordpress.org

== Changelog ==

= 2.2.10 =
* 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)

= 2.2.9 =
* Fapi Member Pro
* Added information about last member login date in member detail
Expand Down
2 changes: 2 additions & 0 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function __construct(FapiMemberPlugin $fapiMemberPlugin)

public function initialize(): void
{
session_start();

$this->addHooks();
$this->generateTokenIfNeeded();
$this->migrateCredentialsIfNeeded();
Expand Down
11 changes: 11 additions & 0 deletions src/Model/Enums/Keys/SessionKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace FapiMember\Model\Enums\Keys;

use FapiMember\Library\SmartEmailing\Types\Enum;

class SessionKey extends Enum
{
const LAST_PAGE_ID = 'fm_last_page_id';

}
27 changes: 27 additions & 0 deletions src/Service/RedirectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use FapiMember\Container\Container;
use FapiMember\Model\Enums\Keys\OptionKey;
use FapiMember\Model\Enums\Keys\SessionKey;
use FapiMember\Model\Enums\Types\LevelUnlockType;
use FapiMember\Model\Enums\UserPermission;
use FapiMember\Repository\LevelRepository;
Expand Down Expand Up @@ -111,6 +112,10 @@ public function checkPageForRedirects(): bool

public function redirectToNoAccessPage($levelId): void
{
global $wp_query;

$_SESSION[SessionKey::LAST_PAGE_ID] = $wp_query->post->ID;

$level = $this->levelRepository->getLevelById($levelId);

if ($level?->getNoAccessPageId() !== null) {
Expand Down Expand Up @@ -143,6 +148,28 @@ public function loginRedirect(int|null $userId)

$memberships = $this->membershipService->getActiveByUserIdAndUpdate($userId);

$allowedPages = [];

foreach ($memberships as $membership) {
$allowedPages = array_merge(
$this->pageRepository->getPageIdsByLevelId($membership->getLevelId()),
$allowedPages,
);
}

$allowedPages = array_unique(array_filter($allowedPages));

if (
isset($_SESSION[SessionKey::LAST_PAGE_ID]) &&
$_SESSION[SessionKey::LAST_PAGE_ID] !== null &&
in_array($_SESSION[SessionKey::LAST_PAGE_ID], $allowedPages)
) {
$this->redirectToPage($_SESSION[SessionKey::LAST_PAGE_ID]);
$_SESSION[SessionKey::LAST_PAGE_ID] = null;
}

$_SESSION[SessionKey::LAST_PAGE_ID] = null;

$pages = array_map(
function ($membership) {
$level = $this->levelRepository->getLevelById($membership->getLevelId());
Expand Down

0 comments on commit 07aa0e3

Please sign in to comment.