|
@@ -56,6 +56,80 @@ function dw_remove_block_library_css(){
|
|
|
}
|
|
}
|
|
|
//add_action( 'wp_enqueue_scripts', 'dw_remove_block_library_css' );
|
|
//add_action( 'wp_enqueue_scripts', 'dw_remove_block_library_css' );
|
|
|
|
|
|
|
|
|
|
+/* Guest Book — publish the "Guest" Gravity Form (id 2) entries below the form on
|
|
|
|
|
+ /contact/guests: 4 Name · 6 Location · 9 Website · 10 Message (Email (7) is never
|
|
|
|
|
+ shown; active entries only). Registered here rather than in the late-loaded
|
|
|
|
|
+ inc/form.php because this block theme renders the page content BEFORE
|
|
|
|
|
+ wp_enqueue_scripts, so the render_block hook has to be attached early. */
|
|
|
|
|
+function dw_guestbook() {
|
|
|
|
|
+ if ( ! class_exists( 'GFAPI' ) ) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $entries = GFAPI::get_entries(
|
|
|
|
|
+ 2,
|
|
|
|
|
+ array( 'status' => 'active' ),
|
|
|
|
|
+ array( 'key' => 'date_created', 'direction' => 'DESC' ),
|
|
|
|
|
+ array( 'offset' => 0, 'page_size' => 200 )
|
|
|
|
|
+ );
|
|
|
|
|
+ if ( is_wp_error( $entries ) || empty( $entries ) ) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rows = '';
|
|
|
|
|
+ foreach ( $entries as $e ) {
|
|
|
|
|
+ $name = trim( rgar( $e, '4' ) );
|
|
|
|
|
+ $loc = trim( rgar( $e, '6' ) );
|
|
|
|
|
+ $web = trim( rgar( $e, '9' ) );
|
|
|
|
|
+ $msg = trim( rgar( $e, '10' ) );
|
|
|
|
|
+ if ( $name === '' && $msg === '' ) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $weblink = '';
|
|
|
|
|
+ if ( $web !== '' ) {
|
|
|
|
|
+ $href = esc_url( $web );
|
|
|
|
|
+ if ( $href !== '' ) {
|
|
|
|
|
+ $label = preg_replace( '#^https?://(www\.)?#i', '', untrailingslashit( $web ) );
|
|
|
|
|
+ $weblink = '<a href="' . $href . '" target="_blank" rel="nofollow ugc noopener">' . esc_html( $label ) . '</a>';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $rows .= '<tr>'
|
|
|
|
|
+ . '<td data-label="Name">' . esc_html( $name ) . '</td>'
|
|
|
|
|
+ . '<td data-label="Location">' . esc_html( $loc ) . '</td>'
|
|
|
|
|
+ . '<td data-label="Website">' . $weblink . '</td>'
|
|
|
|
|
+ . '<td data-label="Message">' . nl2br( esc_html( $msg ) ) . '</td>'
|
|
|
|
|
+ . '<td data-label="Date">' . esc_html( mysql2date( 'M Y', $e['date_created'] ) ) . '</td>'
|
|
|
|
|
+ . '</tr>';
|
|
|
|
|
+ }
|
|
|
|
|
+ if ( $rows === '' ) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ return '<div class="dw-guestbook">'
|
|
|
|
|
+ . '<h3 class="dw-guestbook-title">Guest Book</h3>'
|
|
|
|
|
+ . '<figure class="wp-block-table is-style-stripes"><table>'
|
|
|
|
|
+ . '<thead><tr>'
|
|
|
|
|
+ . '<th scope="col">Name</th><th scope="col">Location</th><th scope="col">Website</th>'
|
|
|
|
|
+ . '<th scope="col">Message</th><th scope="col">Date</th>'
|
|
|
|
|
+ . '</tr></thead>'
|
|
|
|
|
+ . '<tbody>' . $rows . '</tbody>'
|
|
|
|
|
+ . '</table></figure></div>';
|
|
|
|
|
+}
|
|
|
|
|
+function dw_guestbook_once() {
|
|
|
|
|
+ static $done = false;
|
|
|
|
|
+ if ( $done ) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $done = true;
|
|
|
|
|
+ return dw_guestbook();
|
|
|
|
|
+}
|
|
|
|
|
+add_shortcode( 'dw_guestbook', 'dw_guestbook' );
|
|
|
|
|
+add_filter( 'render_block', 'dw_guestbook_render_block', 10, 2 );
|
|
|
|
|
+function dw_guestbook_render_block( $block_content, $block ) {
|
|
|
|
|
+ if ( ! empty( $block['blockName'] ) && 'core/post-content' === $block['blockName'] && is_page( 'guests' ) ) {
|
|
|
|
|
+ $block_content .= dw_guestbook_once();
|
|
|
|
|
+ }
|
|
|
|
|
+ return $block_content;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
add_action( 'wp_enqueue_scripts', 'dw_scripts' );
|
|
add_action( 'wp_enqueue_scripts', 'dw_scripts' );
|
|
|
function dw_scripts() {
|
|
function dw_scripts() {
|
|
|
global $post;
|
|
global $post;
|