-
Notifications
You must be signed in to change notification settings - Fork 1
/
actions.php
49 lines (35 loc) · 1.44 KB
/
actions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Example_WP_CLI\CLI;
use Exception;
use WP_CLI;
/**
* CLI Actions
*/
class Actions extends Base {
public function is_post_author() {
if ( empty( $this->args[0] ) ) {
$this->error_message( 'Please provide the post ID to check.' );
}
$this->disable_emails();
$user_id = $this->get_flag_value( 'user_id', get_current_user_id() );
$post = get_post( absint( $this->args[0] ) );
$is_post_author = $post && absint( $post->post_author ) === absint( $user_id );
$this->success_message( 'Can edit? ' . ( $is_post_author ? 'Yes' : 'No' ) );
}
public function delete_post_if_mine() {
if ( empty( $this->args[0] ) ) {
$this->error_message( 'Please provide the post ID to check.' );
}
$this->disable_emails();
$user_id = absint( $this->get_flag_value( 'user_id', get_current_user_id() ) );
$post_id = absint( $this->args[0] );
$this->confirm( sprintf( 'Are you sure you want to delete the post (%d) for user %d?', $post_id, $user_id ) );
$this->silent_log( sprintf( 'Maybe deleting post (%d) for user (%d)', $post_id, $user_id ) );
$post = get_post( $post_id );
$is_post_author = isset( $post->post_author ) && absint( $post->post_author ) === $user_id;
if ( ! $is_post_author ) {
$this->error_log( sprintf( 'Sorry, post (%d) author does not match the user id (%d), and cannot be deleted.', $plan_id, $member->user_id ) );
}
$this->success_message( 'Can edit? ' . ( $is_post_author ? 'Yes' : 'No' ) );
}
}