From 767d854935c8c72993c8a441605a10093a2cbb83 Mon Sep 17 00:00:00 2001
From: Timi Wahalahti
Date: Tue, 10 Oct 2023 01:40:54 +0300
Subject: [PATCH] Docs: Pre-fill sponsor agreement details from sponsor CPT
(#1052)
---
.../classes/class-wordcamp-docs.php | 56 +++++++++--
.../templates/sponsorship-agreement.php | 95 ++++++++++++++++---
2 files changed, 127 insertions(+), 24 deletions(-)
diff --git a/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php b/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php
index 465fb2259..b21960d5d 100644
--- a/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php
+++ b/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php
@@ -86,21 +86,36 @@ public static function form_handler() {
// Check selected template on any step.
$templates = self::get_templates();
- $template = sanitize_text_field( $_POST['wcdocs_template'] );
- if ( ! array_key_exists( $template, $templates ) )
+ $template_selected = sanitize_text_field( $_POST['wcdocs_template'] );
+ if ( ! array_key_exists( $template_selected, $templates ) ) {
return self::error( __( 'Selected template does not exist', 'wordcamporg' ) );
+ }
- $template = $templates[ $template ];
+ $template = $templates[ $template_selected ];
switch ( $step ) {
- case 1: // submitted step 1
+ case 1: // submitted step 1.
+ if ( 'sponsorship-agreement' == $template_selected ) {
+ self::$step = 10;
+ } else {
+ // Nothing else to check on this step.
+ self::$step = 20;
+ }
- // Nothing else to check on this step.
- self::$step = 2;
break;
- case 2: // submitted step 2
+ case 10: // submitted step 10.
+ $data = $template->sanitize( $_POST );
+
+ if ( 'sponsorship-agreement' == $template_selected ) {
+ if ( 'wcb_sponsor' === get_post_type( $data['sponsor_id'] ) ) {
+ self::$step = 20;
+ }
+ }
+
+ break;
+ case 20: // submitted step 20.
require_once( WORDCAMP_DOCS__PLUGIN_DIR . 'classes/class-wordcamp-docs-pdf-generator.php' );
$generator = new WordCamp_Docs_PDF_Generator;
@@ -133,6 +148,9 @@ private static function error( $message ) {
/**
* Render the contents of our admin section.
+ *
+ * phpcs:disable WordPress.Security.NonceVerification.Missing
+ * nonce is checked on form_handler function
*/
public static function render_menu_page() {
?>
@@ -166,12 +184,29 @@ public static function render_menu_page() {
-
+
+
+
+
+