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