Skip to content

Commit ed44dd4

Browse files
author
David Leal
authored
Merge pull request #61 from CodeProKid/bug/hide-admin-ui
Hiding admin UI from non-admins
2 parents 7fa9526 + 5b5a736 commit ed44dd4

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ cache:
1818

1919
matrix:
2020
include:
21+
- php: 7.2
22+
env: WP_VERSION=latest
2123
- php: 7.1
2224
env: WP_VERSION=latest
2325
- php: 7.0
@@ -48,4 +50,4 @@ script:
4850
fi
4951
5052
after_success:
51-
- bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
53+
- bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"classmap": [
1919
"src/"
2020
]
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "5.6"
2124
}
22-
}
25+
}

src/Register.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
class Register {
88

9+
const POST_TYPE = 'wpqt-task';
10+
911
/**
1012
* Sets up all of the functionality to run in the proper hook
1113
*/
@@ -24,6 +26,10 @@ public function setup() {
2426
// Performance improvement for VIP
2527
add_filter( 'wpcom_async_transition_post_status_schedule_async', [ $this, 'disable_post_transition' ], 10, 2 );
2628

29+
if ( true === Utils::debug_on() ) {
30+
add_action( 'admin_menu', [ $this, 'hide_admin_ui' ] );
31+
}
32+
2733
}
2834

2935
/**
@@ -70,7 +76,7 @@ public function register_taxonomy() {
7076
'graphql_plural_name' => 'queues',
7177
];
7278

73-
register_taxonomy( 'task-queue', 'wpqt-task', $args );
79+
register_taxonomy( 'task-queue', self::POST_TYPE, $args );
7480

7581
}
7682

@@ -119,7 +125,7 @@ public function register_post_type() {
119125
'graphql_plural_name' => 'tasks',
120126
];
121127

122-
register_post_type( 'wpqt-task', $args );
128+
register_post_type( self::POST_TYPE, $args );
123129

124130
}
125131

@@ -137,7 +143,7 @@ public function blacklist_post_type( $post_types ) {
137143
$post_types = [];
138144
}
139145

140-
$post_types[] = 'wpqt-task';
146+
$post_types[] = self::POST_TYPE;
141147

142148
return $post_types;
143149
}
@@ -157,12 +163,24 @@ public function disable_post_transition( $value, $args ) {
157163
return $value;
158164
}
159165

160-
if ( 'wpqt-task' === get_post_type( absint( $args['post_id'] ) ) ) {
166+
if ( self::POST_TYPE === get_post_type( absint( $args['post_id'] ) ) ) {
161167
$value = false;
162168
}
163169

164170
return $value;
165171

166172
}
167173

174+
/**
175+
* Hides the admin UI when the plugin is in debug mode from non-admins
176+
*
177+
* @access public
178+
* @return void
179+
*/
180+
public function hide_admin_ui() {
181+
if ( ! current_user_can( 'manage_options' ) ) {
182+
remove_menu_page( 'edit.php?post_type=' . self::POST_TYPE );
183+
}
184+
}
185+
168186
}

tests/src/test-Processor.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,16 @@ public function testPartialFailureBatchProcessing() {
187187
$result = $processor_obj->run_processor( $queue, $queue_id->term_id, $lock );
188188
global $_test_wpqt_bulk_processing_failed;
189189
$actual = $_test_wpqt_bulk_processing_failed;
190-
$expected = [
191-
'failed_tasks' => 1,
192-
'tasks_to_delete' => [ $task_1_id ],
193-
'tasks' => [
194-
$task_1_id => 'test data',
195-
$task_2_id => 'some other data',
196-
],
197-
'queue_name' => $queue,
198-
];
199190

200191
$this->assertTrue( $result );
201-
$this->assertEquals( $expected, $actual );
202-
$this->assertNull( get_post( $task_1_id ) );
203-
$this->assertNotNull( get_post( $task_2_id ) );
192+
$this->assertEquals( 1, $actual['failed_tasks'] );
193+
$this->assertEquals( 1, count( $actual['tasks_to_delete'] ) );
194+
$this->assertEquals( [
195+
$task_1_id => 'test data',
196+
$task_2_id => 'some other data',
197+
], $actual['tasks'] );
198+
$this->assertEquals( $queue, $actual['queue_name'] );
199+
$this->assertNull( get_post( $actual['tasks_to_delete'][0] ) );
204200
$this->assertFalse( Utils::is_queue_process_locked( $queue ) );
205201

206202
}
@@ -609,12 +605,9 @@ public function testBulkTaskFailure() {
609605
$processor_obj->run_processor( $queue, $queue_id->term_id, uniqid() );
610606

611607
global $_test_wpqt_bulk_processing_error;
612-
$expected = [
613-
'task_ids' => [ $task_1, $task_2 ],
614-
'queue_name' => $queue,
615-
];
616608

617-
$this->assertEquals( $expected, $_test_wpqt_bulk_processing_error );
609+
$this->assertEquals( 2, count( $_test_wpqt_bulk_processing_error['task_ids'] ) );
610+
$this->assertEquals( $queue, $_test_wpqt_bulk_processing_error['queue_name'] );
618611
$this->assertNotNull( get_post( $task_1 ) );
619612
$this->assertNotNull( get_post( $task_2 ) );
620613

0 commit comments

Comments
 (0)