Skip to content

Commit 461c3bf

Browse files
author
Chris Gårdenberg
committed
fix(Programme/Shortcodes)!: Fixed an issue with Programme pages
Current implementations of programme shortcodes _might_ break since we have changed how we output the pages, from a normal include, to use `ob_start()` to collect the entire page, and then get the data with `ob_get_clean()` and return the value. BREAKING CHANGE: Custom code with `do_shortcode` now needs to do `echo do_shortcode( '[eduadmin-programme-list]' );` after the change. Which is the intended way to use `do_shortcode` the previous versions were not working in the correct way.
1 parent 5d0e50e commit 461c3bf

5 files changed

Lines changed: 60 additions & 52 deletions

File tree

PLUGIN-CHECKSUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
081e6567affebd04ee2bd149100373bf
1+
ee9b9f36e06432f3c98b1194d69aab65

content/template/programme/book.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
ob_start();
23
// phpcs:disable WordPress.NamingConventions,Squiz
34

45
if ( ! empty( $_POST['edu-valid-form'] ) && wp_verify_nonce( $_POST['edu-valid-form'], 'edu-booking-confirm' ) && isset( $_POST['act'] ) && 'bookProgramme' === sanitize_text_field( $_POST['act'] ) ) {
@@ -643,3 +644,6 @@ class="last-name" name="contactLastName" maxlength="100"
643644
<?php
644645
do_action( 'eduadmin-programme-bookingform-view', $programme );
645646
}
647+
$out = ob_get_clean();
648+
649+
return $out;
Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
11
<?php
2+
ob_start();
23
$show_headers = EDU()->is_checked( 'eduadmin-showDetailHeaders', true );
34
?>
4-
<div class="eduadmin" data-courseid="<?php echo esc_attr( $programme['ProgrammeId'] ); ?>"
5-
data-eventid="<?php echo( isset( $_REQUEST['id'] ) ? esc_attr( sanitize_text_field( $_REQUEST['id'] ) ) : '' ); ?>">
6-
<?php if ( ! empty( $programme['ImageUrl'] ) ) : ?>
7-
<img src="<?php echo esc_url( $programme['ImageUrl'] ); ?>" class="courseImage" />
8-
<?php endif; ?>
9-
<h1 class="courseTitle"><?php echo esc_html( $programme['ProgrammeName'] ); ?></h1>
10-
<?php if ( ! empty( $programme['Description'] ) ) : ?><?php if ( $show_headers ) { ?>
11-
<h2><?php echo esc_html_x( 'Description', 'frontend', 'eduadmin-booking' ); ?></h2>
12-
<?php } ?><?php echo wp_kses_post( $programme['Description'] ); ?><?php endif; ?>
13-
<?php if ( ! empty( $programme['Prerequisites'] ) ) : ?><?php if ( $show_headers ) { ?>
14-
<h2><?php echo esc_html_x( 'Prerequisites', 'frontend', 'eduadmin-booking' ); ?></h2>
15-
<?php } ?><?php echo wp_kses_post( $programme['Prerequisites'] ); ?><?php endif; ?>
16-
<?php if ( ! empty( $programme['TargetGroup'] ) ) : ?><?php if ( $show_headers ) { ?>
17-
<h2><?php echo esc_html_x( 'Target Group', 'frontend', 'eduadmin-booking' ); ?></h2>
18-
<?php } ?><?php echo wp_kses_post( $programme['TargetGroup'] ); ?><?php endif; ?>
19-
<?php if ( ! empty( $programme['Courses'] ) ) : ?><?php if ( $show_headers ) { ?>
20-
<h2><?php echo esc_html_x( 'Modules', 'frontend', 'eduadmin-booking' ); ?></h2>
21-
<?php } ?>
22-
<ul>
23-
<?php
24-
foreach ( $programme['Courses'] as $module ) {
25-
// TODO: Add link to course template page
26-
echo '<li>' . esc_html( $module['CourseName'] ) . '</li>';
27-
}
28-
?>
29-
</ul>
30-
<?php
31-
endif;
32-
?>
33-
<h2><?php echo esc_html_x( 'Programme starts', 'frontend', 'eduadmin-booking' ); ?></h2>
34-
<?php
35-
if ( ! empty( $programme['ProgrammeStarts'] ) ) {
36-
include_once 'template/detail-list.php';
37-
} else {
38-
echo '<i>' . esc_html_x( 'No programme starts available', 'frontend', 'eduadmin-booking' ) . '</i>';
39-
}
5+
<div class="eduadmin" data-courseid="<?php echo esc_attr( $programme['ProgrammeId'] ); ?>"
6+
data-eventid="<?php echo( isset( $_REQUEST['id'] ) ? esc_attr( sanitize_text_field( $_REQUEST['id'] ) ) : '' ); ?>">
7+
<?php if ( ! empty( $programme['ImageUrl'] ) ) : ?>
8+
<img src="<?php echo esc_url( $programme['ImageUrl'] ); ?>" class="courseImage" />
9+
<?php endif; ?>
10+
<h1 class="courseTitle"><?php echo esc_html( $programme['ProgrammeName'] ); ?></h1>
11+
<?php if ( ! empty( $programme['Description'] ) ) : ?><?php if ( $show_headers ) { ?>
12+
<h2><?php echo esc_html_x( 'Description', 'frontend', 'eduadmin-booking' ); ?></h2>
13+
<?php } ?><?php echo wp_kses_post( $programme['Description'] ); ?><?php endif; ?>
14+
<?php if ( ! empty( $programme['Prerequisites'] ) ) : ?><?php if ( $show_headers ) { ?>
15+
<h2><?php echo esc_html_x( 'Prerequisites', 'frontend', 'eduadmin-booking' ); ?></h2>
16+
<?php } ?><?php echo wp_kses_post( $programme['Prerequisites'] ); ?><?php endif; ?>
17+
<?php if ( ! empty( $programme['TargetGroup'] ) ) : ?><?php if ( $show_headers ) { ?>
18+
<h2><?php echo esc_html_x( 'Target Group', 'frontend', 'eduadmin-booking' ); ?></h2>
19+
<?php } ?><?php echo wp_kses_post( $programme['TargetGroup'] ); ?><?php endif; ?>
20+
<?php if ( ! empty( $programme['Courses'] ) ) : ?><?php if ( $show_headers ) { ?>
21+
<h2><?php echo esc_html_x( 'Modules', 'frontend', 'eduadmin-booking' ); ?></h2>
22+
<?php } ?>
23+
<ul>
24+
<?php
25+
foreach ( $programme['Courses'] as $module ) {
26+
// TODO: Add link to course template page
27+
echo '<li>' . esc_html( $module['CourseName'] ) . '</li>';
28+
}
29+
?>
30+
</ul>
31+
<?php
32+
endif;
33+
?>
34+
<h2><?php echo esc_html_x( 'Programme starts', 'frontend', 'eduadmin-booking' ); ?></h2>
35+
<?php
36+
if ( ! empty( $programme['ProgrammeStarts'] ) ) {
37+
include_once 'template/detail-list.php';
38+
} else {
39+
echo '<i>' . esc_html_x( 'No programme starts available', 'frontend', 'eduadmin-booking' ) . '</i>';
40+
}
4041

