| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| Code Lines | 53 |
| 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 |
||
| 140 | function setup_cpts() { |
||
| 141 | |||
| 142 | /* |
||
| 143 | * ORDER data structure. holds: |
||
| 144 | * title = customer_name | 4xproduct_name |
||
| 145 | * excerpt = customer_name + customer contact info + customer notes from paypal form |
||
| 146 | * metadata: |
||
| 147 | * spay_paypal_id - paypal id of transaction |
||
| 148 | * spay_status |
||
| 149 | * spay_product_id - post_id of bought product |
||
| 150 | * spay_quantity - quantity of product |
||
| 151 | * spay_price - item price at the time of purchase |
||
| 152 | * spay_customer_email - customer email |
||
| 153 | * ... (WIP) |
||
| 154 | */ |
||
| 155 | $order_capabilities = array( |
||
| 156 | 'edit_post' => 'edit_posts', |
||
| 157 | 'read_post' => 'read_private_posts', |
||
| 158 | 'delete_post' => 'delete_posts', |
||
| 159 | 'edit_posts' => 'edit_posts', |
||
| 160 | 'edit_others_posts' => 'edit_others_posts', |
||
| 161 | 'publish_posts' => 'publish_posts', |
||
| 162 | 'read_private_posts' => 'read_private_posts', |
||
| 163 | ); |
||
| 164 | $order_args = array( |
||
| 165 | 'label' => esc_html__( 'Order', 'jetpack' ), |
||
| 166 | 'description' => esc_html__( 'Simple Payments orders', 'jetpack' ), |
||
| 167 | 'supports' => array( 'custom-fields', 'excerpt' ), |
||
| 168 | 'hierarchical' => false, |
||
| 169 | 'public' => false, |
||
| 170 | 'show_ui' => false, |
||
| 171 | 'show_in_menu' => false, |
||
| 172 | 'show_in_admin_bar' => false, |
||
| 173 | 'show_in_nav_menus' => false, |
||
| 174 | 'can_export' => true, |
||
| 175 | 'has_archive' => false, |
||
| 176 | 'exclude_from_search' => true, |
||
| 177 | 'publicly_queryable' => false, |
||
| 178 | 'rewrite' => false, |
||
| 179 | 'capabilities' => $order_capabilities, |
||
| 180 | 'show_in_rest' => true, |
||
| 181 | ); |
||
| 182 | register_post_type( self::$post_type_order, $order_args ); |
||
| 183 | |||
| 184 | /* |
||
| 185 | * PRODUCT data structure. Holds: |
||
| 186 | * title - title |
||
| 187 | * content - description |
||
| 188 | * thumbnail - image |
||
| 189 | * metadata: |
||
| 190 | * spay_price - price |
||
| 191 | * spay_currency - currency code |
||
| 192 | * spay_cta - text with "Buy" or other CTA |
||
| 193 | * spay_email - paypal email |
||
| 194 | * spay_multiple - allow for multiple items |
||
| 195 | * spay_status - status. { enabled | disabled } |
||
| 196 | */ |
||
| 197 | $product_capabilities = array( |
||
| 198 | 'edit_post' => 'edit_posts', |
||
| 199 | 'read_post' => 'read_private_posts', |
||
| 200 | 'delete_post' => 'delete_posts', |
||
| 201 | 'edit_posts' => 'edit_posts', |
||
| 202 | 'edit_others_posts' => 'edit_others_posts', |
||
| 203 | 'publish_posts' => 'publish_posts', |
||
| 204 | 'read_private_posts' => 'read_private_posts', |
||
| 205 | ); |
||
| 206 | $product_args = array( |
||
| 207 | 'label' => esc_html__( 'Product', 'jetpack' ), |
||
| 208 | 'description' => esc_html__( 'Simple Payments products', 'jetpack' ), |
||
| 209 | 'supports' => array( 'title', 'editor','thumbnail', 'custom-fields' ), |
||
| 210 | 'hierarchical' => false, |
||
| 211 | 'public' => false, |
||
| 212 | 'show_ui' => false, |
||
| 213 | 'show_in_menu' => false, |
||
| 214 | 'show_in_admin_bar' => false, |
||
| 215 | 'show_in_nav_menus' => false, |
||
| 216 | 'can_export' => true, |
||
| 217 | 'has_archive' => false, |
||
| 218 | 'exclude_from_search' => true, |
||
| 219 | 'publicly_queryable' => false, |
||
| 220 | 'rewrite' => false, |
||
| 221 | 'capabilities' => $product_capabilities, |
||
| 222 | 'show_in_rest' => true, |
||
| 223 | ); |
||
| 224 | register_post_type( self::$post_type_product, $product_args ); |
||
| 225 | } |
||
| 226 | |||
| 229 |