Completed
Pull Request — trunk (#848)
by
unknown
05:56
created

bootstrap.php ➔ cmb2_bootstrap()   B

Complexity

Conditions 7
Paths 20

Size

Total Lines 64
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 20
nop 0
dl 0
loc 64
ccs 0
cts 23
cp 0
crap 56
rs 7.2058
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Bootstraps the CMB2 process
4
 *
5
 * @category  WordPress_Plugin
6
 * @package   CMB2
7
 * @author    WebDevStudios
8
 * @license   GPL-2.0+
9
 * @link      http://webdevstudios.com
10
 */
11
12
/**
13
 * Function to encapsulate the CMB2 bootstrap process.
14
 * @since  2.2.0
15
 * @return void
16
 */
17
function cmb2_bootstrap() {
18
19
	if ( is_admin() ) {
20
		/**
21
		 * Fires on the admin side when CMB2 is included/loaded.
22
		 *
23
		 * In most cases, this should be used to add metaboxes. See example-functions.php
24
		 */
25
		do_action( 'cmb2_admin_init' );
26
	}
27
28
	/**
29
	 * Fires when CMB2 is included/loaded
30
	 *
31
	 * Can be used to add metaboxes if needed on the front-end or WP-API (or the front and backend).
32
	 */
33
	do_action( 'cmb2_init' );
34
35
	/**
36
	 * For back-compat. Does the dirty-work of instantiating all the
37
	 * CMB2 instances for the cmb2_meta_boxes filter
38
	 * @since  2.0.2
39
	 */
40
	$cmb_config_arrays = apply_filters( 'cmb2_meta_boxes', array() );
41
	foreach ( (array) $cmb_config_arrays as $cmb_config ) {
42
		new CMB2( $cmb_config );
43
	}
44
45
	/**
46
	 * Fires after all CMB2 instances are created
47
	 */
48
	do_action( 'cmb2_init_before_hookup' );
49
50
	/**
51
	 * Get all created metaboxes, and instantiate CMB2_hookup
52
	 * on metaboxes which require it.
53
	 * @since  2.0.2
54
	 */
55
	foreach ( CMB2_Boxes::get_all() as $cmb ) {
56
		
57
		/**
58
		 * Filter media attachments for JS
59
		 * @todo this needs a better home
60
		 * @since  2.x.x.x
61
		 */
62
		CMB2_JS::filter_media();
0 ignored issues
show
Bug introduced by
The method filter_media() does not seem to exist on object<CMB2_JS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
64
		if ( $cmb->prop( 'hookup' ) ) {
65
			$hookup = new CMB2_hookup( $cmb );
66
			$hookup->universal_hooks();
67
		}
68
69
		if ( $cmb->prop( 'show_in_rest' ) && function_exists( 'rest_get_server' ) ) {
70
			$rest = new CMB2_REST( $cmb );
71
			$rest->universal_hooks();
72
		}
73
74
	}
75
76
	/**
77
	 * Fires after CMB2 initiation process has been completed
78
	 */
79
	do_action( 'cmb2_after_init' );
80
}
81
82
// End. That's it, folks! //
83