| 1 |
<?php |
| 2 |
/** |
| 3 |
* The admin preview. |
| 4 |
* |
| 5 |
* @link http://smartpostshow.com/ |
| 6 |
* @since 2.1.4 |
| 7 |
* |
| 8 |
* @package Smart_Post_Show |
| 9 |
* @subpackage Smart_Post_Show/admin |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* The admin preview. |
| 14 |
* |
| 15 |
* @package Smart_Post_Show |
| 16 |
* @subpackage Smart_Post_Show/admin |
| 17 |
* @author ShapedPlugin <support@shapedplugin.com> |
| 18 |
*/ |
| 19 |
class Class_SPSPS_Preview { |
| 20 |
|
| 21 |
/** |
| 22 |
* Script and style suffix |
| 23 |
* |
| 24 |
* @since 2.1.4 |
| 25 |
* @access protected |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
protected $suffix; |
| 29 |
|
| 30 |
/** |
| 31 |
* Initialize the class and set its properties. |
| 32 |
* |
| 33 |
* @since 2.1.4 |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
$this->pcp_preview_action(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Public Action |
| 41 |
* |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
private function pcp_preview_action() { |
| 45 |
// admin Preview. |
| 46 |
add_action( 'wp_ajax_spf_preview_meta_box', array( $this, 'pcp_backend_preview' ) ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Function Backed preview. |
| 51 |
* |
| 52 |
* @since 2.2.5 |
| 53 |
*/ |
| 54 |
public function pcp_backend_preview() { |
| 55 |
$nonce = ! empty( $_POST['nonce'] ) ? sanitize_text_field( |
| 56 |
wp_unslash( $_POST['nonce'] ) |
| 57 |
) : ''; |
| 58 |
if ( ! wp_verify_nonce( $nonce, 'spf_pcp_metabox_nonce' ) ) { |
| 59 |
return false; |
| 60 |
} |
| 61 |
$capability = apply_filters( 'spf_chosen_ajax_capability', 'manage_options' ); |
| 62 |
if ( ! current_user_can( $capability ) ) { |
| 63 |
return esc_html__( 'You do not have required permissions to access.', 'smart-post-show' ); |
| 64 |
} |
| 65 |
$settings = array(); |
| 66 |
$data = ! empty( $_POST['data'] ) ? |
| 67 |
wp_unslash( $_POST['data'] ) // phpcs:ignore |
| 68 |
: ''; |
| 69 |
parse_str( $data, $settings ); |
| 70 |
$settings = array_map( 'wp_kses_post_deep', $settings ); |
| 71 |
// Shortcode id. |
| 72 |
$pcp_gl_id = $settings['post_ID']; |
| 73 |
// Preset Layouts. |
| 74 |
$layout = $settings['sp_pcp_layouts']; |
| 75 |
$layouts = $layout; |
| 76 |
// All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc. |
| 77 |
$view_options = $settings['sp_pcp_view_options']; |
| 78 |
$section_title = $settings['post_title']; |
| 79 |
?><style> |
| 80 |
<?php |
| 81 |
$pcp_id = $pcp_gl_id; |
| 82 |
$custom_css = ''; |
| 83 |
include SP_PC_PATH . 'public/dynamic-css/dynamic-css.php'; |
| 84 |
echo esc_html( $custom_css ); |
| 85 |
?> |
| 86 |
</style> |
| 87 |
<?php |
| 88 |
SP_PC_Output::pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title ); |
| 89 |
?> |
| 90 |
<script src="<?php echo esc_url( SP_PC_URL ); ?>/admin/assets/js/preview.js"></script> |
| 91 |
<?php |
| 92 |
die(); |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
new Class_SPSPS_Preview(); |
| 97 |
|