/** * Parse the Cue shortcode for display within a TinyMCE view. * * @since 1.3.0 */ function cue_ajax_parse_shortcode() { global $wp_scripts; if (empty($_POST['shortcode'])) { wp_send_json_error(); } $shortcode = do_shortcode(wp_unslash($_POST['shortcode'])); if (empty($shortcode)) { wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.'))); } $head = ''; $styles = wpview_media_sandbox_styles(); foreach ($styles as $style) { $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">'; } $head .= '<link rel="stylesheet" href="' . CUE_URL . 'assets/css/cue.min.css' . '">'; $head .= '<style type="text/css">.cue-tracks { max-height: none;}</style>'; if (!empty($wp_scripts)) { $wp_scripts->done = array(); } ob_start(); echo $shortcode; wp_print_scripts('cue'); wp_send_json_success(array('head' => $head, 'body' => ob_get_clean())); }
/** * @since 4.0.0 * * @global WP_Post $post * @global WP_Scripts $wp_scripts */ function wp_ajax_parse_media_shortcode() { global $post, $wp_scripts; if (empty($_POST['shortcode'])) { wp_send_json_error(); } $shortcode = wp_unslash($_POST['shortcode']); if (!empty($_POST['post_ID'])) { $post = get_post((int) $_POST['post_ID']); } // the embed shortcode requires a post if (!$post || !current_user_can('edit_post', $post->ID)) { if ('embed' === $shortcode) { wp_send_json_error(); } } else { setup_postdata($post); } $parsed = do_shortcode($shortcode); if (empty($parsed)) { wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.'))); } $head = ''; $styles = wpview_media_sandbox_styles(); foreach ($styles as $style) { $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">'; } if (!empty($wp_scripts)) { $wp_scripts->done = array(); } ob_start(); echo $parsed; if ('playlist' === $_REQUEST['type']) { wp_underscore_playlist_templates(); wp_print_scripts('wp-playlist'); } else { wp_print_scripts(array('froogaloop', 'wp-mediaelement')); } wp_send_json_success(array('head' => $head, 'body' => ob_get_clean())); }
/** * Parse shortcode for display within a TinyMCE view. */ public static function ajax_parse_shortcode() { global $wp_scripts; static $once = false; if ($once) { return; } $once = true; if (empty($_POST['shortcode'])) { wp_send_json_error(); } $slug = sanitize_text_field($_POST['type']); $full_shortcode = wp_kses_post(wp_unslash($_POST['shortcode'])); $shortcode = do_shortcode($full_shortcode); if (empty($shortcode)) { wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.'))); } $head = ''; $styles = wpview_media_sandbox_styles(); foreach ($styles as $style) { $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">'; } if (!empty($wp_scripts)) { $wp_scripts->done = array(); } ob_start(); echo $shortcode; $send = array('head' => $head, 'body' => ob_get_clean()); $send = apply_filters("shortcode_button_parse_mce_view_before_send", $send); $send = apply_filters("shortcode_button_parse_mce_view_before_send_{$slug}", $send); self::send_json_success($send); }