'boolean', 'description' => __( 'Stackable optimization setting, only load scripts when there are Stackable blocks in the page', STACKABLE_I18N ), 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => true, 'default' => '', ) ); } /** * If the optimize script load is activated, prevent the normal loading * process of the frontend scripts * * @return void * * @since 2.17.0 */ public function disable_frontend_scripts() { if ( get_option( 'stackable_optimize_script_load' ) && ! is_admin() ) { remove_action( 'init', 'stackable_block_assets_v2' ); remove_action( 'enqueue_block_assets', 'stackable_add_required_block_styles_v2' ); } } /** * If the optimize script load is activated, detect when blocks are used * and only load the frontend scripts then. * * @param String $block_content * @param Array $block * * @return void * * @since 2.17.0 */ public function load_frontend_scripts_conditionally( $block_content, $block ) { if ( ! $this->is_script_loaded ) { if ( get_option( 'stackable_optimize_script_load' ) && ! is_admin() ) { if ( stripos( $block['blockName'], 'ugb/' ) === 0 || stripos( $block_content, '