| Conditions | 18 |
| Paths | 8 |
| Total Lines | 53 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 136 | public static function save_meta_boxes( $post_id, $post ) { |
||
| 137 | $post_id = absint( $post_id ); |
||
| 138 | |||
| 139 | // Do not save for ajax requests. |
||
| 140 | if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
||
| 141 | return; |
||
| 142 | } |
||
| 143 | |||
| 144 | // $post_id and $post are required |
||
| 145 | if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
||
| 146 | return; |
||
| 147 | } |
||
| 148 | |||
| 149 | // Dont' save meta boxes for revisions or autosaves. |
||
| 150 | if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
||
| 151 | return; |
||
| 152 | } |
||
| 153 | |||
| 154 | // Check the nonce. |
||
| 155 | if ( empty( $_POST['getpaid_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['getpaid_meta_nonce'] ), 'getpaid_meta_nonce' ) ) { |
||
|
|
|||
| 156 | return; |
||
| 157 | } |
||
| 158 | |||
| 159 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
||
| 160 | if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) { |
||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Check user has permission to edit. |
||
| 165 | if ( ! current_user_can( 'edit_post', $post_id ) ) { |
||
| 166 | return; |
||
| 167 | } |
||
| 168 | |||
| 169 | // Ensure this is our post type. |
||
| 170 | $post_types_map = array( |
||
| 171 | 'wpi_invoice' => 'GetPaid_Meta_Box_Invoice_Address', |
||
| 172 | 'wpi_quote' => 'GetPaid_Meta_Box_Invoice_Address', |
||
| 173 | 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
||
| 174 | 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
||
| 175 | 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
||
| 176 | ); |
||
| 177 | |||
| 178 | // Is this our post type? |
||
| 179 | if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
||
| 180 | return; |
||
| 181 | } |
||
| 182 | |||
| 183 | // We need this save event to run once to avoid potential endless loops. |
||
| 184 | self::$saved_meta_boxes = true; |
||
| 185 | |||
| 186 | // Save the post. |
||
| 187 | $class = $post_types_map[ $post->post_type ]; |
||
| 188 | $class::save( $post_id, $_POST, $post ); |
||
| 189 | |||
| 193 |