| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | su_add_shortcode( |
|---|
| 4 | array( |
|---|
| 5 | 'id' => 'lightbox', |
|---|
| 6 | 'callback' => 'su_shortcode_lightbox', |
|---|
| 7 | 'image' => su_get_plugin_url() . 'admin/images/shortcodes/lightbox.svg', |
|---|
| 8 | 'name' => __( 'Lightbox', 'shortcodes-ultimate' ), |
|---|
| 9 | 'type' => 'wrap', |
|---|
| 10 | 'group' => 'gallery', |
|---|
| 11 | 'possible_sibling' => 'lightbox_content', |
|---|
| 12 | 'article' => 'https://getshortcodes.com/docs/lightbox/', |
|---|
| 13 | 'atts' => array( |
|---|
| 14 | 'type' => array( |
|---|
| 15 | 'type' => 'select', |
|---|
| 16 | 'values' => array( |
|---|
| 17 | 'iframe' => __( 'Iframe', 'shortcodes-ultimate' ), |
|---|
| 18 | 'image' => __( 'Image', 'shortcodes-ultimate' ), |
|---|
| 19 | 'inline' => __( 'Inline (html content)', 'shortcodes-ultimate' ), |
|---|
| 20 | ), |
|---|
| 21 | 'default' => 'iframe', |
|---|
| 22 | 'name' => __( 'Content type', 'shortcodes-ultimate' ), |
|---|
| 23 | 'desc' => __( 'Select type of the lightbox window content', 'shortcodes-ultimate' ), |
|---|
| 24 | ), |
|---|
| 25 | 'src' => array( |
|---|
| 26 | 'default' => '', |
|---|
| 27 | 'name' => __( 'Content source', 'shortcodes-ultimate' ), |
|---|
| 28 | 'desc' => __( 'Insert here URL or CSS selector. Use URL for Iframe and Image content types. Use CSS selector for Inline content type.<br />Example values:<br /><b%value>http://www.youtube.com/watch?v=XXXXXXXXX</b> - YouTube video (iframe)<br /><b%value>http://example.com/wp-content/uploads/image.jpg</b> - uploaded image (image)<br /><b%value>http://example.com/</b> - any web page (iframe)<br /><b%value>#my-custom-popup</b> - any HTML content (inline)', 'shortcodes-ultimate' ), |
|---|
| 29 | ), |
|---|
| 30 | 'mobile' => array( |
|---|
| 31 | 'type' => 'bool', |
|---|
| 32 | 'default' => 'yes', |
|---|
| 33 | 'name' => __( 'Enable on mobile devices', 'shortcodes-ultimate' ), |
|---|
| 34 | 'desc' => __( 'Set this option to No to disable lightbox on mobile devices (≤768px)', 'shortcodes-ultimate' ), |
|---|
| 35 | ), |
|---|
| 36 | 'class' => array( |
|---|
| 37 | 'type' => 'extra_css_class', |
|---|
| 38 | 'name' => __( 'Extra CSS class', 'shortcodes-ultimate' ), |
|---|
| 39 | 'desc' => __( 'Additional CSS class name(s) separated by space(s)', 'shortcodes-ultimate' ), |
|---|
| 40 | 'default' => '', |
|---|
| 41 | ), |
|---|
| 42 | ), |
|---|
| 43 | 'content' => __( 'Click here to open lightbox', 'shortcodes-ultimate' ), |
|---|
| 44 | 'desc' => __( 'Lightbox window with custom content', 'shortcodes-ultimate' ), |
|---|
| 45 | 'icon' => 'external-link', |
|---|
| 46 | ) |
|---|
| 47 | ); |
|---|
| 48 | |
|---|
| 49 | function su_shortcode_lightbox( $atts = null, $content = null ) { |
|---|
| 50 | |
|---|
| 51 | $atts = shortcode_atts( |
|---|
| 52 | array( |
|---|
| 53 | 'src' => false, |
|---|
| 54 | 'type' => 'iframe', |
|---|
| 55 | 'mobile' => 'yes', |
|---|
| 56 | 'class' => '', |
|---|
| 57 | ), |
|---|
| 58 | $atts, |
|---|
| 59 | 'lightbox' |
|---|
| 60 | ); |
|---|
| 61 | |
|---|
| 62 | if ( ! $atts['src'] ) { |
|---|
| 63 | return su_error_message( 'Lightbox', __( 'please specify correct source', 'shortcodes-ultimate' ) ); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | su_query_asset( 'css', 'magnific-popup' ); |
|---|
| 67 | su_query_asset( 'js', 'jquery' ); |
|---|
| 68 | su_query_asset( 'js', 'magnific-popup' ); |
|---|
| 69 | su_query_asset( 'js', 'su-shortcodes' ); |
|---|
| 70 | |
|---|
| 71 | return '<span class="su-lightbox' . su_get_css_class( $atts ) . '" data-mfp-src="' . su_do_attribute( $atts['src'] ) . '" data-mfp-type="' . sanitize_key( $atts['type'] ) . '" data-mobile="' . sanitize_key( $atts['mobile'] ) . '">' . do_shortcode( $content ) . '</span>'; |
|---|
| 72 | |
|---|
| 73 | } |
|---|