PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / functions / actions.php

actions.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/functions/actions.php

226 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' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Get icons from admin ajax
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! function_exists( 'csf_get_icons' ) ) {
11 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
12 function csf_get_icons() {
13
14 // Check user capabilities
15 if ( ! current_user_can( 'manage_options' ) ) {
16 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
17 return wp_send_json_error( array( 'error' => esc_html__( 'Unauthorized access.', 'csf' ) ) );
18
19 }
20
21 $nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
22
23 if ( ! wp_verify_nonce( $nonce, 'csf_icon_nonce' ) ) {
24 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
25 return wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'csf' ) ) );
26
27 }
28
29 ob_start();
30
31 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
32 $icon_library = ( apply_filters( 'csf_fa4', false ) ) ? 'fa4' : 'fa5';
33
34 CSF::include_plugin_file( 'fields/icon/'. $icon_library .'-icons.php' );
35
36 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
37 $icon_lists = apply_filters( 'csf_field_icon_add_icons', csf_get_default_icons() );
38
39 if ( ! empty( $icon_lists ) ) {
40
41 foreach ( $icon_lists as $list ) {
42
43 echo ( count( $icon_lists ) >= 2 ) ? '<div class="csf-icon-title">'. esc_attr( $list['title'] ) .'</div>' : '';
44
45 foreach ( $list['icons'] as $icon ) {
46 echo '<i title="'. esc_attr( $icon ) .'" class="'. esc_attr( $icon ) .'"></i>';
47 }
48
49 }
50
51 } else {
52
53 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
54 echo '<div class="csf-error-text">'. esc_html__( 'No data available.', 'csf' ) .'</div>';
55
56 }
57
58 $content = ob_get_clean();
59
60 wp_send_json_success( array( 'content' => $content ) );
61
62 }
63 add_action( 'wp_ajax_csf-get-icons', 'csf_get_icons' );
64 }
65
66 /**
67 *
68 * Export
69 *
70 * @since 1.0.0
71 * @version 1.0.0
72 *
73 */
74 if ( ! function_exists( 'csf_export' ) ) {
75 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
76 function csf_export() {
77
78 $nonce = ( ! empty( $_GET[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'nonce' ] ) ) : '';
79 $unique = ( ! empty( $_GET[ 'unique' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'unique' ] ) ) : '';
80
81 if ( ! wp_verify_nonce( $nonce, 'csf_backup_nonce' ) ) {
82 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
83 die( esc_html__( 'Error: Invalid nonce verification.', 'csf' ) );
84 }
85
86 if ( empty( $unique ) ) {
87 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
88 die( esc_html__( 'Error: Invalid key.', 'csf' ) );
89 }
90
91 // Export
92 header('Content-Type: application/json');
93 header('Content-disposition: attachment; filename=backup-'. gmdate( 'd-m-Y' ) .'.json');
94 header('Content-Transfer-Encoding: binary');
95 header('Pragma: no-cache');
96 header('Expires: 0');
97
98 echo json_encode( get_option( $unique ) );
99
100 die();
101
102 }
103 add_action( 'wp_ajax_csf-export', 'csf_export' );
104 }
105
106 /**
107 *
108 * Import Ajax
109 *
110 * @since 1.0.0
111 * @version 1.0.0
112 *
113 */
114 if ( ! function_exists( 'csf_import_ajax' ) ) {
115 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
116 function csf_import_ajax() {
117
118 $nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
119 $unique = ( ! empty( $_POST[ 'unique' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'unique' ] ) ) : '';
120 // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
121 $data = ( ! empty( $_POST[ 'data' ] ) ) ? wp_kses_post_deep( json_decode( wp_unslash( trim( $_POST[ 'data' ] ) ), true ) ) : array();
122
123 if ( ! wp_verify_nonce( $nonce, 'csf_backup_nonce' ) ) {
124 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
125 return wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'csf' ) ) );
126
127 }
128
129 if ( empty( $unique ) ) {
130 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
131 return wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid key.', 'csf' ) ) );
132
133 }
134
135 if ( empty( $data ) || ! is_array( $data ) ) {
136 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
137 return wp_send_json_error( array( 'error' => esc_html__( 'Error: The response is not a valid JSON response.', 'csf' ) ) );
138 }
139
140 // Success
141 update_option( $unique, $data );
142
143 wp_send_json_success();
144
145 }
146 add_action( 'wp_ajax_csf-import', 'csf_import_ajax' );
147 }
148
149 /**
150 *
151 * Reset Ajax
152 *
153 * @since 1.0.0
154 * @version 1.0.0
155 *
156 */
157 if ( ! function_exists( 'csf_reset_ajax' ) ) {
158 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
159 function csf_reset_ajax() {
160
161 $nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
162 $unique = ( ! empty( $_POST[ 'unique' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'unique' ] ) ) : '';
163
164 if ( ! wp_verify_nonce( $nonce, 'csf_backup_nonce' ) ) {
165 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
166 return wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'csf' ) ) );
167
168 }
169
170 // Success
171 delete_option( $unique );
172
173 wp_send_json_success();
174
175 }
176 add_action( 'wp_ajax_csf-reset', 'csf_reset_ajax' );
177 }
178
179 /**
180 *
181 * Chosen Ajax
182 *
183 * @since 1.0.0
184 * @version 1.0.0
185 *
186 */
187 if ( ! function_exists( 'csf_chosen_ajax' ) ) {
188 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
189 function csf_chosen_ajax() {
190
191 $nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
192 $type = ( ! empty( $_POST[ 'type' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'type' ] ) ) : '';
193 $term = ( ! empty( $_POST[ 'term' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'term' ] ) ) : '';
194 // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
195 $query = ( ! empty( $_POST[ 'query_args' ] ) ) ? wp_kses_post_deep( wp_unslash( $_POST[ 'query_args' ] ) ) : array();
196
197 if ( ! wp_verify_nonce( $nonce, 'csf_chosen_ajax_nonce' ) ) {
198 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
199 return wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'csf' ) ) );
200
201 }
202
203 if ( empty( $type ) || empty( $term ) ) {
204 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
205 return wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid term ID.', 'csf' ) ) );
206
207 }
208
209 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
210 $capability = apply_filters( 'csf_chosen_ajax_capability', 'manage_options' );
211
212 if ( ! current_user_can( $capability ) ) {
213 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
214 return wp_send_json_error( array( 'error' => esc_html__( 'Error: You do not have permission to do that.', 'csf' ) ) );
215
216 }
217
218 // Success
219 $options = CSF_Fields::field_data( $type, $term, $query );
220
221 wp_send_json_success( $options );
222
223 }
224 add_action( 'wp_ajax_csf-chosen', 'csf_chosen_ajax' );
225 }
226