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
post-carousel / admin / views / sp-framework / functions / actions.php

actions.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.2.10, at admin/views/sp-framework/functions/actions.php

247 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot access directly.
3
4 if ( ! function_exists( 'pcp_get_option' ) ) {
5 /**
6 * The pcp_get_option function.
7 *
8 * @param string $option The option unique ID.
9 * @param mixed $default The default value for the option.
10 * @return statement
11 */
12 function pcp_get_option( $option = '', $default = null ) {
13 $options = get_option( 'sp_pcp_settings' );
14 return ( isset( $options[ $option ] ) ) ? $options[ $option ] : $default;
15 }
16 }
17
18 /**
19 * Populate the taxonomy name list to he select option.
20 *
21 * @return void
22 */
23 function sps_get_taxonomies() {
24 // Check for nonce security.
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' );
28
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>';
34 }
35 }
36 die( 0 );
37 }
38 add_action( 'wp_ajax_sps_get_taxonomies', 'sps_get_taxonomies' );
39
40 /**
41 * Populate the taxonomy terms list to the select option.
42 *
43 * @return void
44 */
45 function sps_get_terms() {
46 // Check for nonce security.
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 }
93 } else {
94 echo '<div class="spf-text-error">' . esc_html__( 'No data provided by developer', 'smart-post-show' ) . '</div>';
95 }
96
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
151 }
152 }
153
154 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
155
156 }
157 add_action( 'wp_ajax_spf-import', 'spf_import_ajax' );
158 }
159
160 if ( ! function_exists( 'spf_reset_ajax' ) ) {
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
182 if ( ! function_exists( 'spf_chosen_ajax' ) ) {
183 /**
184 *
185 * Chosen Ajax
186 *
187 * @since 1.0.0
188 * @version 1.0.0
189 */
190 function spf_chosen_ajax() {
191 if ( ! empty( $_POST['term'] ) && ! empty( $_POST['type'] ) && ! empty( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'spf_chosen_ajax_nonce' ) ) {
192 $capability = apply_filters( 'spf_chosen_ajax_capability', 'manage_options' );
193 if ( current_user_can( $capability ) ) {
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 );
198 wp_send_json_success( $options );
199 } else {
200 wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'smart-post-show' ) ) );
201 }
202 } else {
203 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
204 }
205 }
206 add_action( 'wp_ajax_spf-chosen', 'spf_chosen_ajax' );
207 }
208
209 if ( ! function_exists( 'spf_set_icons' ) ) {
210 /**
211 *
212 * Set icons for wp dialog
213 *
214 * @since 1.0.0
215 * @version 1.0.0
216 */
217 function spf_set_icons() {
218 global $post_type;
219 if ( 'sp_post_carousel' === $post_type ) {
220 ?>
221 <div id="spf-modal-icon" class="spf-modal spf-modal-icon">
222 <div class="spf-modal-table">
223 <div class="spf-modal-table-cell">
224 <div class="spf-modal-overlay"></div>
225 <div class="spf-modal-inner">
226 <div class="spf-modal-title">
227 <?php esc_html_e( 'Add Icon', 'smart-post-show' ); ?>
228 <div class="spf-modal-close spf-icon-close"></div>
229 </div>
230 <div class="spf-modal-header spf-text-center">
231 <input type="text" placeholder="<?php esc_html_e( 'Search a Icon...', 'smart-post-show' ); ?>" class="spf-icon-search" />
232 </div>
233 <div class="spf-modal-content">
234 <div class="spf-modal-loading"><div class="spf-loading"></div></div>
235 <div class="spf-modal-load"></div>
236 </div>
237 </div>
238 </div>
239 </div>
240 </div>
241 <?php
242 }
243
244 }
245 add_action( 'admin_footer', 'spf_set_icons' );
246 add_action( 'customize_controls_print_footer_scripts', 'spf_set_icons' );
247 }