| Total Complexity | 42 |
| Total Lines | 591 |
| Duplicated Lines | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Plan often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Plan, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Plan { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Holds class instance |
||
| 15 | * |
||
| 16 | * @since 1.0.0 |
||
| 17 | * |
||
| 18 | * @var object \lsx_health_plan\classes\Plan() |
||
| 19 | */ |
||
| 20 | protected static $instance = null; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Holds post_type slug used as an index |
||
| 24 | * |
||
| 25 | * @since 1.0.0 |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | public $slug = 'plan'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Constructor |
||
| 33 | */ |
||
| 34 | public function __construct() { |
||
| 35 | |||
| 36 | add_action( 'init', array( $this, 'register_post_type' ) ); |
||
| 37 | add_action( 'init', array( $this, 'plan_type_taxonomy_setup' ) ); |
||
| 38 | add_action( 'init', array( $this, 'week_taxonomy_setup' ) ); |
||
| 39 | |||
| 40 | // Icons for the plan types. |
||
| 41 | add_action( 'create_term', array( $this, 'save_meta' ), 10, 2 ); |
||
| 42 | add_action( 'edit_term', array( $this, 'save_meta' ), 10, 2 ); |
||
| 43 | $prefix_taxonomy = 'plan-type'; |
||
| 44 | add_action( sprintf( '%s_edit_form_fields', $prefix_taxonomy ), array( $this, 'add_thumbnail_form_field' ), 3, 1 ); |
||
| 45 | |||
| 46 | // Register the Metaboxes. |
||
| 47 | add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
||
| 48 | add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ), 5 ); |
||
| 49 | add_action( 'cmb2_admin_init', array( $this, 'plan_connections' ), 5 ); |
||
| 50 | add_action( 'cmb2_admin_init', array( $this, 'sections_metabox_loop' ), 1 ); |
||
| 51 | |||
| 52 | add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
||
| 53 | //add_filter( 'lsx_global_header_title', array( $this, 'hp_recipe_header_title' ), 200, 1 ); |
||
| 54 | |||
| 55 | // Template Redirects. |
||
| 56 | add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
||
| 57 | add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
||
| 58 | |||
| 59 | // Plan Archive Actions. |
||
| 60 | add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
||
| 61 | add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
||
| 62 | add_action( 'lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1 ); |
||
| 63 | add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1 ); |
||
| 64 | add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_filters_disabled', 10, 1 ); |
||
| 65 | |||
| 66 | //Breadcrumbs |
||
| 67 | add_filter( 'wpseo_breadcrumb_links', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
||
| 68 | add_filter( 'woocommerce_get_breadcrumb', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
||
| 69 | |||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Return an instance of this class. |
||
| 74 | * |
||
| 75 | * @since 1.0.0 |
||
| 76 | * |
||
| 77 | * @return object \lsx_health_plan\classes\Meal_Plan() A single instance of this class. |
||
| 78 | */ |
||
| 79 | public static function get_instance() { |
||
| 80 | // If the single instance hasn't been set, set it now. |
||
| 81 | if ( null === self::$instance ) { |
||
| 82 | self::$instance = new self(); |
||
| 83 | } |
||
| 84 | return self::$instance; |
||
| 85 | } |
||
| 86 | /** |
||
| 87 | * Register the post type. |
||
| 88 | */ |
||
| 89 | public function register_post_type() { |
||
| 90 | $labels = array( |
||
| 91 | 'name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
||
| 92 | 'singular_name' => esc_html__( 'Plan', 'lsx-health-plan' ), |
||
| 93 | 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
||
| 94 | 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
||
| 95 | 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
||
| 96 | 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
||
| 97 | 'all_items' => esc_html__( 'All Plans', 'lsx-health-plan' ), |
||
| 98 | 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
||
| 99 | 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
||
| 100 | 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
||
| 101 | 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
||
| 102 | 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
||
| 103 | 'menu_name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
||
| 104 | ); |
||
| 105 | $args = array( |
||
| 106 | 'labels' => $labels, |
||
| 107 | 'public' => true, |
||
| 108 | 'publicly_queryable' => true, |
||
| 109 | 'show_ui' => true, |
||
| 110 | 'show_in_menu' => true, |
||
| 111 | 'show_in_rest' => true, |
||
| 112 | 'menu_icon' => 'dashicons-welcome-write-blog', |
||
| 113 | 'query_var' => true, |
||
| 114 | 'rewrite' => array( |
||
| 115 | 'slug' => \lsx_health_plan\functions\get_option( 'plan_single_slug', 'plan' ), |
||
| 116 | ), |
||
| 117 | 'capability_type' => 'page', |
||
| 118 | 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plans' ), |
||
| 119 | 'hierarchical' => false, |
||
| 120 | 'menu_position' => null, |
||
| 121 | 'supports' => array( |
||
| 122 | 'title', |
||
| 123 | 'editor', |
||
| 124 | 'thumbnail', |
||
| 125 | 'page-attributes', |
||
| 126 | 'custom-fields', |
||
| 127 | ), |
||
| 128 | ); |
||
| 129 | register_post_type( 'plan', $args ); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Register the Type taxonomy. |
||
| 134 | */ |
||
| 135 | public function plan_type_taxonomy_setup() { |
||
| 136 | $labels = array( |
||
| 137 | 'name' => esc_html_x( 'Plan Type', 'taxonomy general name', 'lsx-health-plan' ), |
||
| 138 | 'singular_name' => esc_html_x( 'Plan Type', 'taxonomy singular name', 'lsx-health-plan' ), |
||
| 139 | 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
||
| 140 | 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
||
| 141 | 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
||
| 142 | 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
||
| 143 | 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
||
| 144 | 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
||
| 145 | 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
||
| 146 | 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
||
| 147 | 'menu_name' => esc_html__( 'Plan Types', 'lsx-health-plan' ), |
||
| 148 | ); |
||
| 149 | |||
| 150 | $args = array( |
||
| 151 | 'hierarchical' => true, |
||
| 152 | 'labels' => $labels, |
||
| 153 | 'show_ui' => true, |
||
| 154 | 'show_admin_column' => true, |
||
| 155 | 'query_var' => true, |
||
| 156 | 'rewrite' => array( |
||
| 157 | 'slug' => 'plan-type', |
||
| 158 | ), |
||
| 159 | ); |
||
| 160 | |||
| 161 | register_taxonomy( 'plan-type', array( 'plan' ), $args ); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Register the Week taxonomy. |
||
| 166 | */ |
||
| 167 | public function week_taxonomy_setup() { |
||
| 168 | $labels = array( |
||
| 169 | 'name' => esc_html_x( 'Week', 'taxonomy general name', 'lsx-health-plan' ), |
||
| 170 | 'singular_name' => esc_html_x( 'Week', 'taxonomy singular name', 'lsx-health-plan' ), |
||
| 171 | 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
||
| 172 | 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
||
| 173 | 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
||
| 174 | 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
||
| 175 | 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
||
| 176 | 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
||
| 177 | 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
||
| 178 | 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
||
| 179 | 'menu_name' => esc_html__( 'Weeks', 'lsx-health-plan' ), |
||
| 180 | ); |
||
| 181 | |||
| 182 | $args = array( |
||
| 183 | 'hierarchical' => true, |
||
| 184 | 'labels' => $labels, |
||
| 185 | 'show_ui' => true, |
||
| 186 | 'show_admin_column' => true, |
||
| 187 | 'query_var' => true, |
||
| 188 | 'show_in_rest' => true, |
||
| 189 | 'rewrite' => array( |
||
| 190 | 'slug' => 'week', |
||
| 191 | ), |
||
| 192 | ); |
||
| 193 | |||
| 194 | register_taxonomy( 'week', array( 'plan' ), $args ); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Output the form field for this metadata when adding a new term |
||
| 199 | * |
||
| 200 | * @since 0.1.0 |
||
| 201 | */ |
||
| 202 | public function add_thumbnail_form_field( $term = false ) { |
||
| 203 | if ( is_object( $term ) ) { |
||
| 204 | $value = get_term_meta( $term->term_id, 'thumbnail', true ); |
||
| 205 | $image_preview = wp_get_attachment_image_src( $value, 'thumbnail' ); |
||
| 206 | |||
| 207 | if ( is_array( $image_preview ) ) { |
||
| 208 | $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url( $image_preview[0] ) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
||
| 209 | } |
||
| 210 | } else { |
||
| 211 | $image_preview = false; |
||
| 212 | $value = false; |
||
| 213 | } |
||
| 214 | ?> |
||
| 215 | <tr class="form-field form-required term-thumbnail-wrap"> |
||
| 216 | <th scope="row"><label for="thumbnail"><?php esc_html_e( 'Icon Image', 'lsx-health-plan' ); ?></label></th> |
||
| 217 | <td> |
||
| 218 | <input class="input_image_id" type="hidden" name="thumbnail" value="<?php echo wp_kses_post( $value ); ?>"> |
||
| 219 | <div class="thumbnail-preview"> |
||
| 220 | <?php echo wp_kses_post( $image_preview ); ?> |
||
| 221 | </div> |
||
| 222 | <a style="<?php if ( '' !== $value && false !== $value ) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-add"><?php esc_html_e( 'Choose Image', 'lsx-health-plan' ); ?></a> |
||
| 223 | <a style="<?php if ( '' === $value || false === $value ) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-remove"><?php esc_html_e( 'Remove Image', 'lsx-health-plan' ); ?></a> |
||
| 224 | <?php wp_nonce_field( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ); ?> |
||
| 225 | </td> |
||
| 226 | </tr> |
||
| 227 | <?php |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Saves the Taxonomy term icon image |
||
| 232 | * |
||
| 233 | * @since 0.1.0 |
||
| 234 | * |
||
| 235 | * @param int $term_id |
||
| 236 | * @param string $taxonomy |
||
| 237 | */ |
||
| 238 | public function save_meta( $term_id = 0, $taxonomy = '' ) { |
||
| 239 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
||
| 240 | return; |
||
| 241 | } |
||
| 242 | |||
| 243 | if ( ! isset( $_POST['thumbnail'] ) ) { |
||
| 244 | return; |
||
| 245 | } |
||
| 246 | |||
| 247 | if ( check_admin_referer( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ) ) { |
||
| 248 | if ( ! isset( $_POST['thumbnail'] ) ) { |
||
| 249 | return; |
||
| 250 | } |
||
| 251 | |||
| 252 | $thumbnail_meta = sanitize_text_field( $_POST['thumbnail'] ); |
||
| 253 | $thumbnail_meta = ! empty( $thumbnail_meta ) ? $thumbnail_meta : ''; |
||
| 254 | |||
| 255 | if ( empty( $thumbnail_meta ) ) { |
||
| 256 | delete_term_meta( $term_id, 'thumbnail' ); |
||
| 257 | } else { |
||
| 258 | update_term_meta( $term_id, 'thumbnail', $thumbnail_meta ); |
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Define the metabox and field configurations. |
||
| 265 | */ |
||
| 266 | public function details_metaboxes() { |
||
| 267 | $cmb = new_cmb2_box( array( |
||
| 268 | 'id' => $this->slug . '_details_metabox', |
||
| 269 | 'title' => __( 'Details', 'lsx-health-plan' ), |
||
| 270 | 'object_types' => array( $this->slug ), // Post type |
||
| 271 | 'context' => 'normal', |
||
| 272 | 'priority' => 'high', |
||
| 273 | 'show_names' => true, |
||
| 274 | ) ); |
||
| 275 | |||
| 276 | $cmb->add_field( array( |
||
| 277 | 'name' => __( 'Plan Short Description', 'lsx-health-plan' ), |
||
| 278 | 'id' => $this->slug . '_short_description', |
||
| 279 | 'type' => 'textarea_small', |
||
| 280 | 'desc' => __( 'Add a small description for this plan (optional)', 'lsx-health-plan' ), |
||
| 281 | ) ); |
||
| 282 | |||
| 283 | $warmup_type = 'page'; |
||
| 284 | if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
||
| 285 | $warmup_type = array( 'page', 'workout' ); |
||
| 286 | } |
||
| 287 | $cmb->add_field( array( |
||
| 288 | 'name' => __( 'Warmup', 'lsx-health-plan' ), |
||
| 289 | 'desc' => __( 'Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan' ), |
||
| 290 | 'id' => $this->slug . '_warmup', |
||
| 291 | 'type' => 'post_search_ajax', |
||
| 292 | // Optional : |
||
| 293 | 'limit' => 3, // Limit selection to X items only (default 1) |
||
| 294 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 295 | 'query_args' => array( |
||
| 296 | 'post_type' => $warmup_type, |
||
| 297 | 'post_status' => array( 'publish' ), |
||
| 298 | 'posts_per_page' => -1, |
||
| 299 | ), |
||
| 300 | ) ); |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Adds the post type to the different arrays. |
||
| 305 | * |
||
| 306 | * @param array $post_types |
||
| 307 | * @return array |
||
| 308 | */ |
||
| 309 | public function enable_post_type( $post_types = array() ) { |
||
| 310 | $post_types[] = $this->slug; |
||
| 311 | return $post_types; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Registers the workout connections on the plan post type. |
||
| 316 | * |
||
| 317 | * @return void |
||
| 318 | */ |
||
| 319 | public function plan_connections() { |
||
| 320 | $cmb = new_cmb2_box( |
||
| 321 | array( |
||
| 322 | 'id' => $this->slug . '_connections_metabox', |
||
| 323 | 'title' => __( 'Plans', 'lsx-health-plan' ), |
||
| 324 | 'object_types' => array( 'workout', 'meal', 'tip', 'recipe' ), |
||
| 325 | 'context' => 'normal', |
||
| 326 | 'priority' => 'high', |
||
| 327 | 'show_names' => true, |
||
| 328 | ) |
||
| 329 | ); |
||
| 330 | $cmb->add_field( |
||
| 331 | array( |
||
| 332 | 'name' => __( 'Plan', 'lsx-health-plan' ), |
||
| 333 | 'id' => 'connected_plans', |
||
| 334 | 'desc' => __( 'Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan' ), |
||
| 335 | 'type' => 'post_search_ajax', |
||
| 336 | 'limit' => 15, |
||
| 337 | 'sortable' => true, |
||
| 338 | 'query_args' => array( |
||
| 339 | 'post_type' => array( 'plan' ), |
||
| 340 | 'post_status' => array( 'publish' ), |
||
| 341 | 'posts_per_page' => -1, |
||
| 342 | ), |
||
| 343 | ) |
||
| 344 | ); |
||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Remove the "Archives:" from the post type. |
||
| 349 | * |
||
| 350 | * @param string $title the term title. |
||
| 351 | * @return string |
||
| 352 | */ |
||
| 353 | public function get_the_archive_title( $title ) { |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Set the post type archive to show the parent plans only. |
||
| 362 | * |
||
| 363 | * @param object $wp_query |
||
| 364 | * @return array |
||
| 365 | */ |
||
| 366 | public function set_parent_only( $wp_query ) { |
||
| 367 | if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'plan' ) || $wp_query->is_tax( 'plan-type' ) ) ) { |
||
| 368 | $wp_query->set( 'post_parent', '0' ); |
||
| 369 | } |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Define the metabox and field configurations. |
||
| 374 | */ |
||
| 375 | public function featured_metabox() { |
||
| 393 | ) |
||
| 394 | ); |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Define the metabox and field configurations. |
||
| 399 | */ |
||
| 400 | public function sections_metabox_loop() { |
||
| 401 | $cmb = new_cmb2_box( |
||
| 402 | array( |
||
| 403 | 'id' => $this->slug . '_sections_metabox', |
||
| 404 | 'title' => __( 'Sections', 'lsx-health-plan' ), |
||
| 405 | 'object_types' => array( $this->slug ), // Post type. |
||
| 406 | 'context' => 'normal', |
||
| 407 | 'priority' => 'low', |
||
| 408 | 'show_names' => true, |
||
| 409 | ) |
||
| 410 | ); |
||
| 411 | |||
| 412 | /* |
||
| 413 | This is where the repeatable group is defined, each field has the same ID as the legacy field. |
||
| 414 | There is a function which runs and adds to looped fields to individual fields for WP Query compatability. |
||
| 415 | */ |
||
| 416 | $group = $cmb->add_field( |
||
| 417 | array( |
||
| 418 | 'id' => $this->slug . '_sections', |
||
| 419 | 'type' => 'group', |
||
| 420 | 'options' => array( |
||
| 421 | 'group_title' => __( 'Section', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
||
| 422 | 'add_button' => __( 'Add section', 'lsx-health-plan' ), |
||
| 423 | 'remove_button' => __( 'Remove section', 'lsx-health-plan' ), |
||
| 424 | 'sortable' => true, |
||
| 425 | 'closed' => true, // true to have the groups closed by default |
||
| 426 | ), |
||
| 427 | 'classes' => 'lsx-admin-row', |
||
| 428 | |||
| 429 | ) |
||
| 430 | ); |
||
| 431 | |||
| 432 | $cmb->add_group_field( |
||
| 433 | $group, |
||
| 434 | array( |
||
| 435 | 'name' => __( 'Title', 'lsx-health-plan' ), |
||
| 436 | 'id' => 'title', |
||
| 437 | 'type' => 'text', |
||
| 438 | 'desc' => __( 'e.g Day 1 / Week 1', 'lsx-health-plan' ), |
||
| 439 | 'classes' => 'lsx-field-col lsx-field-col-50', |
||
| 440 | ) |
||
| 441 | ); |
||
| 442 | |||
| 443 | $cmb->add_group_field( |
||
| 444 | $group, |
||
| 445 | array( |
||
| 446 | 'name' => __( 'Group', 'lsx-health-plan' ), |
||
| 447 | 'id' => 'group', |
||
| 448 | 'type' => 'text', |
||
| 449 | 'desc' => __( 'e.g Week 1 / January', 'lsx-health-plan' ), |
||
| 450 | 'classes' => 'lsx-field-col lsx-field-col-50', |
||
| 451 | ) |
||
| 452 | ); |
||
| 453 | |||
| 454 | $cmb->add_group_field( |
||
| 455 | $group, |
||
| 456 | array( |
||
| 457 | 'name' => __( 'Overview', 'lsx-health-plan' ), |
||
| 458 | 'id' => 'description', |
||
| 459 | 'type' => 'wysiwyg', |
||
| 460 | ) |
||
| 461 | ); |
||
| 462 | |||
| 463 | if ( post_type_exists( 'workout' ) ) { |
||
| 464 | $cmb->add_group_field( |
||
| 465 | $group, |
||
| 466 | array( |
||
| 467 | 'name' => __( 'Workouts', 'lsx-health-plan' ), |
||
| 468 | 'id' => 'connected_workouts', |
||
| 469 | 'desc' => __( 'Connect the workout(s) that apply to this section.', 'lsx-health-plan' ), |
||
| 470 | 'type' => 'post_search_ajax', |
||
| 471 | 'limit' => 15, |
||
| 472 | 'sortable' => true, |
||
| 473 | 'query_args' => array( |
||
| 474 | 'post_type' => array( 'workout' ), |
||
| 475 | 'post_status' => array( 'publish' ), |
||
| 476 | 'posts_per_page' => -1, |
||
| 477 | ), |
||
| 478 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
||
| 479 | ) |
||
| 480 | ); |
||
| 481 | $cmb->add_group_field( |
||
| 482 | $group, |
||
| 483 | array( |
||
| 484 | 'name' => __( 'Rest day', 'lsx-health-plan' ), |
||
| 485 | 'id' => 'rest_day_enabled', |
||
| 486 | 'type' => 'checkbox', |
||
| 487 | 'value' => 1, |
||
| 488 | 'default' => 0, |
||
| 489 | 'description' => __( 'Enabling the rest day will add an item called "Rest" with no links.', 'lsx-health-plan' ), |
||
| 490 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
||
| 491 | ) |
||
| 492 | ); |
||
| 493 | } |
||
| 494 | |||
| 495 | if ( post_type_exists( 'meal' ) ) { |
||
| 496 | $cmb->add_group_field( |
||
| 497 | $group, |
||
| 498 | array( |
||
| 499 | 'name' => __( 'Meals', 'lsx-health-plan' ), |
||
| 500 | 'desc' => __( 'Connect the meal(s) that apply to this section.', 'lsx-health-plan' ), |
||
| 501 | 'id' => 'connected_meals', |
||
| 502 | 'type' => 'post_search_ajax', |
||
| 503 | // Optional : |
||
| 504 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 505 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 506 | 'query_args' => array( |
||
| 507 | 'post_type' => array( 'meal' ), |
||
| 508 | 'post_status' => array( 'publish' ), |
||
| 509 | 'posts_per_page' => -1, |
||
| 510 | ), |
||
| 511 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
||
| 512 | ) |
||
| 513 | ); |
||
| 514 | } |
||
| 515 | if ( post_type_exists( 'tip' ) ) { |
||
| 516 | $cmb->add_group_field( |
||
| 517 | $group, |
||
| 518 | array( |
||
| 519 | 'name' => __( 'Tips', 'lsx-health-plan' ), |
||
| 520 | 'id' => 'connected_tips', |
||
| 521 | 'desc' => __( 'Connect the tip(s) that apply to this section.', 'lsx-health-plan' ), |
||
| 522 | 'type' => 'post_search_ajax', |
||
| 523 | // Optional : |
||
| 524 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 525 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 526 | 'query_args' => array( |
||
| 527 | 'post_type' => array( 'tip' ), |
||
| 528 | 'post_status' => array( 'publish' ), |
||
| 529 | 'posts_per_page' => -1, |
||
| 530 | ), |
||
| 531 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
||
| 532 | ) |
||
| 533 | ); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Holds the array for the single plan breadcrumbs. |
||
| 539 | * |
||
| 540 | * @var array $crumbs |
||
| 541 | * @return array |
||
| 542 | */ |
||
| 543 | public function plan_breadcrumb_filter( $crumbs ) { |
||
| 602 | } |
||
| 603 | } |
||
| 604 |