| Conditions | 8 |
| Paths | 9 |
| Total Lines | 82 |
| 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 |
||
| 75 | public function handler() { |
||
| 76 | // Validate action. |
||
| 77 | // @codingStandardsIgnoreStart |
||
| 78 | if ( |
||
| 79 | ! isset( $_REQUEST['form_id'] ) |
||
| 80 | || ! isset( $_REQUEST['action'] ) |
||
| 81 | || ( 'give_duplicate_form' !== $_REQUEST['action'] ) |
||
| 82 | ) { |
||
| 83 | wp_die( esc_html__( 'Form ID not found in the query string', 'give' ) ); |
||
| 84 | |||
| 85 | } elseif ( ! wp_verify_nonce( give_clean( $_REQUEST['_wpnonce'] ), 'give-duplicate-form' ) ) { |
||
| 86 | |||
| 87 | wp_die( esc_html__( 'Nonce verification failed', 'give' ) ); |
||
| 88 | } |
||
| 89 | // @codingStandardsIgnoreEnd |
||
| 90 | |||
| 91 | $form_id = give_clean( $_REQUEST['form_id'] ); // @codingStandardsIgnoreLine |
||
| 92 | $post_data = get_post( $form_id ); |
||
| 93 | $current_user = wp_get_current_user(); |
||
| 94 | $error_notice = sprintf( |
||
| 95 | /* translators: %s: Form ID */ |
||
| 96 | esc_html__( 'Cloning failed. Form with ID %s does not exist.', 'give' ), |
||
| 97 | absint( $form_id ) |
||
| 98 | ); |
||
| 99 | |||
| 100 | if ( isset( $post_data ) && null !== $post_data ) { |
||
| 101 | |||
| 102 | $args = array( |
||
| 103 | 'comment_status' => $post_data->comment_status, |
||
| 104 | 'ping_status' => $post_data->ping_status, |
||
| 105 | 'post_author' => $current_user->ID, |
||
| 106 | 'post_content' => $post_data->post_content, |
||
| 107 | 'post_excerpt' => $post_data->post_excerpt, |
||
| 108 | 'post_name' => $post_data->post_name, |
||
| 109 | 'post_parent' => $post_data->post_parent, |
||
| 110 | 'post_password' => $post_data->post_password, |
||
| 111 | 'post_status' => 'draft', |
||
| 112 | 'post_title' => $post_data->post_title, |
||
| 113 | 'post_type' => $post_data->post_type, |
||
| 114 | 'to_ping' => $post_data->to_ping, |
||
| 115 | 'menu_order' => $post_data->menu_order, |
||
| 116 | ); |
||
| 117 | |||
| 118 | // Get the ID of the cloned post. |
||
| 119 | $duplicate_form_id = wp_insert_post( $args ); |
||
| 120 | |||
| 121 | $this->duplicate_taxonomies( $duplicate_form_id, $post_data ); |
||
| 122 | $this->duplicate_meta_data( $duplicate_form_id, $post_data ); |
||
| 123 | $this->reset_stats( $duplicate_form_id ); |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Fire the action |
||
| 127 | * |
||
| 128 | * @since 2.2.0 |
||
| 129 | * |
||
| 130 | * @param int $duplicate_form_id Duplicated form ID. |
||
| 131 | * @param int $form_id Form ID. |
||
| 132 | */ |
||
| 133 | do_action( 'give_form_duplicated', $duplicate_form_id, $form_id ); |
||
| 134 | |||
| 135 | if ( ! is_wp_error( $duplicate_form_id ) ) { |
||
| 136 | // Redirect to the cloned form editor page. |
||
| 137 | wp_safe_redirect( |
||
| 138 | add_query_arg( |
||
| 139 | array( |
||
| 140 | 'action' => 'edit', |
||
| 141 | 'post' => $duplicate_form_id, |
||
| 142 | ), |
||
| 143 | admin_url( 'post.php' ) |
||
| 144 | ) |
||
| 145 | ); |
||
| 146 | } else { |
||
| 147 | wp_die( $error_notice ); // @codingStandardsIgnoreLine |
||
| 148 | } |
||
| 149 | |||
| 150 | exit; |
||
| 151 | |||
| 152 | } else { |
||
| 153 | |||
| 154 | wp_die( $error_notice ); // @codingStandardsIgnoreLine |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 263 |