PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.26
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.26
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.4.26, at admin/views/sp-framework/functions/actions.php

158 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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' ) ) {
10 die; } // Cannot access directly.
11
12 if ( ! function_exists( 'pcp_get_option' ) ) {
13 /**
14 * The pcp_get_option function.
15 *
16 * @param string $option The option unique ID.
17 * @param mixed $default The default value for the option.
18 * @return statement
19 */
20 function pcp_get_option( $option = '', $default = null ) {
21 $options = get_option( 'sp_pcp_settings' );
22 return ( isset( $options[ $option ] ) ) ? $options[ $option ] : $default;
23 }
24 }
25
26 /**
27 * Populate the taxonomy name list to the select option.
28 *
29 * @return void
30 */
31 function sps_get_taxonomies() {
32 // 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' );
40
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' ) ) );
50 }
51 } else {
52 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'post-carousel' ) ) );
53 }
54 }
55 add_action( 'wp_ajax_sps_get_taxonomies', 'sps_get_taxonomies' );
56
57 /**
58 * Populate the taxonomy terms list to the select option.
59 *
60 * @return void
61 */
62 function sps_get_terms() {
63 $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
64 // 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 ) );
73 } else {
74 $terms = get_terms( array( $pcp_taxonomy ) );
75 }
76
77 foreach ( $terms as $key => $value ) {
78 echo '<option value="' . esc_attr( $value->term_id ) . '">' . esc_html( $value->name ) . '</option>';
79 }
80 } else {
81 wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'post-carousel' ) ) );
82 }
83 } else {
84 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'post-carousel' ) ) );
85 }
86 }
87
88 add_action( 'wp_ajax_sps_get_terms', 'sps_get_terms' );
89
90 if ( ! function_exists( 'spf_chosen_ajax' ) ) {
91 /**
92 *
93 * Chosen Ajax
94 *
95 * @since 1.0.0
96 * @version 1.0.0
97 */
98 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' ) ) {
105 $capability = apply_filters( 'spf_chosen_ajax_capability', 'manage_options' );
106 if ( current_user_can( $capability ) ) {
107 $options = SP_PC_Fields::field_data( $type, $term, $query );
108 wp_send_json_success( $options );
109 } else {
110 wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'post-carousel' ) ) );
111 }
112 } else {
113 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'post-carousel' ) ) );
114 }
115 }
116 add_action( 'wp_ajax_spf-chosen', 'spf_chosen_ajax' );
117 }
118
119 if ( ! function_exists( 'spf_set_icons' ) ) {
120 /**
121 *
122 * Set icons for wp dialog
123 *
124 * @since 1.0.0
125 * @version 1.0.0
126 */
127 function spf_set_icons() {
128 global $post_type;
129 if ( 'sp_post_carousel' === $post_type ) {
130 ?>
131 <div id="spf-modal-icon" class="spf-modal spf-modal-icon">
132 <div class="spf-modal-table">
133 <div class="spf-modal-table-cell">
134 <div class="spf-modal-overlay"></div>
135 <div class="spf-modal-inner">
136 <div class="spf-modal-title">
137 <?php esc_html_e( 'Add Icon', 'post-carousel' ); ?>
138 <div class="spf-modal-close spf-icon-close"></div>
139 </div>
140 <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" />
142 </div>
143 <div class="spf-modal-content">
144 <div class="spf-modal-loading"><div class="spf-loading"></div></div>
145 <div class="spf-modal-load"></div>
146 </div>
147 </div>
148 </div>
149 </div>
150 </div>
151 <?php
152 }
153
154 }
155 add_action( 'admin_footer', 'spf_set_icons' );
156 add_action( 'customize_controls_print_footer_scripts', 'spf_set_icons' );
157 }
158