'negahnama_sanitize' ) ); } ); add_action( 'admin_enqueue_scripts', function ( $hook ) { if ( 'settings_page_negahnama' !== $hook ) { return; } wp_enqueue_media(); wp_enqueue_style( 'negahnama-font', NEGAHNAMA_URL . 'assets/font.css', array(), '1.0.1' ); wp_enqueue_style( 'negahnama-admin', NEGAHNAMA_URL . 'assets/admin.css', array(), '1.5.2' ); wp_enqueue_script( 'negahnama-admin', NEGAHNAMA_URL . 'assets/admin.js', array( 'jquery' ), '1.5.1', true ); } ); function negahnama_sanitize( $input ) { $old = negahnama_options(); $out = $old; $input = is_array( $input ) ? $input : array(); foreach ( array( 'enabled', 'countdown', 'delete_data', 'footer_enabled' ) as $key ) { $out[$key] = empty( $input[$key] ) ? 0 : 1; } foreach ( array( 'mode'=>array( 'maintenance', 'coming' ), 'layout'=>array_keys( negahnama_layouts() ), 'font'=>array( 'vazirmatn', 'system' ), 'text_align'=>array( 'theme', 'left', 'center', 'right' ), 'logo_align'=>array( 'theme', 'left', 'center', 'right' ), 'motion'=>array( 'subtle', 'rise', 'glow', 'float', 'drift', 'none' ), 'seo_robots'=>array( 'noindex', 'index' ) ) as $key=>$allowed ) { if ( isset( $input[$key] ) && in_array( $input[$key], $allowed, true ) ) { $out[$key] = $input[$key]; } } foreach ( array( 'title', 'description' ) as $key ) { if ( isset( $input[$key] ) && is_string( $input[$key] ) ) { $out[$key] = 'description' === $key ? sanitize_textarea_field( $input[$key] ) : sanitize_text_field( $input[$key] ); } } foreach ( array( 'seo_title', 'seo_description', 'footer_text' ) as $key ) { if ( isset( $input[$key] ) && is_string( $input[$key] ) ) { $out[$key] = sanitize_text_field( $input[$key] ); } } if ( isset( $input['seo_canonical'] ) && is_string( $input['seo_canonical'] ) ) { $raw = trim( $input['seo_canonical'] ); $url = esc_url_raw( $raw, array( 'http', 'https' ) ); if ( '' === $raw || ( $url && preg_match( '~^https?://~i', $url ) && wp_parse_url( $url, PHP_URL_HOST ) ) ) { $out['seo_canonical'] = $url; } else { add_settings_error( 'negahnama_settings', 'seo_canonical', __( 'Invalid canonical URL; the previous value was kept.', 'negahnama' ) ); } } if ( isset( $input['wc_exempt_present'] ) && class_exists( 'WooCommerce' ) ) { $selected = isset( $input['wc_exempt'] ) && is_array( $input['wc_exempt'] ) ? array_filter( $input['wc_exempt'], 'is_string' ) : array(); $out['wc_exempt'] = array_values( array_intersect( array( 'shop', 'product', 'cart', 'checkout', 'account' ), $selected ) ); } foreach ( array( 'accent', 'bg_color' ) as $key ) { $color = isset( $input[$key] ) && is_string( $input[$key] ) ? sanitize_hex_color( $input[$key] ) : null; if ( $color ) { $out[$key] = $color; } else { add_settings_error( 'negahnama_settings', $key, __( 'An invalid color was kept unchanged.', 'negahnama' ) ); } } foreach ( array( 'logo', 'background' ) as $key ) { $id = isset( $input[$key] ) ? absint( $input[$key] ) : 0; if ( ! $id || wp_attachment_is_image( $id ) ) { $out[$key] = $id; } else { add_settings_error( 'negahnama_settings', $key, __( 'Please choose an image from the media library.', 'negahnama' ) ); } } foreach ( array( 'contact', 'instagram', 'telegram', 'linkedin', 'youtube' ) as $key ) { $raw = isset( $input[$key] ) && is_string( $input[$key] ) ? trim( $input[$key] ) : ''; $value = negahnama_contact_value( $key, $raw ); if ( null !== $value ) { $out[$key] = $value; } elseif ( $raw !== $old[$key] ) { add_settings_error( 'negahnama_settings', $key, __( 'Invalid contact information; the previous value was kept.', 'negahnama' ) ); } } $end = isset( $input['end'] ) && is_string( $input['end'] ) ? sanitize_text_field( $input['end'] ) : ''; if ( '' === $end || negahnama_timestamp( $end ) ) { $out['end'] = $end; } else { add_settings_error( 'negahnama_settings', 'end', __( 'Invalid date; the previous value was kept.', 'negahnama' ) ); } $out['exclude'] = array(); if ( isset( $input['exclude'] ) && is_array( $input['exclude'] ) ) { foreach ( $input['exclude'] as $id ) { $id = absint( $id ); if ( $id && 'page' === get_post_type( $id ) && 'publish' === get_post_status( $id ) ) { $out['exclude'][] = $id; } } } return $out; } function negahnama_admin_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = negahnama_options(); $preview = wp_nonce_url( add_query_arg( 'negahnama_preview', '1', home_url( '/' ) ), 'negahnama_preview' ); ?>