Skip to content

Instantly share code, notes, and snippets.

View fdaciuk's full-sized avatar
🔥

Fernando Daciuk fdaciuk

🔥
View GitHub Profile
@fdaciuk
fdaciuk / month-year-wp.php
Created July 4, 2013 19:07
Pegar posts separados por Ano / Mês no WordPress
<?php
// Meses
$mes = array( '', 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro' );
$years = $wpdb->get_col( "SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC" );
foreach( $years as $year ) {
$months = $wpdb->get_col( "SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND YEAR(post_date) = '" . $year . "' ORDER BY post_date DESC" );
foreach( $months as $key => $month ) {
@fdaciuk
fdaciuk / roles.php
Last active December 18, 2015 19:39
Separar roles wordpress
<?php
$result = count_users();
$subscribers;
$admin;
foreach($result['avail_roles'] as $role => $count) {
if( $role == 'administrator' )
$admin = $count;
if( $role == 'subscriber' )
$subscribers = $count;
@fdaciuk
fdaciuk / email-validate.js
Created June 21, 2013 17:12
Validação de e-mail com JS
function is_email( email ) {
var exclude = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check = /@[\w\-]+\./;
var checkend = /\.[a-zA-Z]{2,3}$/;
if( ( ( email.search( exclude ) != -1 )||( email.search( check ) ) == -1 )||( email.search( checkend ) == -1 ) ) { return false }
else { return true }
}
@fdaciuk
fdaciuk / .htaccess
Created June 10, 2013 14:58
Padrão para sites institucionais em PHP
RewriteEngine On
# URLs Amigaveis
RewriteRule ^(sobre|produtos|contato)/?$ ?p=$1
# Erro 404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !\.(jpg|png|gif)
RewriteRule ^(.*)$ ?p=404 [L]
@fdaciuk
fdaciuk / functions_windows.php
Created May 20, 2013 18:39
Função para incluir o index.php no home_url em servers Windows
<?php
/*--------------------------------------------------------------------------------------
*
* @name: my_home_url
* @description: Modificar home_url para Windows
* @author: Volts Digital
*
*-------------------------------------------------------------------------------------*/
function my_home_url( $url ) {
$other_url = explode( '://', $url ); // quebra em http e restante do site
@fdaciuk
fdaciuk / app.js
Created May 5, 2013 01:25
Teste Rotas com API History HTML5 no Angular
var app = angular.module('myApp', []);
app.config(['$locationProvider', '$routeProvider', function( $locationProvider, $routeProvider ) {
$locationProvider.html5Mode( true );
$routeProvider
.when('/', { controller : 'controller', templateUrl : 'views/home.html' })
.when('/empresa', { controller : 'controller', templateUrl : 'views/register-company.html' })
.when('/profissional', { controller : 'controller', templateUrl : 'views/register-professional.html' })
.otherwise({ redirectTo : 'views/404.html' });
@fdaciuk
fdaciuk / functions.php
Created May 4, 2013 22:46
Funções para minimizar o caminho das pedras no WP :P (Na real, só pra não ficar chamando as funções gigantes do WP pra pegar o caminho dos arquivos)
<?php
/*
Use para chamar qualquer arquivo dentro do tema.
Ex: echo theme_url( 'assets/images/logo.png' );
*/
function theme_url( $path = null ) {
return get_template_directory_uri() . '/' . $path;
}
@fdaciuk
fdaciuk / functions.php
Created May 4, 2013 14:33
Adicionar jQuery UI do WordPress para usar no tema.
<?php
function enqueue_scripts() {
wp_enqueue_script( 'jquery-ui-core' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
@fdaciuk
fdaciuk / gmaps_v3.js
Created May 3, 2013 18:26
Google Maps v3 - Javascript (jQuery) Busca a latitude e longitude a partir do endereço passado em "data-address" na div #map-canvas.
jQuery(function($) {
var $map = $( '#map-canvas' ),
address = $map.data( 'address' ),
lat, lng,
map_options = {},
map, marker;
$.ajax({
url : 'http://maps.googleapis.com/maps/api/geocode/json',
dataType : 'json',
@fdaciuk
fdaciuk / just_number.js
Last active December 16, 2015 22:09
Somente números com jQuery
$(function() {
// Somente números
$( 'input.numero' ).on( 'keydown', function(e) {
var keyCode = e.keyCode || e.which,
pattern = /\d/,
// Permite somente Backspace, Delete e as setas direita e esquerda, números do teclado numérico - 96 a 105 - (além dos números)
keys = [ 46, 8, 9, 37, 39, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105 ];
if( ! pattern.test( String.fromCharCode( keyCode ) ) && $.inArray( keyCode, keys ) === -1 ) {