Passed
Push — add/multiplan ( d12ed5...af87c7 )
by Warwick
04:00
created
classes/post-types/class-tip.php 2 patches
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -14,152 +14,152 @@
 block discarded – undo
14 14
  */
15 15
 class Tip {
16 16
 
17
-	/**
18
-	 * Holds class instance
19
-	 *
20
-	 * @since 1.0.0
21
-	 *
22
-	 * @var      object \lsx_health_plan\classes\Tip()
23
-	 */
24
-	protected static $instance = null;
17
+     /**
18
+      * Holds class instance
19
+      *
20
+      * @since 1.0.0
21
+      *
22
+      * @var      object \lsx_health_plan\classes\Tip()
23
+      */
24
+     protected static $instance = null;
25 25
 
26
-	/**
27
-	 * Holds post_type slug used as an index
28
-	 *
29
-	 * @since 1.0.0
30
-	 *
31
-	 * @var      string
32
-	 */
33
-	public $slug = 'tip';
26
+     /**
27
+      * Holds post_type slug used as an index
28
+      *
29
+      * @since 1.0.0
30
+      *
31
+      * @var      string
32
+      */
33
+     public $slug = 'tip';
34 34
 
35
-	/**
36
-	 * Constructor
37
-	 */
38
-	public function __construct() {
39
-		$this->default_types = array(
40
-			\lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' ),
41
-			\lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ),
42
-			\lsx_health_plan\functions\get_option( 'endpoint_recipe_single', 'recipe' ),
43
-			\lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ),
44
-			\lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ),
45
-		);
46
-		add_action( 'init', array( $this, 'register_post_type' ) );
47
-		add_action( 'admin_menu', array( $this, 'register_menus' ) );
48
-		add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 );
49
-		add_action( 'cmb2_admin_init', array( $this, 'tips_connections' ), 15 );
50
-	}
35
+     /**
36
+      * Constructor
37
+      */
38
+     public function __construct() {
39
+          $this->default_types = array(
40
+               \lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' ),
41
+               \lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ),
42
+               \lsx_health_plan\functions\get_option( 'endpoint_recipe_single', 'recipe' ),
43
+               \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ),
44
+               \lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ),
45
+          );
46
+          add_action( 'init', array( $this, 'register_post_type' ) );
47
+          add_action( 'admin_menu', array( $this, 'register_menus' ) );
48
+          add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 );
49
+          add_action( 'cmb2_admin_init', array( $this, 'tips_connections' ), 15 );
50
+     }
51 51
 
52
-	/**
53
-	 * Return an instance of this class.
54
-	 *
55
-	 * @since 1.0.0
56
-	 *
57
-	 * @return    object \lsx_health_plan\classes\Tip()    A single instance of this class.
58
-	 */
59
-	public static function get_instance() {
60
-		// If the single instance hasn't been set, set it now.
61
-		if ( null === self::$instance ) {
62
-			self::$instance = new self();
63
-		}
64
-		return self::$instance;
65
-	}
66
-	/**
67
-	 * Register the post type.
68
-	 */
69
-	public function register_post_type() {
70
-		$labels = array(
71
-			'name'               => esc_html__( 'Tips', 'lsx-health-plan' ),
72
-			'singular_name'      => esc_html__( 'Tip', 'lsx-health-plan' ),
73
-			'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ),
74
-			'add_new_item'       => esc_html__( 'Add New', 'lsx-health-plan' ),
75
-			'edit_item'          => esc_html__( 'Edit', 'lsx-health-plan' ),
76
-			'new_item'           => esc_html__( 'New', 'lsx-health-plan' ),
77
-			'all_items'          => esc_html__( 'All Tips', 'lsx-health-plan' ),
78
-			'view_item'          => esc_html__( 'View', 'lsx-health-plan' ),
79
-			'search_items'       => esc_html__( 'Search', 'lsx-health-plan' ),
80
-			'not_found'          => esc_html__( 'None found', 'lsx-health-plan' ),
81
-			'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ),
82
-			'parent_item_colon'  => '',
83
-			'menu_name'          => esc_html__( 'Tips', 'lsx-health-plan' ),
84
-		);
85
-		$args   = array(
86
-			'labels'             => $labels,
87
-			'public'             => true,
88
-			'publicly_queryable' => false,
89
-			'show_ui'            => true,
90
-			'show_in_menu'       => false,
91
-			'show_in_rest'       => true,
92
-			'menu_icon'          => 'dashicons-admin-post',
93
-			'query_var'          => true,
94
-			'rewrite'            => false,
95
-			'capability_type'    => 'post',
96
-			'has_archive'        => false,
97
-			'hierarchical'       => false,
98
-			'menu_position'      => null,
99
-			'supports'           => array(
100
-				'title',
101
-				'editor',
102
-				'thumbnail',
103
-				'custom-fields',
104
-			),
105
-		);
106
-		register_post_type( 'tip', $args );
107
-	}
52
+     /**
53
+      * Return an instance of this class.
54
+      *
55
+      * @since 1.0.0
56
+      *
57
+      * @return    object \lsx_health_plan\classes\Tip()    A single instance of this class.
58
+      */
59
+     public static function get_instance() {
60
+          // If the single instance hasn't been set, set it now.
61
+          if ( null === self::$instance ) {
62
+               self::$instance = new self();
63
+          }
64
+          return self::$instance;
65
+     }
66
+     /**
67
+      * Register the post type.
68
+      */
69
+     public function register_post_type() {
70
+          $labels = array(
71
+               'name'               => esc_html__( 'Tips', 'lsx-health-plan' ),
72
+               'singular_name'      => esc_html__( 'Tip', 'lsx-health-plan' ),
73
+               'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ),
74
+               'add_new_item'       => esc_html__( 'Add New', 'lsx-health-plan' ),
75
+               'edit_item'          => esc_html__( 'Edit', 'lsx-health-plan' ),
76
+               'new_item'           => esc_html__( 'New', 'lsx-health-plan' ),
77
+               'all_items'          => esc_html__( 'All Tips', 'lsx-health-plan' ),
78
+               'view_item'          => esc_html__( 'View', 'lsx-health-plan' ),
79
+               'search_items'       => esc_html__( 'Search', 'lsx-health-plan' ),
80
+               'not_found'          => esc_html__( 'None found', 'lsx-health-plan' ),
81
+               'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ),
82
+               'parent_item_colon'  => '',
83
+               'menu_name'          => esc_html__( 'Tips', 'lsx-health-plan' ),
84
+          );
85
+          $args   = array(
86
+               'labels'             => $labels,
87
+               'public'             => true,
88
+               'publicly_queryable' => false,
89
+               'show_ui'            => true,
90
+               'show_in_menu'       => false,
91
+               'show_in_rest'       => true,
92
+               'menu_icon'          => 'dashicons-admin-post',
93
+               'query_var'          => true,
94
+               'rewrite'            => false,
95
+               'capability_type'    => 'post',
96
+               'has_archive'        => false,
97
+               'hierarchical'       => false,
98
+               'menu_position'      => null,
99
+               'supports'           => array(
100
+                    'title',
101
+                    'editor',
102
+                    'thumbnail',
103
+                    'custom-fields',
104
+               ),
105
+          );
106
+          register_post_type( 'tip', $args );
107
+     }
108 108
 
109
-	/**
110
-	 * Registers the Recipes under the Meals Post type menu.
111
-	 *
112
-	 * @return void
113
-	 */
114
-	public function register_menus() {
115
-		add_submenu_page( 'edit.php?post_type=plan', esc_html__( 'Tips', 'lsx-health-plan' ), esc_html__( 'Tips', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=tip' );
116
-	}
109
+     /**
110
+      * Registers the Recipes under the Meals Post type menu.
111
+      *
112
+      * @return void
113
+      */
114
+     public function register_menus() {
115
+          add_submenu_page( 'edit.php?post_type=plan', esc_html__( 'Tips', 'lsx-health-plan' ), esc_html__( 'Tips', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=tip' );
116
+     }
117 117
 
118
-	/**
119
-	 * Enables the Bi Directional relationships
120
-	 *
121
-	 * @param array $connections
122
-	 * @return void
123
-	 */
124
-	public function enable_connections( $connections = array() ) {
125
-		$connections['tip']['connected_plans']      = 'plan_connected_tips';
126
-		$connections['plan']['plan_connected_tips'] = 'connected_plans';
127
-		return $connections;
128
-	}
118
+     /**
119
+      * Enables the Bi Directional relationships
120
+      *
121
+      * @param array $connections
122
+      * @return void
123
+      */
124
+     public function enable_connections( $connections = array() ) {
125
+          $connections['tip']['connected_plans']      = 'plan_connected_tips';
126
+          $connections['plan']['plan_connected_tips'] = 'connected_plans';
127
+          return $connections;
128
+     }
129 129
 
130
-	/**
131
-	 * Registers the workout connections on the plan post type.
132
-	 *
133
-	 * @return void
134
-	 */
135
-	public function tips_connections() {
136
-		foreach ( $this->default_types as $type => $default_type ) {
137
-			$cmb = new_cmb2_box(
138
-				array(
139
-					'id'           => $default_type . '_tips_connections_metabox',
140
-					'title'        => __( 'Related Tips', 'lsx-health-plan' ),
141
-					'object_types' => array( $default_type ), // Post types.
142
-					'context'      => 'normal',
143
-					'priority'     => 'high',
144
-					'show_names'   => false,
145
-				)
146
-			);
147
-			$cmb->add_field(
148
-				array(
149
-					'name'       => __( 'Tips', 'lsx-health-plan' ),
150
-					'id'         => $default_type . '_connected_tips',
151
-					'desc'       => __( 'Connect the tips that apply to this', 'lsx-health-plan' ) . $default_type,
152
-					'type'       => 'post_search_ajax',
153
-					'limit'      => 15,
154
-					'sortable'   => true,
155
-					'query_args' => array(
156
-						'post_type'      => array( 'tip' ),
157
-						'post_status'    => array( 'publish' ),
158
-						'posts_per_page' => -1,
159
-					),
160
-				)
161
-			);
162
-		}
163
-	}
130
+     /**
131
+      * Registers the workout connections on the plan post type.
132
+      *
133
+      * @return void
134
+      */
135
+     public function tips_connections() {
136
+          foreach ( $this->default_types as $type => $default_type ) {
137
+               $cmb = new_cmb2_box(
138
+                    array(
139
+                         'id'           => $default_type . '_tips_connections_metabox',
140
+                         'title'        => __( 'Related Tips', 'lsx-health-plan' ),
141
+                         'object_types' => array( $default_type ), // Post types.
142
+                         'context'      => 'normal',
143
+                         'priority'     => 'high',
144
+                         'show_names'   => false,
145
+                    )
146
+               );
147
+               $cmb->add_field(
148
+                    array(
149
+                         'name'       => __( 'Tips', 'lsx-health-plan' ),
150
+                         'id'         => $default_type . '_connected_tips',
151
+                         'desc'       => __( 'Connect the tips that apply to this', 'lsx-health-plan' ) . $default_type,
152
+                         'type'       => 'post_search_ajax',
153
+                         'limit'      => 15,
154
+                         'sortable'   => true,
155
+                         'query_args' => array(
156
+                              'post_type'      => array( 'tip' ),
157
+                              'post_status'    => array( 'publish' ),
158
+                              'posts_per_page' => -1,
159
+                         ),
160
+                    )
161
+               );
162
+          }
163
+     }
164 164
 
165 165
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	public function __construct() {
39 39
 		$this->default_types = array(
40
-			\lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' ),
41
-			\lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ),
42
-			\lsx_health_plan\functions\get_option( 'endpoint_recipe_single', 'recipe' ),
43
-			\lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ),
44
-			\lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ),
40
+			\lsx_health_plan\functions\get_option('endpoint_meal', 'meal'),
41
+			\lsx_health_plan\functions\get_option('endpoint_exercise_single', 'exercise'),
42
+			\lsx_health_plan\functions\get_option('endpoint_recipe_single', 'recipe'),
43
+			\lsx_health_plan\functions\get_option('endpoint_workout', 'workout'),
44
+			\lsx_health_plan\functions\get_option('endpoint_plan', 'plan'),
45 45
 		);
46
-		add_action( 'init', array( $this, 'register_post_type' ) );
47
-		add_action( 'admin_menu', array( $this, 'register_menus' ) );
48
-		add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 );
49
-		add_action( 'cmb2_admin_init', array( $this, 'tips_connections' ), 15 );
46
+		add_action('init', array($this, 'register_post_type'));
47
+		add_action('admin_menu', array($this, 'register_menus'));
48
+		add_filter('lsx_health_plan_connections', array($this, 'enable_connections'), 10, 1);
49
+		add_action('cmb2_admin_init', array($this, 'tips_connections'), 15);
50 50
 	}
51 51
 
52 52
 	/**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	public static function get_instance() {
60 60
 		// If the single instance hasn't been set, set it now.
61
-		if ( null === self::$instance ) {
61
+		if (null === self::$instance) {
62 62
 			self::$instance = new self();
63 63
 		}
64 64
 		return self::$instance;
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function register_post_type() {
70 70
 		$labels = array(
71
-			'name'               => esc_html__( 'Tips', 'lsx-health-plan' ),
72
-			'singular_name'      => esc_html__( 'Tip', 'lsx-health-plan' ),
73
-			'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ),
74
-			'add_new_item'       => esc_html__( 'Add New', 'lsx-health-plan' ),
75
-			'edit_item'          => esc_html__( 'Edit', 'lsx-health-plan' ),
76
-			'new_item'           => esc_html__( 'New', 'lsx-health-plan' ),
77
-			'all_items'          => esc_html__( 'All Tips', 'lsx-health-plan' ),
78
-			'view_item'          => esc_html__( 'View', 'lsx-health-plan' ),
79
-			'search_items'       => esc_html__( 'Search', 'lsx-health-plan' ),
80
-			'not_found'          => esc_html__( 'None found', 'lsx-health-plan' ),
81
-			'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ),
71
+			'name'               => esc_html__('Tips', 'lsx-health-plan'),
72
+			'singular_name'      => esc_html__('Tip', 'lsx-health-plan'),
73
+			'add_new'            => esc_html_x('Add New', 'post type general name', 'lsx-health-plan'),
74
+			'add_new_item'       => esc_html__('Add New', 'lsx-health-plan'),
75
+			'edit_item'          => esc_html__('Edit', 'lsx-health-plan'),
76
+			'new_item'           => esc_html__('New', 'lsx-health-plan'),
77
+			'all_items'          => esc_html__('All Tips', 'lsx-health-plan'),
78
+			'view_item'          => esc_html__('View', 'lsx-health-plan'),
79
+			'search_items'       => esc_html__('Search', 'lsx-health-plan'),
80
+			'not_found'          => esc_html__('None found', 'lsx-health-plan'),
81
+			'not_found_in_trash' => esc_html__('None found in Trash', 'lsx-health-plan'),
82 82
 			'parent_item_colon'  => '',
83
-			'menu_name'          => esc_html__( 'Tips', 'lsx-health-plan' ),
83
+			'menu_name'          => esc_html__('Tips', 'lsx-health-plan'),
84 84
 		);
85
-		$args   = array(
85
+		$args = array(
86 86
 			'labels'             => $labels,
87 87
 			'public'             => true,
88 88
 			'publicly_queryable' => false,
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 				'custom-fields',
104 104
 			),
105 105
 		);
106
-		register_post_type( 'tip', $args );
106
+		register_post_type('tip', $args);
107 107
 	}
108 108
 
109 109
 	/**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return void
113 113
 	 */