41-
do_action( 'eduadmin-programme-detail-view', $programme );
42-
?>
43-
</div>
42+
do_action( 'eduadmin-programme-detail-view', $programme );
43+
?>
44+
</div>
45+
<?php
46+
$out = ob_get_clean();
47+
48+
return $out;

content/template/programme/list.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
ob_start();
23
$spot_left_option = EDU()->get_option( 'eduadmin-spotsLeft', 'exactNumbers' );
34
$always_few_spots = EDU()->get_option( 'eduadmin-alwaysFewSpots', '3' );
45
$spot_settings = EDU()->get_option( 'eduadmin-spotsSettings', "1-5\n5-10\n10+" );
@@ -22,3 +23,6 @@
2223
</div>
2324
<?php
2425
}
26+
$out = ob_get_clean();
27+
28+
return $out;

includes/edu-shortcodes.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,7 @@ function eduadmin_get_programme_list( $attributes ) {
698698
'StartDate),Courses'
699699
);
700700

701-
ob_start();
702-
include_once EDUADMIN_PLUGIN_PATH . '/content/template/programme/list.php';
703-
704-
return ob_get_clean();
701+
return include_once EDUADMIN_PLUGIN_PATH . '/content/template/programme/list.php';
705702
}
706703

707704
function eduadmin_get_programme_details( $attributes ) {
@@ -752,11 +749,10 @@ function eduadmin_get_programme_details( $attributes ) {
752749
'),PriceNames'
753750
);
754751

755-
ob_start();
756-
include_once EDUADMIN_PLUGIN_PATH . '/content/template/programme/detail.php';
757-
758-
return ob_get_clean();
752+
return include_once EDUADMIN_PLUGIN_PATH . '/content/template/programme/detail.php';
759753
}
754+
755+
return '';
760756
}
761757

762758
function eduadmin_get_programme_booking( $attributes ) {
@@ -803,11 +799,10 @@ function eduadmin_get_programme_booking( $attributes ) {
803799
'Courses,Events,PaymentMethods,PriceNames'
804800
);
805801

806-
ob_start();
807-
include_once EDUADMIN_PLUGIN_PATH . '/content/template/programme/book.php';
808-
809-
return ob_get_clean();
802+
return include_once EDUADMIN_PLUGIN_PATH . '/content/template/programme/book.php';
810803
}
804+
805+
return '';
811806
}
812807

813808
if ( is_callable( 'add_shortcode' ) ) {

0 commit comments

Comments
 (0)