Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Apr 16, 2024
1 parent 44f4ce4 commit c66c38a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 20 additions & 1 deletion includes/event/event-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
namespace Wporg\TranslationEvents\Event;

class Event_Capabilities {
private array $caps = array();
private const CREATE_EVENT = 'create_translation_event';

private array $caps = array(
self::CREATE_EVENT,
);

public static function can_create_event(): bool {
return current_user_can( self::CREATE_EVENT );
}

private function check_create(): bool {
// TODO.
return true;
}

public function register_hooks(): void {
add_action(
Expand All @@ -21,6 +34,12 @@ private function map_meta_cap( array $caps, string $cap, int $user_id, array $ar
return $caps;
}

if ( self::CREATE_EVENT === $cap && ! $this->check_create() ) {
$caps[] = ;

Check failure on line 38 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

PHP syntax error: syntax error, unexpected token ";"

Check failure on line 38 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

Space found before semicolon; expected "=;" but found "= ;"
}

var_dump($cap, $caps);die;

Check warning on line 41 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

var_dump() found. Debug code should not normally be used in production.

Check failure on line 41 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 41 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 spaces before closing parenthesis; 0 found

Check failure on line 41 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

Each PHP statement must be on a line by itself

return $caps;

Check warning on line 43 in includes/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / phpcs

Code after the EXIT statement on line 41 cannot be executed
}
}
6 changes: 6 additions & 0 deletions includes/routes/event/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Wporg\TranslationEvents\Routes\Event;

use Wporg\TranslationEvents\Event\Event_Capabilities;
use Wporg\TranslationEvents\Event\Event_End_Date;
use Wporg\TranslationEvents\Event\Event_Start_Date;
use Wporg\TranslationEvents\Routes\Route;
Expand All @@ -16,6 +17,11 @@ public function handle(): void {
wp_safe_redirect( wp_login_url( home_url( $wp->request ) ) );
exit;
}

if ( ! Event_Capabilities::can_create_event() ) {
$this->die_with_error( 'You do not have permission to create events.' );
}

$event_page_title = 'Create Event';
$event_form_name = 'create_event';
$css_show_url = 'hide-event-url';
Expand Down

0 comments on commit c66c38a

Please sign in to comment.