114 114
 	public function register_menus() {
115
-		add_submenu_page( 'edit.php?post_type=plan', esc_html__( 'Tips', 'lsx-health-plan' ), esc_html__( 'Tips', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=tip' );
115
+		add_submenu_page('edit.php?post_type=plan', esc_html__('Tips', 'lsx-health-plan'), esc_html__('Tips', 'lsx-health-plan'), 'edit_posts', 'edit.php?post_type=tip');
116 116
 	}
117 117
 
118 118
 	/**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @param array $connections
122 122
 	 * @return void
123 123
 	 */
124
-	public function enable_connections( $connections = array() ) {
124
+	public function enable_connections($connections = array()) {
125 125
 		$connections['tip']['connected_plans']      = 'plan_connected_tips';
126 126
 		$connections['plan']['plan_connected_tips'] = 'connected_plans';
127 127
 		return $connections;
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
 	 * @return void
134 134
 	 */
135 135
 	public function tips_connections() {
136
-		foreach ( $this->default_types as $type => $default_type ) {
136
+		foreach ($this->default_types as $type => $default_type) {
137 137
 			$cmb = new_cmb2_box(
138 138
 				array(
139 139
 					'id'           => $default_type . '_tips_connections_metabox',
140
-					'title'        => __( 'Related Tips', 'lsx-health-plan' ),
141
-					'object_types' => array( $default_type ), // Post types.
140
+					'title'        => __('Related Tips', 'lsx-health-plan'),
141
+					'object_types' => array($default_type), // Post types.
142 142
 					'context'      => 'normal',
143 143
 					'priority'     => 'high',
144 144
 					'show_names'   => false,
@@ -146,15 +146,15 @@  discard block
 block discarded – undo
146 146
 			);
147 147
 			$cmb->add_field(
148 148
 				array(
149
-					'name'       => __( 'Tips', 'lsx-health-plan' ),
149
+					'name'       => __('Tips', 'lsx-health-plan'),
150 150
 					'id'         => $default_type . '_connected_tips',
151
-					'desc'       => __( 'Connect the tips that apply to this', 'lsx-health-plan' ) . $default_type,
151
+					'desc'       => __('Connect the tips that apply to this', 'lsx-health-plan') . $default_type,
152 152
 					'type'       => 'post_search_ajax',
153 153
 					'limit'      => 15,
154 154
 					'sortable'   => true,
155 155
 					'query_args' => array(
156
-						'post_type'      => array( 'tip' ),
157
-						'post_status'    => array( 'publish' ),
156
+						'post_type'      => array('tip'),
157
+						'post_status'    => array('publish'),
158 158
 						'posts_per_page' => -1,
159 159
 					),
160 160
 				)
Please login to merge, or discard this patch.
includes/functions.php 2 patches
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -17,27 +17,27 @@  discard block
 block discarded – undo
17 17
  * @return boolean
18 18
  */
19 19
 function has_attached_post( $post_id = '', $meta_key = '', $single = true ) {
20
-	$has_post = false;
21
-	if ( '' === $post_id ) {
22
-		$post_id = get_the_ID();
23
-	}
24
-	$items = get_post_meta( $post_id, $meta_key, $single );
25
-	if ( '' !== $items && false !== $items && 0 !== $items ) {
26
-		if ( ! is_array( $items ) ) {
27
-			$items = array( $items );
28
-		}
29
-		$items = check_posts_exist( $items );
30
-		if ( ! empty( $items ) ) {
31
-			$has_post = true;
32
-		}
33
-	} else {
34
-		// Check for defaults.
35
-		$options = get_option( 'all' );
36
-		if ( isset( $options[ $meta_key ] ) && '' !== $options[ $meta_key ] && ! empty( $options[ $meta_key ] ) ) {
37
-			$has_post = true;
38
-		}
39
-	}
40
-	return $has_post;
20
+     $has_post = false;
21
+     if ( '' === $post_id ) {
22
+          $post_id = get_the_ID();
23
+     }
24
+     $items = get_post_meta( $post_id, $meta_key, $single );
25
+     if ( '' !== $items && false !== $items && 0 !== $items ) {
26
+          if ( ! is_array( $items ) ) {
27
+               $items = array( $items );
28
+          }
29
+          $items = check_posts_exist( $items );
30
+          if ( ! empty( $items ) ) {
31
+               $has_post = true;
32
+          }
33
+     } else {
34
+          // Check for defaults.
35
+          $options = get_option( 'all' );
36
+          if ( isset( $options[ $meta_key ] ) && '' !== $options[ $meta_key ] && ! empty( $options[ $meta_key ] ) ) {
37
+               $has_post = true;
38
+          }
39
+     }
40
+     return $has_post;
41 41
 }
42 42
 
43 43
 /**
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
  * @return mixed           Option value
49 49
  */
50 50
 function get_option( $key = '', $default = false ) {
51
-	if ( function_exists( 'cmb2_get_option' ) ) {
52
-		return cmb2_get_option( 'lsx_health_plan_options', $key, $default );
53
-	}
54
-	// Fallback to get_option if CMB2 is not loaded yet.
55
-	$opts = \get_option( 'lsx_health_plan_options', $default );
56
-	$val  = $default;
57
-	if ( 'all' === $key ) {
58
-		$val = $opts;
59
-	} elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
60
-		$val = $opts[ $key ];
61
-	}
62
-	return $val;
51
+     if ( function_exists( 'cmb2_get_option' ) ) {
52
+          return cmb2_get_option( 'lsx_health_plan_options', $key, $default );
53
+     }
54
+     // Fallback to get_option if CMB2 is not loaded yet.
55
+     $opts = \get_option( 'lsx_health_plan_options', $default );
56
+     $val  = $default;
57
+     if ( 'all' === $key ) {
58
+          $val = $opts;
59
+     } elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
60
+          $val = $opts[ $key ];
61
+     }
62
+     return $val;
63 63
 }
64 64
 
65 65
 /**
@@ -70,54 +70,54 @@  discard block
 block discarded – undo
70 70
  * @return mixed           Option value
71 71
  */
72 72
 function get_downloads( $type = 'all', $post_id = '' ) {
73
-	$lsx_health_plan = \lsx_health_plan();
74
-	$post_types      = $lsx_health_plan->get_post_types();
75
-	if ( '' === $post_id ) {
76
-		$post_id = get_the_ID();
77
-	}
78
-	$downloads = array();
79
-	$options   = get_option( 'all' );
80
-
81
-	foreach ( $post_types as $post_type ) {
82
-		if ( 'all' === $type || in_array( $type, $post_types, true ) ) {
83
-
84
-			// Get the default downloads for this post type.
85
-			$default_downloads = array();
86
-			$new_downloads     = array();
87
-			if ( isset( $options[ 'download_' . $post_type ] ) ) {
88
-				if ( is_array( $options[ 'download_' . $post_type ] ) ) {
89
-					$default_downloads = $options[ 'download_' . $post_type ];
90
-				} else {
91
-					$default_downloads[] = $options[ 'download_' . $post_type ];
92
-				}
93
-			}
94
-
95
-			if ( 'page' === $post_type ) {
96
-				$key = 'plan_warmup';
97
-			} else {
98
-				$key = 'connected_' . $post_type . 's';
99
-			}
100
-
101
-			$connected_items = get_post_meta( $post_id, $key, true );
102
-			if ( ! empty( $connected_items ) ) {
103
-				foreach ( $connected_items as $connected_item ) {
104
-					$current_downloads = get_post_meta( $connected_item, 'connected_downloads', true );
105
-					if ( false !== $current_downloads && ! empty( $current_downloads ) ) {
106
-						$new_downloads = array_merge( $new_downloads, $current_downloads );
107
-					}
108
-				}
109
-			}
110
-
111
-			if ( ! empty( $new_downloads ) ) {
112
-				$downloads = array_merge( $downloads, $new_downloads );
113
-			} elseif ( ! empty( $default_downloads ) ) {
114
-				$downloads = array_merge( $downloads, $default_downloads );
115
-			}
116
-			$downloads = array_unique( $downloads );
117
-		}
118
-	}
119
-	$downloads = check_posts_exist( $downloads );
120
-	return $downloads;
73
+     $lsx_health_plan = \lsx_health_plan();
74
+     $post_types      = $lsx_health_plan->get_post_types();
75
+     if ( '' === $post_id ) {
76
+          $post_id = get_the_ID();
77
+     }
78
+     $downloads = array();
79
+     $options   = get_option( 'all' );
80
+
81
+     foreach ( $post_types as $post_type ) {
82
+          if ( 'all' === $type || in_array( $type, $post_types, true ) ) {
83
+
84
+               // Get the default downloads for this post type.
85
+               $default_downloads = array();
86
+               $new_downloads     = array();
87
+               if ( isset( $options[ 'download_' . $post_type ] ) ) {
88
+                    if ( is_array( $options[ 'download_' . $post_type ] ) ) {
89
+                         $default_downloads = $options[ 'download_' . $post_type ];
90
+                    } else {
91
+                         $default_downloads[] = $options[ 'download_' . $post_type ];
92
+                    }
93
+               }
94
+
95
+               if ( 'page' === $post_type ) {
96
+                    $key = 'plan_warmup';
97
+               } else {
98
+                    $key = 'connected_' . $post_type . 's';
99
+               }
100
+
101
+               $connected_items = get_post_meta( $post_id, $key, true );
102
+               if ( ! empty( $connected_items ) ) {
103
+                    foreach ( $connected_items as $connected_item ) {
104
+                         $current_downloads = get_post_meta( $connected_item, 'connected_downloads', true );
105
+                         if ( false !== $current_downloads && ! empty( $current_downloads ) ) {
106
+                              $new_downloads = array_merge( $new_downloads, $current_downloads );
107
+                         }
108
+                    }
109
+               }
110
+
111
+               if ( ! empty( $new_downloads ) ) {
112
+                    $downloads = array_merge( $downloads, $new_downloads );
113
+               } elseif ( ! empty( $default_downloads ) ) {
114
+                    $downloads = array_merge( $downloads, $default_downloads );
115
+               }
116
+               $downloads = array_unique( $downloads );
117
+          }
118
+     }
119
+     $downloads = check_posts_exist( $downloads );
120
+     return $downloads;
121 121
 }
122 122
 
123 123
 /**
@@ -127,35 +127,35 @@  discard block
 block discarded – undo
127 127
  * @return array           an array of the downloads or empty.
128 128
  */
129 129
 function get_weekly_downloads( $week = '' ) {
130
-	$downloads = array();
131
-	if ( '' !== $week ) {
132
-		$saved_downloads = get_transient( 'lsx_hp_weekly_downloads_' . $week );
133
-		if ( false !== $saved_downloads && ! empty( $saved_downloads ) ) {
134
-			$downloads = $saved_downloads;
135
-		} else {
136
-			$args = array(
137
-				'orderby'        => 'title',
138
-				'order'          => 'ASC',
139
-				'post_type'      => 'dlm_download',
140
-				'posts_per_page' => -1,
141
-				'nopagin'        => true,
142
-				'fields'         => 'ids',
143
-				'tax_query'      => array(
144
-					array(
145
-						'taxonomy' => 'dlm_download_category',
146
-						'field'    => 'slug',
147
-						'terms'    => array( $week ),
148
-					),
149
-				),
150
-			);
151
-			$download_query = new \WP_Query( $args );
152
-			if ( $download_query->have_posts() ) {
153
-				$downloads = $download_query->posts;
154
-			}
155
-		}
156
-	}
157
-	$downloads = check_posts_exist( $downloads );
158
-	return $downloads;
130
+     $downloads = array();
131
+     if ( '' !== $week ) {
132
+          $saved_downloads = get_transient( 'lsx_hp_weekly_downloads_' . $week );
133
+          if ( false !== $saved_downloads && ! empty( $saved_downloads ) ) {
134
+               $downloads = $saved_downloads;
135
+          } else {
136
+               $args = array(
137
+                    'orderby'        => 'title',
138
+                    'order'          => 'ASC',
139
+                    'post_type'      => 'dlm_download',
140
+                    'posts_per_page' => -1,
141
+                    'nopagin'        => true,
142
+                    'fields'         => 'ids',
143
+                    'tax_query'      => array(
144
+                         array(
145
+                              'taxonomy' => 'dlm_download_category',
146
+                              'field'    => 'slug',
147
+                              'terms'    => array( $week ),
148
+                         ),
149
+                    ),
150
+               );
151
+               $download_query = new \WP_Query( $args );
152
+               if ( $download_query->have_posts() ) {
153
+                    $downloads = $download_query->posts;
154
+               }
155
+          }
156
+     }
157
+     $downloads = check_posts_exist( $downloads );
158
+     return $downloads;
159 159
 }
160 160
 
161 161
 /**
@@ -165,22 +165,22 @@  discard block
 block discarded – undo
165 165
  * @return void
166 166
  */
167 167
 function check_posts_exist( $post_ids = array() ) {
168
-	$new_ids = array();
169
-	global $wpdb;
170
-	if ( is_array( $post_ids ) && ! empty( $post_ids ) ) {
171
-		$post_ids = "'" . implode( "','", $post_ids ) . "'";
172
-		$query    = "
168
+     $new_ids = array();
169
+     global $wpdb;
170
+     if ( is_array( $post_ids ) && ! empty( $post_ids ) ) {
171
+          $post_ids = "'" . implode( "','", $post_ids ) . "'";
172
+          $query    = "
173 173
 			SELECT `ID` 
174 174
 			FROM `{$wpdb->posts}`
175 175
 			WHERE `ID` IN ({$post_ids})
176 176
 			AND `post_status` != 'trash'
177 177
 		";
178
-		$results = $wpdb->get_results( $query ); // WPCS: unprepared SQL
179
-		if ( ! empty( $results ) ) {
180
-			$new_ids = wp_list_pluck( $results, 'ID' );
181
-		}
182
-	}
183
-	return $new_ids;
178
+          $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL
179
+          if ( ! empty( $results ) ) {
180
+               $new_ids = wp_list_pluck( $results, 'ID' );
181
+          }
182
+     }
183
+     return $new_ids;
184 184
 }
185 185
 
186 186
 /**
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
  * @return void
193 193
  */
194 194
 function register_modal( $id = '', $title = '', $body = '' ) {
195
-	lsx_health_plan()->frontend->modals->register_modal(
196
-		array(
197
-			'title' => $title,
198
-			'body'  => $body,
199
-		),
200
-		$id
201
-	);
195
+     lsx_health_plan()->frontend->modals->register_modal(
196
+          array(
197
+               'title' => $title,
198
+               'body'  => $body,
199
+          ),
200
+          $id
201
+     );
202 202
 }
203 203
 
204 204
 /**
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
  * @return void
209 209
  */
210 210
 function output_modal( $args = array() ) {
211
-	$defaults = array(
212
-		'id'    => '',
213
-		'title' => '',
214
-		'body'  => '',
215
-	);
216
-	$args     = wp_parse_args( $args, $defaults );
217
-	?>
211
+     $defaults = array(
212
+          'id'    => '',
213
+          'title' => '',
214
+          'body'  => '',
215
+     );
216
+     $args     = wp_parse_args( $args, $defaults );
217
+     ?>
218 218
 	<!-- Modal -->
219 219
 	<div class="modal fade lsx-health-plan-modal" id="<?php echo esc_html( $args['id'] ); ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo esc_html( $args['id'] ); ?>"  aria-hidden="true">
220 220
 		<div class="modal-dialog" role="document">
@@ -222,36 +222,36 @@  discard block
 block discarded – undo
222 222
 			<button type="button" class="close" data-dismiss="modal">&times;</button>			
223 223
 				<div class="modal-header">
224 224
 					<?php
225
-					if ( '' !== $args['title'] ) {
226
-						echo wp_kses_post( '<h2>' . $args['title'] . '</h2>' );
227
-					}
228
-					?>
225
+                         if ( '' !== $args['title'] ) {
226
+                              echo wp_kses_post( '<h2>' . $args['title'] . '</h2>' );
227
+                         }
228
+                         ?>
229 229
 				</div>
230 230
 				<div class="modal-body">
231 231
 				<?php
232
-				if ( '' !== $args['body'] ) {
233
-					$allowed_html = array(
234
-						'iframe' => array(
235
-							'data-src'        => array(),
236
-							'src'             => array(),
237
-							'width'           => array(),
238
-							'height'          => array(),
239
-							'frameBorder'     => array( '0' ),
240
-							'class'           => array(),
241
-							'allowFullScreen' => array(),
242
-							'style'           => array(),
243
-						),
244
-						'h5'     => array(
245
-							'class' => array(),
246
-						),
247
-					);
248
-					if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) {
249
-						echo wp_kses_post( $args['body'] );
250
-					} else {
251
-						echo wp_kses( $args['body'], $allowed_html );
252
-					}
253
-				}
254
-				?>
232
+                    if ( '' !== $args['body'] ) {
233
+                         $allowed_html = array(
234
+                              'iframe' => array(
235
+                                   'data-src'        => array(),
236
+                                   'src'             => array(),
237
+                                   'width'           => array(),
238
+                                   'height'          => array(),
239
+                                   'frameBorder'     => array( '0' ),
240
+                                   'class'           => array(),
241
+                                   'allowFullScreen' => array(),
242
+                                   'style'           => array(),
243
+                              ),
244
+                              'h5'     => array(
245
+                                   'class' => array(),
246
+                              ),
247
+                         );
248
+                         if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) {
249
+                              echo wp_kses_post( $args['body'] );
250
+                         } else {
251
+                              echo wp_kses( $args['body'], $allowed_html );
252
+                         }
253
+                    }
254
+                    ?>
255 255
 				</div>
256 256
 			</div>
257 257
 		</div>
@@ -267,18 +267,18 @@  discard block
 block discarded – undo
267 267
  * @return void
268 268
  */
269 269
 function get_video_url( $embed ) {
270
-	$url = '';
271
-	if ( false !== stripos( $embed, '<iframe' ) ) {
272
-		preg_match( '/src="([^"]+)"/', $embed, $match );
273
-		if ( is_array( $match ) && isset( $match[1] ) ) {
274
-			$url = '<iframe data-src="' . $match[1] . '" style="border: 0;" frameBorder="0" class="giphy-embed" allowFullScreen height="300" width="100%"></iframe>';
275
-		} else {
276
-			$url = $embed;
277
-		}
278
-	} else {
279
-		$url = $embed;
280
-	}
281
-	return $url;
270
+     $url = '';
271
+     if ( false !== stripos( $embed, '<iframe' ) ) {
272
+          preg_match( '/src="([^"]+)"/', $embed, $match );
273
+          if ( is_array( $match ) && isset( $match[1] ) ) {
274
+               $url = '<iframe data-src="' . $match[1] . '" style="border: 0;" frameBorder="0" class="giphy-embed" allowFullScreen height="300" width="100%"></iframe>';
275
+          } else {
276
+               $url = $embed;
277
+          }
278
+     } else {
279
+          $url = $embed;
280
+     }
281
+     return $url;
282 282
 }
283 283
 
284 284
 /**
@@ -289,18 +289,18 @@  discard block
 block discarded – undo
289 289
  * @return boolean
290 290
  */
291 291
 function is_week_complete( $term_id = false, $section_keys = array(), $group_title = '' ) {
292
-	$return = false;
293
-	if ( ! empty( $section_keys ) ) {
294
-		$group_count = count( $section_keys );
295
-		foreach ( $section_keys as &$pid ) {
296
-			$pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id( $pid ) . '_complete';
297
-		}
298
-		$days_complete = get_meta_amounts( $section_keys );
299
-		if ( (int) $group_count === (int) $days_complete ) {
300
-			$return = true;
301
-		}
302
-	}
303
-	return $return;
292
+     $return = false;
293
+     if ( ! empty( $section_keys ) ) {
294
+          $group_count = count( $section_keys );
295
+          foreach ( $section_keys as &$pid ) {
296
+               $pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id( $pid ) . '_complete';
297
+          }
298
+          $days_complete = get_meta_amounts( $section_keys );
299
+          if ( (int) $group_count === (int) $days_complete ) {
300
+               $return = true;
301
+          }
302
+     }
303
+     return $return;
304 304
 }
305 305
 
306 306
 /**
@@ -311,23 +311,23 @@  discard block
 block discarded – undo
311 311
  * @return void
312 312
  */
313 313
 function get_meta_amounts( $post_ids = array() ) {
314
-	global $wpdb;
315
-	$amount       = 0;
316
-	$current_user = wp_get_current_user();
317
-	if ( false !== $current_user && ! empty( $post_ids ) ) {
318
-		$post_ids = "'" . implode( "','", $post_ids ) . "'";
319
-		$query    = "
314
+     global $wpdb;
315
+     $amount       = 0;
316
+     $current_user = wp_get_current_user();
317
+     if ( false !== $current_user && ! empty( $post_ids ) ) {
318
+          $post_ids = "'" . implode( "','", $post_ids ) . "'";
319
+          $query    = "
320 320
 			SELECT COUNT(`meta_value`) 
321 321
 			FROM `{$wpdb->usermeta}`
322 322
 			WHERE `meta_key` IN ({$post_ids})
323 323
 			AND `user_id` = '{$current_user->ID}'
324 324
 		";
325
-		$results  = $wpdb->get_var( $query ); // WPCS: unprepared SQL
326
-		if ( ! empty( $results ) ) {
327
-			$amount = $results;
328
-		}
329
-	}
330
-	return $amount;
325
+          $results  = $wpdb->get_var( $query ); // WPCS: unprepared SQL
326
+          if ( ! empty( $results ) ) {
327
+               $amount = $results;
328
+          }
329
+     }
330
+     return $amount;
331 331
 }
332 332
 
333 333
 /**
@@ -337,39 +337,39 @@  discard block
 block discarded – undo
337 337
  * @return void
338 338
  */
339 339
 function hp_get_plan_type_meta( $post ) {
340
-	$plan_meta = '';
340
+     $plan_meta = '';
341 341
 
342
-	$term_obj_list = get_the_terms( $post->ID, 'plan-type' );
343
-	if ( false !== $term_obj_list ) {
344
-		$terms_string  = join( ' & ', wp_list_pluck( $term_obj_list, 'name' ) );
345
-		$terms_ids     = wp_list_pluck( $term_obj_list, 'term_id' );
342
+     $term_obj_list = get_the_terms( $post->ID, 'plan-type' );
343
+     if ( false !== $term_obj_list ) {
344
+          $terms_string  = join( ' & ', wp_list_pluck( $term_obj_list, 'name' ) );
345
+          $terms_ids     = wp_list_pluck( $term_obj_list, 'term_id' );
346 346
 
347
-		foreach ( $terms_ids as $terms_id ) {
348
-			$term_thumbnail_id = get_term_meta( $terms_id, 'thumbnail', true );
349
-			$img               = wp_get_attachment_image_src( $term_thumbnail_id, 'thumbnail' );
350
-			if ( ! empty( $img ) ) {
351
-				$image_url         = $img[0];
352
-				$img               = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url( $image_url ) . '" />';
353
-			}
347
+          foreach ( $terms_ids as $terms_id ) {
348
+               $term_thumbnail_id = get_term_meta( $terms_id, 'thumbnail', true );
349
+               $img               = wp_get_attachment_image_src( $term_thumbnail_id, 'thumbnail' );
350
+               if ( ! empty( $img ) ) {
351
+                    $image_url         = $img[0];
352
+                    $img               = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url( $image_url ) . '" />';
353
+               }
354 354
 
355
-			$plan_meta .= $img;
356
-		}
355
+               $plan_meta .= $img;
356
+          }
357 357
 
358
-		$plan_meta = '<div class="plan-meta">' . $plan_meta . '<span>' . $terms_string . '</span></div>';
359
-	}
358
+          $plan_meta = '<div class="plan-meta">' . $plan_meta . '<span>' . $terms_string . '</span></div>';
359
+     }
360 360
 
361
-	return $plan_meta;
361
+     return $plan_meta;
362 362
 }
363 363
 
364 364
 /**
365 365
  * Limit media library access
366 366
  */
367 367
 function set_only_author( $wp_query ) {
368
-	global $current_user;
369
-	if ( is_admin() && ! current_user_can( 'edit_others_posts' ) ) {
370
-		$wp_query->set( 'administrator', $current_user->ID );
371
-		add_filter( 'views_upload', 'fix_media_counts' );
372
-	}
368
+     global $current_user;
369
+     if ( is_admin() && ! current_user_can( 'edit_others_posts' ) ) {
370
+          $wp_query->set( 'administrator', $current_user->ID );
371
+          add_filter( 'views_upload', 'fix_media_counts' );
372
+     }
373 373
 }
374 374
 add_action( 'pre_get_posts', '\lsx_health_plan\functions\set_only_author' );
375 375
 
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
  * @return void
381 381
  */
382 382
 function hp_excerpt( $post_id ) {
383
-	if ( ! has_excerpt( $post_id ) ) {
384
-		$content = wp_trim_words( get_post_field( 'post_content', $post_id ), 10 );
385
-	} else {
386
-		$content = get_the_excerpt( $post_id );
387
-	}
388
-	return $content;
383
+     if ( ! has_excerpt( $post_id ) ) {
384
+          $content = wp_trim_words( get_post_field( 'post_content', $post_id ), 10 );
385
+     } else {
386
+          $content = get_the_excerpt( $post_id );
387
+     }
388
+     return $content;
389 389
 }
390 390
 
391 391
 /**
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
  * @return void
396 396
  */
397 397
 function column_class( $columns = '3' ) {
398
-	$cols .= '5' === $columns ? '15' : 12 / $columns;
399
-	return $cols;
398
+     $cols .= '5' === $columns ? '15' : 12 / $columns;
399
+     return $cols;
400 400
 }
401 401
 
402 402
 /**
@@ -406,22 +406,22 @@  discard block
 block discarded – undo
406 406
  * @return void
407 407
  */
408 408
 function get_exercises_by_workout( $workout = '' ) {
409
-	$exercises = array();
410
-	$i               = 1;
411
-	$section_counter = 6;
412
-	while ( $i <= $section_counter ) {
413
-		$group_name = 'workout_section_' . $i;
414
-		$groups     = get_post_meta( $workout, $group_name, true );
415
-		if ( ! empty( $groups ) ) {
416
-			foreach ( $groups as $group ) {
417
-				if ( isset( $group['connected_exercises'] ) ) {
418
-					$exercises[] = $group['connected_exercises'];
419
-				}
420
-			}
421
-		}
422
-		$i++;
423
-	}
424
-	return $exercises;
409
+     $exercises = array();
410
+     $i               = 1;
411
+     $section_counter = 6;
412
+     while ( $i <= $section_counter ) {
413
+          $group_name = 'workout_section_' . $i;
414
+          $groups     = get_post_meta( $workout, $group_name, true );
415
+          if ( ! empty( $groups ) ) {
416
+               foreach ( $groups as $group ) {
417
+                    if ( isset( $group['connected_exercises'] ) ) {
418
+                         $exercises[] = $group['connected_exercises'];
419
+                    }
420
+               }
421
+          }
422
+          $i++;
423
+     }
424
+     return $exercises;
425 425
 }
426 426
 
427 427
 
@@ -432,20 +432,20 @@  discard block
 block discarded – undo
432 432
  * @return int
433 433
  */
434 434
 function get_progress( $plan_id = false ) {
435
-	$progress = 0;
436
-	$complete = array();
437
-	$count    = 0;
438
-	if ( false !== $plan_id &&  \lsx_health_plan\functions\plan\has_sections( $plan_id ) ) {
439
-		$sections = \lsx_health_plan\functions\plan\get_sections( $plan_id );
440
-		$all_count = count( $sections );
441
-		foreach ( $sections as $section_key => $section_values ) {
442
-			if ( lsx_health_plan_is_day_complete( $plan_id, $section_values['title'] ) ) {
443
-				$complete[] = true;
444
-			}
445
-		}
446
-		$progress = (int) count( $complete ) / (int) $all_count * 100;
447
-	}
448
-	return $progress;
435
+     $progress = 0;
436
+     $complete = array();
437
+     $count    = 0;
438
+     if ( false !== $plan_id &&  \lsx_health_plan\functions\plan\has_sections( $plan_id ) ) {
439
+          $sections = \lsx_health_plan\functions\plan\get_sections( $plan_id );
440
+          $all_count = count( $sections );
441
+          foreach ( $sections as $section_key => $section_values ) {
442
+               if ( lsx_health_plan_is_day_complete( $plan_id, $section_values['title'] ) ) {
443
+                    $complete[] = true;
444
+               }
445
+          }
446
+          $progress = (int) count( $complete ) / (int) $all_count * 100;
447
+     }
448
+     return $progress;
449 449
 }
450 450
 
451 451
 
@@ -457,18 +457,18 @@  discard block
 block discarded – undo
457 457
  */
458 458
 function hp_back_archive_link() {
459 459
 
460
-	$post_type = 'exercise';
461
-	if ( is_tax( 'recipe-cuisine' ) || is_tax( 'recipe-type' ) ) {
462
-		$post_type = 'recipe';
463
-	}
460
+     $post_type = 'exercise';
461
+     if ( is_tax( 'recipe-cuisine' ) || is_tax( 'recipe-type' ) ) {
462
+          $post_type = 'recipe';
463
+     }
464 464
 
465
-	if ( is_tax() ) {
466
-		?>
465
+     if ( is_tax() ) {
466
+          ?>
467 467
 		<div class="archive-category-title hp-archive-category-title">
468 468
 			<a class="back-to-blog" href="<?php echo ( esc_url( get_post_type_archive_link( $post_type ) ) ); ?>"><?php echo esc_html__( 'Back To ', 'lsx' ) . esc_html( $post_type ) . 's'; ?></a>
469 469
 		</div>
470 470
 		<?php
471
-	}
471
+     }
472 472
 }
473 473
 add_action( 'lsx_content_wrap_before', '\lsx_health_plan\functions\hp_back_archive_link', 20 );
474 474
 
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
  * @return array
480 480
  */
481 481
 function prep_array( $item ) {
482
-	if ( ! is_array( $item ) ) {
483
-		$item = explode( ',', $item );
484
-		if ( ! is_array( $item ) ) {
485
-			$item = array( $item );
486
-		}
487
-	}
488
-	return $item;
482
+     if ( ! is_array( $item ) ) {
483
+          $item = explode( ',', $item );
484
+          if ( ! is_array( $item ) ) {
485
+               $item = array( $item );
486
+          }
487
+     }
488
+     return $item;
489 489
 }
Please login to merge, or discard this patch.
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -16,24 +16,24 @@  discard block
 block discarded – undo
16 16
  * @param boolean $single
17 17
  * @return boolean
18 18
  */
19
-function has_attached_post( $post_id = '', $meta_key = '', $single = true ) {
19
+function has_attached_post($post_id = '', $meta_key = '', $single = true) {
20 20
 	$has_post = false;
21
-	if ( '' === $post_id ) {
21
+	if ('' === $post_id) {
22 22
 		$post_id = get_the_ID();
23 23
 	}
24
-	$items = get_post_meta( $post_id, $meta_key, $single );
25
-	if ( '' !== $items && false !== $items && 0 !== $items ) {
26
-		if ( ! is_array( $items ) ) {
27
-			$items = array( $items );
24
+	$items = get_post_meta($post_id, $meta_key, $single);
25
+	if ('' !== $items && false !== $items && 0 !== $items) {
26
+		if ( ! is_array($items)) {
27
+			$items = array($items);
28 28
 		}
29
-		$items = check_posts_exist( $items );
30
-		if ( ! empty( $items ) ) {
29
+		$items = check_posts_exist($items);
30
+		if ( ! empty($items)) {
31 31
 			$has_post = true;
32 32
 		}
33 33
 	} else {
34 34
 		// Check for defaults.
35
-		$options = get_option( 'all' );
36
-		if ( isset( $options[ $meta_key ] ) && '' !== $options[ $meta_key ] && ! empty( $options[ $meta_key ] ) ) {
35
+		$options = get_option('all');
36
+		if (isset($options[$meta_key]) && '' !== $options[$meta_key] && ! empty($options[$meta_key])) {
37 37
 			$has_post = true;
38 38
 		}
39 39
 	}
@@ -47,17 +47,17 @@  discard block
 block discarded – undo
47 47
  * @param  mixed  $default Optional default value
48 48
  * @return mixed           Option value
49 49
  */
50
-function get_option( $key = '', $default = false ) {
51
-	if ( function_exists( 'cmb2_get_option' ) ) {
52
-		return cmb2_get_option( 'lsx_health_plan_options', $key, $default );
50
+function get_option($key = '', $default = false) {
51
+	if (function_exists('cmb2_get_option')) {
52
+		return cmb2_get_option('lsx_health_plan_options', $key, $default);
53 53
 	}
54 54
 	// Fallback to get_option if CMB2 is not loaded yet.
55
-	$opts = \get_option( 'lsx_health_plan_options', $default );
55
+	$opts = \get_option('lsx_health_plan_options', $default);
56 56
 	$val  = $default;
57
-	if ( 'all' === $key ) {
57
+	if ('all' === $key) {
58 58
 		$val = $opts;
59
-	} elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
60
-		$val = $opts[ $key ];
59
+	} elseif (is_array($opts) && array_key_exists($key, $opts) && false !== $opts[$key]) {
60
+		$val = $opts[$key];
61 61
 	}
62 62
 	return $val;
63 63
 }
@@ -69,54 +69,54 @@  discard block
 block discarded – undo
69 69
  * @param  mixed  $default Optional default value
70 70
  * @return mixed           Option value
71 71
  */
72
-function get_downloads( $type = 'all', $post_id = '' ) {
72
+function get_downloads($type = 'all', $post_id = '') {
73 73
 	$lsx_health_plan = \lsx_health_plan();
74 74
 	$post_types      = $lsx_health_plan->get_post_types();
75
-	if ( '' === $post_id ) {
75
+	if ('' === $post_id) {
76 76
 		$post_id = get_the_ID();
77 77
 	}
78 78
 	$downloads = array();
79
-	$options   = get_option( 'all' );
79
+	$options   = get_option('all');
80 80
 
81
-	foreach ( $post_types as $post_type ) {
82
-		if ( 'all' === $type || in_array( $type, $post_types, true ) ) {
81
+	foreach ($post_types as $post_type) {
82
+		if ('all' === $type || in_array($type, $post_types, true)) {
83 83
 
84 84
 			// Get the default downloads for this post type.
85 85
 			$default_downloads = array();
86 86
 			$new_downloads     = array();
87
-			if ( isset( $options[ 'download_' . $post_type ] ) ) {
88
-				if ( is_array( $options[ 'download_' . $post_type ] ) ) {
89
-					$default_downloads = $options[ 'download_' . $post_type ];
87
+			if (isset($options['download_' . $post_type])) {
88
+				if (is_array($options['download_' . $post_type])) {
89
+					$default_downloads = $options['download_' . $post_type];
90 90
 				} else {
91
-					$default_downloads[] = $options[ 'download_' . $post_type ];
91
+					$default_downloads[] = $options['download_' . $post_type];
92 92
 				}
93 93
 			}
94 94
 
95
-			if ( 'page' === $post_type ) {
95
+			if ('page' === $post_type) {
96 96
 				$key = 'plan_warmup';
97 97
 			} else {
98 98
 				$key = 'connected_' . $post_type . 's';
99 99
 			}
100 100
 
101
-			$connected_items = get_post_meta( $post_id, $key, true );
102
-			if ( ! empty( $connected_items ) ) {
103
-				foreach ( $connected_items as $connected_item ) {
104
-					$current_downloads = get_post_meta( $connected_item, 'connected_downloads', true );
105
-					if ( false !== $current_downloads && ! empty( $current_downloads ) ) {
106
-						$new_downloads = array_merge( $new_downloads, $current_downloads );
101
+			$connected_items = get_post_meta($post_id, $key, true);
102
+			if ( ! empty($connected_items)) {
103
+				foreach ($connected_items as $connected_item) {
104
+					$current_downloads = get_post_meta($connected_item, 'connected_downloads', true);
105
+					if (false !== $current_downloads && ! empty($current_downloads)) {
106
+						$new_downloads = array_merge($new_downloads, $current_downloads);
107 107
 					}
108 108
 				}
109 109
 			}
110 110
 
111
-			if ( ! empty( $new_downloads ) ) {
112
-				$downloads = array_merge( $downloads, $new_downloads );
113
-			} elseif ( ! empty( $default_downloads ) ) {
114
-				$downloads = array_merge( $downloads, $default_downloads );
111
+			if ( ! empty($new_downloads)) {
112
+				$downloads = array_merge($downloads, $new_downloads);
113
+			} elseif ( ! empty($default_downloads)) {
114
+				$downloads = array_merge($downloads, $default_downloads);
115 115
 			}
116
-			$downloads = array_unique( $downloads );
116
+			$downloads = array_unique($downloads);
117 117
 		}
118 118
 	}
119
-	$downloads = check_posts_exist( $downloads );
119
+	$downloads = check_posts_exist($downloads);
120 120
 	return $downloads;
121 121
 }
122 122
 
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
  * @param  string $week    Week name 'week-1'.
127 127
  * @return array           an array of the downloads or empty.
128 128
  */
129
-function get_weekly_downloads( $week = '' ) {
129
+function get_weekly_downloads($week = '') {
130 130
 	$downloads = array();
131
-	if ( '' !== $week ) {
132
-		$saved_downloads = get_transient( 'lsx_hp_weekly_downloads_' . $week );
133
-		if ( false !== $saved_downloads && ! empty( $saved_downloads ) ) {
131
+	if ('' !== $week) {
132
+		$saved_downloads = get_transient('lsx_hp_weekly_downloads_' . $week);
133
+		if (false !== $saved_downloads && ! empty($saved_downloads)) {
134 134
 			$downloads = $saved_downloads;
135 135
 		} else {
136 136
 			$args = array(
@@ -144,17 +144,17 @@  discard block
 block discarded – undo
144 144
 					array(
145 145
 						'taxonomy' => 'dlm_download_category',
146 146
 						'field'    => 'slug',
147
-						'terms'    => array( $week ),
147
+						'terms'    => array($week),
148 148
 					),
149 149
 				),
150 150
 			);
151
-			$download_query = new \WP_Query( $args );
152
-			if ( $download_query->have_posts() ) {
151
+			$download_query = new \WP_Query($args);
152
+			if ($download_query->have_posts()) {
153 153
 				$downloads = $download_query->posts;
154 154
 			}
155 155
 		}
156 156
 	}
157
-	$downloads = check_posts_exist( $downloads );
157
+	$downloads = check_posts_exist($downloads);
158 158
 	return $downloads;
159 159
 }
160 160
 
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
  * @param array $post_ids
165 165
  * @return void
166 166
  */
167
-function check_posts_exist( $post_ids = array() ) {
167
+function check_posts_exist($post_ids = array()) {
168 168
 	$new_ids = array();
169 169
 	global $wpdb;
170
-	if ( is_array( $post_ids ) && ! empty( $post_ids ) ) {
171
-		$post_ids = "'" . implode( "','", $post_ids ) . "'";
170
+	if (is_array($post_ids) && ! empty($post_ids)) {
171
+		$post_ids = "'" . implode("','", $post_ids) . "'";
172 172
 		$query    = "
173 173
 			SELECT `ID` 
174 174
 			FROM `{$wpdb->posts}`
175 175
 			WHERE `ID` IN ({$post_ids})
176 176
 			AND `post_status` != 'trash'
177 177
 		";
178
-		$results = $wpdb->get_results( $query ); // WPCS: unprepared SQL
179
-		if ( ! empty( $results ) ) {
180
-			$new_ids = wp_list_pluck( $results, 'ID' );
178
+		$results = $wpdb->get_results($query); // WPCS: unprepared SQL
179
+		if ( ! empty($results)) {
180
+			$new_ids = wp_list_pluck($results, 'ID');
181 181
 		}
182 182
 	}
183 183
 	return $new_ids;
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
  * @param string $body
192 192
  * @return void
193 193
  */
194
-function register_modal( $id = '', $title = '', $body = '' ) {
194
+function register_modal($id = '', $title = '', $body = '') {
195 195
 	lsx_health_plan()->frontend->modals->register_modal(
196 196
 		array(
197 197
 			'title' => $title,
@@ -207,36 +207,36 @@  discard block
 block discarded – undo
207 207
  * @param array $args
208 208
  * @return void
209 209
  */
210
-function output_modal( $args = array() ) {
210
+function output_modal($args = array()) {
211 211
 	$defaults = array(
212 212
 		'id'    => '',
213 213
 		'title' => '',
214 214
 		'body'  => '',
215 215
 	);
216
-	$args     = wp_parse_args( $args, $defaults );
216
+	$args = wp_parse_args($args, $defaults);
217 217
 	?>
218 218
 	<!-- Modal -->
219
-	<div class="modal fade lsx-health-plan-modal" id="<?php echo esc_html( $args['id'] ); ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo esc_html( $args['id'] ); ?>"  aria-hidden="true">
219
+	<div class="modal fade lsx-health-plan-modal" id="<?php echo esc_html($args['id']); ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo esc_html($args['id']); ?>"  aria-hidden="true">
220 220
 		<div class="modal-dialog" role="document">
221 221
 			<div class="modal-content">
222 222
 			<button type="button" class="close" data-dismiss="modal">&times;</button>			
223 223
 				<div class="modal-header">
224 224
 					<?php
225
-					if ( '' !== $args['title'] ) {
226
-						echo wp_kses_post( '<h2>' . $args['title'] . '</h2>' );
225
+					if ('' !== $args['title']) {
226
+						echo wp_kses_post('<h2>' . $args['title'] . '</h2>');
227 227
 					}
228 228
 					?>
229 229
 				</div>
230 230
 				<div class="modal-body">
231 231
 				<?php
232
-				if ( '' !== $args['body'] ) {
232
+				if ('' !== $args['body']) {
233 233
 					$allowed_html = array(
234 234
 						'iframe' => array(
235 235
 							'data-src'        => array(),
236 236
 							'src'             => array(),
237 237
 							'width'           => array(),
238 238
 							'height'          => array(),
239
-							'frameBorder'     => array( '0' ),
239
+							'frameBorder'     => array('0'),
240 240
 							'class'           => array(),
241 241
 							'allowFullScreen' => array(),
242 242
 							'style'           => array(),
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 							'class' => array(),
246 246
 						),
247 247
 					);
248
-					if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) {
249
-						echo wp_kses_post( $args['body'] );
248
+					if (false !== \lsx_health_plan\functions\get_option('exercise_enabled', false)) {
249
+						echo wp_kses_post($args['body']);
250 250
 					} else {
251
-						echo wp_kses( $args['body'], $allowed_html );
251
+						echo wp_kses($args['body'], $allowed_html);
252 252
 					}
253 253
 				}
254 254
 				?>
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
  * @param [type] $embed
267 267
  * @return void
268 268
  */
269
-function get_video_url( $embed ) {
269
+function get_video_url($embed) {
270 270
 	$url = '';
271
-	if ( false !== stripos( $embed, '<iframe' ) ) {
272
-		preg_match( '/src="([^"]+)"/', $embed, $match );
273
-		if ( is_array( $match ) && isset( $match[1] ) ) {
271
+	if (false !== stripos($embed, '<iframe')) {
272
+		preg_match('/src="([^"]+)"/', $embed, $match);
273
+		if (is_array($match) && isset($match[1])) {
274 274
 			$url = '<iframe data-src="' . $match[1] . '" style="border: 0;" frameBorder="0" class="giphy-embed" allowFullScreen height="300" width="100%"></iframe>';
275 275
 		} else {
276 276
 			$url = $embed;
@@ -288,15 +288,15 @@  discard block
 block discarded – undo
288 288
  * @param array $post_ids
289 289
  * @return boolean
290 290
  */
291
-function is_week_complete( $term_id = false, $section_keys = array(), $group_title = '' ) {
291
+function is_week_complete($term_id = false, $section_keys = array(), $group_title = '') {
292 292
 	$return = false;
293
-	if ( ! empty( $section_keys ) ) {
294
-		$group_count = count( $section_keys );
295
-		foreach ( $section_keys as &$pid ) {
296
-			$pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id( $pid ) . '_complete';
293
+	if ( ! empty($section_keys)) {
294
+		$group_count = count($section_keys);
295
+		foreach ($section_keys as &$pid) {
296
+			$pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id($pid) . '_complete';
297 297
 		}
298
-		$days_complete = get_meta_amounts( $section_keys );
299
-		if ( (int) $group_count === (int) $days_complete ) {
298
+		$days_complete = get_meta_amounts($section_keys);
299
+		if ((int) $group_count === (int) $days_complete) {
300 300
 			$return = true;
301 301
 		}
302 302
 	}
@@ -310,20 +310,20 @@  discard block
 block discarded – undo
310 310
  * @param string $key
311 311
  * @return void
312 312
  */
313
-function get_meta_amounts( $post_ids = array() ) {
313
+function get_meta_amounts($post_ids = array()) {
314 314
 	global $wpdb;
315 315
 	$amount       = 0;
316 316
 	$current_user = wp_get_current_user();
317
-	if ( false !== $current_user && ! empty( $post_ids ) ) {
318
-		$post_ids = "'" . implode( "','", $post_ids ) . "'";
317
+	if (false !== $current_user && ! empty($post_ids)) {
318
+		$post_ids = "'" . implode("','", $post_ids) . "'";
319 319
 		$query    = "
320 320
 			SELECT COUNT(`meta_value`) 
321 321
 			FROM `{$wpdb->usermeta}`
322 322
 			WHERE `meta_key` IN ({$post_ids})
323 323
 			AND `user_id` = '{$current_user->ID}'
324 324
 		";
325
-		$results  = $wpdb->get_var( $query ); // WPCS: unprepared SQL
326
-		if ( ! empty( $results ) ) {
325
+		$results = $wpdb->get_var($query); // WPCS: unprepared SQL
326
+		if ( ! empty($results)) {
327 327
 			$amount = $results;
328 328
 		}
329 329
 	}
@@ -336,20 +336,20 @@  discard block
 block discarded – undo
336 336
  * @param [type] $post
337 337
  * @return void
338 338
  */
339
-function hp_get_plan_type_meta( $post ) {
339
+function hp_get_plan_type_meta($post) {
340 340
 	$plan_meta = '';
341 341
 
342
-	$term_obj_list = get_the_terms( $post->ID, 'plan-type' );
343
-	if ( false !== $term_obj_list ) {
344
-		$terms_string  = join( ' & ', wp_list_pluck( $term_obj_list, 'name' ) );
345
-		$terms_ids     = wp_list_pluck( $term_obj_list, 'term_id' );
342
+	$term_obj_list = get_the_terms($post->ID, 'plan-type');
343
+	if (false !== $term_obj_list) {
344
+		$terms_string  = join(' & ', wp_list_pluck($term_obj_list, 'name'));
345
+		$terms_ids     = wp_list_pluck($term_obj_list, 'term_id');
346 346
 
347
-		foreach ( $terms_ids as $terms_id ) {
348
-			$term_thumbnail_id = get_term_meta( $terms_id, 'thumbnail', true );
349
-			$img               = wp_get_attachment_image_src( $term_thumbnail_id, 'thumbnail' );
350
-			if ( ! empty( $img ) ) {
347
+		foreach ($terms_ids as $terms_id) {
348
+			$term_thumbnail_id = get_term_meta($terms_id, 'thumbnail', true);
349
+			$img               = wp_get_attachment_image_src($term_thumbnail_id, 'thumbnail');
350
+			if ( ! empty($img)) {
351 351
 				$image_url         = $img[0];
352
-				$img               = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url( $image_url ) . '" />';
352
+				$img               = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url($image_url) . '" />';
353 353
 			}
354 354
 
355 355
 			$plan_meta .= $img;
@@ -364,14 +364,14 @@  discard block
 block discarded – undo
364 364
 /**
365 365
  * Limit media library access
366 366
  */
367
-function set_only_author( $wp_query ) {
367
+function set_only_author($wp_query) {
368 368
 	global $current_user;
369
-	if ( is_admin() && ! current_user_can( 'edit_others_posts' ) ) {
370
-		$wp_query->set( 'administrator', $current_user->ID );
371
-		add_filter( 'views_upload', 'fix_media_counts' );
369
+	if (is_admin() && ! current_user_can('edit_others_posts')) {
370
+		$wp_query->set('administrator', $current_user->ID);
371
+		add_filter('views_upload', 'fix_media_counts');
372 372
 	}
373 373
 }
374
-add_action( 'pre_get_posts', '\lsx_health_plan\functions\set_only_author' );
374
+add_action('pre_get_posts', '\lsx_health_plan\functions\set_only_author');
375 375
 
376 376
 /**
377 377
  * Outputs an excerpt even if there is not excerpt.
@@ -379,11 +379,11 @@  discard block
 block discarded – undo
379 379
  * @param [type] $post_id
380 380
  * @return void
381 381
  */
382
-function hp_excerpt( $post_id ) {
383
-	if ( ! has_excerpt( $post_id ) ) {
384
-		$content = wp_trim_words( get_post_field( 'post_content', $post_id ), 10 );
382
+function hp_excerpt($post_id) {
383
+	if ( ! has_excerpt($post_id)) {
384
+		$content = wp_trim_words(get_post_field('post_content', $post_id), 10);
385 385
 	} else {
386
-		$content = get_the_excerpt( $post_id );
386
+		$content = get_the_excerpt($post_id);
387 387
 	}
388 388
 	return $content;
389 389
 }
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
  * @param string $columns
395 395
  * @return void
396 396
  */
397
-function column_class( $columns = '3' ) {
397
+function column_class($columns = '3') {
398 398
 	$cols .= '5' === $columns ? '15' : 12 / $columns;
399 399
 	return $cols;
400 400
 }
@@ -405,16 +405,16 @@  discard block
 block discarded – undo
405 405
  * @param string $workout
406 406
  * @return void
407 407
  */
408
-function get_exercises_by_workout( $workout = '' ) {
408
+function get_exercises_by_workout($workout = '') {
409 409
 	$exercises = array();
410 410
 	$i               = 1;
411 411
 	$section_counter = 6;
412
-	while ( $i <= $section_counter ) {
412
+	while ($i <= $section_counter) {
413 413
 		$group_name = 'workout_section_' . $i;
414
-		$groups     = get_post_meta( $workout, $group_name, true );
415
-		if ( ! empty( $groups ) ) {
416
-			foreach ( $groups as $group ) {
417
-				if ( isset( $group['connected_exercises'] ) ) {
414
+		$groups     = get_post_meta($workout, $group_name, true);
415
+		if ( ! empty($groups)) {
416
+			foreach ($groups as $group) {
417
+				if (isset($group['connected_exercises'])) {
418 418
 					$exercises[] = $group['connected_exercises'];
419 419
 				}
420 420
 			}
@@ -431,19 +431,19 @@  discard block
 block discarded – undo
431 431
  * @param  int $plan_id
432 432
  * @return int
433 433
  */
434
-function get_progress( $plan_id = false ) {
434
+function get_progress($plan_id = false) {
435 435
 	$progress = 0;
436 436
 	$complete = array();
437 437
 	$count    = 0;
438
-	if ( false !== $plan_id &&  \lsx_health_plan\functions\plan\has_sections( $plan_id ) ) {
439
-		$sections = \lsx_health_plan\functions\plan\get_sections( $plan_id );
440
-		$all_count = count( $sections );
441
-		foreach ( $sections as $section_key => $section_values ) {
442
-			if ( lsx_health_plan_is_day_complete( $plan_id, $section_values['title'] ) ) {
438
+	if (false !== $plan_id && \lsx_health_plan\functions\plan\has_sections($plan_id)) {
439
+		$sections = \lsx_health_plan\functions\plan\get_sections($plan_id);
440
+		$all_count = count($sections);
441
+		foreach ($sections as $section_key => $section_values) {
442
+			if (lsx_health_plan_is_day_complete($plan_id, $section_values['title'])) {
443 443
 				$complete[] = true;
444 444
 			}
445 445
 		}
446
-		$progress = (int) count( $complete ) / (int) $all_count * 100;
446
+		$progress = (int) count($complete) / (int) $all_count * 100;
447 447
 	}
448 448
 	return $progress;
449 449
 }
@@ -458,19 +458,19 @@  discard block
 block discarded – undo
458 458
 function hp_back_archive_link() {
459 459
 
460 460
 	$post_type = 'exercise';
461
-	if ( is_tax( 'recipe-cuisine' ) || is_tax( 'recipe-type' ) ) {
461
+	if (is_tax('recipe-cuisine') || is_tax('recipe-type')) {
462 462
 		$post_type = 'recipe';
463 463
 	}
464 464
 
465
-	if ( is_tax() ) {
465
+	if (is_tax()) {
466 466
 		?>
467 467
 		<div class="archive-category-title hp-archive-category-title">
468
-			<a class="back-to-blog" href="<?php echo ( esc_url( get_post_type_archive_link( $post_type ) ) ); ?>"><?php echo esc_html__( 'Back To ', 'lsx' ) . esc_html( $post_type ) . 's'; ?></a>
468
+			<a class="back-to-blog" href="<?php echo (esc_url(get_post_type_archive_link($post_type))); ?>"><?php echo esc_html__('Back To ', 'lsx') . esc_html($post_type) . 's'; ?></a>
469 469
 		</div>
470 470
 		<?php
471 471
 	}
472 472
 }
473
-add_action( 'lsx_content_wrap_before', '\lsx_health_plan\functions\hp_back_archive_link', 20 );
473
+add_action('lsx_content_wrap_before', '\lsx_health_plan\functions\hp_back_archive_link', 20);
474 474
 
475 475
 /**
476 476
  * Returns an array.
@@ -478,11 +478,11 @@  discard block
 block discarded – undo
478 478
  * @param  mixed $item
479 479
  * @return array
480 480
  */
481
-function prep_array( $item ) {
482
-	if ( ! is_array( $item ) ) {
483
-		$item = explode( ',', $item );
484
-		if ( ! is_array( $item ) ) {
485
-			$item = array( $item );
481
+function prep_array($item) {
482
+	if ( ! is_array($item)) {
483
+		$item = explode(',', $item);
484
+		if ( ! is_array($item)) {
485
+			$item = array($item);
486 486
 		}
487 487
 	}
488 488
 	return $item;
Please login to merge, or discard this patch.
classes/class-admin.php 2 patches
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -8,442 +8,442 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class Admin {
10 10
 
11
-	/**
12
-	 * Holds class instance
13
-	 *
14
-	 * @since 1.0.0
15
-	 *
16
-	 * @var      object \lsx_health_plan\classes\Admin()
17
-	 */
18
-	protected static $instance = null;
19
-
20
-	/**
21
-	 * The post relation fields
22
-	 *
23
-	 * @var array
24
-	 */
25
-	public $connections = array();
26
-
27
-	/**
28
-	 * Stores the previous values needed to remove the post relations
29
-	 *
30
-	 * @var array
31
-	 */
32
-	public $previous_values = array();
33
-
34
-	/**
35
-	 * @var object \lsx_health_plan\classes\admin\Settings();
36
-	 */
37
-	public $settings;
38
-
39
-	/**
40
-	 * @var object \lsx_health_plan\classes\admin\Help_Page();
41
-	 */
42
-	public $help;
43
-
44
-	/**
45
-	 * Holds the settings page theme functions
46
-	 *
47
-	 * @var object \lsx_health_plan\classes\admin\Settings_Theme();
48
-	 */
49
-	public $settings_theme;
50
-
51
-	/**
52
-	 * Contructor
53
-	 */
54
-	public function __construct() {
55
-		$this->load_classes();
56
-		add_action( 'admin_menu', array( $this, 'order_menus' ), 200 );
57
-		add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
58
-		add_filter( 'cmb2_override_meta_save', array( $this, 'save_previous_values' ), 20, 4 );
59
-		add_filter( 'cmb2_override_meta_remove', array( $this, 'save_previous_values' ), 20, 4 );
60
-		add_action( 'cmb2_save_field', array( $this, 'post_relations' ), 20, 4 );
61
-		add_action( 'cmb2_save_field', array( $this, 'create_query_fields' ), 20, 4 );
62
-		add_action( 'before_delete_post', array( $this, 'delete_post_meta_connections' ), 20, 1 );
63
-		add_action( 'cmb2_save_post_fields', array( $this, 'extract_plan_fields' ), 10, 4 );
64
-
65
-		//add_action( 'cmb2_save_post_fields', array( $this, 'debugger_for_cmb2' ), 10, 4 );
66
-
67
-		// Customizer.
68
-		add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 );
69
-	}
70
-
71
-	/**
72
-	 * Return an instance of this class.
73
-	 *
74
-	 * @return object \lsx\member_directory\classes\Admin()    A single instance of this class.
75
-	 */
76
-	public static function get_instance() {
77
-		// If the single instance hasn't been set, set it now.
78
-		if ( null === self::$instance ) {
79
-			self::$instance = new self();
80
-		}
81
-		return self::$instance;
82
-	}
83
-
84
-	/**
85
-	 * Loads the admin subclasses
86
-	 */
87
-	private function load_classes() {
88
-		require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings.php';
89
-		$this->settings = admin\Settings::get_instance();
90
-
91
-		require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-help-page.php';
92
-		$this->help = admin\Help_Page::get_instance();
93
-
94
-		require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings-theme.php';
95
-		$this->settings_theme = admin\Settings_Theme::get_instance();
96
-	}
97
-
98
-	/**
99
-	 * Orders the HP menu Items
100
-	 *
101
-	 * @return void
102
-	 */
103
-	public function order_menus() {
104
-		global $menu, $submenu;
105
-		if ( ! empty( $submenu ) ) {
106
-			$parent_check = array(
107
-				'edit.php?post_type=plan',
108
-				'edit.php?post_type=workout',
109
-				'edit.php?post_type=meal',
110
-			);
111
-			foreach ( $submenu as $menu_id => $menu_values ) {
112
-				if ( in_array( $menu_id, $parent_check ) ) {
113
-					foreach ( $menu_values as $sub_menu_key => $sub_menu_values ) {
114
-						switch ( $sub_menu_values[0] ) {
115
-
116
-							case __( 'Add New', 'lsx-health-plan' ):
117
-								unset( $submenu[ $menu_id ][ $sub_menu_key ] );
118
-								break;
119
-
120
-							case __( 'All', 'lsx-health-plan' ):
121
-								$title = $sub_menu_values[0];
122
-								// Check and change the label.
123
-								switch ( $sub_menu_values[2] ) {
124
-									case 'edit.php?post_type=meal':
125
-										$title = esc_attr__( 'Meals', 'lsx-health-plan' );
126
-										break;
127
-
128
-									case 'edit.php?post_type=recipe':
129
-										$title = esc_attr__( 'Recipes', 'lsx-health-plan' );
130
-										break;
131
-
132
-									case 'edit.php?post_type=workout':
133
-										$title = esc_attr__( 'Workouts', 'lsx-health-plan' );
134
-										break;
135
-
136
-									case 'edit.php?post_type=plan':
137
-										$title = esc_attr__( 'Plans', 'lsx-health-plan' );
138
-										break;
139
-
140
-									case 'edit.php?post_type=video':
141
-										$title = esc_attr__( 'Videos', 'lsx-health-plan' );
142
-										break;
143
-
144
-									case 'edit.php?post_type=exercise':
145
-										$title = esc_attr__( 'Exercises', 'lsx-health-plan' );
146
-										break;
147
-
148
-									case 'edit.php?post_type=tip':
149
-										$title = esc_attr__( 'Tips', 'lsx-health-plan' );
150
-										break;
151
-
152
-									default:
153
-										break;
154
-								}
155
-								$submenu[ $menu_id ][ $sub_menu_key ][0] = $title; // @codingStandardsIgnoreLine
156
-								break;
157
-
158
-							default:
159
-								break;
160
-						}
161
-					}
162
-				}
163
-			}
164
-		}
165
-	}
166
-
167
-	/**
168
-	 * Undocumented function
169
-	 *
170
-	 * @return void
171
-	 */
172
-	public function assets() {
173
-		wp_enqueue_script( 'media-upload' );
174
-		wp_enqueue_script( 'thickbox' );
175
-		wp_enqueue_style( 'thickbox' );
176
-
177
-		wp_enqueue_script( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/js/lsx-health-plan-admin.min.js', array( 'jquery' ), LSX_HEALTH_PLAN_VER, true );
178
-		wp_enqueue_style( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-admin.css', array(), LSX_HEALTH_PLAN_VER );
179
-	}
180
-
181
-	/**
182
-	 * Returns the registered connections.
183
-	 *
184
-	 * @return void
185
-	 */
186
-	public function get_connections() {
187
-		return apply_filters( 'lsx_health_plan_connections', $this->connections );
188
-	}
189
-
190
-	/**
191
-	 * Saves the previous values before they are overwritten by the new ones.
192
-	 *
193
-	 * @param [type] $value_to_save
194
-	 * @param [type] $a
195
-	 * @param [type] $args
196
-	 * @param [type] $cmb2
197
-	 * @return void
198
-	 */
199
-	public function save_previous_values( $value_to_save, $a, $args, $cmb2 ) {
200
-		if ( isset( $cmb2->data_to_save['ID'] ) ) {
201
-			$connections = $this->get_connections();
202
-			$post_type   = get_post_type( $cmb2->data_to_save['ID'] );
203
-			if ( isset( $connections[ $post_type ] ) && array_key_exists( $a['field_id'], $connections[ $post_type ] ) ) {
204
-				// Get the previous values if the field, so we can run through them and remove the current ID from them later.
205
-				$this->previous_values = get_post_meta( $a['id'], $a['field_id'], true );
206
-			}
207
-		}
208
-		return $value_to_save;
209
-	}
210
-
211
-	/**
212
-	 * Sets up the "post relations"
213
-	 *
214
-	 * @return    void
215
-	 */
216
-	public function post_relations( $field_id, $updated, $action, $cmb2 ) {
217
-		// If the connections are empty then skip this function.
218
-		$connections = $this->get_connections();
219
-		if ( empty( $connections ) ) {
220
-			return;
221
-		}
222
-
223
-		// If the field has been updated.
224
-		if ( isset( $cmb2->data_to_save['ID'] ) ) {
225
-			$post_type = get_post_type( $cmb2->data_to_save['ID'] );
226
-			if ( isset( $connections[ $post_type ] ) && array_key_exists( $field_id, $connections[ $post_type ] ) ) {
227
-				$saved_values = get_post_meta( $cmb2->data_to_save['ID'], $field_id, true );
228
-
229
-				if ( 'updated' === $action ) {
230
-					$this->add_connected_posts( $saved_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
231
-					// Check if any posts have been removed.
232
-					if ( count( $this->previous_values ) > count( $saved_values ) ) {
233
-						$posts_to_remove = array_diff( $this->previous_values, $saved_values );
234
-						if ( ! empty( $posts_to_remove ) ) {
235
-							$this->remove_connected_posts( $posts_to_remove, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
236
-						}
237
-					}
238
-				} else if ( 'removed' === $action && ! empty( $this->previous_values ) ) {
239
-					$this->remove_connected_posts( $this->previous_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
240
-				}
241
-			}
242
-		}
243
-	}
244
-
245
-	/**
246
-	 * Updates the connected posts witht he current post ID
247
-	 *
248
-	 * @param [type] $values
249
-	 * @param [type] $current_id
250
-	 * @param [type] $connected_key
251
-	 * @return void
252
-	 */
253
-	public function add_connected_posts( $values, $current_id, $connected_key ) {
254
-		foreach ( $values as $value ) {
255
-			$current_post_array = get_post_meta( $value, $connected_key, true );
256
-			$previous_values    = $current_post_array;
257
-
258
-			if ( ! empty( $current_post_array ) ) {
259
-				$current_post_array = array_map( 'strval', $current_post_array );
260
-				array_unique( $current_post_array );
261
-			}
262
-
263
-			// If the current connected post has no saved connections then we create it.
264
-			if ( false === $current_post_array || empty( $current_post_array ) ) {
265
-				$current_post_array = array( $current_id );
266
-			} elseif ( ! in_array( (string) $current_id, $current_post_array, true ) ) {
267
-				$current_post_array[] = $current_id;
268
-			}
269
-
270
-			// Check if the values are empty, if not update them.
271
-			if ( ! empty( $current_post_array ) ) {
272
-				update_post_meta( $value, $connected_key, $current_post_array, $previous_values );
273
-			}
274
-		}
275
-	}
276
-
277
-	/**
278
-	 * Removes the post ID from the connected posts.
279
-	 *
280
-	 * @param [type] $values
281
-	 * @param [type] $current_ID
282
-	 * @param [type] $connected_key
283
-	 * @return void
284
-	 */
285
-	public function remove_connected_posts( $values, $current_ID, $connected_key ) {
286
-		foreach ( $values as $value ) {
287
-			$current_post_array = get_post_meta( $value, $connected_key, true );
288
-			$new_array          = array();
289
-			// Loop through only if the current ID has been saved against the post.
290
-			if ( in_array( $current_ID, $current_post_array, false ) ) {
291
-
292
-				// Loop through all the connected saved IDS.
293
-				foreach ( $current_post_array as $cpa ) {
294
-					if ( (int) $cpa !== (int) $current_ID ) {
295
-						$new_array[] = $cpa;
296
-					}
297
-				}
298
-				if ( ! empty( $new_array ) ) {
299
-					$new_array = array_unique( $new_array );
300
-					delete_post_meta( $value, $connected_key );
301
-					add_post_meta( $value, $connected_key, $new_array, true );
302
-				} else {
303
-					delete_post_meta( $value, $connected_key );
304
-				}
305
-			}
306
-		}
307
-	}
308
-
309
-	/**
310
-	 * Runs on 'before_delete_post' to run through and remove this post ID from its connected values.
311
-	 *
312
-	 * @param string $item_id
313
-	 * @return void
314
-	 */
315
-	public function delete_post_meta_connections( $item_id = '' ) {
316
-		if ( '' !== $item_id ) {
317
-			$post_type   = get_post_type( $item_id );
318
-			$connections = $this->get_connections();
319
-			if ( isset( $connections[ $post_type ] ) && ! empty( $connections[ $post_type ] ) && is_array( $connections[ $post_type ] ) ) {
320
-				foreach ( $connections[ $post_type ] as $this_key => $connected_key ) {
321
-					$this->delete_connected_items( $item_id, $this_key, $connected_key );
322
-				}
323
-			}
324
-		}
325
-	}
326
-
327
-	/**
328
-	 * This function will remvoe the post id fomr its connected posts.
329
-	 *
330
-	 * @param string $item_id
331
-	 * @param string $this_key
332
-	 * @param string $connected_key
333
-	 * @return void
334
-	 */
335
-	public function delete_connected_items( $item_id = '', $this_key, $connected_key ) {
336
-		if ( '' !== $item_id ) {
337
-			$connected_items = get_post_meta( $item_id, $this_key, true );
338
-			if ( ! empty( $connected_items ) ) {
339
-				foreach ( $connected_items as $con_id ) {
340
-					// Get the connected item array from the connected item.
341
-					$their_connections = get_post_meta( $con_id, $connected_key, true );
342
-					if ( ! empty( $their_connections ) ) {
343
-						$new_connections = $their_connections;
344
-						// Run through the array and remove the post to be deleteds ID.
345
-						foreach ( $their_connections as $ckey => $cvalue ) {
346
-							if ( (int) $item_id === (int) $cvalue ) {
347
-								unset( $new_connections[ $ckey ] );
348
-							}
349
-						}
350
-						// Now we save the field.
351
-						update_post_meta( $con_id, $connected_key, $new_connections, $their_connections );
352
-					}
353
-				}
354
-			}
355
-		}
356
-	}
357
-
358
-	/**
359
-	 * Saves the serialized post ids in singular custom fields so they are easily queried using WP_Query
360
-	 *
361
-	 * @return    void
362
-	 */
363
-	public function create_query_fields( $field_id, $updated, $action, $cmb2 ) {
364
-		// If the connections are empty then skip this function.
365
-		$search_fields = array(
366
-			'plan_product',
367
-		);
368
-		if ( ! in_array( $field_id, $search_fields ) ) {
369
-			return;
370
-		}
371
-
372
-		// If the field has been updated.
373
-		if ( isset( $cmb2->data_to_save['ID'] ) && isset( $cmb2->data_to_save[ $field_id . '_results' ] ) && ! empty( $cmb2->data_to_save[ $field_id . '_results' ] ) ) {
374
-			delete_post_meta( $cmb2->data_to_save['ID'], '_' . $field_id . '_id' );
375
-			foreach ( $cmb2->data_to_save[ $field_id . '_results' ] as $temp ) {
376
-				add_post_meta( $cmb2->data_to_save['ID'], '_' . $field_id . '_id', $temp, false );
377
-			}
378
-		}
379
-	}
380
-
381
-	/**
382
-	 * Extract the plan fields so they save to an indexable array.
383
-	 *
384
-	 * @param [type] $object_id
385
-	 * @param [type] $cmb_id
386
-	 * @param [type] $updated
387
-	 * @param [type] $cmb2
388
-	 * @return void
389
-	 */
390
-	public function extract_plan_fields( $object_id, $cmb_id, $updated, $cmb2 ) {
391
-		if ( 'plan_sections_metabox' === $cmb_id ) {
392
-			// Check if our fields are available, and cycle through them.
393
-			if ( isset( $cmb2->data_to_save['plan_sections'] ) && ! empty( $cmb2->data_to_save['plan_sections'] ) ) {
394
-				$fields_to_save = array();
395
-				// Run through each row of fields.
396
-				foreach ( $cmb2->data_to_save['plan_sections'] as $field_index => $fields ) {
397
-					// Run through each field in that section.
398
-					foreach ( $fields as $field_key => $field_value ) {
399
-						$stored_values_key = 'plan_sections_' . $field_index . '_' . $field_key . '_store';
400
-						if ( isset( $cmb2->data_to_save[ $stored_values_key ] ) && ! empty( $cmb2->data_to_save[ $stored_values_key ] ) ) {
401
-							$stored_values = $cmb2->data_to_save[ $stored_values_key ];
402
-							$stored_values = explode( ',', $stored_values );
403
-							foreach ( $stored_values as $id_to_save ) {
404
-								$fields_to_save[ $field_key ][] = $id_to_save;
405
-							}
406
-						}
407
-					}
408
-				}
409
-				$this->save_field_array( $object_id, $fields_to_save );
410
-			}
411
-		}
412
-	}
413
-
414
-	/**
415
-	 * Runs through the supplied array and saved the fields to the current Object.
416
-	 *
417
-	 * @param integer $object_id
418
-	 * @param array   $fields_to_save
419
-	 * @return void
420
-	 */
421
-	public function save_field_array( $object_id = 0, $fields_to_save = array() ) {
422
-
423
-		// Run through the fields and save the meta items.
424
-		if ( ! empty( $fields_to_save ) ) {
425
-			foreach ( $fields_to_save as $field_key => $field_values ) {
426
-				delete_post_meta( $object_id, $field_key );
427
-
428
-				$field_values = array_unique( $field_values );
429
-				foreach ( $field_values as $field_value ) {
430
-					add_post_meta( $object_id, $field_key, $field_value, false );
431
-				}
432
-			}
433
-		}
434
-	}
435
-
436
-	public function debugger_for_cmb2( $object_id, $cmb_id, $updated, $cmb2 ) {
437
-		if ( 'workout_section_6_metabox' === $cmb_id ) {
438
-			die();
439
-		}
440
-	}
441
-
442
-	/**
443
-	 * Handle body colours that might be change by LSX Customizer.
444
-	 */
445
-	public function customizer_body_colours_handler( $css, $colors ) {
446
-		$css .= '
11
+     /**
12
+      * Holds class instance
13
+      *
14
+      * @since 1.0.0
15
+      *
16
+      * @var      object \lsx_health_plan\classes\Admin()
17
+      */
18
+     protected static $instance = null;
19
+
20
+     /**
21
+      * The post relation fields
22
+      *
23
+      * @var array
24
+      */
25
+     public $connections = array();
26
+
27
+     /**
28
+      * Stores the previous values needed to remove the post relations
29
+      *
30
+      * @var array
31
+      */
32
+     public $previous_values = array();
33
+
34
+     /**
35
+      * @var object \lsx_health_plan\classes\admin\Settings();
36
+      */
37
+     public $settings;
38
+
39
+     /**
40
+      * @var object \lsx_health_plan\classes\admin\Help_Page();
41
+      */
42
+     public $help;
43
+
44
+     /**
45
+      * Holds the settings page theme functions
46
+      *
47
+      * @var object \lsx_health_plan\classes\admin\Settings_Theme();
48
+      */
49
+     public $settings_theme;
50
+
51
+     /**
52
+      * Contructor
53
+      */
54
+     public function __construct() {
55
+          $this->load_classes();
56
+          add_action( 'admin_menu', array( $this, 'order_menus' ), 200 );
57
+          add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
58
+          add_filter( 'cmb2_override_meta_save', array( $this, 'save_previous_values' ), 20, 4 );
59
+          add_filter( 'cmb2_override_meta_remove', array( $this, 'save_previous_values' ), 20, 4 );
60
+          add_action( 'cmb2_save_field', array( $this, 'post_relations' ), 20, 4 );
61
+          add_action( 'cmb2_save_field', array( $this, 'create_query_fields' ), 20, 4 );
62
+          add_action( 'before_delete_post', array( $this, 'delete_post_meta_connections' ), 20, 1 );
63
+          add_action( 'cmb2_save_post_fields', array( $this, 'extract_plan_fields' ), 10, 4 );
64
+
65
+          //add_action( 'cmb2_save_post_fields', array( $this, 'debugger_for_cmb2' ), 10, 4 );
66
+
67
+          // Customizer.
68
+          add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 );
69
+     }
70
+
71
+     /**
72
+      * Return an instance of this class.
73
+      *
74
+      * @return object \lsx\member_directory\classes\Admin()    A single instance of this class.
75
+      */
76
+     public static function get_instance() {
77
+          // If the single instance hasn't been set, set it now.
78
+          if ( null === self::$instance ) {
79
+               self::$instance = new self();
80
+          }
81
+          return self::$instance;
82
+     }
83
+
84
+     /**
85
+      * Loads the admin subclasses
86
+      */
87
+     private function load_classes() {
88
+          require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings.php';
89
+          $this->settings = admin\Settings::get_instance();
90
+
91
+          require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-help-page.php';
92
+          $this->help = admin\Help_Page::get_instance();
93
+
94
+          require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings-theme.php';
95
+          $this->settings_theme = admin\Settings_Theme::get_instance();
96
+     }
97
+
98
+     /**
99
+      * Orders the HP menu Items
100
+      *
101
+      * @return void
102
+      */
103
+     public function order_menus() {
104
+          global $menu, $submenu;
105
+          if ( ! empty( $submenu ) ) {
106
+               $parent_check = array(
107
+                    'edit.php?post_type=plan',
108
+                    'edit.php?post_type=workout',
109
+                    'edit.php?post_type=meal',
110
+               );
111
+               foreach ( $submenu as $menu_id => $menu_values ) {
112
+                    if ( in_array( $menu_id, $parent_check ) ) {
113
+                         foreach ( $menu_values as $sub_menu_key => $sub_menu_values ) {
114
+                              switch ( $sub_menu_values[0] ) {
115
+
116
+                                   case __( 'Add New', 'lsx-health-plan' ):
117
+                                        unset( $submenu[ $menu_id ][ $sub_menu_key ] );
118
+                                        break;
119
+
120
+                                   case __( 'All', 'lsx-health-plan' ):
121
+                                        $title = $sub_menu_values[0];
122
+                                        // Check and change the label.
123
+                                        switch ( $sub_menu_values[2] ) {
124
+                                             case 'edit.php?post_type=meal':
125
+                                                  $title = esc_attr__( 'Meals', 'lsx-health-plan' );
126
+                                                  break;
127
+
128
+                                             case 'edit.php?post_type=recipe':
129
+                                                  $title = esc_attr__( 'Recipes', 'lsx-health-plan' );
130
+                                                  break;
131
+
132
+                                             case 'edit.php?post_type=workout':
133
+                                                  $title = esc_attr__( 'Workouts', 'lsx-health-plan' );
134
+                                                  break;
135
+
136
+                                             case 'edit.php?post_type=plan':
137
+                                                  $title = esc_attr__( 'Plans', 'lsx-health-plan' );
138
+                                                  break;
139
+
140
+                                             case 'edit.php?post_type=video':
141
+                                                  $title = esc_attr__( 'Videos', 'lsx-health-plan' );
142
+                                                  break;
143
+
144
+                                             case 'edit.php?post_type=exercise':
145
+                                                  $title = esc_attr__( 'Exercises', 'lsx-health-plan' );
146
+                                                  break;
147
+
148
+                                             case 'edit.php?post_type=tip':
149
+                                                  $title = esc_attr__( 'Tips', 'lsx-health-plan' );
150
+                                                  break;
151
+
152
+                                             default:
153
+                                                  break;
154
+                                        }
155
+                                        $submenu[ $menu_id ][ $sub_menu_key ][0] = $title; // @codingStandardsIgnoreLine
156
+                                        break;
157
+
158
+                                   default:
159
+                                        break;
160
+                              }
161
+                         }
162
+                    }
163
+               }
164
+          }
165
+     }
166
+
167
+     /**
168
+      * Undocumented function
169
+      *
170
+      * @return void
171
+      */
172
+     public function assets() {
173
+          wp_enqueue_script( 'media-upload' );
174
+          wp_enqueue_script( 'thickbox' );
175
+          wp_enqueue_style( 'thickbox' );
176
+
177
+          wp_enqueue_script( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/js/lsx-health-plan-admin.min.js', array( 'jquery' ), LSX_HEALTH_PLAN_VER, true );
178
+          wp_enqueue_style( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-admin.css', array(), LSX_HEALTH_PLAN_VER );
179
+     }
180
+
181
+     /**
182
+      * Returns the registered connections.
183
+      *
184
+      * @return void
185
+      */
186
+     public function get_connections() {
187
+          return apply_filters( 'lsx_health_plan_connections', $this->connections );
188
+     }
189
+
190
+     /**
191
+      * Saves the previous values before they are overwritten by the new ones.
192
+      *
193
+      * @param [type] $value_to_save
194
+      * @param [type] $a
195
+      * @param [type] $args
196
+      * @param [type] $cmb2
197
+      * @return void
198
+      */
199
+     public function save_previous_values( $value_to_save, $a, $args, $cmb2 ) {
200
+          if ( isset( $cmb2->data_to_save['ID'] ) ) {
201
+               $connections = $this->get_connections();
202
+               $post_type   = get_post_type( $cmb2->data_to_save['ID'] );
203
+               if ( isset( $connections[ $post_type ] ) && array_key_exists( $a['field_id'], $connections[ $post_type ] ) ) {
204
+                    // Get the previous values if the field, so we can run through them and remove the current ID from them later.
205
+                    $this->previous_values = get_post_meta( $a['id'], $a['field_id'], true );
206
+               }
207
+          }
208
+          return $value_to_save;
209
+     }
210
+
211
+     /**
212
+      * Sets up the "post relations"
213
+      *
214
+      * @return    void
215
+      */
216
+     public function post_relations( $field_id, $updated, $action, $cmb2 ) {
217
+          // If the connections are empty then skip this function.
218
+          $connections = $this->get_connections();
219
+          if ( empty( $connections ) ) {
220
+               return;
221
+          }
222
+
223
+          // If the field has been updated.
224
+          if ( isset( $cmb2->data_to_save['ID'] ) ) {
225
+               $post_type = get_post_type( $cmb2->data_to_save['ID'] );
226
+               if ( isset( $connections[ $post_type ] ) && array_key_exists( $field_id, $connections[ $post_type ] ) ) {
227
+                    $saved_values = get_post_meta( $cmb2->data_to_save['ID'], $field_id, true );
228
+
229
+                    if ( 'updated' === $action ) {
230
+                         $this->add_connected_posts( $saved_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
231
+                         // Check if any posts have been removed.
232
+                         if ( count( $this->previous_values ) > count( $saved_values ) ) {
233
+                              $posts_to_remove = array_diff( $this->previous_values, $saved_values );
234
+                              if ( ! empty( $posts_to_remove ) ) {
235
+                                   $this->remove_connected_posts( $posts_to_remove, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
236
+                              }
237
+                         }
238
+                    } else if ( 'removed' === $action && ! empty( $this->previous_values ) ) {
239
+                         $this->remove_connected_posts( $this->previous_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
240
+                    }
241
+               }
242
+          }
243
+     }
244
+
245
+     /**
246
+      * Updates the connected posts witht he current post ID
247
+      *
248
+      * @param [type] $values
249
+      * @param [type] $current_id
250
+      * @param [type] $connected_key
251
+      * @return void
252
+      */
253
+     public function add_connected_posts( $values, $current_id, $connected_key ) {
254
+          foreach ( $values as $value ) {
255
+               $current_post_array = get_post_meta( $value, $connected_key, true );
256
+               $previous_values    = $current_post_array;
257
+
258
+               if ( ! empty( $current_post_array ) ) {
259
+                    $current_post_array = array_map( 'strval', $current_post_array );
260
+                    array_unique( $current_post_array );
261
+               }
262
+
263
+               // If the current connected post has no saved connections then we create it.
264
+               if ( false === $current_post_array || empty( $current_post_array ) ) {
265
+                    $current_post_array = array( $current_id );
266
+               } elseif ( ! in_array( (string) $current_id, $current_post_array, true ) ) {
267
+                    $current_post_array[] = $current_id;
268
+               }
269
+
270
+               // Check if the values are empty, if not update them.
271
+               if ( ! empty( $current_post_array ) ) {
272
+                    update_post_meta( $value, $connected_key, $current_post_array, $previous_values );
273
+               }
274
+          }
275
+     }
276
+
277
+     /**
278
+      * Removes the post ID from the connected posts.
279
+      *
280
+      * @param [type] $values
281
+      * @param [type] $current_ID
282
+      * @param [type] $connected_key
283
+      * @return void
284
+      */
285
+     public function remove_connected_posts( $values, $current_ID, $connected_key ) {
286
+          foreach ( $values as $value ) {
287
+               $current_post_array = get_post_meta( $value, $connected_key, true );
288
+               $new_array          = array();
289
+               // Loop through only if the current ID has been saved against the post.
290
+               if ( in_array( $current_ID, $current_post_array, false ) ) {
291
+
292
+                    // Loop through all the connected saved IDS.
293
+                    foreach ( $current_post_array as $cpa ) {
294
+                         if ( (int) $cpa !== (int) $current_ID ) {
295
+                              $new_array[] = $cpa;
296
+                         }
297
+                    }
298
+                    if ( ! empty( $new_array ) ) {
299
+                         $new_array = array_unique( $new_array );
300
+                         delete_post_meta( $value, $connected_key );
301
+                         add_post_meta( $value, $connected_key, $new_array, true );
302
+                    } else {
303
+                         delete_post_meta( $value, $connected_key );
304
+                    }
305
+               }
306
+          }
307
+     }
308
+
309
+     /**
310
+      * Runs on 'before_delete_post' to run through and remove this post ID from its connected values.
311
+      *
312
+      * @param string $item_id
313
+      * @return void
314
+      */
315
+     public function delete_post_meta_connections( $item_id = '' ) {
316
+          if ( '' !== $item_id ) {
317
+               $post_type   = get_post_type( $item_id );
318
+               $connections = $this->get_connections();
319
+               if ( isset( $connections[ $post_type ] ) && ! empty( $connections[ $post_type ] ) && is_array( $connections[ $post_type ] ) ) {
320
+                    foreach ( $connections[ $post_type ] as $this_key => $connected_key ) {
321
+                         $this->delete_connected_items( $item_id, $this_key, $connected_key );
322
+                    }
323
+               }
324
+          }
325
+     }
326
+
327
+     /**
328
+      * This function will remvoe the post id fomr its connected posts.
329
+      *
330
+      * @param string $item_id
331
+      * @param string $this_key
332
+      * @param string $connected_key
333
+      * @return void
334
+      */
335
+     public function delete_connected_items( $item_id = '', $this_key, $connected_key ) {
336
+          if ( '' !== $item_id ) {
337
+               $connected_items = get_post_meta( $item_id, $this_key, true );
338
+               if ( ! empty( $connected_items ) ) {
339
+                    foreach ( $connected_items as $con_id ) {
340
+                         // Get the connected item array from the connected item.
341
+                         $their_connections = get_post_meta( $con_id, $connected_key, true );
342
+                         if ( ! empty( $their_connections ) ) {
343
+                              $new_connections = $their_connections;
344
+                              // Run through the array and remove the post to be deleteds ID.
345
+                              foreach ( $their_connections as $ckey => $cvalue ) {
346
+                                   if ( (int) $item_id === (int) $cvalue ) {
347
+                                        unset( $new_connections[ $ckey ] );
348
+                                   }
349
+                              }
350
+                              // Now we save the field.
351
+                              update_post_meta( $con_id, $connected_key, $new_connections, $their_connections );
352
+                         }
353
+                    }
354
+               }
355
+          }
356
+     }
357
+
358
+     /**
359
+      * Saves the serialized post ids in singular custom fields so they are easily queried using WP_Query
360
+      *
361
+      * @return    void
362
+      */
363
+     public function create_query_fields( $field_id, $updated, $action, $cmb2 ) {
364
+          // If the connections are empty then skip this function.
365
+          $search_fields = array(
366
+               'plan_product',
367
+          );
368
+          if ( ! in_array( $field_id, $search_fields ) ) {
369
+               return;
370
+          }
371
+
372
+          // If the field has been updated.
373
+          if ( isset( $cmb2->data_to_save['ID'] ) && isset( $cmb2->data_to_save[ $field_id . '_results' ] ) && ! empty( $cmb2->data_to_save[ $field_id . '_results' ] ) ) {
374
+               delete_post_meta( $cmb2->data_to_save['ID'], '_' . $field_id . '_id' );
375
+               foreach ( $cmb2->data_to_save[ $field_id . '_results' ] as $temp ) {
376
+                    add_post_meta( $cmb2->data_to_save['ID'], '_' . $field_id . '_id', $temp, false );
377
+               }
378
+          }
379
+     }
380
+
381
+     /**
382
+      * Extract the plan fields so they save to an indexable array.
383
+      *
384
+      * @param [type] $object_id
385
+      * @param [type] $cmb_id
386
+      * @param [type] $updated
387
+      * @param [type] $cmb2
388
+      * @return void
389
+      */
390
+     public function extract_plan_fields( $object_id, $cmb_id, $updated, $cmb2 ) {
391
+          if ( 'plan_sections_metabox' === $cmb_id ) {
392
+               // Check if our fields are available, and cycle through them.
393
+               if ( isset( $cmb2->data_to_save['plan_sections'] ) && ! empty( $cmb2->data_to_save['plan_sections'] ) ) {
394
+                    $fields_to_save = array();
395
+                    // Run through each row of fields.
396
+                    foreach ( $cmb2->data_to_save['plan_sections'] as $field_index => $fields ) {
397
+                         // Run through each field in that section.
398
+                         foreach ( $fields as $field_key => $field_value ) {
399
+                              $stored_values_key = 'plan_sections_' . $field_index . '_' . $field_key . '_store';
400
+                              if ( isset( $cmb2->data_to_save[ $stored_values_key ] ) && ! empty( $cmb2->data_to_save[ $stored_values_key ] ) ) {
401
+                                   $stored_values = $cmb2->data_to_save[ $stored_values_key ];
402
+                                   $stored_values = explode( ',', $stored_values );
403
+                                   foreach ( $stored_values as $id_to_save ) {
404
+                                        $fields_to_save[ $field_key ][] = $id_to_save;
405
+                                   }
406
+                              }
407
+                         }
408
+                    }
409
+                    $this->save_field_array( $object_id, $fields_to_save );
410
+               }
411
+          }
412
+     }
413
+
414
+     /**
415
+      * Runs through the supplied array and saved the fields to the current Object.
416
+      *
417
+      * @param integer $object_id
418
+      * @param array   $fields_to_save
419
+      * @return void
420
+      */
421
+     public function save_field_array( $object_id = 0, $fields_to_save = array() ) {
422
+
423
+          // Run through the fields and save the meta items.
424
+          if ( ! empty( $fields_to_save ) ) {
425
+               foreach ( $fields_to_save as $field_key => $field_values ) {
426
+                    delete_post_meta( $object_id, $field_key );
427
+
428
+                    $field_values = array_unique( $field_values );
429
+                    foreach ( $field_values as $field_value ) {
430
+                         add_post_meta( $object_id, $field_key, $field_value, false );
431
+                    }
432
+               }
433
+          }
434
+     }
435
+
436
+     public function debugger_for_cmb2( $object_id, $cmb_id, $updated, $cmb2 ) {
437
+          if ( 'workout_section_6_metabox' === $cmb_id ) {
438
+               die();
439
+          }
440
+     }
441
+
442
+     /**
443
+      * Handle body colours that might be change by LSX Customizer.
444
+      */
445
+     public function customizer_body_colours_handler( $css, $colors ) {
446
+          $css .= '
447 447
 			@import "' . LSX_HEALTH_PLAN_PATH . '/assets/css/scss/partials/customizer-health-plan-body-colours";
448 448
 
449 449
 			/**
@@ -459,6 +459,6 @@  discard block
 block discarded – undo
459 459
 			);
460 460
 		';
461 461
 
462
-		return $css;
463
-	}
462
+          return $css;
463
+     }
464 464
 }
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -53,19 +53,19 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function __construct() {
55 55
 		$this->load_classes();
56
-		add_action( 'admin_menu', array( $this, 'order_menus' ), 200 );
57
-		add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
58
-		add_filter( 'cmb2_override_meta_save', array( $this, 'save_previous_values' ), 20, 4 );
59
-		add_filter( 'cmb2_override_meta_remove', array( $this, 'save_previous_values' ), 20, 4 );
60
-		add_action( 'cmb2_save_field', array( $this, 'post_relations' ), 20, 4 );
61
-		add_action( 'cmb2_save_field', array( $this, 'create_query_fields' ), 20, 4 );
62
-		add_action( 'before_delete_post', array( $this, 'delete_post_meta_connections' ), 20, 1 );
63
-		add_action( 'cmb2_save_post_fields', array( $this, 'extract_plan_fields' ), 10, 4 );
56
+		add_action('admin_menu', array($this, 'order_menus'), 200);
57
+		add_action('admin_enqueue_scripts', array($this, 'assets'));
58
+		add_filter('cmb2_override_meta_save', array($this, 'save_previous_values'), 20, 4);
59
+		add_filter('cmb2_override_meta_remove', array($this, 'save_previous_values'), 20, 4);
60
+		add_action('cmb2_save_field', array($this, 'post_relations'), 20, 4);
61
+		add_action('cmb2_save_field', array($this, 'create_query_fields'), 20, 4);
62
+		add_action('before_delete_post', array($this, 'delete_post_meta_connections'), 20, 1);
63
+		add_action('cmb2_save_post_fields', array($this, 'extract_plan_fields'), 10, 4);
64 64
 
65 65
 		//add_action( 'cmb2_save_post_fields', array( $this, 'debugger_for_cmb2' ), 10, 4 );
66 66
 
67 67
 		// Customizer.
68
-		add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 );
68
+		add_filter('lsx_customizer_colour_selectors_body', array($this, 'customizer_body_colours_handler'), 15, 2);
69 69
 	}
70 70
 
71 71
 	/**
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public static function get_instance() {
77 77
 		// If the single instance hasn't been set, set it now.
78
-		if ( null === self::$instance ) {
78
+		if (null === self::$instance) {
79 79
 			self::$instance = new self();
80 80
 		}
81 81
 		return self::$instance;
@@ -102,57 +102,57 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	public function order_menus() {
104 104
 		global $menu, $submenu;
105
-		if ( ! empty( $submenu ) ) {
105
+		if ( ! empty($submenu)) {
106 106
 			$parent_check = array(
107 107
 				'edit.php?post_type=plan',
108 108
 				'edit.php?post_type=workout',
109 109
 				'edit.php?post_type=meal',
110 110
 			);
111
-			foreach ( $submenu as $menu_id => $menu_values ) {
112
-				if ( in_array( $menu_id, $parent_check ) ) {
113
-					foreach ( $menu_values as $sub_menu_key => $sub_menu_values ) {
114
-						switch ( $sub_menu_values[0] ) {
111
+			foreach ($submenu as $menu_id => $menu_values) {
112
+				if (in_array($menu_id, $parent_check)) {
113
+					foreach ($menu_values as $sub_menu_key => $sub_menu_values) {
114
+						switch ($sub_menu_values[0]) {
115 115
 
116
-							case __( 'Add New', 'lsx-health-plan' ):
117
-								unset( $submenu[ $menu_id ][ $sub_menu_key ] );
116
+							case __('Add New', 'lsx-health-plan'):
117
+								unset($submenu[$menu_id][$sub_menu_key]);
118 118
 								break;
119 119
 
120
-							case __( 'All', 'lsx-health-plan' ):
120
+							case __('All', 'lsx-health-plan'):
121 121
 								$title = $sub_menu_values[0];
122 122
 								// Check and change the label.
123
-								switch ( $sub_menu_values[2] ) {
123
+								switch ($sub_menu_values[2]) {
124 124
 									case 'edit.php?post_type=meal':
125
-										$title = esc_attr__( 'Meals', 'lsx-health-plan' );
125
+										$title = esc_attr__('Meals', 'lsx-health-plan');
126 126
 										break;
127 127
 
128 128
 									case 'edit.php?post_type=recipe':
129
-										$title = esc_attr__( 'Recipes', 'lsx-health-plan' );
129
+										$title = esc_attr__('Recipes', 'lsx-health-plan');
130 130
 										break;
131 131
 
132 132
 									case 'edit.php?post_type=workout':
133
-										$title = esc_attr__( 'Workouts', 'lsx-health-plan' );
133
+										$title = esc_attr__('Workouts', 'lsx-health-plan');
134 134
 										break;
135 135
 
136 136
 									case 'edit.php?post_type=plan':
137
-										$title = esc_attr__( 'Plans', 'lsx-health-plan' );
137
+										$title = esc_attr__('Plans', 'lsx-health-plan');
138 138
 										break;
139 139
 
140 140
 									case 'edit.php?post_type=video':
141
-										$title = esc_attr__( 'Videos', 'lsx-health-plan' );
141
+										$title = esc_attr__('Videos', 'lsx-health-plan');
142 142
 										break;
143 143
 
144 144
 									case 'edit.php?post_type=exercise':
145
-										$title = esc_attr__( 'Exercises', 'lsx-health-plan' );
145
+										$title = esc_attr__('Exercises', 'lsx-health-plan');
146 146
 										break;
147 147
 
148 148
 									case 'edit.php?post_type=tip':
149
-										$title = esc_attr__( 'Tips', 'lsx-health-plan' );
149
+										$title = esc_attr__('Tips', 'lsx-health-plan');
150 150
 										break;
151 151
 
152 152
 									default:
153 153
 										break;
154 154
 								}
155
-								$submenu[ $menu_id ][ $sub_menu_key ][0] = $title; // @codingStandardsIgnoreLine
155
+								$submenu[$menu_id][$sub_menu_key][0] = $title; // @codingStandardsIgnoreLine
156 156
 								break;
157 157
 
158 158
 							default:
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
 	 * @return void
171 171
 	 */
172 172
 	public function assets() {
173
-		wp_enqueue_script( 'media-upload' );
174
-		wp_enqueue_script( 'thickbox' );
175
-		wp_enqueue_style( 'thickbox' );
173
+		wp_enqueue_script('media-upload');
174
+		wp_enqueue_script('thickbox');
175
+		wp_enqueue_style('thickbox');
176 176
 
177
-		wp_enqueue_script( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/js/lsx-health-plan-admin.min.js', array( 'jquery' ), LSX_HEALTH_PLAN_VER, true );
178
-		wp_enqueue_style( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-admin.css', array(), LSX_HEALTH_PLAN_VER );
177
+		wp_enqueue_script('lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/js/lsx-health-plan-admin.min.js', array('jquery'), LSX_HEALTH_PLAN_VER, true);
178
+		wp_enqueue_style('lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-admin.css', array(), LSX_HEALTH_PLAN_VER);
179 179
 	}
180 180
 
181 181
 	/**
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	 * @return void
185 185
 	 */
186 186
 	public function get_connections() {
187
-		return apply_filters( 'lsx_health_plan_connections', $this->connections );
187
+		return apply_filters('lsx_health_plan_connections', $this->connections);
188 188
 	}
189 189
 
190 190
 	/**
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 	 * @param [type] $cmb2
197 197
 	 * @return void
198 198
 	 */
199
-	public function save_previous_values( $value_to_save, $a, $args, $cmb2 ) {
200
-		if ( isset( $cmb2->data_to_save['ID'] ) ) {
199
+	public function save_previous_values($value_to_save, $a, $args, $cmb2) {
200
+		if (isset($cmb2->data_to_save['ID'])) {
201 201
 			$connections = $this->get_connections();
202
-			$post_type   = get_post_type( $cmb2->data_to_save['ID'] );
203
-			if ( isset( $connections[ $post_type ] ) && array_key_exists( $a['field_id'], $connections[ $post_type ] ) ) {
202
+			$post_type   = get_post_type($cmb2->data_to_save['ID']);
203
+			if (isset($connections[$post_type]) && array_key_exists($a['field_id'], $connections[$post_type])) {
204 204
 				// Get the previous values if the field, so we can run through them and remove the current ID from them later.
205
-				$this->previous_values = get_post_meta( $a['id'], $a['field_id'], true );
205
+				$this->previous_values = get_post_meta($a['id'], $a['field_id'], true);
206 206
 			}
207 207
 		}
208 208
 		return $value_to_save;
@@ -213,30 +213,30 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @return    void
215 215
 	 */
216
-	public function post_relations( $field_id, $updated, $action, $cmb2 ) {
216
+	public function post_relations($field_id, $updated, $action, $cmb2) {
217 217
 		// If the connections are empty then skip this function.
218 218
 		$connections = $this->get_connections();
219
-		if ( empty( $connections ) ) {
219
+		if (empty($connections)) {
220 220
 			return;
221 221
 		}
222 222
 
223 223
 		// If the field has been updated.
224
-		if ( isset( $cmb2->data_to_save['ID'] ) ) {
225
-			$post_type = get_post_type( $cmb2->data_to_save['ID'] );
226
-			if ( isset( $connections[ $post_type ] ) && array_key_exists( $field_id, $connections[ $post_type ] ) ) {
227
-				$saved_values = get_post_meta( $cmb2->data_to_save['ID'], $field_id, true );
224
+		if (isset($cmb2->data_to_save['ID'])) {
225
+			$post_type = get_post_type($cmb2->data_to_save['ID']);
226
+			if (isset($connections[$post_type]) && array_key_exists($field_id, $connections[$post_type])) {
227
+				$saved_values = get_post_meta($cmb2->data_to_save['ID'], $field_id, true);
228 228
 
229
-				if ( 'updated' === $action ) {
230
-					$this->add_connected_posts( $saved_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
229
+				if ('updated' === $action) {
230
+					$this->add_connected_posts($saved_values, $cmb2->data_to_save['ID'], $connections[$post_type][$field_id]);
231 231
 					// Check if any posts have been removed.
232
-					if ( count( $this->previous_values ) > count( $saved_values ) ) {
233
-						$posts_to_remove = array_diff( $this->previous_values, $saved_values );
234
-						if ( ! empty( $posts_to_remove ) ) {
235
-							$this->remove_connected_posts( $posts_to_remove, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
232
+					if (count($this->previous_values) > count($saved_values)) {
233
+						$posts_to_remove = array_diff($this->previous_values, $saved_values);
234
+						if ( ! empty($posts_to_remove)) {
235
+							$this->remove_connected_posts($posts_to_remove, $cmb2->data_to_save['ID'], $connections[$post_type][$field_id]);
236 236
 						}
237 237
 					}
238
-				} else if ( 'removed' === $action && ! empty( $this->previous_values ) ) {
239
-					$this->remove_connected_posts( $this->previous_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] );
238
+				} else if ('removed' === $action && ! empty($this->previous_values)) {
239
+					$this->remove_connected_posts($this->previous_values, $cmb2->data_to_save['ID'], $connections[$post_type][$field_id]);
240 240
 				}
241 241
 			}
242 242
 		}
@@ -250,26 +250,26 @@  discard block
 block discarded – undo
250 250
 	 * @param [type] $connected_key
251 251
 	 * @return void
252 252
 	 */
253
-	public function add_connected_posts( $values, $current_id, $connected_key ) {
254
-		foreach ( $values as $value ) {
255
-			$current_post_array = get_post_meta( $value, $connected_key, true );
253
+	public function add_connected_posts($values, $current_id, $connected_key) {
254
+		foreach ($values as $value) {
255
+			$current_post_array = get_post_meta($value, $connected_key, true);
256 256
 			$previous_values    = $current_post_array;
257 257
 
258
-			if ( ! empty( $current_post_array ) ) {
259
-				$current_post_array = array_map( 'strval', $current_post_array );
260
-				array_unique( $current_post_array );
258
+			if ( ! empty($current_post_array)) {
259
+				$current_post_array = array_map('strval', $current_post_array);
260
+				array_unique($current_post_array);
261 261
 			}
262 262
 
263 263
 			// If the current connected post has no saved connections then we create it.
264
-			if ( false === $current_post_array || empty( $current_post_array ) ) {
265
-				$current_post_array = array( $current_id );
266
-			} elseif ( ! in_array( (string) $current_id, $current_post_array, true ) ) {
264
+			if (false === $current_post_array || empty($current_post_array)) {
265
+				$current_post_array = array($current_id);
266
+			} elseif ( ! in_array((string) $current_id, $current_post_array, true)) {
267 267
 				$current_post_array[] = $current_id;
268 268
 			}
269 269
 
270 270
 			// Check if the values are empty, if not update them.
271
-			if ( ! empty( $current_post_array ) ) {
272
-				update_post_meta( $value, $connected_key, $current_post_array, $previous_values );
271
+			if ( ! empty($current_post_array)) {
272
+				update_post_meta($value, $connected_key, $current_post_array, $previous_values);
273 273
 			}
274 274
 		}
275 275
 	}
@@ -282,25 +282,25 @@  discard block
 block discarded – undo
282 282
 	 * @param [type] $connected_key
283 283
 	 * @return void
284 284
 	 */
285
-	public function remove_connected_posts( $values, $current_ID, $connected_key ) {
286
-		foreach ( $values as $value ) {
287
-			$current_post_array = get_post_meta( $value, $connected_key, true );
285
+	public function remove_connected_posts($values, $current_ID, $connected_key) {
286
+		foreach ($values as $value) {
287
+			$current_post_array = get_post_meta($value, $connected_key, true);
288 288
 			$new_array          = array();
289 289
 			// Loop through only if the current ID has been saved against the post.
290
-			if ( in_array( $current_ID, $current_post_array, false ) ) {
290
+			if (in_array($current_ID, $current_post_array, false)) {
291 291
 
292 292
 				// Loop through all the connected saved IDS.
293
-				foreach ( $current_post_array as $cpa ) {
294
-					if ( (int) $cpa !== (int) $current_ID ) {
293
+				foreach ($current_post_array as $cpa) {
294
+					if ((int) $cpa !== (int) $current_ID) {
295 295
 						$new_array[] = $cpa;
296 296
 					}
297 297
 				}
298
-				if ( ! empty( $new_array ) ) {
299
-					$new_array = array_unique( $new_array );
300
-					delete_post_meta( $value, $connected_key );
301
-					add_post_meta( $value, $connected_key, $new_array, true );
298
+				if ( ! empty($new_array)) {
299
+					$new_array = array_unique($new_array);
300
+					delete_post_meta($value, $connected_key);
301
+					add_post_meta($value, $connected_key, $new_array, true);
302 302
 				} else {
303
-					delete_post_meta( $value, $connected_key );
303
+					delete_post_meta($value, $connected_key);
304 304
 				}
305 305
 			}
306 306
 		}
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
 	 * @param string $item_id
313 313
 	 * @return void
314 314
 	 */
315
-	public function delete_post_meta_connections( $item_id = '' ) {
316
-		if ( '' !== $item_id ) {
317
-			$post_type   = get_post_type( $item_id );
315
+	public function delete_post_meta_connections($item_id = '') {
316
+		if ('' !== $item_id) {
317
+			$post_type   = get_post_type($item_id);
318 318
 			$connections = $this->get_connections();
319
-			if ( isset( $connections[ $post_type ] ) && ! empty( $connections[ $post_type ] ) && is_array( $connections[ $post_type ] ) ) {
320
-				foreach ( $connections[ $post_type ] as $this_key => $connected_key ) {
321
-					$this->delete_connected_items( $item_id, $this_key, $connected_key );
319
+			if (isset($connections[$post_type]) && ! empty($connections[$post_type]) && is_array($connections[$post_type])) {
320
+				foreach ($connections[$post_type] as $this_key => $connected_key) {
321
+					$this->delete_connected_items($item_id, $this_key, $connected_key);
322 322
 				}
323 323
 			}
324 324
 		}
@@ -332,23 +332,23 @@  discard block
 block discarded – undo
332 332
 	 * @param string $connected_key
333 333
 	 * @return void
334 334
 	 */
335
-	public function delete_connected_items( $item_id = '', $this_key, $connected_key ) {
336
-		if ( '' !== $item_id ) {
337
-			$connected_items = get_post_meta( $item_id, $this_key, true );
338
-			if ( ! empty( $connected_items ) ) {
339
-				foreach ( $connected_items as $con_id ) {
335
+	public function delete_connected_items($item_id = '', $this_key, $connected_key) {
336
+		if ('' !== $item_id) {
337
+			$connected_items = get_post_meta($item_id, $this_key, true);
338
+			if ( ! empty($connected_items)) {
339
+				foreach ($connected_items as $con_id) {
340 340
 					// Get the connected item array from the connected item.
341
-					$their_connections = get_post_meta( $con_id, $connected_key, true );
342
-					if ( ! empty( $their_connections ) ) {
341
+					$their_connections = get_post_meta($con_id, $connected_key, true);
342
+					if ( ! empty($their_connections)) {
343 343
 						$new_connections = $their_connections;
344 344
 						// Run through the array and remove the post to be deleteds ID.
345
-						foreach ( $their_connections as $ckey => $cvalue ) {
346
-							if ( (int) $item_id === (int) $cvalue ) {
347
-								unset( $new_connections[ $ckey ] );
345
+						foreach ($their_connections as $ckey => $cvalue) {
346
+							if ((int) $item_id === (int) $cvalue) {
347
+								unset($new_connections[$ckey]);
348 348
 							}
349 349
 						}
350 350
 						// Now we save the field.
351
-						update_post_meta( $con_id, $connected_key, $new_connections, $their_connections );
351
+						update_post_meta($con_id, $connected_key, $new_connections, $their_connections);
352 352
 					}
353 353
 				}
354 354
 			}
@@ -360,20 +360,20 @@  discard block
 block discarded – undo
360 360
 	 *
361 361
 	 * @return    void
362 362
 	 */
363
-	public function create_query_fields( $field_id, $updated, $action, $cmb2 ) {
363
+	public function create_query_fields($field_id, $updated, $action, $cmb2) {
364 364
 		// If the connections are empty then skip this function.
365 365
 		$search_fields = array(
366 366
 			'plan_product',
367 367
 		);
368
-		if ( ! in_array( $field_id, $search_fields ) ) {
368
+		if ( ! in_array($field_id, $search_fields)) {
369 369
 			return;
370 370
 		}
371 371
 
372 372
 		// If the field has been updated.
373
-		if ( isset( $cmb2->data_to_save['ID'] ) && isset( $cmb2->data_to_save[ $field_id . '_results' ] ) && ! empty( $cmb2->data_to_save[ $field_id . '_results' ] ) ) {
374
-			delete_post_meta( $cmb2->data_to_save['ID'], '_' . $field_id . '_id' );
375
-			foreach ( $cmb2->data_to_save[ $field_id . '_results' ] as $temp ) {
376
-				add_post_meta( $cmb2->data_to_save['ID'], '_' . $field_id . '_id', $temp, false );
373
+		if (isset($cmb2->data_to_save['ID']) && isset($cmb2->data_to_save[$field_id . '_results']) && ! empty($cmb2->data_to_save[$field_id . '_results'])) {
374
+			delete_post_meta($cmb2->data_to_save['ID'], '_' . $field_id . '_id');
375
+			foreach ($cmb2->data_to_save[$field_id . '_results'] as $temp) {
376
+				add_post_meta($cmb2->data_to_save['ID'], '_' . $field_id . '_id', $temp, false);
377 377
 			}
378 378
 		}
379 379
 	}
@@ -387,26 +387,26 @@  discard block
 block discarded – undo
387 387
 	 * @param [type] $cmb2
388 388
 	 * @return void
389 389
 	 */
390
-	public function extract_plan_fields( $object_id, $cmb_id, $updated, $cmb2 ) {
391
-		if ( 'plan_sections_metabox' === $cmb_id ) {
390
+	public function extract_plan_fields($object_id, $cmb_id, $updated, $cmb2) {
391
+		if ('plan_sections_metabox' === $cmb_id) {
392 392
 			// Check if our fields are available, and cycle through them.
393
-			if ( isset( $cmb2->data_to_save['plan_sections'] ) && ! empty( $cmb2->data_to_save['plan_sections'] ) ) {
393
+			if (isset($cmb2->data_to_save['plan_sections']) && ! empty($cmb2->data_to_save['plan_sections'])) {
394 394
 				$fields_to_save = array();
395 395
 				// Run through each row of fields.
396
-				foreach ( $cmb2->data_to_save['plan_sections'] as $field_index => $fields ) {
396
+				foreach ($cmb2->data_to_save['plan_sections'] as $field_index => $fields) {
397 397
 					// Run through each field in that section.
398
-					foreach ( $fields as $field_key => $field_value ) {
398
+					foreach ($fields as $field_key => $field_value) {
399 399
 						$stored_values_key = 'plan_sections_' . $field_index . '_' . $field_key . '_store';
400
-						if ( isset( $cmb2->data_to_save[ $stored_values_key ] ) && ! empty( $cmb2->data_to_save[ $stored_values_key ] ) ) {
401
-							$stored_values = $cmb2->data_to_save[ $stored_values_key ];
402
-							$stored_values = explode( ',', $stored_values );
403
-							foreach ( $stored_values as $id_to_save ) {
404
-								$fields_to_save[ $field_key ][] = $id_to_save;
400
+						if (isset($cmb2->data_to_save[$stored_values_key]) && ! empty($cmb2->data_to_save[$stored_values_key])) {
401
+							$stored_values = $cmb2->data_to_save[$stored_values_key];
402
+							$stored_values = explode(',', $stored_values);
403
+							foreach ($stored_values as $id_to_save) {
404
+								$fields_to_save[$field_key][] = $id_to_save;
405 405
 							}
406 406
 						}
407 407
 					}
408 408
 				}
409
-				$this->save_field_array( $object_id, $fields_to_save );
409
+				$this->save_field_array($object_id, $fields_to_save);
410 410
 			}
411 411
 		}
412 412
 	}
@@ -418,23 +418,23 @@  discard block
 block discarded – undo
418 418
 	 * @param array   $fields_to_save
419 419
 	 * @return void
420 420
 	 */
421
-	public function save_field_array( $object_id = 0, $fields_to_save = array() ) {
421
+	public function save_field_array($object_id = 0, $fields_to_save = array()) {
422 422
 
423 423
 		// Run through the fields and save the meta items.
424
-		if ( ! empty( $fields_to_save ) ) {
425
-			foreach ( $fields_to_save as $field_key => $field_values ) {
426
-				delete_post_meta( $object_id, $field_key );
424
+		if ( ! empty($fields_to_save)) {
425
+			foreach ($fields_to_save as $field_key => $field_values) {
426
+				delete_post_meta($object_id, $field_key);
427 427
 
428
-				$field_values = array_unique( $field_values );
429
-				foreach ( $field_values as $field_value ) {
430
-					add_post_meta( $object_id, $field_key, $field_value, false );
428
+				$field_values = array_unique($field_values);
429
+				foreach ($field_values as $field_value) {
430
+					add_post_meta($object_id, $field_key, $field_value, false);
431 431
 				}
432 432
 			}
433 433
 		}
434 434
 	}
435 435
 
436
-	public function debugger_for_cmb2( $object_id, $cmb_id, $updated, $cmb2 ) {
437
-		if ( 'workout_section_6_metabox' === $cmb_id ) {
436
+	public function debugger_for_cmb2($object_id, $cmb_id, $updated, $cmb2) {
437
+		if ('workout_section_6_metabox' === $cmb_id) {
438 438
 			die();
439 439
 		}
440 440
 	}
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 	/**
443 443
 	 * Handle body colours that might be change by LSX Customizer.
444 444
 	 */
445
-	public function customizer_body_colours_handler( $css, $colors ) {
445
+	public function customizer_body_colours_handler($css, $colors) {
446 446
 		$css .= '
447 447
 			@import "' . LSX_HEALTH_PLAN_PATH . '/assets/css/scss/partials/customizer-health-plan-body-colours";
448 448
 
Please login to merge, or discard this patch.