Skip to content

Commit

Permalink
phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
timiwahalahti committed Sep 20, 2023
1 parent 2b19ae8 commit e8856a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public static function form_handler() {
// Check selected template on any step.
$templates = self::get_templates();
$template_selected = sanitize_text_field( $_POST['wcdocs_template'] );
if ( ! array_key_exists( $template_selected, $templates ) )
if ( ! array_key_exists( $template_selected, $templates ) ) {
return self::error( __( 'Selected template does not exist', 'wordcamporg' ) );
}

$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 {
Expand All @@ -104,19 +104,18 @@ public static function form_handler() {

break;

case 10; // submitted step 10
// Sanitize input
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
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;

Expand Down Expand Up @@ -149,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() {
?>
Expand Down Expand Up @@ -182,7 +184,7 @@ public static function render_menu_page() {
</p>
</form>

<?php elseif ( self::$step == 10 ) : ?>
<?php elseif ( 10 == self::$step ) : ?>

<form method="POST">
<input type="hidden" name="wcdocs_submit" value="10" />
Expand All @@ -199,7 +201,7 @@ public static function render_menu_page() {
</p>
</form>

<?php elseif ( self::$step == 20 ) : ?>
<?php elseif ( 20 == self::$step ) : ?>

<form method="POST">
<input type="hidden" name="wcdocs_submit" value="20" />
Expand All @@ -220,6 +222,7 @@ public static function render_menu_page() {
</div>
<?php
}
// phpcs:enable WordPress.Security.NonceVerification.Missing

private function __construct() {} // Not this time.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* Sponsorship Agreement Template
*/
class WordCamp_Docs_Template_Sponsorship_Agreement implements WordCamp_Docs_Template {
/**
* Step 10. Select the sposnor post from which the form will be pre-filled.
*/
public function form_prefill_select( $data ) {
$sponsors = get_posts( array(
'post_type' => 'wcb_sponsor',
'post_status' => 'publish',
'posts_per_page' => 500,
'post_type' => 'wcb_sponsor',
'post_status' => 'publish',
'posts_per_page' => 500,
) );
?>
<style>
Expand All @@ -34,17 +37,17 @@ public function form_prefill_select( $data ) {
</style>

<div class="wcorg-sponsorship-agreement-form">
<label><?php _e( 'Sponsor:', 'wordcamporg' ); ?></label>
<label><?php esc_html_e( 'Sponsor:', 'wordcamporg' ); ?></label>
<select name="sponsor_id">
<?php foreach ( $sponsors as $sponsor ) : ?>
<option value="<?php echo esc_attr( $sponsor->ID ) ?>"><?php echo esc_html( get_the_title( $sponsor ) ) ?></option>
<?php endforeach; ?>
</select>
<span class="description"><?php _e( 'Sponsorship details will be pre-filled with the data on sponsor post.', 'wordcamporg' ); ?></span>
<span class="description"><?php esc_html_e( 'Sponsorship details will be pre-filled with the data on sponsor post.', 'wordcamporg' ); ?></span>

<label><?php _e( 'Sponsorship Benefits:', 'wordcamporg' ); ?></label>
<label><?php esc_html_e( 'Sponsorship Benefits:', 'wordcamporg' ); ?></label>
<textarea name="sponsorship_benefits"><?php echo esc_textarea( $data['sponsorship_benefits'] ); ?></textarea>
<span class="description"><?php _e( 'Use multiple lines.', 'wordcamporg' ); ?></span>
<span class="description"><?php esc_html_e( 'Use multiple lines.', 'wordcamporg' ); ?></span>
</div>

<?php
Expand All @@ -58,16 +61,16 @@ public function form( $data ) {
$sponsor_currency = get_post_meta( $sponsor_id, '_wcb_sponsor_currency', true );

$wordcamp = get_wordcamp_post();
$start_date = ! empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ? date( $date_format, $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) : '';
$end_date = ! empty( $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) ? date( $date_format, $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) : $start_date;
$start_date = ! empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ? gmdate( $date_format, $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) : '';
$end_date = ! empty( $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) ? gmdate( $date_format, $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) : $start_date;

$number_formatter = new NumberFormatter( get_locale(), NumberFormatter::SPELLOUT );
$sponsorship_amount = $number_formatter->format( $sponsor_amount ) . " {$sponsor_currency}";

$number_formatter = new NumberFormatter( get_locale(), NumberFormatter::CURRENCY );
$sponsorship_amount_num = $number_formatter->formatCurrency( $sponsor_amount, $sponsor_currency );

$data = wp_parse_args( $data, array(
$data = wp_parse_args( $data, array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'sponsor_name' => get_the_title( $sponsor_id ),
'sponsor_rep_name' => get_post_meta( $sponsor_id, '_wcpt_sponsor_first_name', true ) . ' ' . get_post_meta( $sponsor_id, '_wcpt_sponsor_last_name', true ),
'sponsor_rep_title' => '',
Expand Down

0 comments on commit e8856a3

Please sign in to comment.