post_type ) { return false; } $allowed_method_ids_raw = get_post_meta( $form_id, '_afridirect_form_allowed_method_ids', true ); $allowed_method_ids = self::normalize_method_ids( $allowed_method_ids_raw ); return array( 'id' => $form_id, 'title' => $post->post_title, 'mode' => get_post_meta( $form_id, '_afridirect_form_mode', true ) ?: 'fixed', 'fixed_amount' => floatval( get_post_meta( $form_id, '_afridirect_form_fixed_amount', true ) ), 'min_amount' => floatval( get_post_meta( $form_id, '_afridirect_form_min_amount', true ) ), 'max_amount' => floatval( get_post_meta( $form_id, '_afridirect_form_max_amount', true ) ), 'currency' => get_post_meta( $form_id, '_afridirect_form_currency', true ) ?: 'USD', 'allowed_method_ids' => $allowed_method_ids, 'require_name' => get_post_meta( $form_id, '_afridirect_form_require_name', true ) !== '0', 'require_email' => get_post_meta( $form_id, '_afridirect_form_require_email', true ) !== '0', 'require_phone' => get_post_meta( $form_id, '_afridirect_form_require_phone', true ) === '1', 'success_message' => get_post_meta( $form_id, '_afridirect_form_success_message', true ) ?: __( 'Your payment request has been created. Taking you to the payment instructions...', 'afridirect-payment' ), 'button_text' => get_post_meta( $form_id, '_afridirect_form_button_text', true ) ?: __( 'Continue', 'afridirect-payment' ), ); } /** * Normalize method IDs from various formats to array. * * @param mixed $method_ids Method IDs (array, serialized string, comma-separated string, etc.). * @return array Normalized array of method IDs. */ public static function normalize_method_ids( $method_ids ) { // If already an array, validate and return. if ( is_array( $method_ids ) ) { // Filter out empty values and ensure they're strings. $method_ids = array_filter( array_map( 'sanitize_key', $method_ids ) ); return array_values( $method_ids ); // Re-index. } // If empty or false, return empty array. if ( empty( $method_ids ) ) { return array(); } // If it's a string, try to unserialize first (WordPress might have serialized it). if ( is_string( $method_ids ) ) { // Try to unserialize (WordPress serialized format). $unserialized = maybe_unserialize( $method_ids ); if ( is_array( $unserialized ) ) { $method_ids = array_filter( array_map( 'sanitize_key', $unserialized ) ); return array_values( $method_ids ); } // Try comma-separated string. if ( strpos( $method_ids, ',' ) !== false ) { $method_ids = array_map( 'trim', explode( ',', $method_ids ) ); $method_ids = array_filter( array_map( 'sanitize_key', $method_ids ) ); return array_values( $method_ids ); } // Single value as string. $sanitized = sanitize_key( $method_ids ); return ! empty( $sanitized ) ? array( $sanitized ) : array(); } // Fallback: empty array. return array(); } }