Passed
Push — add/multiplan ( 2b4659...5fcd18 )
by Virginia
03:23
created

LSX_Team::get_instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
namespace lsx_health_plan\classes;
3
4
/**
5
 * Contains the LSX_Team functions post type
6
 *
7
 * @package lsx-health-plan
8
 */
9
class LSX_Team {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @var      object \lsx_health_plan\classes\LSX_Team()
15
	 */
16
	protected static $instance = null;
17
18
	/**
19
	 * Constructor.
20
	 */
21
	public function __construct() {
22
		$this->default_types = array(
0 ignored issues
show
Bug Best Practice introduced by
The property default_types does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
			\lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' ),
24
			\lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ),
25
			\lsx_health_plan\functions\get_option( 'endpoint_recipe_single', 'recipe' ),
26
			\lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ),
27
			\lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ),
28
		);
29
		add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 );
30
		add_action( 'cmb2_admin_init', array( $this, 'related_team_metabox' ) );
31
	}
32
33
	/**
34
	 * Return an instance of this class.
35
	 *
36
	 * @since 1.0.0
37
	 *
38
	 * @return    object \lsx_health_plan\classes\LSX_Team()    A single instance of this class.
39
	 */
40
	public static function get_instance() {
41
		// If the single instance hasn't been set, set it now.
42
		if ( null === self::$instance ) {
43
			self::$instance = new self();
44
		}
45
		return self::$instance;
46
	}
47
48
	/**
49
	 * Load lsx team related css.
50
	 *
51
	 * @package    lsx
52
	 * @subpackage lsx-health-plan
53
	 *
54
	 */
55
	public function assets() {
56
		wp_enqueue_style( 'lsx-health-plan-team', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-team.css', array(), LSX_HEALTH_PLAN_VER );
57
	}
58
59
	/**
60
	 * Define the related team member metabox and field configurations.
61
	 */
62
	public function related_team_metabox() {
63
		foreach ( $this->default_types as $type => $default_type ) {
64
			$cmb = new_cmb2_box(
65
				array(
66
					'id'           => $default_type . '_related_team_member__metabox',
0 ignored issues
show
Bug introduced by
Are you sure $default_type of type array|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
					'id'           => /** @scrutinizer ignore-type */ $default_type . '_related_team_member__metabox',
Loading history...
67
					'title'        => __( 'Related Team Member', 'lsx-health-plan' ),
68
					'object_types' => array( $default_type ), // Post type.
69
					'context'      => 'normal',
70
					'priority'     => 'low',
71
					'show_names'   => true,
72
				)
73
			);
74
75
			$cmb->add_field(
76
				array(
77
					'name'       => __( 'Related Team Member', 'lsx-health-plan' ),
78
					'desc'       => __( 'Connect the related team member that applies to this ', 'lsx-health-plan' ) . $default_type,
79
					'id'         => $default_type . '_connected_team_member',
80
					'type'       => 'post_search_ajax',
81
					'limit'      => 4,  // Limit selection to X items only (default 1).
82
					'sortable'   => true, // Allow selected items to be sortable (default false).
83
					'query_args' => array(
84
						'post_type'      => array( 'team' ),
85
						'post_status'    => array( 'publish' ),
86
						'posts_per_page' => -1,
87
					),
88
				)
89
			);
90
		}
91
92
	}
93
94
}
95