| @@ -1,0 +1,87 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Bootstraps the CMB2 process | |
| 4 | + * | |
| 5 | + * @category WordPress_Plugin | |
| 6 | + * @package CMB2 | |
| 7 | + * @author CMB2 | |
| 8 | + * @license GPL-2.0+ | |
| 9 | + * @link https://cmb2.io | |
| 10 | + */ | |
| 11 | + | |
| 12 | +// Exit if accessed directly | |
| 13 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Function to encapsulate the CMB2 bootstrap process. | |
| 17 | + * | |
| 18 | + * @since 2.2.0 | |
| 19 | + * @return void | |
| 20 | + */ | |
| 21 | +function cmb2_bootstrap() { | |
| 22 | + | |
| 23 | + if ( is_admin() ) { | |
| 24 | + /** | |
| 25 | + * Fires on the admin side when CMB2 is included/loaded. | |
| 26 | + * | |
| 27 | + * In most cases, this should be used to add metaboxes. See example-functions.php | |
| 28 | + */ | |
| 29 | + do_action( 'cmb2_admin_init' ); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Fires when CMB2 is included/loaded | |
| 34 | + * | |
| 35 | + * Can be used to add metaboxes if needed on the front-end or WP-API (or the front and backend). | |
| 36 | + */ | |
| 37 | + do_action( 'cmb2_init' ); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * For back-compat. Does the dirty-work of instantiating all the | |
| 41 | + * CMB2 instances for the cmb2_meta_boxes filter | |
| 42 | + * | |
| 43 | + * @since 2.0.2 | |
| 44 | + */ | |
| 45 | + $cmb_config_arrays = apply_filters( 'cmb2_meta_boxes', array() ); | |
| 46 | + foreach ( (array) $cmb_config_arrays as $cmb_config ) { | |
| 47 | + new CMB2( $cmb_config ); | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Fires after all CMB2 instances are created | |
| 52 | + */ | |
| 53 | + do_action( 'cmb2_init_before_hookup' ); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Get all created metaboxes, and instantiate CMB2_Hookup | |
| 57 | + * on metaboxes which require it. | |
| 58 | + * | |
| 59 | + * @since 2.0.2 | |
| 60 | + */ | |
| 61 | + foreach ( CMB2_Boxes::get_all() as $cmb ) { | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Initiates the box "hookup" into WordPress. | |
| 65 | + * | |
| 66 | + * Unless the 'hookup' box property is `false`, the box will be hooked in as | |
| 67 | + * a post/user/comment/option/term box. | |
| 68 | + * | |
| 69 | + * And if the 'show_in_rest' box property is set, the box will be hooked | |
| 70 | + * into the CMB2 REST API. | |
| 71 | + * | |
| 72 | + * The dynamic portion of the hook name, $cmb->cmb_id, is the box id. | |
| 73 | + * | |
| 74 | + * @since 2.2.6 | |
| 75 | + * | |
| 76 | + * @param array $cmb The CMB2 object to hookup. | |
| 77 | + */ | |
| 78 | + do_action( "cmb2_init_hookup_{$cmb->cmb_id}", $cmb ); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Fires after CMB2 initiation process has been completed | |
| 83 | + */ | |
| 84 | + do_action( 'cmb2_after_init' ); | |
| 85 | +} | |
| 86 | + | |
| 87 | +/* End. That's it, folks! */ | |