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
19 changes: 18 additions & 1 deletion bootstrap-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct() {
register_activation_hook( __FILE__, array( &$this, 'add_options_defaults' ) );
add_action( 'admin_init', array( &$this, 'register_settings' ) );
add_action( 'admin_menu', array( &$this, 'register_settings_page' ) );
add_action( 'wp_ajax_bss_do_shortcode', array( &$this, 'bss_do_shortcode') );
}

function init() {
Expand All @@ -63,6 +64,7 @@ function init() {
if ( get_user_option( 'rich_editing' ) == 'true' ) {
add_filter( 'mce_external_plugins', array( &$this, 'regplugins' ) );
add_filter( 'mce_buttons_3', array( &$this, 'regbtns' ) );
add_filter( 'tiny_mce_before_init', array( &$this ,'register_tinymce_settings') );
}
}

Expand All @@ -83,6 +85,21 @@ function regplugins( $plgs) {
return $plgs;
}

function register_tinymce_settings( $settings ) {
$settings['ajaxurl'] = admin_url( 'admin-ajax.php' );
$settings['bss_nonce'] = wp_create_nonce( 'bss_ajax_do_shortcode' );
return $settings;
}

function bss_do_shortcode() {
if( false === check_ajax_referer('bss_ajax_do_shortcode', 'nonce', false) ) {
_e( 'Security Issue - No Preview', 'bsshortcodes');
} else {
echo do_shortcode( wp_unslash( $_POST['shortcode'] ) ) ;
}
wp_die(); // this is required to terminate immediately and return a proper response
}

function register_settings_page() {
add_options_page( __( 'BS Shortcodes', 'bsshortcodes' ), __( 'BS Shortcodes', 'bsshortcodes' ), 'manage_options', __FILE__, array( &$this, 'dw_render_form') );
}
Expand Down Expand Up @@ -162,4 +179,4 @@ function dw_render_form() {
}
}

$bscodes = new BootstrapShortcodes();
$bscodes = new BootstrapShortcodes();
10 changes: 7 additions & 3 deletions js/plugins/alerts.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
}

function renderAlertPreview() {
var closebutton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
var template = '<div class="alert alert-' + alertType() + '" role="alert">Your content here.' + (isDismissable()? closebutton: '') + '</div>'
$('#alert-demo').html(template);
jQuery.post(top.tinymce.settings.ajaxurl, {
'action': 'bss_do_shortcode',
'nonce': top.tinymce.settings.bss_nonce,
'shortcode': alertShortcode()
}, function(response) {
$('#alert-demo').html( response );
});
}

function insertShortcode(event) {
Expand Down