esc_html__( 'Error: Invalid nonce verification.', 'adminify' ) ) );
}
// Authorization: this icon picker is an editor-facing admin helper.
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: You do not have permission to perform this action.', 'adminify' ) ) );
}
ob_start();
$icon_library = ( apply_filters( 'adminify_fa4', false ) ) ? 'fa4' : 'fa5';
ADMINIFY::include_plugin_file( 'fields/icon/'. $icon_library .'-icons.php' );
$icon_lists = apply_filters( 'pxlbsadminify_field_icon_add_icons', adminify_get_default_icons() );
if ( ! empty( $icon_lists ) ) {
foreach ( $icon_lists as $list ) {
echo ( count( $icon_lists ) >= 2 ) ? '
'. esc_attr( $list['title'] ) .'
' : '';
foreach ( $list['icons'] as $icon ) {
echo '';
}
}
} else {
echo ''. esc_html__( 'No data available.', 'adminify' ) .'
';
}
$content = ob_get_clean();
wp_send_json_success( array( 'content' => $content ) );
}
add_action( 'wp_ajax_adminify-get-icons', 'adminify_get_icons' );
}
/**
*
* Export
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! function_exists( 'adminify_export' ) ) {
function adminify_export() {
$nonce = ( ! empty( $_GET[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'nonce' ] ) ) : '';
$unique = ( ! empty( $_GET[ 'unique' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'unique' ] ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'adminify_backup_nonce' ) ) {
die( esc_html__( 'Error: Invalid nonce verification.', 'adminify' ) );
}
// Authorization: only administrators may export settings.
if ( ! current_user_can( 'manage_options' ) ) {
die( esc_html__( 'Error: You do not have permission to perform this action.', 'adminify' ) );
}
if ( empty( $unique ) ) {
die( esc_html__( 'Error: Invalid key.', 'adminify' ) );
}
// Export
header('Content-Type: application/json');
header('Content-disposition: attachment; filename=backup-'. gmdate( 'd-m-Y' ) .'.json');
header('Content-Transfer-Encoding: binary');
header('Pragma: no-cache');
header('Expires: 0');
echo wp_json_encode( get_option( $unique ) );
die();
}
add_action( 'wp_ajax_adminify-export', 'adminify_export' );
}
/**
*
* Import Ajax
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! function_exists( 'adminify_import_ajax' ) ) {
function adminify_import_ajax() {
$nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
$unique = ( ! empty( $_POST[ 'unique' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'unique' ] ) ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified below before any data is processed.
$data = ( ! empty( $_POST[ 'data' ] ) ) ? wp_kses_post_deep( json_decode( trim( wp_unslash( $_POST[ 'data' ] ) ), true ) ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- each field is sanitized individually by the framework's per-field sanitize handlers.
if ( ! wp_verify_nonce( $nonce, 'adminify_backup_nonce' ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'adminify' ) ) );
}
// Authorization: only administrators may import settings.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: You do not have permission to perform this action.', 'adminify' ) ) );
}
if ( empty( $unique ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid key.', 'adminify' ) ) );
}
if ( empty( $data ) || ! is_array( $data ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: The response is not a valid JSON response.', 'adminify' ) ) );
}
// Success
update_option( $unique, $data );
wp_send_json_success();
}
add_action( 'wp_ajax_adminify-import', 'adminify_import_ajax' );
}
/**
*
* Reset Ajax
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! function_exists( 'adminify_reset_ajax' ) ) {
function adminify_reset_ajax() {
$nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
$unique = ( ! empty( $_POST[ 'unique' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'unique' ] ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'adminify_backup_nonce' ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'adminify' ) ) );
}
// Success
delete_option( $unique );
wp_send_json_success();
}
add_action( 'wp_ajax_adminify-reset', 'adminify_reset_ajax' );
}
/**
*
* Chosen Ajax
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! function_exists( 'adminify_chosen_ajax' ) ) {
function adminify_chosen_ajax() {
$nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
$type = ( ! empty( $_POST[ 'type' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'type' ] ) ) : '';
$term = ( ! empty( $_POST[ 'term' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'term' ] ) ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified below before any data is processed.
$query = ( ! empty( $_POST[ 'query_args' ] ) ) ? wp_kses_post_deep( wp_unslash( $_POST[ 'query_args' ] ) ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- each field is sanitized individually by the framework's per-field sanitize handlers.
if ( ! wp_verify_nonce( $nonce, 'adminify_chosen_ajax_nonce' ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid nonce verification.', 'adminify' ) ) );
}
if ( empty( $type ) || empty( $term ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: Invalid term ID.', 'adminify' ) ) );
}
$capability = apply_filters( 'adminify_chosen_ajax_capability', 'manage_options' );
if ( ! current_user_can( $capability ) ) {
wp_send_json_error( array( 'error' => esc_html__( 'Error: You do not have permission to do that.', 'adminify' ) ) );
}
// Success
$options = ADMINIFY_Fields::field_data( $type, $term, $query );
wp_send_json_success( $options );
}
add_action( 'wp_ajax_adminify-chosen', 'adminify_chosen_ajax' );
}