Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/assets/js/rtmedia-gallery-shortcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This file is used to handle rtMedia Gallery shortcode
*/
jQuery(document).ready(function() {
// show notice: "rtMedia Gallery shortcode can be used only once."
wp.data.dispatch( 'core/notices' ).createNotice(
'warning',
rtmedia_gallery_shortcode.notice_message,
{
isDismissible: true
}
);
});
44 changes: 43 additions & 1 deletion app/main/controllers/shortcodes/RTMediaGalleryShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function __construct() {
add_shortcode( 'rtmedia_gallery', array( 'RTMediaGalleryShortcode', 'render' ) );
add_action( 'wp_ajax_rtmedia_get_template', array( &$this, 'ajax_rtmedia_get_template' ) );
add_action( 'wp_ajax_nopriv_rtmedia_get_template', array( &$this, 'ajax_rtmedia_get_template' ) );
add_action( 'admin_notices', array( 'RTMediaGalleryShortcode', 'rtmedia_gallery_shortcode_admin_notice' ) );
add_action( 'enqueue_block_editor_assets', array( 'RTMediaGalleryShortcode', 'rtmedia_gallery_shortcode_block_editor_assets' ) );
}

/**
Expand Down Expand Up @@ -158,10 +160,19 @@ public static function display_allowed() {
* Render a shortcode according to the attributes passed with it
*
* @param bool|array $attr Shortcode attributes.
* @param null $content Shortcode content.
* @param string $shortcode_tag Shortcode tag.
*
* @return bool|string
*/
public static function render( $attr ) {
public static function render( $attr, $content = null, $shortcode_tag = '' ) {
static $run_shortcode = false;

if ( true === $run_shortcode ) {
return '';
}

$run_shortcode = true;

if ( self::display_allowed() ) {

Expand Down Expand Up @@ -359,4 +370,35 @@ public static function rtmedia_query_where_filter( $where, $table_name, $join )

return $where;
}

/**
* Display admin notice for rtMedia Gallery shortcode.
*/
public static function rtmedia_gallery_shortcode_admin_notice() {
?>
<div class="notice notice-warning is-dismissible">
<p>
<?php esc_html_e( 'rtMedia Gallery shortcode can be used only once.', 'buddypress-media' ); ?>
</p>
</div>
<?php
}

/**
* Enqueue block editor assets for rtMedia Gallery shortcode.
*/
public static function rtmedia_gallery_shortcode_block_editor_assets() {
wp_enqueue_script(
'rtmedia-gallery-shortcode',
RTMEDIA_URL . 'app/assets/js/rtmedia-gallery-shortcode.js',
array(
'jquery',
),
RTMEDIA_VERSION,
true
);

// localizing the script for the rtMedia Gallery shortcode.
wp_localize_script( 'rtmedia-gallery-shortcode', 'rtmedia_gallery_shortcode', array( 'notice_message' => esc_html__( 'rtMedia Gallery shortcode can be used only once.', 'buddypress-media' ) ) );
}
}
Loading