Skip to content

Instantly share code, notes, and snippets.

View Page-Carbajal's full-sized avatar

Page Carbajal Page-Carbajal

View GitHub Profile
@Page-Carbajal
Page-Carbajal / Pre-Get-Posts-Filter.class.php
Last active August 29, 2015 14:21
WordPress pre_get_posts Filter
<?php
namespace WordPress\Filters;
class PreGetPosts{
public $filterPriority = 10;
public function __construct( $priority = 10 ){
//TODO: Set your custom properties if needed
$this->filterPriority;
@Page-Carbajal
Page-Carbajal / Aggregate Posts by Day of the Year
Last active August 29, 2015 14:24
Query to Aggregate Published posts by Day
Select post_date, count(post_date) as post_count from wp_posts
where post_status = 'publish'
and ( post_date between '2015-05-01' And '2015-05-30' )
Group By DAYOFYEAR( post_date )
;
@Page-Carbajal
Page-Carbajal / curly-sintax-demo.php
Created August 30, 2015 20:40
Un ejemplo simple de como usar la Sintaxis Curly de PHP en cadenas.
<?php
// Este es un demo de la Sintaxis Curly de PHP
class Empleado{
public $id;
public $nombre;
public $apellido;
public $email;
@Page-Carbajal
Page-Carbajal / getByMeta.php
Last active September 30, 2015 22:15
Get WordPress Posts By Meta
<?php
function getPostByMeta( $metaKey, $metaValue, $operatos = '=' ){
$args = array(
'showposts' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => $metaKey,
'value' => $metaValue,
@Page-Carbajal
Page-Carbajal / ext-xdebug.ini
Created January 4, 2016 03:37
XDebug Sample Configuration
xdebug.remote_enable=1
xdebug.profiler_enable=1
xdebug.profiler_output_name = xdebug.profiler.%H.%t
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir=/set/a/path
@Page-Carbajal
Page-Carbajal / Override nested dependencies with Composer.json
Last active February 11, 2016 23:04
Override nested dependencies with Composer
{
"name": "page-carbajal/my-awesome-package",
"description": "My Awesome Package",
"type": "Plugin",
"authors": [
{
"name": "Page Carbajal",
"email": "awesom@pagecarbajal.com"
}
],
<?php
// Late Static Binding in PHP are great.
// However they are not supported in every version of PHP
// Use the code below in a new 3val.org window to test support
// for Late Static Bindings inside closures.
abstract class Demo
{
protected $item;
@Page-Carbajal
Page-Carbajal / functions.php
Created June 17, 2016 22:20
WordPress - How to dynamically load scripts and styles based on post content
<?php
add_action('template_redirect','justIfContentHas');
function justIfContentHas()
{
global $post;
// Set the condition for loading your resources
if( has_shortcode($post->post_content, 'my_short_code') ){
@Page-Carbajal
Page-Carbajal / jquery-injection.js
Created May 14, 2018 15:00
Injecting jQuery on Runtime
// Force jQuery Injection
(function($d){
if( 'undefined' === typeof jQuery ){
var head = document.getElementsByTagName("head")[0];
var customScript = document.createElement("script");
customScript.src = scriptSource;
customScript.onload = function(){
if( jQuery ){
/******** Start writing you jQuery code here ************/
@Page-Carbajal
Page-Carbajal / get-post-thumbnail.gist.class.php
Last active May 19, 2018 03:20
WordPress - Get Post Thumbnail URL
<?php
/**
* Return the Post Thumbnail URL if $post has thumbnail
* $post is a WordPress Post Object
* @param $post
* @return string
*/
private function getPostThumbnailURL( $post ){
if ( has_post_thumbnail( $post->ID ) ){