prefix . 'axilweb_ajl_app_process'; // Create cache key for this specific query $cache_key = 'axilweb_ajl_process_order_' . absint($order); $cache_group = 'axilweb_ajl_app_process'; // Try to get from cache first $result = wp_cache_get($cache_key, $cache_group); // If not in cache, fetch from database if (false === $result) { // Use %i placeholder for proper table name escaping // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query is necessary for custom table operations. Caching is implemented with the check above. $result = $wpdb->get_results( $wpdb->prepare( "SELECT `id` FROM %i WHERE `order` = %d", $table_app_process, $order ), ARRAY_A ); // Cache the result for future requests if ($result) { wp_cache_set($cache_key, $result, $cache_group, HOUR_IN_SECONDS); } } return $result; } /** * Get the previous step in the application process based on process ID. * * @param int $process_id The ID of the current process * @return array Array of previous step data (id, key, name) */ private static function _query_get_previous_step($process_id) { global $wpdb; // Table name $table_app_process = $wpdb->prefix . 'axilweb_ajl_app_process'; // Create cache key for this specific query $cache_key = 'axilweb_ajl_process_prev_' . sanitize_key($process_id); $cache_group = 'axilweb_ajl_app_process'; // Try to get from cache first $result = wp_cache_get($cache_key, $cache_group); // If not in cache, fetch from database if (false === $result) { // Properly escape table name $table_name = esc_sql($table_app_process); // First, execute the subquery to get the order value // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query is necessary for custom table operations to retrieve process ordering information $order_value = $wpdb->get_var( $wpdb->prepare( "SELECT `order` FROM %s WHERE id = %d", $table_name, $process_id ) ); // If we have a valid order value, use it in the main query if ($order_value !== null) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query is necessary for custom table operations to retrieve previous process in sequence $result = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `key`, `name` FROM %s WHERE `id` < %d ORDER BY `order` DESC LIMIT 1", $table_name, $process_id ), ARRAY_A ); } else { $result = array(); } // Cache the result for future requests wp_cache_set($cache_key, $result, $cache_group, HOUR_IN_SECONDS); } return $result; } /** * Get the next step in the application process based on process ID. * * @param int $process_id The ID of the current process * @return array Array of next step data (id, key, name) */ private static function _query_get_next_step($process_id) { global $wpdb; // Table name $table_app_process = $wpdb->prefix . 'axilweb_ajl_app_process'; // Create cache key for this specific query $cache_key = 'axilweb_ajl_process_next_' . sanitize_key($process_id); $cache_group = 'axilweb_ajl_app_process'; // Try to get from cache first $result = wp_cache_get($cache_key, $cache_group); // If not in cache, fetch from database if (false === $result) { // Properly escape table name $table_name = esc_sql($table_app_process); // First, execute the subquery to get the order value // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query is necessary for custom table operations to retrieve process ordering information $order_value = $wpdb->get_var( $wpdb->prepare( "SELECT `order` FROM %s WHERE id = %d", $table_name, $process_id ) ); // If we have a valid order value, use it in the main query if ($order_value !== null) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query is necessary for custom table operations to retrieve next process in sequence $result = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `key`, `name` FROM %s WHERE `id` > %d ORDER BY `order` ASC LIMIT 1", $table_name, $process_id ), ARRAY_A ); } else { $result = array(); } // Cache the result for future requests wp_cache_set($cache_key, $result, $cache_group, HOUR_IN_SECONDS); } return $result; } }