Conditions | 13 |
Paths | 67 |
Total Lines | 72 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
30 | */ |
||
31 | public function request_handler() { |
||
32 | if ( isset( $_POST['bd_action'] ) ) { |
||
33 | $bd_action = sanitize_text_field( $_POST['bd_action'] ); |
||
34 | $nonce_valid = false; |
||
35 | |||
36 | if ( 'delete_pages_' === substr( $bd_action, 0, strlen( 'delete_pages_' ) ) |
||
37 | && check_admin_referer( 'sm-bulk-delete-pages', 'sm-bulk-delete-pages-nonce' ) ) { |
||
38 | $nonce_valid = true; |
||
39 | } |
||
40 | |||
41 | if ( 'delete_posts_' === substr( $bd_action, 0, strlen( 'delete_posts_' ) ) |
||
42 | && check_admin_referer( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' ) ) { |
||
43 | $nonce_valid = true; |
||
44 | } |
||
45 | |||
46 | if ( 'delete_meta_' === substr( $bd_action, 0, strlen( 'delete_meta_' ) ) |
||
47 | && check_admin_referer( 'sm-bulk-delete-meta', 'sm-bulk-delete-meta-nonce' ) ) { |
||
48 | $nonce_valid = true; |
||
49 | } |
||
50 | |||
51 | if ( 'delete_jetpack_messages' === $bd_action && wp_verify_nonce( $_POST['sm-bulk-delete-misc-nonce'], 'sm-bulk-delete-misc' ) ) { |
||
52 | $nonce_valid = true; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Perform nonce check. |
||
57 | * |
||
58 | * @since 5.5 |
||
59 | */ |
||
60 | if ( ! apply_filters( 'bd_action_nonce_check', $nonce_valid, $bd_action ) ) { |
||
61 | return; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Before performing a bulk action. |
||
66 | * This hook is for doing actions just before performing any bulk operation. |
||
67 | * |
||
68 | * @since 5.4 |
||
69 | */ |
||
70 | do_action( 'bd_pre_bulk_action', $bd_action ); |
||
71 | |||
72 | /** |
||
73 | * Perform the bulk operation. |
||
74 | * This hook is for doing the bulk operation. Nonce check has already happened by this point. |
||
75 | * |
||
76 | * @since 5.4 |
||
77 | */ |
||
78 | do_action( 'bd_' . $bd_action, $_POST ); |
||
79 | } |
||
80 | |||
81 | if ( isset( $_GET['bd_action'] ) ) { |
||
82 | $bd_action = sanitize_text_field( $_GET['bd_action'] ); |
||
83 | $nonce_valid = false; |
||
84 | |||
85 | /** |
||
86 | * Perform nonce check. |
||
87 | * |
||
88 | * @since 5.5.4 |
||
89 | */ |
||
90 | if ( ! apply_filters( 'bd_get_action_nonce_check', $nonce_valid, $bd_action ) ) { |
||
91 | return; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Perform the bulk operation. |
||
96 | * This hook is for doing the bulk operation. Nonce check has already happened by this point. |
||
97 | * |
||
98 | * @since 5.5.4 |
||
99 | */ |
||
100 | do_action( 'bd_' . $bd_action, $_GET ); |
||
101 | } |
||
102 | } |
||
135 |