Passed
Push — add/multiplan ( 5fcd18...02fcf7 )
by Virginia
03:32
created

LSX_Team::additional_single_team_metabox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 33
rs 9.504
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
		add_action( 'cmb2_admin_init', array( $this, 'additional_single_team_metabox' ) );
32
		add_action( 'lsx_entry_bottom', array( $this, 'hp_team_member_tabs' ) );
33
	}
34
35
	/**
36
	 * Return an instance of this class.
37
	 *
38
	 * @since 1.0.0
39
	 *
40
	 * @return    object \lsx_health_plan\classes\LSX_Team()    A single instance of this class.
41
	 */
42
	public static function get_instance() {
43
		// If the single instance hasn't been set, set it now.
44
		if ( null === self::$instance ) {
45
			self::$instance = new self();
46
		}
47
		return self::$instance;
48
	}
49
50
	/**
51
	 * Load lsx team related css.
52
	 *
53
	 * @package    lsx
54
	 * @subpackage lsx-health-plan
55
	 *
56
	 */
57
	public function assets() {
58
		wp_enqueue_style( 'lsx-health-plan-team', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-team.css', array(), LSX_HEALTH_PLAN_VER );
59
	}
60
61
	/**
62
	 * Define the related team member metabox and field configurations.
63
	 */
64
	public function related_team_metabox() {
65
		foreach ( $this->default_types as $type => $default_type ) {
66
			$cmb = new_cmb2_box(
67
				array(
68
					'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

68
					'id'           => /** @scrutinizer ignore-type */ $default_type . '_related_team_member__metabox',
Loading history...
69
					'title'        => __( 'Related Team Member', 'lsx-health-plan' ),
70
					'object_types' => array( $default_type ), // Post type.
71
					'context'      => 'normal',
72
					'priority'     => 'low',
73
					'show_names'   => true,
74
				)
75
			);
76
77
			$cmb->add_field(
78
				array(
79
					'name'       => __( 'Related Team Member', 'lsx-health-plan' ),
80
					'desc'       => __( 'Connect the related team member that applies to this ', 'lsx-health-plan' ) . $default_type,
81
					'id'         => $default_type . '_connected_team_member',
82
					'type'       => 'post_search_ajax',
83
					'limit'      => 4,  // Limit selection to X items only (default 1).
84
					'sortable'   => true, // Allow selected items to be sortable (default false).
85
					'query_args' => array(
86
						'post_type'      => array( 'team' ),
87
						'post_status'    => array( 'publish' ),
88
						'posts_per_page' => -1,
89
					),
90
				)
91
			);
92
		}
93
94
	}
95
96
	/**
97
	 * Adding additional custom fields to the single members, related with Health Plan.
98
	 */
99
	public function additional_single_team_metabox() {
100
		$cmb = new_cmb2_box(
101
			array(
102
				'id'           => 'lsx__team',
103
				'title'        => '',
104
				'object_types' => array( 'team' ), // Post type.
105
				'context'      => 'normal',
106
				'priority'     => 'high',
107
				'show_names'   => true,
108
			)
109
		);
110
111
		$cmb->add_field(
112
			array(
113
				'name'       => __( 'Team Member Experience', 'lsx-health-plan' ),
114
				'desc'       => __( 'Add additional experience to this team member', 'lsx-health-plan' ),
115
				'id'         => 'team_member_experience',
116
				'type'       => 'wysiwyg',
117
			)
118
		);
119
120
		$cmb->add_field(
121
			array(
122
				'name'       => __( 'Featured Plans', 'lsx-health-plan' ),
123
				'desc'       => __( 'Connect the related plans to this team member', 'lsx-health-plan' ),
124
				'id'         => 'connected_team_member_plan',
125
				'type'       => 'post_search_ajax',
126
				'limit'      => 3,
127
				'sortable'   => true,
128
				'query_args' => array(
129
					'post_type'      => array( 'plan' ),
130
					'post_status'    => array( 'publish' ),
131
					'posts_per_page' => -1,
132
				),
133
			)
134
		);
135
136
	}
137
138
	/**
139
	 * Adds custom tabs to the team member single pages.
140
	 *
141
	 * @return void
142
	 */
143
	public function hp_team_member_tabs() {
144
		if ( is_single() && is_singular( 'team' ) ) {
145
			require_once LSX_HEALTH_PLAN_PATH . '/includes/template-tags/team.php';
146
		}	
147
	}
148
149
}
150