Video::details_metaboxes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 29
rs 9.52
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes;
3
4
/**
5
 * Contains the video post type
6
 *
7
 * @package lsx-health-plan
8
 */
9
class Video {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @var      object \lsx_health_plan\classes\Video()
17
	 */
18
	protected static $instance = null;
19
20
	/**
21
	 * Holds post_type slug used as an index
22
	 *
23
	 * @since 1.0.0
24
	 *
25
	 * @var      string
26
	 */
27
	public $slug = 'video';
28
29
	/**
30
	 * Constructor
31
	 */
32
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
33
		add_action( 'init', array( $this, 'register_post_type' ) );
34
		add_action( 'admin_menu', array( $this, 'register_menus' ) );
35
		add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 );
36
		add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 );
37
		add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) );
38
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
39
40
	/**
41
	 * Return an instance of this class.
42
	 *
43
	 * @since 1.0.0
44
	 *
45
	 * @return    object \lsx_health_plan\classes\Video()    A single instance of this class.
46
	 */
47
	public static function get_instance() {
48
		// If the single instance hasn't been set, set it now.
49
		if ( null === self::$instance ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
50
			self::$instance = new self();
51
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
52
		return self::$instance;
53
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
54
	/**
55
	 * Register the post type.
56
	 */
57
	public function register_post_type() {
58
		$labels = array(
59
			'name'               => esc_html__( 'Videos', 'lsx-health-plan' ),
60
			'singular_name'      => esc_html__( 'Video', 'lsx-health-plan' ),
61
			'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ),
62
			'add_new_item'       => esc_html__( 'Add New', 'lsx-health-plan' ),
63
			'edit_item'          => esc_html__( 'Edit', 'lsx-health-plan' ),
64
			'new_item'           => esc_html__( 'New', 'lsx-health-plan' ),
65
			'all_items'          => esc_html__( 'All Videos', 'lsx-health-plan' ),
66
			'view_item'          => esc_html__( 'View', 'lsx-health-plan' ),
67
			'search_items'       => esc_html__( 'Search', 'lsx-health-plan' ),
68
			'not_found'          => esc_html__( 'None found', 'lsx-health-plan' ),
69
			'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ),
70
			'parent_item_colon'  => '',
71
			'menu_name'          => esc_html__( 'Videos', 'lsx-health-plan' ),
72
		);
73
		$args   = array(
74
			'labels'             => $labels,
75
			'public'             => true,
76
			'publicly_queryable' => true,
77
			'show_ui'            => true,
78
			'show_in_menu'       => false,
79
			'show_in_rest'       => true,
80
			'menu_icon'          => 'dashicons-format-video',
81
			'query_var'          => true,
82
			'rewrite'            => false,
83
			'capability_type'    => 'post',
84
			'has_archive'        => false,
85
			'hierarchical'       => false,
86
			'menu_position'      => null,
87
			'supports'           => array(
88
				'title',
89
				'editor',
90
				'custom-fields',
91
			),
92
		);
93
		register_post_type( 'video', $args );
94
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
95
96
	/**
97
	 * Registers the Recipes under the Meals Post type menu.
98
	 *
99
	 * @return void
100
	 */
101
	public function register_menus() {
102
		add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Videos', 'lsx-health-plan' ), esc_html__( 'Videos', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=video' );
103
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
104
105
	/**
106
	 * Adds the post type to the different arrays.
107
	 *
108
	 * @param array $post_types
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
109
	 * @return array
110
	 */
111
	public function enable_post_type( $post_types = array() ) {
112
		$post_types[] = $this->slug;
113
		return $post_types;
114
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
115
116
	/**
117
	 * Enables the Bi Directional relationships
118
	 *
119
	 * @param array $connections
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
120
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
121
	 */
122
	public function enable_connections( $connections = array() ) {
123
		$connections['video']['connected_plans']    = 'connected_videos';
124
		$connections['plan']['connected_videos']    = 'connected_plans';
125
		$connections['video']['connected_workouts'] = 'connected_videos';
126
		$connections['plan']['connected_videos']    = 'connected_workouts';
127
		return $connections;
128
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
129
130
	/**
131
	 * Define the metabox and field configurations.
132
	 */
133
	public function details_metaboxes() {
134
		$cmb = new_cmb2_box( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
135
			'id'           => $this->slug . '_details_metabox',
136
			'title'        => __( 'Video Details', 'lsx-health-plan' ),
137
			'object_types' => array( $this->slug ), // Post type
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
138
			'context'      => 'normal',
139
			'priority'     => 'high',
140
			'show_names'   => true,
141
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
142
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
143
			'name'       => __( 'Featured Video', 'lsx-health-plan' ),
144
			'desc'       => __( 'Enable the checkbox to feature this video, featured videos display in any page that has the video shortcode: [lsx_health_plan_featured_videos_block]', 'lsx-health-plan' ),
145
			'id'         => $this->slug . '_featured_video',
146
			'type'       => 'checkbox',
147
			'show_on_cb' => 'cmb2_hide_if_no_cats',
148
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
149
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
150
			'name'       => __( 'Youtube Source', 'lsx-health-plan' ),
151
			'desc'       => __( 'Drop in the url for your video from YouTube in this field, i.e: "https://www.youtube.com/watch?v=9xwazD5SyVg"', 'lsx-health-plan' ),
152
			'id'         => $this->slug . '_youtube_source',
153
			'type'       => 'oembed',
154
			'show_on_cb' => 'cmb2_hide_if_no_cats',
155
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
156
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
157
			'name'       => __( 'Giphy Source', 'lsx-health-plan' ),
158
			'desc'       => __( 'Drop in the iFrame embed code from Giphy in this field, i.e: &lt;iframe src="https://giphy.com/embed/3o7527Rn1HxXWqgxuo" width="480" height="270" frameborder="0" class="giphy-embed" allowfullscreen&gt;&lt;/iframe&gt;', 'lsx-health-plan' ),
159
			'id'         => $this->slug . '_giphy_source',
160
			'type'       => 'textarea_code',
161
			'show_on_cb' => 'cmb2_hide_if_no_cats',
162
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
163
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
164
165
	// /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
	//  * Registers the workout connections on the workout post type.
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
167
	//  *
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
168
	//  * @return void
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
169
	//  */
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
170
	// public function videos_connections() {
171
	// 	$cmb = new_cmb2_box( array(
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
172
	// 		'id'           => $this->slug . '_videos_connections_metabox',
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
173
	// 		'title'        => __( 'Videos', 'lsx-health-plan' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
174
	// 		'desc'         => __( 'Start typing to search for your workouts', 'lsx-health-plan' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
175
	// 		'object_types' => array( 'workout' ), // Post type
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
176
	// 		'context'      => 'normal',
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
177
	// 		'priority'     => 'high',
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
178
	// 		'show_names'   => false,
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
179
	// 	) );
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
180
	// 	$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
181
	// 		'name'       => __( 'Videos', 'lsx-health-plan' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
182
	// 		'id'         => 'connected_videos',
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
183
	// 		'type'       => 'post_search_ajax',
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
184
	// 		// Optional :
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
185
	// 		'limit'      => 15, // Limit selection to X items only (default 1)
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
186
	// 		'sortable'   => true, // Allow selected items to be sortable (default false)
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
187
	// 		'query_args' => array(
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
188
	// 			'post_type'      => array( 'video' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 10; use block comment if you need indentation
Loading history...
189
	// 			'post_status'    => array( 'publish' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 10; use block comment if you need indentation
Loading history...
190
	// 			'posts_per_page' => -1,
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 10; use block comment if you need indentation
Loading history...
191
	// 		),
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 6; use block comment if you need indentation
Loading history...
192
	// 	) );
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 2; use block comment if you need indentation
Loading history...
193
	// }
194
195
}
196