-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 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,46 @@ | ||
<?php | ||
|
||
namespace Wporg\TranslationEvents\Event; | ||
|
||
use WP_User; | ||
|
||
class Event_Capabilities { | ||
private const CREATE = 'create_translation_event'; | ||
|
||
private const CAPS = array( | ||
self::CREATE, | ||
); | ||
|
||
private function has_cap( string $cap, array $args, WP_User $user ): bool { | ||
switch ( $cap ) { | ||
case self::CREATE: | ||
return $this->has_create( $user ); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private function has_create( WP_User $user ): bool { | ||
// TODO. | ||
return true; | ||
} | ||
|
||
public function register_hooks(): void { | ||
add_action( | ||
'user_has_cap', | ||
function ( $allcaps, $caps, $args, $user ) { | ||
foreach ( $caps as $cap ) { | ||
if ( ! in_array( $cap, self::CAPS, true ) ) { | ||
continue; | ||
} | ||
if ( $this->has_cap( $cap, $args, $user ) ) { | ||
$allcaps[ $cap ] = true; | ||
} | ||
} | ||
return $allcaps; | ||
}, | ||
10, | ||
4, | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Wporg\Tests\Event; | ||
|
||
use GP_UnitTestCase; | ||
use Wporg\TranslationEvents\Attendee\Attendee_Repository; | ||
use Wporg\TranslationEvents\Event\Event_Capabilities; | ||
use Wporg\TranslationEvents\Event\Event_Repository; | ||
use Wporg\TranslationEvents\Tests\Event_Factory; | ||
use Wporg\TranslationEvents\Tests\Stats_Factory; | ||
|
||
class Event_Capabilities_Test extends GP_UnitTestCase { | ||
public function setUp(): void { | ||
parent::setUp(); | ||
$this->event_factory = new Event_Factory(); | ||
$this->stats_factory = new Stats_Factory(); | ||
$this->attendee_repository = new Attendee_Repository(); | ||
$this->event_repository = new Event_Repository( $this->attendee_repository ); | ||
$this->capilities = new Event_Capabilities(); | ||
} | ||
} |
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