'sanitize_text_field' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['action'] ) && sanitize_text_field( wp_unslash( $_GET['action'] ) ) === 'affloc_export' && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'affloc_export' ) ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( wp_kses_post( __( 'Unauthorized', 'affloc' ) ) ); } global $wpdb; $table_name = $wpdb->prefix . 'aff_links'; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->prepare( "SELECT slug, country_code, url, aff_text FROM {$table_name} WHERE 1=%d", 1 ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $json_data = [ 'version' => '1.0', 'exported_at' => gmdate( 'Y-m-d H:i:s' ), 'mappings' => empty($rows) ? [] : $rows ]; $json_string = wp_json_encode( $json_data ); header( 'Content-Type: application/json; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="affloc-mappings-' . gmdate( 'Y-m-d' ) . '.json"' ); header( 'Content-Length: ' . strlen( $json_string ) ); echo $json_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['action'] ) && sanitize_text_field( wp_unslash( $_GET['action'] ) ) === 'delete' && isset( $_GET['id'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'affloc_delete_mapping_' . absint( wp_unslash( $_GET['id'] ) ) ) ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'affloc' ) ); } Affloc_DB::delete_link( absint( wp_unslash( $_GET['id'] ) ) ); add_settings_error( 'affloc_messages', 'affloc_message', __( 'Link Deleted', 'affloc' ), 'updated' ); wp_safe_redirect( admin_url( 'admin.php?page=aff-localization' ) ); exit; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['action'] ) && sanitize_text_field( wp_unslash( $_GET['action'] ) ) === 'dismiss_review' && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'affloc_dismiss_review' ) ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'affloc' ) ); } update_option( 'affloc_review_dismissed', 1 ); wp_safe_redirect( admin_url( 'admin.php?page=aff-localization' ) ); exit; } if ( isset( $_POST['affloc_save_mapping'] ) && check_admin_referer( 'affloc_save_mapping_action' ) ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'affloc' ) ); } $slug = isset( $_POST['slug'] ) ? sanitize_title( wp_unslash( $_POST['slug'] ) ) : ''; $country = isset( $_POST['country'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['country'] ) ) ) : ''; $url = isset( $_POST['url'] ) ? esc_url_raw( wp_unslash( $_POST['url'] ) ) : ''; $aff_text = isset( $_POST['aff_text'] ) ? sanitize_text_field( wp_unslash( $_POST['aff_text'] ) ) : ''; if ( ! empty( $slug ) && ! empty( $country ) && ! empty( $url ) ) { global $wpdb; $table_name = $wpdb->prefix . 'aff_links'; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $existing_id = $wpdb->get_var( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->prepare( "SELECT id FROM {$table_name} WHERE slug = %s AND country_code = %s", $slug, $country ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $total_links = Affloc_DB::get_total_count(); $is_pro = ( function_exists( 'affloc_fs' ) && affloc_fs()->can_use_premium_code() ); if ( ! $existing_id && $total_links >= 20 && ! $is_pro ) { $upgrade_url = function_exists( 'affloc_fs' ) ? affloc_fs()->get_upgrade_url() : 'https://checkout.freemius.com/plugin/25997/plan/42936/'; add_settings_error( 'affloc_messages', 'affloc_message', wp_kses_post( __( 'Free version limit reached (20 mappings).', 'affloc' ) . ' ' . __( 'Upgrade to Pro', 'affloc' ) . '' ), 'error' ); } else { $saved = Affloc_DB::save_link( $slug, $country, $url, $aff_text ); if ( false !== $saved ) { add_settings_error( 'affloc_messages', 'affloc_message', __( 'Link Saved', 'affloc' ), 'updated' ); } else { global $wpdb; add_settings_error( 'affloc_messages', 'affloc_message', wp_kses_post( __( 'Database Error: Could not save. ', 'affloc' ) . esc_html( $wpdb->last_error ) ), 'error' ); } } } } if ( isset( $_POST['affloc_save_settings'] ) && check_admin_referer( 'affloc_save_settings_action' ) ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'affloc' ) ); } $custom_shortcode = isset( $_POST['custom_shortcode'] ) ? sanitize_title( wp_unslash( $_POST['custom_shortcode'] ) ) : ''; if ( ! empty( $custom_shortcode ) ) { update_option( 'affloc_custom_shortcode', $custom_shortcode ); add_settings_error( 'affloc_messages', 'affloc_message', __( 'Settings saved.', 'affloc' ), 'updated' ); } } if ( isset( $_POST['affloc_import'] ) && check_admin_referer( 'affloc_import_action' ) ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( wp_kses_post( __( 'Unauthorized', 'affloc' ) ) ); } if ( ! empty( $_FILES['import_file']['tmp_name'] ) && empty( $_FILES['import_file']['error'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $file_name = isset( $_FILES['import_file']['name'] ) ? sanitize_file_name( wp_unslash( $_FILES['import_file']['name'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash $tmp_name = sanitize_text_field( wp_unslash( $_FILES['import_file']['tmp_name'] ) ); $file_size = isset( $_FILES['import_file']['size'] ) ? absint( $_FILES['import_file']['size'] ) : 0; if ( ! is_uploaded_file( $tmp_name ) ) { add_settings_error( 'affloc_messages', 'affloc_message', __( 'Error: Invalid file upload.', 'affloc' ), 'error' ); return; } $filetype = wp_check_filetype( $file_name, array( 'json' => 'application/json' ) ); if ( empty( $filetype['ext'] ) ) { add_settings_error( 'affloc_messages', 'affloc_message', __( 'Error: Only JSON files are allowed.', 'affloc' ), 'error' ); } elseif ( $file_size > 1048576 ) { add_settings_error( 'affloc_messages', 'affloc_message', __( 'Error: File size too large (max 1MB).', 'affloc' ), 'error' ); } else { if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; $contents = $wp_filesystem->get_contents( $tmp_name ); $data = json_decode( $contents, true ); if ( is_array( $data ) && isset( $data['version'] ) && isset( $data['mappings'] ) && is_array( $data['mappings'] ) && ! empty( $data['mappings'] ) ) { $count = 0; foreach ( $data['mappings'] as $mapping ) { $slug = isset( $mapping['slug'] ) ? sanitize_title( $mapping['slug'] ) : ''; $country = isset( $mapping['country_code'] ) ? strtoupper( sanitize_text_field( $mapping['country_code'] ) ) : ''; $url = isset( $mapping['url'] ) ? esc_url_raw( $mapping['url'] ) : ''; $aff_text = isset( $mapping['aff_text'] ) ? sanitize_text_field( $mapping['aff_text'] ) : ''; if ( ! empty( $slug ) && ! empty( $url ) ) { if ( empty( $country ) ) { $country = 'default'; } $saved = Affloc_DB::save_link( $slug, $country, $url, $aff_text ); if ( false !== $saved ) { $count++; } } } /* translators: %d: number of successfully imported mappings */ add_settings_error( 'affloc_messages', 'affloc_message', sprintf( __( 'Successfully imported %d mappings.', 'affloc' ), $count ), 'updated' ); } else { add_settings_error( 'affloc_messages', 'affloc_message', __( 'Error: No valid mappings found in file.', 'affloc' ), 'error' ); } } } else { add_settings_error( 'affloc_messages', 'affloc_message', __( 'Error: File upload failed.', 'affloc' ), 'error' ); } } } public function enqueue_admin_assets( $hook ) { if ( 'toplevel_page_aff-localization' !== $hook ) return; wp_enqueue_style( 'affloc-admin', AFFLOC_URL . 'assets/css/admin.css', [], AFFLOC_VERSION ); wp_enqueue_script( 'affloc-admin-js', AFFLOC_URL . 'assets/js/admin.js', [ 'jquery' ], AFFLOC_VERSION, true ); wp_localize_script( 'affloc-admin-js', 'afflocAdmin', [ 'countries' => affloc_get_countries(), 'aliases' => affloc_get_country_aliases() ] ); } public function render_settings_page() { global $wpdb; $table_name = $wpdb->prefix . 'aff_links'; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $links = $wpdb->get_results( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->prepare( "SELECT * FROM {$table_name} WHERE 1=%d ORDER BY slug ASC, created_at DESC", 1 ), ARRAY_A ); $countries = affloc_get_countries(); $total_links = Affloc_DB::get_total_count(); $show_review_banner = ( $total_links >= 10 && ! get_option( 'affloc_review_dismissed' ) ); $dismiss_url = wp_nonce_url( admin_url( 'admin.php?page=aff-localization&action=dismiss_review' ), 'affloc_dismiss_review' ); $grouped_links = []; foreach ( $links as $link ) { $grouped_links[ $link['slug'] ][] = $link; } ?>

⭐
×

$name ) : $aliases = isset( $all_aliases[ $code ] ) ? implode( ', ', $all_aliases[ $code ] ) : ''; ?>
()

[ slug="your-slug" text="Buy Now"]

$items ) : ?>
▲ ▼
▼ 📁
|