PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
← All changes | admin/views/sp-framework/functions/actions.php +147 -57 2.4.132.2.10 View file →
@@ -1,13 +1,5 @@
1 -<?php
2 -/**
3 - * The admin action file.
4 - *
5 - * @package Smart_Post_Show
6 - * @subpackage Smart_Post_Show/admin/views
7 - */
8 -
9 -if ( ! defined( 'ABSPATH' ) ) {
1 +<?php if ( ! defined( 'ABSPATH' ) ) {
10 2 die; } // Cannot access directly.
11 3
12 4 if ( ! function_exists( 'pcp_get_option' ) ) {
13 5 /**
@@ -23,35 +15,26 @@
23 15 }
24 16 }
25 17
26 18 /**
27 - * Populate the taxonomy name list to the select option.
19 + * Populate the taxonomy name list to he select option.
28 20 *
29 21 * @return void
30 22 */
31 23 function sps_get_taxonomies() {
32 24 // Check for nonce security.
33 - $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
34 - // Check for nonce security.
35 - if ( wp_verify_nonce( $nonce, 'spf_pcp_metabox_nonce' ) ) {
36 - $capability = apply_filters( 'sp_pc_dashboard_capability', 'manage_options' );
37 - if ( current_user_can( $capability ) ) {
38 - $the_pcp_post_types = ( ! empty( $_POST['pcp_post_types'] ) ) ? sanitize_text_field( wp_unslash( $_POST['pcp_post_types'] ) ) : '';
39 - $sp_post_types = $the_pcp_post_types ? $the_pcp_post_types : get_post_types( array(), 'names' );
25 + check_ajax_referer( 'spf_pcp_metabox_nonce', wp_unslash( $_POST['ajax_nonce'] ), false );
26 + $the_pcp_post_types = wp_unslash( $_POST['pcp_post_types'] );
27 + $sp_post_types = $the_pcp_post_types ? $the_pcp_post_types : get_post_types( [], 'names' );
40 28
41 - $taxonomy_names = get_object_taxonomies( $sp_post_types, 'names' );
42 - if ( ! is_wp_error( $taxonomy_names ) && ! empty( $taxonomy_names ) ) {
43 - echo '<option value="">' . esc_html__( 'Select Taxonomy', 'post-carousel' ) . '</option>';
44 - foreach ( $taxonomy_names as $taxonomy => $label ) {
45 - echo '<option value="' . esc_attr( $label ) . '">' . esc_html( $label ) . '</option>';
46 - }
47 - }
48 - } else {
49 - wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'post-carousel' ) ) );
29 + $taxonomy_names = get_object_taxonomies( $sp_post_types, 'names' );
30 + if ( ! is_wp_error( $taxonomy_names ) && ! empty( $taxonomy_names ) ) {
31 + echo '<option value="">' . __( 'Select Taxonomy', 'smart-post-show' ) . '</option>';
32 + foreach ( $taxonomy_names as $taxonomy => $label ) {
33 + echo '<option value="' . $label . '">' . $label . '</option>';
50 34 }
51 - } else {
52 - wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'post-carousel' ) ) );
53 35 }
36 + die( 0 );
54 37 }
55 38 add_action( 'wp_ajax_sps_get_taxonomies', 'sps_get_taxonomies' );
56 39
57 40 /**
@@ -59,35 +42,144 @@
59 42 *
60 43 * @return void
61 44 */
62 45 function sps_get_terms() {
63 - $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
64 46 // Check for nonce security.
65 - if ( wp_verify_nonce( $nonce, 'spf_pcp_metabox_nonce' ) ) {
66 - $capability = apply_filters( 'sp_pc_dashboard_capability', 'manage_options' );
67 - if ( current_user_can( $capability ) ) {
68 - $the_pcp_taxonomy = ( ! empty( $_POST['pcp_post_taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_POST['pcp_post_taxonomy'] ) ) : '';
69 - $sp_post_types = get_post_types( array(), 'names' );
70 - $pcp_taxonomy = $the_pcp_taxonomy ? $the_pcp_taxonomy : get_object_taxonomies( $sp_post_types, 'names' );
71 - if ( version_compare( get_bloginfo( 'version' ), '4.5', '>=' ) ) {
72 - $terms = get_terms( array( 'taxonomy' => $pcp_taxonomy ) );
47 + check_ajax_referer( 'spf_pcp_metabox_nonce', wp_unslash( $_POST['ajax_nonce'] ), false );
48 + $the_pcp_taxonomy = wp_unslash( $_POST['pcp_post_taxonomy'] );
49 + $sp_post_types = get_post_types( [], 'names' );
50 + $pcp_taxonomy = $the_pcp_taxonomy ? $the_pcp_taxonomy : get_object_taxonomies( $sp_post_types, 'names' );
51 + if ( version_compare( get_bloginfo( 'version' ), '4.5', '>=' ) ) {
52 + $terms = get_terms( array( 'taxonomy' => $pcp_taxonomy ) );
53 + } else {
54 + $terms = get_terms( array( $pcp_taxonomy ) );
55 + }
56 +
57 + foreach ( $terms as $key => $value ) {
58 + echo '<option value="' . $value->term_id . '">' . $value->name . '</option>';
59 + }
60 + wp_die();
61 +}
62 +add_action( 'wp_ajax_sps_get_terms', 'sps_get_terms' );
63 +
64 +
65 +if ( ! function_exists( 'sps_get_icons' ) ) {
66 + /**
67 + *
68 + * Get icons from admin ajax
69 + *
70 + * @since 1.0.0
71 + * @version 1.0.0
72 + */
73 + function sps_get_icons() {
74 +
75 + if ( ! empty( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'spf_icon_nonce' ) ) {
76 +
77 + ob_start();
78 +
79 + SP_PC::include_plugin_file( 'fields/icon/default-icons.php' );
80 +
81 + $icon_lists = apply_filters( 'spf_field_icon_add_icons', spf_get_default_icons() );
82 +
83 + if ( ! empty( $icon_lists ) ) {
84 +
85 + foreach ( $icon_lists as $list ) {
86 +
87 + echo ( count( $icon_lists ) >= 2 ) ? '<div class="spf-icon-title">' . $list['title'] . '</div>' : '';
88 +
89 + foreach ( $list['icons'] as $icon ) {
90 + echo '<a class="spf-icon-tooltip" data-spf-icon="' . $icon . '" title="' . $icon . '"><span class="spf-icon spf-selector"><i class="' . $icon . '"></i></span></a>';
91 + }
92 + }
73 93 } else {
74 - $terms = get_terms( array( $pcp_taxonomy ) );
94 + echo '<div class="spf-text-error">' . esc_html__( 'No data provided by developer', 'smart-post-show' ) . '</div>';
75 95 }
76 96
77 - foreach ( $terms as $key => $value ) {
78 - echo '<option value="' . esc_attr( $value->term_id ) . '">' . esc_html( $value->name ) . '</option>';
97 + wp_send_json_success( array( 'content' => ob_get_clean() ) );
98 +
99 + } else {
100 +
101 + wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
102 +
103 + }
104 +
105 + }
106 + add_action( 'wp_ajax_spf-get-icons', 'sps_get_icons' );
107 +}
108 +
109 +if ( ! function_exists( 'spf_export' ) ) {
110 +
111 + /**
112 + *
113 + * Export
114 + *
115 + * @since 1.0.0
116 + * @version 1.0.0
117 + */
118 + function spf_export() {
119 +
120 + if ( ! empty( $_GET['export'] ) && ! empty( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'spf_backup_nonce' ) ) {
121 + header( 'Content-Type: application/json' );
122 + header( 'Content-disposition: attachment; filename=backup-' . gmdate( 'd-m-Y' ) . '.json' );
123 + header( 'Content-Transfer-Encoding: binary' );
124 + header( 'Pragma: no-cache' );
125 + header( 'Expires: 0' );
126 + echo json_encode( get_option( wp_unslash( $_GET['export'] ) ) );
127 + }
128 + die();
129 + }
130 + add_action( 'wp_ajax_spf-export', 'spf_export' );
131 +}
132 +
133 +if ( ! function_exists( 'spf_import_ajax' ) ) {
134 + /**
135 + *
136 + * Import Ajax
137 + *
138 + * @since 1.0.0
139 + * @version 1.0.0
140 + */
141 + function spf_import_ajax() {
142 +
143 + if ( ! empty( $_POST['import_data'] ) && ! empty( $_POST['unique'] ) && ! empty( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'spf_backup_nonce' ) ) {
144 + $import_data = json_decode( wp_unslash( trim( $_POST['import_data'] ) ), true );
145 +
146 + if ( is_array( $import_data ) ) {
147 +
148 + update_option( wp_unslash( $_POST['unique'] ), wp_unslash( $import_data ) );
149 + wp_send_json_success();
150 +
79 151 }
80 - } else {
81 - wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'post-carousel' ) ) );
82 152 }
83 - } else {
84 - wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'post-carousel' ) ) );
153 +
154 + wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
155 +
85 156 }
157 + add_action( 'wp_ajax_spf-import', 'spf_import_ajax' );
86 158 }
87 159
88 - add_action( 'wp_ajax_sps_get_terms', 'sps_get_terms' );
160 +if ( ! function_exists( 'spf_reset_ajax' ) ) {
89 161
162 + /**
163 + *
164 + * Reset Ajax
165 + *
166 + * @since 1.0.0
167 + * @version 1.0.0
168 + */
169 + function spf_reset_ajax() {
170 +
171 + if ( ! empty( $_POST['unique'] ) && ! empty( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'spf_backup_nonce' ) ) {
172 + delete_option( wp_unslash( $_POST['unique'] ) );
173 + wp_send_json_success();
174 + }
175 +
176 + wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
177 +
178 + }
179 + add_action( 'wp_ajax_spf-reset', 'spf_reset_ajax' );
180 +}
181 +
90 182 if ( ! function_exists( 'spf_chosen_ajax' ) ) {
91 183 /**
92 184 *
93 185 * Chosen Ajax
@@ -95,23 +187,21 @@
95 187 * @since 1.0.0
96 188 * @version 1.0.0
97 189 */
98 190 function spf_chosen_ajax() {
99 -
100 - $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
101 - $type = ( ! empty( $_POST['type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
102 - $term = ( ! empty( $_POST['term'] ) ) ? sanitize_text_field( wp_unslash( $_POST['term'] ) ) : '';
103 - $query = ( ! empty( $_POST['query_args'] ) ) ? wp_kses_post_deep( wp_unslash( $_POST['query_args'] ) ) : array(); // phpcs:ignore
104 - if ( wp_verify_nonce( $nonce, 'spf_chosen_ajax_nonce' ) ) {
191 + if ( ! empty( $_POST['term'] ) && ! empty( $_POST['type'] ) && ! empty( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'spf_chosen_ajax_nonce' ) ) {
105 192 $capability = apply_filters( 'spf_chosen_ajax_capability', 'manage_options' );
106 193 if ( current_user_can( $capability ) ) {
107 - $options = SP_PC_Fields::field_data( $type, $term, $query );
194 + $type = $_POST['type'];
195 + $term = $_POST['term'];
196 + $query_args = ( ! empty( $_POST['query_args'] ) ) ? $_POST['query_args'] : array();
197 + $options = SP_PC_Fields::field_data( $type, $term, $query_args );
108 198 wp_send_json_success( $options );
109 199 } else {
110 - wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'post-carousel' ) ) );
200 + wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'smart-post-show' ) ) );
111 201 }
112 202 } else {
113 - wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'post-carousel' ) ) );
203 + wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
114 204 }
115 205 }
116 206 add_action( 'wp_ajax_spf-chosen', 'spf_chosen_ajax' );
117 207 }
@@ -133,13 +223,13 @@
133 223 <div class="spf-modal-table-cell">
134 224 <div class="spf-modal-overlay"></div>
135 225 <div class="spf-modal-inner">
136 226 <div class="spf-modal-title">
137 - <?php esc_html_e( 'Add Icon', 'post-carousel' ); ?>
227 + <?php esc_html_e( 'Add Icon', 'smart-post-show' ); ?>
138 228 <div class="spf-modal-close spf-icon-close"></div>
139 229 </div>
140 230 <div class="spf-modal-header spf-text-center">
141 - <input type="text" placeholder="<?php esc_html_e( 'Search a Icon...', 'post-carousel' ); ?>" class="spf-icon-search" />
231 + <input type="text" placeholder="<?php esc_html_e( 'Search a Icon...', 'smart-post-show' ); ?>" class="spf-icon-search" />
142 232 </div>
143 233 <div class="spf-modal-content">
144 234 <div class="spf-modal-loading"><div class="spf-loading"></div></div>
145 235 <div class="spf-modal-load"></div>
@@ -153,5 +243,5 @@
153 243
154 244 }
155 245 add_action( 'admin_footer', 'spf_set_icons' );
156 246 add_action( 'customize_controls_print_footer_scripts', 'spf_set_icons' );
157 -}
247 +}