• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / load_assets() – Calendly block registration/dependency declaration.

You appear to be a bot. Output may be restricted

Description

Calendly block registration/dependency declaration.

Usage

$string = load_assets( $attr, $content );

Parameters

$attr
( array ) required – Array containing the Calendly block attributes.
$content
( string ) required – String containing the Calendly block content.

Returns

string

Source

File name: jetpack/extensions/blocks/calendly/calendly.php


Lines:

1 to 86 of 86
function load_assets( $attr, $content ) {

  if ( is_admin() ) {
    return;
  }
  $url = Jetpack_Gutenberg::validate_block_embed_url(
    get_attribute( $attr, 'url' ),
    array( 'calendly.com' )
  );
  if ( empty( $url ) ) {
    return;
  }

  /*
	 * Enqueue necessary scripts and styles.
	 */
  Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );

  $style                   = get_attribute( $attr, 'style' );
  $hide_event_type_details = get_attribute( $attr, 'hideEventTypeDetails' );
  $background_color        = get_attribute( $attr, 'backgroundColor' );
  $text_color              = get_attribute( $attr, 'textColor' );
  $primary_color           = get_attribute( $attr, 'primaryColor' );
  $classes                 = Blocks::classes( FEATURE_NAME, $attr, array( 'calendly-style-' . $style ) );
  $block_id                = wp_unique_id( 'calendly-block-' );
  $is_amp_request          = Blocks::is_amp_request();

  if ( ! wp_script_is( 'jetpack-calendly-external-js' ) && ! $is_amp_request ) {
    enqueue_calendly_js();
  }

  $base_url = $url;
  $url      = add_query_arg(
    array(
      'hide_event_type_details' => (int) $hide_event_type_details,
      'background_color'        => sanitize_hex_color_no_hash( $background_color ),
      'text_color'              => sanitize_hex_color_no_hash( $text_color ),
      'primary_color'           => sanitize_hex_color_no_hash( $primary_color ),
    ),
    $url
  );

  if ( 'link' === $style ) {
    if ( ! wp_style_is( 'jetpack-calendly-external-css' ) ) {
      wp_enqueue_style( 'jetpack-calendly-external-css', 'https://assets.calendly.com/assets/external/widget.css', null, JETPACK__VERSION );
    }

    // Render deprecated version of Calendly block if needed. New markup block button class before rendering here.
    if ( false === strpos( $content, 'wp-block-jetpack-button' ) ) {
      $content = deprecated_render_button_v1( $attr, $block_id, $classes, $url );
    } else {
      $content = str_replace( 'calendly-widget-id', esc_attr( $block_id ), $content );
      $content = str_replace( $base_url, $url, $content );
    }

    if ( ! $is_amp_request ) {
      wp_add_inline_script(
        'jetpack-calendly-external-js',
        sprintf( "calendly_attach_link_events( '%s' )", esc_js( $block_id ) )
      );
    }
  } else { // Inline style.
    if ( $is_amp_request ) {
      $content = sprintf(
        '<div class="%1$s" id="%2$s"><a href="%3$s" role="button" target="_blank">%4$s</a></div>',
        esc_attr( Blocks::classes( FEATURE_NAME, $attr ) ),
        esc_attr( $block_id ),
        esc_js( $url ),
        wp_kses_post( get_attribute( $attr, 'submitButtonText' ) )
      );
    } else {
      $content = sprintf(
        '<div class="%1$s" id="%2$s"></div>',
        esc_attr( $classes ),
        esc_attr( $block_id )
      );
      $script  = <<<JS_END
jetpackInitCalendly( '%s', '%s' );
JS_END;
      wp_add_inline_script( 'jetpack-calendly-external-js', sprintf( $script, esc_url( $url ), esc_js( $block_id ) ) );
    }
  }

  return $content;
}
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 4 April 2020 | Last updated: 22 February 2021

Primary Sidebar

Information

Function name: load_assets
Plugin ref: Jetpack
Version: 9.4
Sourcefile: extensions/blocks/calendly/calendly.php
File ref: extensions/blocks/calendly/calendly.php
Deprecated?: No
API Letters: A,L

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites