Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
everaldomatias / conditional-metabox-to-page-template.php
Created December 19, 2016 22:33
Conditional Metabox to Page Template
<?php
if ( is_admin() && !empty( $_POST['post_ID'] ) ) {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta( $post_id,'_wp_page_template',TRUE );
if ( $template_file == 'page_custom_template.php' ) {
add_action( 'init', 'custom_metabox', 1 );
}
}
@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 );
@everaldomatias
everaldomatias / contact-form-7-select-estados-shortcode.md
Last active November 30, 2018 16:24
Shortcode do plugin (WP) Contact Form 7 para select com os estados brasileiros.

[select* estados "AC" "AL" "AP" "AM" "BA" "CE" "DF" "ES" "GO" "MA" "MT" "MS" "MG" "PA" "PB" "PR" "PE" "PI" "RJ" "RN" "RS" "RO" "RR" "SC" "SP" "SE" "TO"]

@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>';
function mobile_home_redirect(){
if( wp_is_mobile() && is_front_page() ){
include( get_stylesheet_directory() . '/index-mobile.php' );
exit;
}
}
// 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' ) )