Fliptale_Url::custom_domains(), 'defaultHeight' => Fliptale_Embed::DEFAULT_HEIGHT, 'minHeight' => Fliptale_Embed::MIN_HEIGHT, 'maxHeight' => Fliptale_Embed::MAX_HEIGHT, ) ) . ';', 'before' ); add_shortcode( 'fliptale', array( __CLASS__, 'shortcode' ) ); // A Fliptale link on its own line, or in an Embed block, becomes the book. wp_embed_register_handler( 'fliptale', '#^https?://(?:[a-z0-9-]+\.)?fliptale\.io/\S*$#i', array( __CLASS__, 'embed_handler' ) ); $domains = Fliptale_Url::custom_domains(); if ( $domains ) { $hosts = implode( '|', array_map( static function ( $domain ) { return preg_quote( $domain, '#' ); }, $domains ) ); wp_embed_register_handler( 'fliptale-custom-domains', '#^https?://(?:' . $hosts . ')(?:/\S*)?$#i', array( __CLASS__, 'embed_handler' ) ); } } /** * The [fliptale] shortcode: `[fliptale url="https://fliptale.io/b/…" height="640" title="Spring catalog"]`. * * @param array|string $atts Shortcode attributes: url (or id), height, title. * @return string */ public static function shortcode( $atts ) { $atts = shortcode_atts( array( 'url' => '', 'id' => '', 'height' => Fliptale_Embed::DEFAULT_HEIGHT, 'title' => '', ), $atts, 'fliptale' ); $embed_url = Fliptale_Url::to_embed_url( '' !== $atts['url'] ? $atts['url'] : $atts['id'] ); if ( null === $embed_url ) { return ''; } return wp_kses( Fliptale_Embed::html( $embed_url, $atts ), Fliptale_Embed::allowed_html() ); } /** * Turns a pasted Fliptale link into the embed. * * @param array $matches The regex matches. * @param array $attr Embed attributes, with WordPress' default width and height. * @param string $url The pasted link. * @param array $rawattr Only the attributes set in an [embed] shortcode. * @return string|false The embed, or false to leave the link to WordPress. */ public static function embed_handler( $matches, $attr, $url, $rawattr ) { $embed_url = Fliptale_Url::to_embed_url( $url ); if ( null === $embed_url ) { return false; } $height = isset( $rawattr['height'] ) ? $rawattr['height'] : Fliptale_Embed::DEFAULT_HEIGHT; return wp_kses( Fliptale_Embed::html( $embed_url, array( 'height' => $height ) ), Fliptale_Embed::allowed_html() ); } }