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