Created
December 1, 2013 01:58
-
-
Save guwordpressbrasil/7727666 to your computer and use it in GitHub Desktop.
Query Vars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Cliente { | |
function __construct(){ | |
add_filter('query_vars', array( $this, 'add_query_vars')); | |
add_filter('rewrite_rules_array', array( $this, 'add_rewrite_rules')); | |
add_action('template_redirect', array( $this, 'altera_status_cliente')); | |
} | |
function add_query_vars( $vars) { | |
$vars[] = "ativar"; | |
$vars[] = "cancelar"; | |
$vars[] = "funcionario"; | |
return $vars; | |
} | |
function add_rewrite_rules($rules) { | |
$new_rules = array( | |
'ativar/([^/]+)/?$' => 'index.php?ativar=$matches[1]', | |
'cancelar/([^/]+)/?$' => 'index.php?cancelar=$matches[1]', | |
'funcionario/([^/]+)/?$' => 'index.php?funcionario=$matches[1]', | |
); | |
$rules = $new_rules + $rules; | |
return $rules; | |
} | |
function altera_status_cliente() { | |
global $wp_query; | |
if(isset($wp_query->query_vars['ativar'])) { | |
$user_id = get_query_var('ativar'); | |
update_user_meta($user_id, 'ativo', true); | |
$user_info = get_userdata($user_id); | |
$nome = $user_info->display_name; | |
$email = $user_info->user_email; | |
global $Emails; | |
$envia_email = $Emails->cadastro_confirmado($email, $nome);//envia email para o cliente avisando que o cadastro foi confirmado | |
} | |
if(isset($wp_query->query_vars['cancelar'])) { | |
$user_id = get_query_var('cancelar'); | |
require_once (ABSPATH. 'wp-admin/includes/user.php'); | |
$deletado = wp_delete_user($user_id); | |
if($deletado){ | |
$user_info = get_userdata($user_id); | |
$nome = $user_info->display_name; | |
$email = $user_info->user_email; | |
global $Emails; | |
$envia_email = $Emails->cadastro_removido($email, $nome);//envia email para o cliente avisando que o cadastro foi removido | |
}else{ | |
} | |
} | |
} | |
} | |
add_action("init", "ClienteInit",1); | |
function ClienteInit() { | |
global $Cliente; | |
$Cliente = new Cliente(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment