Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
everaldomatias / create_user_by_post_published.php
Created February 6, 2017 11:53
Função para criar usuário a partir de um custom post publicado
/**
* Create user by Perfil is published or updated.
*
* @param int $post_id The post ID.
* @param post $post The post object.
* @param bool $update Whether this is an existing post being updated or not.
*/
function perfil_save_create_user( $post_id, $post, $update ) {
$post_type = get_post_type( $post_id );
// Cria a tabela Configuracoes se não existir
$conexao_configuracoes = mysqli_connect( $host, $user, $pass, $banco ) or die( "ERROR : " . mysqli_error() );
$configuracoes = "configuracoes";
$cria_configuracoes = $conexao_configuracoes->query("CREATE TABLE IF NOT EXISTS $configuracoes(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
km_inicial VARCHAR(50) NOT NULL,
data_inicial DATE NOT NULL,
valor_compra VARCHAR(50) NOT NULL
)");
git clone https://github.com/aikiframework/json.git --recursive
// JS
jQuery(function() {
jQuery('.add-request-quote-button').on('click', function() {
jQuery.ajax({
type : 'POST',
url : 'wp-admin/admin-ajax.php',
dataType: 'json',
data : action_agp_qdt_itens,
success: function (response) {
jQuery('#raq_item_number').addClass('teste');
@everaldomatias
everaldomatias / redirect-single-result-search.php
Created December 7, 2017 12:49
Snippet to redirect single result search in WP.
/**
* Redirect single result search in WP.
* @author Everaldo Matias <matiaseveraldo@gmail.com>
*/
add_action( 'template_redirect', 'redirect_single_result_search' );
function redirect_single_result_search() {
if ( is_search() ) {
global $wp_query;
if ( $wp_query->post_count == 1 ) {
@everaldomatias
everaldomatias / add-search-in-nav.php
Last active January 12, 2018 12:16
Add search field in nav menu WP
/**
* Add search field in nav menu WP.
* @author Everaldo Matias <matiaseveraldo@gmail.com>
* @link https://developer.wordpress.org/reference/functions/get_search_form/
*/
add_filter( 'wp_nav_menu_items', 'add_search_in_nav' );
function add_search_in_nav() {
// If this isn't the responsive-menu, do nothing.
if ( ! ( $args->theme_location == 'responsive-menu' ) )
@everaldomatias
everaldomatias / get_glyphicon.php
Last active February 22, 2018 12:20
Função para retornar tag <span> com ícone da biblioteca Glyphicons
/**
*
* Função para retornar tag <span> com ícone da biblioteca Glyphicons
*
* @author Everaldo Matias <http://everaldomatias.github.io>
* @version 0.1
* @since 22/02/2018
* @link https://gist.github.com/everaldomatias/e3f7af6eaa19037d7046c39f6c860390
* @param $icon string que irá receber a especificação do ícone
* @example <?php echo get_glyphicon( 'glyphicon-heart' ); ?>
@everaldomatias
everaldomatias / user_by_ftp.php
Last active April 17, 2018 17:08
Função para criar usuário administrador no WordPress via FTP
/**
*
* Função para criar usuário administrador no WordPress via FTP
*
* @since 17/04/2018
* @see https://brasa.art.br/como-adicionar-um-usuario-no-wordpress-pelo-ftp/
* @return void
*
*/
@everaldomatias
everaldomatias / mask_cpf_cnpj.js
Created May 18, 2018 11:57
Máscara jQuery para CPF e CNPJ no mesmo campo
/*
Adiciona máscara em CPF e CNPJ no mesmo campo
Caso precise você pode mudar o seletor para usar um ID ou class.
Fonte: https://jsfiddle.net/pdd8g4mf/
*/
var CpfCnpjMaskBehavior = function (val) {
return val.replace(/\D/g, '').length <= 11 ? '000.000.000-009' : '00.000.000/0000-00';
},
cpfCnpjpOptions = {
@everaldomatias
everaldomatias / list-filters-in-hook.php
Last active May 18, 2018 12:01
Debug para listar filtros no WordPress
<?php
/**
* Mude 'wp_head' para o hook que deseja debugar
*/
global $wp_filter;
echo '<pre>';
var_dump( $wp_filter['wp_head'] );
echo '</pre>';