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

150 lines 5.7 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 the select option.
20 *
21 * @return void
22 */
23 function sps_get_taxonomies() {
24 // Check for nonce security.
25 $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
26 // Check for nonce security.
27 if ( wp_verify_nonce( $nonce, 'spf_pcp_metabox_nonce' ) ) {
28 $capability = apply_filters( 'sp_pc_dashboard_capability', 'manage_options' );
29 if ( current_user_can( $capability ) ) {
30 $the_pcp_post_types = ( ! empty( $_POST['pcp_post_types'] ) ) ? sanitize_text_field( wp_unslash( $_POST['pcp_post_types'] ) ) : '';
31 $sp_post_types = $the_pcp_post_types ? $the_pcp_post_types : get_post_types( array(), 'names' );
32
33 $taxonomy_names = get_object_taxonomies( $sp_post_types, 'names' );
34 if ( ! is_wp_error( $taxonomy_names ) && ! empty( $taxonomy_names ) ) {
35 echo '<option value="">' . esc_html__( 'Select Taxonomy', 'smart-post-show' ) . '</option>';
36 foreach ( $taxonomy_names as $taxonomy => $label ) {
37 echo '<option value="' . esc_attr( $label ) . '">' . esc_html( $label ) . '</option>';
38 }
39 }
40 } else {
41 wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'smart-post-show' ) ) );
42 }
43 } else {
44 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
45 }
46 }
47 add_action( 'wp_ajax_sps_get_taxonomies', 'sps_get_taxonomies' );
48
49 /**
50 * Populate the taxonomy terms list to the select option.
51 *
52 * @return void
53 */
54 function sps_get_terms() {
55 $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
56 // Check for nonce security.
57 if ( wp_verify_nonce( $nonce, 'spf_pcp_metabox_nonce' ) ) {
58 $capability = apply_filters( 'sp_pc_dashboard_capability', 'manage_options' );
59 if ( current_user_can( $capability ) ) {
60 $the_pcp_taxonomy = ( ! empty( $_POST['pcp_post_taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_POST['pcp_post_taxonomy'] ) ) : '';
61 $sp_post_types = get_post_types( array(), 'names' );
62 $pcp_taxonomy = $the_pcp_taxonomy ? $the_pcp_taxonomy : get_object_taxonomies( $sp_post_types, 'names' );
63 if ( version_compare( get_bloginfo( 'version' ), '4.5', '>=' ) ) {
64 $terms = get_terms( array( 'taxonomy' => $pcp_taxonomy ) );
65 } else {
66 $terms = get_terms( array( $pcp_taxonomy ) );
67 }
68
69 foreach ( $terms as $key => $value ) {
70 echo '<option value="' . esc_attr( $value->term_id ) . '">' . esc_html( $value->name ) . '</option>';
71 }
72 } else {
73 wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'smart-post-show' ) ) );
74 }
75 } else {
76 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
77 }
78 }
79
80 add_action( 'wp_ajax_sps_get_terms', 'sps_get_terms' );
81
82 if ( ! function_exists( 'spf_chosen_ajax' ) ) {
83 /**
84 *
85 * Chosen Ajax
86 *
87 * @since 1.0.0
88 * @version 1.0.0
89 */
90 function spf_chosen_ajax() {
91
92 $nonce = ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
93 $type = ( ! empty( $_POST['type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
94 $term = ( ! empty( $_POST['term'] ) ) ? sanitize_text_field( wp_unslash( $_POST['term'] ) ) : '';
95 $query = ( ! empty( $_POST['query_args'] ) ) ? wp_kses_post_deep( wp_unslash( $_POST['query_args'] ) ) : array(); // phpcs:ignore
96 if ( wp_verify_nonce( $nonce, 'spf_chosen_ajax_nonce' ) ) {
97 $capability = apply_filters( 'spf_chosen_ajax_capability', 'manage_options' );
98 if ( current_user_can( $capability ) ) {
99 $options = SP_PC_Fields::field_data( $type, $term, $query );
100 wp_send_json_success( $options );
101 } else {
102 wp_send_json_error( array( 'error' => esc_html__( 'You do not have required permissions to access.', 'smart-post-show' ) ) );
103 }
104 } else {
105 wp_send_json_error( array( 'error' => esc_html__( 'Error: Nonce verification has failed. Please try again.', 'smart-post-show' ) ) );
106 }
107 }
108 add_action( 'wp_ajax_spf-chosen', 'spf_chosen_ajax' );
109 }
110
111 if ( ! function_exists( 'spf_set_icons' ) ) {
112 /**
113 *
114 * Set icons for wp dialog
115 *
116 * @since 1.0.0
117 * @version 1.0.0
118 */
119 function spf_set_icons() {
120 global $post_type;
121 if ( 'sp_post_carousel' === $post_type ) {
122 ?>
123 <div id="spf-modal-icon" class="spf-modal spf-modal-icon">
124 <div class="spf-modal-table">
125 <div class="spf-modal-table-cell">
126 <div class="spf-modal-overlay"></div>
127 <div class="spf-modal-inner">
128 <div class="spf-modal-title">
129 <?php esc_html_e( 'Add Icon', 'smart-post-show' ); ?>
130 <div class="spf-modal-close spf-icon-close"></div>
131 </div>
132 <div class="spf-modal-header spf-text-center">
133 <input type="text" placeholder="<?php esc_html_e( 'Search a Icon...', 'smart-post-show' ); ?>" class="spf-icon-search" />
134 </div>
135 <div class="spf-modal-content">
136 <div class="spf-modal-loading"><div class="spf-loading"></div></div>
137 <div class="spf-modal-load"></div>
138 </div>
139 </div>
140 </div>
141 </div>
142 </div>
143 <?php
144 }
145
146 }
147 add_action( 'admin_footer', 'spf_set_icons' );
148 add_action( 'customize_controls_print_footer_scripts', 'spf_set_icons' );
149 }
150