admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('eventos_manager_nonce') ) ); } public function get_eventos_calendario() { check_ajax_referer('eventos_manager_nonce', 'security'); $start_date = isset($_POST['start']) ? sanitize_text_field($_POST['start']) : date('Y-m-d', strtotime('-1 month')); $end_date = isset($_POST['end']) ? sanitize_text_field($_POST['end']) : date('Y-m-d', strtotime('+1 month')); $args = array( 'post_type' => 'evento', 'posts_per_page' => -1, 'meta_key' => 'data_evento', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'data_evento', 'value' => array($start_date, $end_date), 'compare' => 'BETWEEN', 'type' => 'DATE' ) ) ); $eventos = new WP_Query($args); $calendar_events = array(); if ($eventos->have_posts()) { while ($eventos->have_posts()) { $eventos->the_post(); $data_evento = get_post_meta(get_the_ID(), 'data_evento', true); $hora_evento = get_post_meta(get_the_ID(), 'hora_evento', true); $tipos = get_the_terms(get_the_ID(), 'tipo_evento'); $tipo = !empty($tipos) && !is_wp_error($tipos) ? $tipos[0]->name : ''; $calendar_events[] = array( 'title' => get_the_title(), 'start' => $data_evento . ($hora_evento ? 'T' . $hora_evento : ''), 'tipo' => $tipo, 'url' => get_permalink() ); } wp_reset_postdata(); } wp_send_json_success($calendar_events); } public function load_single_template($template) { global $post; if ($post->post_type === 'evento') { $plugin_template = EVENTOS_MANAGER_PLUGIN_DIR . 'single-evento.php'; if (file_exists($plugin_template)) { return $plugin_template; } } return $template; } } new Eventos_Manager(); // Register widget class Eventos_Upcoming_Widget extends WP_Widget { public function __construct() { parent::__construct( 'eventos_upcoming_widget', __('Próximos Eventos', 'eventos-manager'), array('description' => __('Mostra os próximos eventos', 'eventos-manager')) ); } public function widget($args, $instance) { echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } echo do_shortcode('[mostra-prox-eventos limit="' . esc_attr($instance['limit']) . '"]'); echo $args['after_widget']; } public function form($instance) { $title = !empty($instance['title']) ? $instance['title'] : ''; $limit = !empty($instance['limit']) ? $instance['limit'] : 5; ?>