-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add and implement site switcher
- Loading branch information
Sebastian Thulin
committed
Jan 17, 2025
1 parent
dc2282d
commit 5bc5a35
Showing
3 changed files
with
206 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Municipio\Helper\SiteSwitcher; | ||
|
||
class SiteSwitcher | ||
{ | ||
/** | ||
* Execute a callable within the context of a specific site. | ||
* | ||
* @param int $siteId | ||
* @param callable $callable | ||
* @param mixed $callableContext Contextual data to pass to the callable. | ||
* @return mixed The result of the callable execution. | ||
*/ | ||
public function runInSite(int $siteId, callable $callable, mixed $callableContext = null): mixed | ||
{ | ||
switch_to_blog($siteId); | ||
|
||
try { | ||
return $callable(...func_get_args()); | ||
} finally { | ||
restore_current_blog(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters