Skip to content

Instantly share code, notes, and snippets.

View luancmaia's full-sized avatar

Luan Maia luancmaia

View GitHub Profile
<?php
//pattern examples: '*.jpg', '*_GREEN.png', 'file.jpg'
$rq = exec("find . -name 'YOUR_PATTERN_HERE'", $out, $err);
require_once("vendor/autoload.php");
$tinify_key = '';
if ( !empty($out) ){
$image = new Imagick();
$image->newImage(1100, 460, new ImagickPixel('red'));
$image->setImageFormat("jpg");
$type=$image->getFormat();
header("Content-type: $type");
$iw = $image->getimagewidth();
$ih = $image->getimageheight();
$inw = $iw / $ih * 460;
$texture = new Imagick();
$texture->readImage($pathToImage);
@luancmaia
luancmaia / functions.php
Created December 6, 2017 16:12
PHP Filtro
add_action( 'pre_get_posts', 'query_filter_category' );
function query_filter_category( $query ) {
if ( $_GET && isset( $_GET['tid'] ) && $query->is_main_query() ) {
$tid = $_GET['tid'];
$tids = [];
$tax_query = ['relation' => 'OR'];
global $wpdb;
foreach($tid as $t):
$result = $wpdb->get_results( 'SELECT object_id FROM ' . $wpdb->prefix . 'term_relationships WHERE term_taxonomy_id = ' . $t );
@luancmaia
luancmaia / global.js
Created December 6, 2017 16:11
JS Filtro
$(document).on('ready', function(){
var check_img = 'http://petitpapier.com.br/wp-content/uploads/2017/12/square-check-x.png';
var uncheck_img = 'http://petitpapier.com.br/wp-content/uploads/2017/12/square-x.png';
$('a.remove-category-url').on('click', function(e){
e.preventDefault();
var url = $('.actual-url').val();
url = url.replace('&tid[]=' + $(this).attr('data-id'), '');
url = url.replace('?tid[]=' + $(this).attr('data-id'), '');
add_action( 'init', 'update_post_tags' );
function update_post_tags() {
$q = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1 ) );
if ( $q->have_posts() ):
while ( $q->have_posts() ):
$q->the_post();
$post_id = get_the_ID();
$args = array( 'fields' => 'names' );
//Just include it to your functions.php
// VALIDATE YOUR COUPON CODE FOR THE FIRST ORDER ONLY
add_filter( 'woocommerce_coupon_is_valid', 'woocommerce_coupon_first_order', 10, 2 );
function woocommerce_coupon_first_order( $true, $instance ) {
if ( ( $instance->code != 'COUPONCODE' ) || ! is_user_logged_in() ) return $true;
$customer_orders = get_posts( array(
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
@luancmaia
luancmaia / youtube_api
Created June 2, 2015 13:18
Youtube API
function auth_authorize_user() {
require_once get_template_directory() . '/google-api-php-client/src/Google/autoload.php'; // or wherever autoload.php is located
$OAUTH2_CLIENT_ID = '563013973974-kadbdid56ilvk6fk0digm27llbub88h3.apps.googleusercontent.com';
$OAUTH2_CLIENT_SECRET = '2Gb9oII1mk-mXi5EOPSO8S6z';
$client = new Google_Client();
$client->setClientId( $OAUTH2_CLIENT_ID );
$client->setClientSecret( $OAUTH2_CLIENT_SECRET );
$client->setScopes( 'https://www.googleapis.com/auth/youtube' );
$redirect = filter_var( home_url(),FILTER_SANITIZE_URL );
//Requisição Ajax
Parametros :
'post_type' => 'Nome do Post Type Usado',
'type' => 'search' para buscas ou 'load' para carregar mais conteudos,
'param' => em 'search' o valor buscado, em 'load' um array com os ids que não devem ser buscados,
'img_field' => caso queira que retorne imagem passe o nome do campo do acf,
'quantity' => quantidade de posts que vai buscar
OBS: O Modelo abaixo está com os parametros preenchidos só para melhor entendimento.
@luancmaia
luancmaia / shortcode.php
Created October 2, 2014 02:14
Shortcode to restrict a piece of content
<?php
Class Shortcode {
public function __construct(){
add_shortcode( 'restricted:content', array( &$this, 'restricted_content' ) );
}
private function explode_params( $params = null, $flag = ',' ){
if ( is_null( $params ) || empty( $params ) ) {
return null;