PUM_Admin_Shortcode_UI::do_shortcode()
Description Description
Source Source
File: classes/Admin/Shortcode/UI.php
public static function do_shortcode() { check_ajax_referer( 'pum-shortcode-ui-nonce', 'nonce' ); $tag = ! empty( $_REQUEST['tag'] ) ? sanitize_key( $_REQUEST['tag'] ) : false; $shortcode = ! empty( $_REQUEST['shortcode'] ) ? stripslashes( sanitize_text_field( $_REQUEST['shortcode'] ) ) : null; $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : null; if ( ! current_user_can( 'edit_post', $post_id ) ) { return esc_html__( "You do not have access to preview this post.", 'popup-maker' ); } /** @var PUM_Shortcode $shortcode */ $shortcode_object = PUM_Shortcodes::instance()->get_shortcode( $tag ); if ( ! defined( 'PUM_DOING_PREVIEW' ) ) { define( 'PUM_DOING_PREVIEW', true ); } /** * Often the global $post is not set yet. Set it in case for proper rendering. */ if ( ! empty( $post_id ) ) { global $post; $post = get_post( $post_id ); setup_postdata( $post ); } /** @var string $content Rendered shortcode content. */ $content = PUM_Helpers::do_shortcode( $shortcode ); /** If no matching tag or $content wasn't rendered die. */ if ( ! $shortcode_object || $content == $shortcode ) { wp_send_json_error(); } /** Generate inline styles when needed. */ $styles = "<style>" . $shortcode_object->get_template_styles() . "</style>"; wp_send_json_success( $styles . $content ); }
Expand full source code Collapse full source code View on Trac