Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

codigo certo

=== Lista de Inscritos ===

== Installation ==
/**
* Plugin Name: Lista de Inscritos
* Plugin URI: http://localhost/
* Description: Plugin para gerenciar lista dos inscritos nas corridas
* Version: 1.0 or whatever version of the plugin (pretty self explanatory)
* Author: Henrique Wilson
* Author URI: http://henriquewilson.com.br
* License: A "Slug" license name e.g. GPL12
*/


// EVENTOS DB

global $jal_db_version;
$jal_db_version = '1.0';

function jal_install() {
	global $wpdb;
	global $jal_db_version;

	$table_name = $wpdb->prefix . 'inscritos';

	$charset_collate = $wpdb->get_charset_collate();

	$sql = "CREATE TABLE $table_name (
	id mediumint(9) NOT NULL AUTO_INCREMENT,
	time datetime DEFAULT '0000-00-00 00:00:00',
	modalidade text ,
	evento_id mediumint(9) ,
	nome text ,
	telefone text ,
	celular text ,
	sexo text ,
	nascimento text ,
	email text ,
	rg text ,
	cpf text ,
	cep text ,
	endereco text ,
	numero text ,
	cidade text ,
	estado text ,
	nome_contato text ,
	telefone_contato text ,
	celular_contato text ,
	pais text , 
	complemento text , 
	profissao text ,
	equipe text ,
	UNIQUE KEY id (id)
	) $charset_collate;";
	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
	dbDelta( $sql );
	add_option( 'jal_db_version', $jal_db_version );
}
register_activation_hook( __FILE__, 'jal_install' );
class PageSubscribers {
	protected $plugin_slug;
	private static $instance;
	protected $templates;
	public static function get_instance() {
		if( null == self::$instance ) {
			self::$instance = new PageSubscribers();
		}
		return self::$instance;
	}
	private function __construct() {
		$this->templates = array();
		// Add a filter to the attributes metabox to inject template into the cache.
		add_filter(
			'page_attributes_dropdown_pages_args',
			array( $this, 'register_project_templates' )
		);
		// Add a filter to the save post to inject out template into the page cache
		add_filter(
			'wp_insert_post_data',
			array( $this, 'register_project_templates' )
		);
		// Add a filter to the template include to determine if the page has our
		// template assigned and return it's path
		add_filter(
			'template_include',
			array( $this, 'view_project_template')
		);
		// Add your templates to this array.
		$this->templates = array(
			'report-template.php'     => 'Relatórios de inscritos',
		);
	}
	/**
	 * Adds our template to the pages cache in order to trick WordPress
	 * into thinking the template file exists where it doens't really exist.
	 *
	 */
	public function register_project_templates( $atts ) {
		// Create the key used for the themes cache
		$cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
		// Retrieve the cache list.
		// If it doesn't exist, or it's empty prepare an array
		$templates = wp_get_theme()->get_page_templates();
		if ( empty( $templates ) ) {
			$templates = array();
		}
		// New cache, therefore remove the old one
		wp_cache_delete( $cache_key , 'themes');
		// Now add our template to the list of templates by merging our templates
		// with the existing templates array from the cache.
		$templates = array_merge( $templates, $this->templates );
		// Add the modified cache to allow WordPress to pick it up for listing
		// available templates
		wp_cache_add( $cache_key, $templates, 'themes', 1800 );
		return $atts;
	}
	/**
	 * Checks if the template is assigned to the page
	 */
	public function view_project_template( $template ) {
		global $post;
		if (!isset($this->templates[get_post_meta($post->ID, '_wp_page_template', true)])){
			return $template;
		}
		$file = plugin_dir_path(__FILE__). get_post_meta(
			$post->ID, '_wp_page_template', true
		);
		// Just to be safe, we check if the file exist first
		if( file_exists( $file ) ) {
			return $file;
		} else { echo $file; }
		return $template;
	}
}
add_action( 'plugins_loaded', array( 'PageSubscribers', 'get_instance' ) );

add_action( 'init', 'addRewritesHW' );
function addRewritesHW() {
	add_rewrite_endpoint( "xls-download", EP_PERMALINK );
	add_feed( "xls-download", 'xls_download' );
}

function xls_download() {
	$evento_id = $_GET['id'];
	$eventoNome = get_the_title( $evento_id );
	header("Content-type: application/vnd-ms-excel");
	header("Content-Disposition: attachment; filename=$eventoNome.xls");

	global $wpdb;
	$table_name = $wpdb->prefix . 'inscritos';
	$subscribList = $wpdb->get_results( "SELECT * FROM $table_name WHERE evento_id='$evento_id' ORDER BY modalidade ", OBJECT );
	echo '';
	echo '';
	$modalidade = "";
	foreach ($subscribList as $key => $item) :
		if ($modalidade != $item->modalidade) :
		$modalidade = $item->modalidade;
	?>	
    
	<?php
	endif;
	echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
		echo '';
	echo '';
	if ($modalidade != $subscribList[$key + 1]->modalidade) : ?>
	
	<?php 
	endforeach;
	echo '
NOME SEXO DATA NASC. CPF PROFISSÃO EQUIPE TELEFONE CELULAR EMAIL CONTATO DE EMERGÊNCIA TELEFONE DO CONTATO CELULAR DO CONTATO PAÍS CEP ESTADO CIDADE ENDEREÇO NÚMERO COMPLEMENTO
'; } add_filter( 'request', 'pmg_rewrite_filter_request' ); function pmg_rewrite_filter_request( $vars ) { if( isset( $vars['json'] ) ) $vars['json'] = true; return $vars; } register_activation_hook( __FILE__, 'activationHW' ); function activationHW() { addRewritesHW(); flush_rewrite_rules(); } add_action( 'wp_ajax_report_send', 'report_send_callback' ); add_action( 'wp_ajax_nopriv_report_send', 'report_send_callback' ); function report_send_callback() { $email = $_POST['email']; if (isEmail($email)) { echo report_email_builder($email); } echo false; wp_die(); // this is required to terminate immediately and return a proper response } function report_email_builder($email) { add_filter( 'wp_mail_content_type', 'set_html_content_type' ); $to = $email; $subject = 'Relatório SpeedCrono'; $headers[] = 'From: SpeedCrono '; $headers[] = 'Content-Type: text/html; charset=UTF-8'; $message = '
SpeedCrono | Inscrição
SpeedCrono | Inscrição
Confira o relatório SpeedCrono.
Acesse o link: Relatório SpeedCrono
'; $resultReport = wp_mail( $to, $subject, $message, $headers ); remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); return $resultReport; } function isEmail($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) { return true; } return false; }