Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 110 |
|
0.00% |
0 / 5 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE\populate_wp_template_data | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE\wpcom_fse_register_template_post_types | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE\wpcom_fse_register_blocks | |
0.00% |
0 / 63 |
|
0.00% |
0 / 1 |
2 | |||
| Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE\load_wpcom_fse | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE\enqueue_coblocks_gallery_scripts | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Register a8c blocks. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE; |
| 9 | |
| 10 | require_once __DIR__ . '/blocks/navigation-menu/index.php'; |
| 11 | require_once __DIR__ . '/blocks/post-content/index.php'; |
| 12 | require_once __DIR__ . '/blocks/site-description/index.php'; |
| 13 | require_once __DIR__ . '/blocks/site-title/index.php'; |
| 14 | require_once __DIR__ . '/blocks/template/index.php'; |
| 15 | require_once __DIR__ . '/helpers/index.php'; |
| 16 | require_once __DIR__ . '/templates/class-wp-template.php'; |
| 17 | require_once __DIR__ . '/templates/class-wp-template-inserter.php'; |
| 18 | |
| 19 | /** |
| 20 | * Inserts default full site editing data for current theme on plugin/theme activation. |
| 21 | * |
| 22 | * This will populate the default header and footer for current theme, and create |
| 23 | * About and Contact pages. Nothing will populate if the data already exists, or |
| 24 | * if the theme is unsupported. |
| 25 | */ |
| 26 | function populate_wp_template_data() { |
| 27 | if ( ! is_theme_supported() ) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $theme_slug = normalize_theme_slug( get_theme_slug() ); |
| 32 | $template_inserter = new WP_Template_Inserter( $theme_slug ); |
| 33 | $template_inserter->insert_default_template_data(); |
| 34 | } |
| 35 | register_activation_hook( __FILE__, __NAMESPACE__ . '\populate_wp_template_data' ); |
| 36 | add_action( 'switch_theme', __NAMESPACE__ . '\populate_wp_template_data' ); |
| 37 | |
| 38 | /** |
| 39 | * Register wpcom fse template post types. |
| 40 | */ |
| 41 | function wpcom_fse_register_template_post_types() { |
| 42 | $theme_slug = normalize_theme_slug( get_stylesheet() ); |
| 43 | $wp_template_inserter = new WP_Template_Inserter( $theme_slug ); |
| 44 | $wp_template_inserter->register_template_post_types(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Register wpcom fse blocks. |
| 49 | */ |
| 50 | function wpcom_fse_register_blocks() { |
| 51 | register_block_type( |
| 52 | 'a8c/navigation-menu', |
| 53 | array( |
| 54 | 'attributes' => array( |
| 55 | 'className' => array( |
| 56 | 'type' => 'string', |
| 57 | 'default' => '', |
| 58 | ), |
| 59 | 'align' => array( |
| 60 | 'type' => 'string', |
| 61 | 'default' => 'wide', |
| 62 | ), |
| 63 | 'textAlign' => array( |
| 64 | 'type' => 'string', |
| 65 | 'default' => 'center', |
| 66 | ), |
| 67 | 'textColor' => array( |
| 68 | 'type' => 'string', |
| 69 | ), |
| 70 | 'customTextColor' => array( |
| 71 | 'type' => 'string', |
| 72 | ), |
| 73 | 'backgroundColor' => array( |
| 74 | 'type' => 'string', |
| 75 | ), |
| 76 | 'customBackgroundColor' => array( |
| 77 | 'type' => 'string', |
| 78 | ), |
| 79 | 'fontSize' => array( |
| 80 | 'type' => 'string', |
| 81 | 'default' => 'normal', |
| 82 | ), |
| 83 | 'customFontSize' => array( |
| 84 | 'type' => 'number', |
| 85 | ), |
| 86 | ), |
| 87 | 'render_callback' => __NAMESPACE__ . '\render_navigation_menu_block', |
| 88 | ) |
| 89 | ); |
| 90 | |
| 91 | register_block_type( |
| 92 | 'a8c/post-content', |
| 93 | array( |
| 94 | 'render_callback' => __NAMESPACE__ . '\render_post_content_block', |
| 95 | ) |
| 96 | ); |
| 97 | |
| 98 | register_block_type( |
| 99 | 'a8c/site-description', |
| 100 | array( |
| 101 | 'render_callback' => __NAMESPACE__ . '\render_site_description_block', |
| 102 | ) |
| 103 | ); |
| 104 | |
| 105 | register_block_type( |
| 106 | 'a8c/template', |
| 107 | array( |
| 108 | 'render_callback' => __NAMESPACE__ . '\render_template_block', |
| 109 | ) |
| 110 | ); |
| 111 | |
| 112 | register_block_type( |
| 113 | 'a8c/site-title', |
| 114 | array( |
| 115 | 'render_callback' => __NAMESPACE__ . '\render_site_title_block', |
| 116 | ) |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Load wpcom FSE. |
| 122 | */ |
| 123 | function load_wpcom_fse() { |
| 124 | // Bail if FSE should not be active on the site. We do not |
| 125 | // want to load FSE functionality on non-supported sites! |
| 126 | if ( ! is_full_site_editing_active() ) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | add_action( 'init', __NAMESPACE__ . '\wpcom_fse_register_blocks', 100 ); |
| 131 | add_action( 'init', __NAMESPACE__ . '\wpcom_fse_register_template_post_types' ); |
| 132 | } |
| 133 | add_action( 'plugins_loaded', __NAMESPACE__ . '\load_wpcom_fse' ); |
| 134 | |
| 135 | /** |
| 136 | * Add front-end CoBlocks gallery block scripts. |
| 137 | * |
| 138 | * This function performs the same enqueueing duties as `CoBlocks_Block_Assets::frontend_scripts`, |
| 139 | * but for dotcom FSE header and footer content. `frontend_scripts` uses |
| 140 | * `has_block` to determine if gallery blocks are present, and `has_block` is |
| 141 | * not aware of content sections outside of post_content yet. |
| 142 | */ |
| 143 | function enqueue_coblocks_gallery_scripts() { |
| 144 | if ( ! defined( 'COBLOCKS_VERSION' ) || ! function_exists( 'CoBlocks' ) || ! is_full_site_editing_active() ) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | $template = new WP_Template(); |
| 149 | $header = $template->get_template_content( 'header' ); |
| 150 | $footer = $template->get_template_content( 'footer' ); |
| 151 | |
| 152 | // Define where the asset is loaded from. |
| 153 | // @phan-suppress-next-line PhanUndeclaredFunction |
| 154 | $dir = CoBlocks()->asset_source( 'js' ); |
| 155 | |
| 156 | // Define where the vendor asset is loaded from. |
| 157 | // @phan-suppress-next-line PhanUndeclaredFunction |
| 158 | $vendors_dir = CoBlocks()->asset_source( 'js', 'vendors' ); |
| 159 | |
| 160 | // Masonry block. |
| 161 | if ( has_block( 'coblocks/gallery-masonry', $header . $footer ) ) { |
| 162 | wp_enqueue_script( |
| 163 | 'coblocks-masonry', |
| 164 | $dir . 'coblocks-masonry.min.js', |
| 165 | array( 'jquery', 'masonry', 'imagesloaded' ), |
| 166 | COBLOCKS_VERSION, |
| 167 | true |
| 168 | ); |
| 169 | } |
| 170 | |
| 171 | // Carousel block. |
| 172 | if ( has_block( 'coblocks/gallery-carousel', $header . $footer ) ) { |
| 173 | wp_enqueue_script( |
| 174 | 'coblocks-flickity', |
| 175 | $vendors_dir . '/flickity.js', |
| 176 | array( 'jquery' ), |
| 177 | COBLOCKS_VERSION, |
| 178 | true |
| 179 | ); |
| 180 | } |
| 181 | } |
| 182 | add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_coblocks_gallery_scripts' ); |