Changeset 3285893
- Timestamp:
- 05/01/2025 09:46:06 PM (11 months ago)
- Location:
- rsvpify-oembed/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
rsvpify-embedder.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rsvpify-oembed/trunk/readme.txt
r3285891 r3285893 8 8 Requires at least: 5.6 9 9 Tested up to: 6.8 10 Stable tag: 3.1 110 Stable tag: 3.12 11 11 Requires PHP: 7.0 12 12 License: GNU General Public License v3 -
rsvpify-oembed/trunk/rsvpify-embedder.php
r3285891 r3285893 4 4 * Plugin URI: https://wordpress.org/plugins/rsvpify-oembed/ 5 5 * Description: Easily embed your RSVPify event RSVP and ticket forms by pasting your event URL. 6 * Version: 3.1 16 * Version: 3.12 7 7 * Author: RSVPify Inc. 8 8 * Author URI: https://www.rsvpify.com … … 22 22 23 23 public function __construct() { 24 // Admin 24 // Admin UI 25 25 add_action( 'admin_menu', [ $this, 'register_admin_page' ] ); 26 26 add_action( 'admin_enqueue_scripts', 'rsvpify_embedder_styles' ); … … 28 28 add_action( 'wp_ajax_rsvpify_delete_shortcode', [ $this, 'ajax_delete_shortcode' ] ); 29 29 30 // oEmbed 30 // oEmbed provider + filters 31 31 wp_oembed_add_provider( 'https://*.rsvpify.com', 'https://app3.rsvpify.com/api/rsvp/oembed' ); 32 32 add_filter( 'oembed_dataparse', [ $this, 'set_sandbox_attribute' ], 99, 4 ); 33 33 add_filter( 'oembed_result', 'rsvpify_embedder_auto_resize', 10, 3 ); 34 34 35 // Shortcode 35 // Shortcode registration 36 36 add_shortcode( 'rsvpify_form', 'rsvpify_form_shortcode' ); 37 37 38 // Front‐end CSS override on both front andElementor editor38 // Enqueue responsive CSS on front and in Elementor editor 39 39 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_frontend_css' ] ); 40 40 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_frontend_css' ] ); 41 41 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' ] ); 43 43 } 44 44 … … 88 88 </div> 89 89 90 <script >90 <script type="text/javascript"> 91 91 (function(){ 92 92 var list = document.getElementById('rsvpify_list'), … … 147 147 var item = d.parentNode, 148 148 code = item.getAttribute('data-code'); 149 149 150 var data = new URLSearchParams(); 150 151 data.append('action','rsvpify_delete_shortcode'); 151 152 data.append('code', code); 153 152 154 fetch(ajaxUrl, { 153 155 method:'POST', … … 167 169 } 168 170 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 169 212 public function enqueue_frontend_css() { 170 213 wp_enqueue_style( … … 175 218 ); 176 219 } 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 $result214 );215 }216 return str_replace('security="restricted"', '', $result);217 }218 220 } 219 221 new RsvpifyEmbedder(); 220 222 221 223 /** 222 * Shortcode handler: wraps the oEmbed iframe in a full-width, height-autocontainer.224 * Shortcode handler: wraps the oEmbed iframe in a responsive 16:9 container. 223 225 */ 224 226 function rsvpify_form_shortcode( $atts ) { 225 $atts = shortcode_atts( [ 'url' =>'' ], $atts, 'rsvpify_form' );227 $atts = shortcode_atts( [ 'url' => '' ], $atts, 'rsvpify_form' ); 226 228 $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 ) ) { 230 236 return '<!-- Invalid RSVPify URL -->'; 231 237 } 232 return '<div class="rsvpify-embed-wrap">' 238 239 return '<div class="rsvpify-embed-wrapper">' 233 240 . wp_oembed_get( esc_url_raw( $raw ) ) 234 241 . '</div>'; … … 236 243 237 244 /** 238 * Enqueue admin styles.245 * Admin styles enqueue. 239 246 */ 240 247 function rsvpify_embedder_styles() { … … 243 250 plugins_url( 'style.css', __FILE__ ), 244 251 [], 245 filemtime( plugin_dir_path( __FILE__).'style.css' )252 filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ) 246 253 ); 247 254 } … … 252 259 */ 253 260 function 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 ); 257 264 } 258 265 return $html;
Note: See TracChangeset
for help on using the changeset viewer.