summaryrefslogblamecommitdiffstats
path: root/includes/giglogadmin-shortcodes.php
blob: 5a3d70d0f3d010acda9e7005a5b59418efe2aad3 (plain) (tree)























                                                                               
                         
                          
                          
          




                                                                                  
                                                                   




                                                                      



                                                                   
<?php
/**
 * Shortcodes for GiglogAdmin.
 *
 * @package giglogadmin
 *
 * SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
 * SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

declare(strict_types=1);

if ( ! function_exists( 'giglogadmin_shortcode_public' ) ) {

    /**
     * Shortcode that displays the public concert list.
     *
     * Usage: `[getconcerts]`
     *
     * This shortcode does not have any attributes.
     */
    function giglogadmin_shortcode_public() : string {
        $filters = array(
            'offset' => 0,
            'limit' => 15,
        );

        if ( isset( $_GET['city'] ) && ! empty( $_GET['city'] ) ) {
            $filters['city'] = sanitize_text_field( wp_unslash( $_GET['city'] ) );
        }

        $concerts = GiglogAdmin_Concert::find_concerts( $filters );

        ob_start();
        include __DIR__ . '/templates/giglogadmin-concerts-table.php';

        return ob_get_clean();
    }

    add_shortcode( 'getconcerts', 'giglogadmin_shortcode_public' );
}