Initial commit
This commit is contained in:
116
includes/class-eventos-admin.php
Normal file
116
includes/class-eventos-admin.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
class Eventos_Admin {
|
||||
public function __construct() {
|
||||
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
|
||||
add_action('save_post', array($this, 'save_evento_meta'));
|
||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
|
||||
add_action('admin_menu', array($this, 'add_help_page'));
|
||||
}
|
||||
|
||||
public function add_meta_boxes() {
|
||||
add_meta_box(
|
||||
'evento_metabox',
|
||||
__('Detalhes do Evento', 'eventos-manager'),
|
||||
array($this, 'render_evento_metabox'),
|
||||
'evento',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
public function render_evento_metabox($post) {
|
||||
wp_nonce_field('evento_meta_nonce', 'evento_meta_nonce');
|
||||
|
||||
$data_evento = get_post_meta($post->ID, 'data_evento', true);
|
||||
$hora_evento = get_post_meta($post->ID, 'hora_evento', true);
|
||||
$local_evento = get_post_meta($post->ID, 'local_evento', true);
|
||||
?>
|
||||
<div class="evento-metabox">
|
||||
<div class="meta-field">
|
||||
<label for="data_evento"><?php _e('Data do Evento', 'eventos-manager'); ?></label>
|
||||
<input type="date" id="data_evento" name="data_evento" value="<?php echo esc_attr($data_evento); ?>" required>
|
||||
</div>
|
||||
<div class="meta-field">
|
||||
<label for="hora_evento"><?php _e('Hora do Evento', 'eventos-manager'); ?></label>
|
||||
<input type="time" id="hora_evento" name="hora_evento" value="<?php echo esc_attr($hora_evento); ?>">
|
||||
</div>
|
||||
<div class="meta-field">
|
||||
<label for="local_evento"><?php _e('Local do Evento', 'eventos-manager'); ?></label>
|
||||
<input type="text" id="local_evento" name="local_evento" value="<?php echo esc_attr($local_evento); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function save_evento_meta($post_id) {
|
||||
if (!isset($_POST['evento_meta_nonce']) || !wp_verify_nonce($_POST['evento_meta_nonce'], 'evento_meta_nonce')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current_user_can('edit_post', $post_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($_POST['data_evento']) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $_POST['data_evento'])) {
|
||||
update_post_meta($post_id, 'data_evento', sanitize_text_field($_POST['data_evento']));
|
||||
}
|
||||
|
||||
if (isset($_POST['hora_evento']) && preg_match('/^\d{2}:\d{2}$/', $_POST['hora_evento'])) {
|
||||
update_post_meta($post_id, 'hora_evento', sanitize_text_field($_POST['hora_evento']));
|
||||
}
|
||||
|
||||
if (isset($_POST['local_evento'])) {
|
||||
update_post_meta($post_id, 'local_evento', sanitize_text_field($_POST['local_evento']));
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_admin_scripts() {
|
||||
global $post_type;
|
||||
|
||||
if ('evento' == $post_type) {
|
||||
wp_enqueue_style(
|
||||
'eventos-manager-admin-css',
|
||||
EVENTOS_MANAGER_PLUGIN_URL . 'assets/css/admin.css',
|
||||
array(),
|
||||
EVENTOS_MANAGER_VERSION
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'eventos-manager-admin-js',
|
||||
EVENTOS_MANAGER_PLUGIN_URL . 'assets/js/admin.js',
|
||||
array('jquery'),
|
||||
EVENTOS_MANAGER_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_help_page() {
|
||||
add_submenu_page(
|
||||
'edit.php?post_type=evento',
|
||||
__('Ajuda - Gerenciador de Eventos', 'eventos-manager'),
|
||||
__('Ajuda', 'eventos-manager'),
|
||||
'manage_options',
|
||||
'eventos-manager-help',
|
||||
array($this, 'render_help_page')
|
||||
);
|
||||
}
|
||||
|
||||
public function render_help_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php _e('Ajuda - Gerenciador de Eventos', 'eventos-manager'); ?></h1>
|
||||
<p><?php _e('Este plugin permite gerenciar eventos com um calendário e shortcodes.', 'eventos-manager'); ?></p>
|
||||
<h2><?php _e('Shortcodes Disponíveis', 'eventos-manager'); ?></h2>
|
||||
<ul>
|
||||
<li><code>[mostra-calendario]</code>: <?php _e('Exibe o calendário de eventos.', 'eventos-manager'); ?></li>
|
||||
<li><code>[mostra-prox-eventos limit="5" tipo=""]</code>: <?php _e('Exibe uma lista de próximos eventos. Atributos: limit (número de eventos), tipo (slug do tipo de evento).', 'eventos-manager'); ?></li>
|
||||
<li><code>[eventos-completo]</code>: <?php _e('Exibe o calendário e a lista de próximos eventos juntos.', 'eventos-manager'); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
61
includes/class-eventos-post-type.php
Normal file
61
includes/class-eventos-post-type.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
class Eventos_Post_Type {
|
||||
public function __construct() {
|
||||
add_action('init', array($this, 'register_post_type'));
|
||||
add_action('init', array($this, 'register_taxonomy'));
|
||||
}
|
||||
|
||||
public function register_post_type() {
|
||||
$labels = array(
|
||||
'name' => __('Eventos', 'eventos-manager'),
|
||||
'singular_name' => __('Evento', 'eventos-manager'),
|
||||
'menu_name' => __('Eventos', 'eventos-manager'),
|
||||
'add_new' => __('Adicionar Novo', 'eventos-manager'),
|
||||
'add_new_item' => __('Adicionar Novo Evento', 'eventos-manager'),
|
||||
'edit_item' => __('Editar Evento', 'eventos-manager'),
|
||||
'new_item' => __('Novo Evento', 'eventos-manager'),
|
||||
'view_item' => __('Ver Evento', 'eventos-manager'),
|
||||
'search_items' => __('Buscar Eventos', 'eventos-manager'),
|
||||
'not_found' => __('Nenhum evento encontrado', 'eventos-manager'),
|
||||
'not_found_in_trash' => __('Nenhum evento encontrado na lixeira', 'eventos-manager')
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'menu_icon' => 'dashicons-calendar-alt',
|
||||
'supports' => array('title', 'editor', 'thumbnail'),
|
||||
'rewrite' => array('slug' => 'eventos'),
|
||||
'show_in_rest' => true
|
||||
);
|
||||
|
||||
register_post_type('evento', $args);
|
||||
}
|
||||
|
||||
public function register_taxonomy() {
|
||||
$labels = array(
|
||||
'name' => __('Tipos de Evento', 'eventos-manager'),
|
||||
'singular_name' => __('Tipo de Evento', 'eventos-manager'),
|
||||
'search_items' => __('Buscar Tipos', 'eventos-manager'),
|
||||
'all_items' => __('Todos os Tipos', 'eventos-manager'),
|
||||
'edit_item' => __('Editar Tipo', 'eventos-manager'),
|
||||
'update_item' => __('Atualizar Tipo', 'eventos-manager'),
|
||||
'add_new_item' => __('Adicionar Novo Tipo', 'eventos-manager'),
|
||||
'new_item_name' => __('Novo Nome de Tipo', 'eventos-manager'),
|
||||
'menu_name' => __('Tipos de Evento', 'eventos-manager')
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array('slug' => 'tipo-evento'),
|
||||
'show_in_rest' => true
|
||||
);
|
||||
|
||||
register_taxonomy('tipo_evento', 'evento', $args);
|
||||
}
|
||||
}
|
135
includes/class-eventos-shortcodes.php
Normal file
135
includes/class-eventos-shortcodes.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
class Eventos_Shortcodes {
|
||||
public function __construct() {
|
||||
add_shortcode('mostra-calendario', array($this, 'render_calendario'));
|
||||
add_shortcode('mostra-prox-eventos', array($this, 'render_proximos_eventos'));
|
||||
add_shortcode('eventos-completo', array($this, 'render_eventos_completo'));
|
||||
add_shortcode('mostra-calendario-widget', array($this, 'render_calendario_widget')); // NOVO SHORTCODE
|
||||
}
|
||||
|
||||
public function render_calendario($atts) {
|
||||
ob_start();
|
||||
?>
|
||||
<div id="eventos-calendario" class="em-calendario-wrapper" data-view="full">
|
||||
<div class="em-calendario-header em-toolbar">
|
||||
<div class="em-toolbar-section">
|
||||
<button class="em-nav-btn" data-nav="prev"><</button>
|
||||
<button class="em-nav-btn" data-nav="next">></button>
|
||||
<button class="em-nav-btn em-today-btn" data-nav="today">Hoje</button>
|
||||
</div>
|
||||
<div class="em-toolbar-section em-toolbar-center"><h3 class="em-mes-ano"></h3></div>
|
||||
<div class="em-toolbar-section em-toolbar-right">
|
||||
<button class="em-view-btn" data-view="fullscreen" title="Tela Cheia">⛶</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="em-dias-semana"></div>
|
||||
<div class="em-dias-grid"></div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function render_proximos_eventos($atts) {
|
||||
$atts = shortcode_atts(array(
|
||||
'limit' => 5,
|
||||
'tipo' => ''
|
||||
), $atts, 'mostra-prox-eventos');
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'evento',
|
||||
'posts_per_page' => intval($atts['limit']),
|
||||
'meta_key' => 'data_evento',
|
||||
'orderby' => 'meta_value',
|
||||
'order' => 'ASC',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'data_evento',
|
||||
'value' => date('Y-m-d'),
|
||||
'compare' => '>=',
|
||||
'type' => 'DATE'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($atts['tipo'])) {
|
||||
$args['tax_query'] = array(
|
||||
array(
|
||||
'taxonomy' => 'tipo_evento',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field($atts['tipo'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$eventos = new WP_Query($args);
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="proximos-eventos-box">
|
||||
<h4>Próximos Eventos</h4>
|
||||
<ul class="proximos-eventos-lista">
|
||||
<?php if ($eventos->have_posts()) : ?>
|
||||
<?php while ($eventos->have_posts()) : $eventos->the_post(); ?>
|
||||
<?php
|
||||
$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');
|
||||
?>
|
||||
<li>
|
||||
<div class="evento-data">
|
||||
<?php echo date_i18n('d M', strtotime($data_evento)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<div class="evento-titulo"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
|
||||
<?php if ($hora_evento) : ?>
|
||||
<div class="evento-hora"><?php echo $hora_evento; ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($tipos && !is_wp_error($tipos)) : ?>
|
||||
<span class="evento-tipo"><?php echo $tipos[0]->name; ?></span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endwhile; wp_reset_postdata(); ?>
|
||||
<?php else : ?>
|
||||
<li>Nenhum evento agendado</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function render_eventos_completo($atts) {
|
||||
ob_start();
|
||||
?>
|
||||
<div class="noticias-eventos-wrapper">
|
||||
<div class="noticias-col">
|
||||
<?php echo $this->render_calendario($atts); ?>
|
||||
</div>
|
||||
<div class="eventos-col">
|
||||
<?php echo $this->render_proximos_eventos($atts); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function render_calendario_widget($atts) {
|
||||
ob_start();
|
||||
?>
|
||||
<div id="eventos-calendario-widget" class="em-calendario-wrapper" data-view="widget">
|
||||
<div class="em-calendario-header em-toolbar">
|
||||
<div class="em-toolbar-section">
|
||||
<button class="em-nav-btn" data-nav="prev"><</button>
|
||||
<button class="em-nav-btn" data-nav="next">></button>
|
||||
</div>
|
||||
<div class="em-toolbar-section em-toolbar-center"><h3 class="em-mes-ano"></h3></div>
|
||||
<div class="em-toolbar-section"></div>
|
||||
</div>
|
||||
<div class="em-dias-semana"></div>
|
||||
<div class="em-dias-grid"></div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user