Plugin Directory

Changeset 3285893


Ignore:
Timestamp:
05/01/2025 09:46:06 PM (11 months ago)
Author:
rsvpify
Message:

3.12: responsive 16:9 wrapper for full-height embeds

Location:
rsvpify-oembed/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rsvpify-oembed/trunk/readme.txt

    r3285891 r3285893  
    88Requires at least: 5.6
    99Tested up to:      6.8
    10 Stable tag:        3.11
     10Stable tag:        3.12
    1111Requires PHP:      7.0
    1212License:           GNU General Public License v3
  • rsvpify-oembed/trunk/rsvpify-embedder.php

    r3285891 r3285893  
    44 * Plugin URI:      https://wordpress.org/plugins/rsvpify-oembed/
    55 * Description:     Easily embed your RSVPify event RSVP and ticket forms by pasting your event URL.
    6  * Version:         3.11
     6 * Version:         3.12
    77 * Author:          RSVPify Inc.
    88 * Author URI:      https://www.rsvpify.com
     
    2222
    2323    public function __construct() {
    24         // Admin
     24        // Admin UI
    2525        add_action( 'admin_menu', [ $this, 'register_admin_page' ] );
    2626        add_action( 'admin_enqueue_scripts', 'rsvpify_embedder_styles' );
     
    2828        add_action( 'wp_ajax_rsvpify_delete_shortcode', [ $this, 'ajax_delete_shortcode' ] );
    2929
    30         // oEmbed
     30        // oEmbed provider + filters
    3131        wp_oembed_add_provider( 'https://*.rsvpify.com', 'https://app3.rsvpify.com/api/rsvp/oembed' );
    3232        add_filter( 'oembed_dataparse', [ $this, 'set_sandbox_attribute' ], 99, 4 );
    3333        add_filter( 'oembed_result',      'rsvpify_embedder_auto_resize', 10, 3 );
    3434
    35         // Shortcode
     35        // Shortcode registration
    3636        add_shortcode( 'rsvpify_form', 'rsvpify_form_shortcode' );
    3737
    38         // Front‐end CSS override on both front and Elementor editor
     38        // Enqueue responsive CSS on front and in Elementor editor
    3939        add_action( 'wp_enqueue_scripts',                     [ $this, 'enqueue_frontend_css' ] );
    4040        add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_frontend_css' ] );
    4141        add_action( 'elementor/editor/after_enqueue_styles',   [ $this, 'enqueue_frontend_css' ] );
    42         add_action( 'elementor/preview/enqueue_styles',       [ $this, 'enqueue_frontend_css' ] );
     42        add_action( 'elementor/preview/enqueue_styles',        [ $this, 'enqueue_frontend_css' ] );
    4343    }
    4444
     
    8888        </div>
    8989
    90         <script>
     90        <script type="text/javascript">
    9191        (function(){
    9292          var list    = document.getElementById('rsvpify_list'),
     
    147147              var item = d.parentNode,
    148148                  code = item.getAttribute('data-code');
     149
    149150              var data = new URLSearchParams();
    150151              data.append('action','rsvpify_delete_shortcode');
    151152              data.append('code', code);
     153
    152154              fetch(ajaxUrl, {
    153155                method:'POST',
     
    167169    }
    168170
     171    public function ajax_save_shortcode() {
     172        if ( ! current_user_can('manage_options') || empty($_POST['code']) ) {
     173            wp_send_json_error();
     174        }
     175        $code = wp_unslash( $_POST['code'] );
     176        $all  = get_option( self::OPTION_KEY, [] );
     177        if ( ! in_array( $code, $all, true ) ) {
     178            $all[] = $code;
     179            update_option( self::OPTION_KEY, $all );
     180        }
     181        wp_send_json_success();
     182    }
     183
     184    public function ajax_delete_shortcode() {
     185        if ( ! current_user_can('manage_options') || empty($_POST['code']) ) {
     186            wp_send_json_error();
     187        }
     188        $code = wp_unslash( $_POST['code'] );
     189        $all  = get_option( self::OPTION_KEY, [] );
     190        $key  = array_search( $code, $all, true );
     191        if ( false !== $key ) {
     192            unset( $all[ $key ] );
     193            update_option( self::OPTION_KEY, $all );
     194        }
     195        wp_send_json_success();
     196    }
     197
     198    public function set_sandbox_attribute( $result, $data, $url ) {
     199        if ( empty( $data->provider_url ) || $data->provider_url !== 'https://www.rsvpify.com' ) {
     200            return $result;
     201        }
     202        if ( preg_match( '/sandbox=["\']([^"\']+)["\']/', $data->html, $m ) ) {
     203            $result = preg_replace(
     204                '/sandbox=["\']allow-scripts["\']/',
     205                'sandbox="' . esc_attr( $m[1] ) . '"',
     206                $result
     207            );
     208        }
     209        return str_replace( 'security="restricted"', '', $result );
     210    }
     211
    169212    public function enqueue_frontend_css() {
    170213        wp_enqueue_style(
     
    175218        );
    176219    }
    177 
    178     public function ajax_save_shortcode() {
    179         if ( ! current_user_can('manage_options') || empty($_POST['code']) ) {
    180             wp_send_json_error();
    181         }
    182         $code = wp_unslash( $_POST['code'] );
    183         $all  = get_option( self::OPTION_KEY, [] );
    184         if ( ! in_array($code, $all, true) ) {
    185             $all[] = $code;
    186             update_option( self::OPTION_KEY, $all );
    187         }
    188         wp_send_json_success();
    189     }
    190 
    191     public function ajax_delete_shortcode() {
    192         if ( ! current_user_can('manage_options') || empty($_POST['code']) ) {
    193             wp_send_json_error();
    194         }
    195         $code = wp_unslash( $_POST['code'] );
    196         $all  = get_option( self::OPTION_KEY, [] );
    197         $key  = array_search($code, $all, true);
    198         if ( false !== $key ) {
    199             unset($all[$key]);
    200             update_option( self::OPTION_KEY, $all );
    201         }
    202         wp_send_json_success();
    203     }
    204 
    205     public function set_sandbox_attribute( $result, $data, $url ) {
    206         if ( empty($data->provider_url) || $data->provider_url !== 'https://www.rsvpify.com' ) {
    207             return $result;
    208         }
    209         if ( preg_match('/sandbox=["\']([^"\']+)["\']/', $data->html, $m) ) {
    210             $result = preg_replace(
    211                 '/sandbox=["\']allow-scripts["\']/',
    212                 'sandbox="'. esc_attr($m[1]) .'"',
    213                 $result
    214             );
    215         }
    216         return str_replace('security="restricted"', '', $result);
    217     }
    218220}
    219221new RsvpifyEmbedder();
    220222
    221223/**
    222  * Shortcode handler: wraps the oEmbed iframe in a full-width, height-auto container.
     224 * Shortcode handler: wraps the oEmbed iframe in a responsive 16:9 container.
    223225 */
    224226function rsvpify_form_shortcode( $atts ) {
    225     $atts = shortcode_atts( [ 'url'=>'' ], $atts, 'rsvpify_form' );
     227    $atts = shortcode_atts( [ 'url' => '' ], $atts, 'rsvpify_form' );
    226228    $raw  = trim( $atts['url'] );
    227     if ( ! $raw ) return '';
    228     if ( ! preg_match('#^https?://#i',$raw) ) $raw = 'https://'.$raw;
    229     if ( ! preg_match('#^https?://[A-Za-z0-9-]+\.rsvpify\.com#i', $raw) ) {
     229    if ( ! $raw ) {
     230        return '';
     231    }
     232    if ( ! preg_match( '#^https?://#i', $raw ) ) {
     233        $raw = 'https://' . $raw;
     234    }
     235    if ( ! preg_match( '#^https?://[A-Za-z0-9-]+\.rsvpify\.com#i', $raw ) ) {
    230236        return '<!-- Invalid RSVPify URL -->';
    231237    }
    232     return '<div class="rsvpify-embed-wrap">'
     238
     239    return '<div class="rsvpify-embed-wrapper">'
    233240         . wp_oembed_get( esc_url_raw( $raw ) )
    234241         . '</div>';
     
    236243
    237244/**
    238  * Enqueue admin styles.
     245 * Admin styles enqueue.
    239246 */
    240247function rsvpify_embedder_styles() {
     
    243250        plugins_url( 'style.css', __FILE__ ),
    244251        [],
    245         filemtime( plugin_dir_path(__FILE__).'style.css' )
     252        filemtime( plugin_dir_path( __FILE__ ) . 'style.css' )
    246253    );
    247254}
     
    252259 */
    253260function rsvpify_embedder_auto_resize( $html, $url, $args ) {
    254     if ( false !== strpos($url,'rsvpify.com') ) {
    255         $html = preg_replace('/width="[^"]+"/','width="100%"',$html);
    256         $html = preg_replace('/height="[^"]+"/','height="auto"',$html);
     261    if ( false !== strpos( $url, 'rsvpify.com' ) ) {
     262        $html = preg_replace( '/width="[^"]+"/', 'width="100%"', $html );
     263        $html = preg_replace( '/height="[^"]+"/', 'height="auto"',   $html );
    257264    }
    258265    return $html;
Note: See TracChangeset for help on using the changeset viewer.