Skip to content

Instantly share code, notes, and snippets.

View bordoni's full-sized avatar
:shipit:
Working on The Events Calendar

Gustavo Bordoni bordoni

:shipit:
Working on The Events Calendar
View GitHub Profile
@bordoni
bordoni / git.bash
Created August 23, 2012 10:47
Git Bash terminal output
function parse_git_dirty {
[[ "$(git status 2> /dev/null | tail -n1)" != "nothing to commit (working directory clean)" ]] && echo "*"
}
function bord_git_unpushed {
branchinfo=$(git branch -v 2> /dev/null)
if [[ $branchinfo != "" ]]
then
brinfo=$($branchinfo | grep $(bord_git_parse_branch) | egrep " \[ahead [[:digit:]]{1,}\] ")
@bordoni
bordoni / wordpress-upload.php
Created August 24, 2012 17:51
How to upload a file to WordPress
<?php
/**
* Handle file uploading and add attachment.
*
* @return array Uploaded file's details on success, error message on failure
*/
function wp_import_handle_upload() {
if ( !isset($_FILES['filefield_name']) ) {
$file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' );
return $file;
@bordoni
bordoni / gist:3836854
Created October 4, 2012 22:23
Query posts with thumbnail or any attachments within a certain category
<?php
global $wpdb;
$possible_ids = $wpdb->get_col($wpdb->prepare("SELECT `post_parent` FROM {$wpdb->$posts} WHERE `post_parent`!=0 AND `post_type`='attachment' GROUP BY `post_parent`;"));
$args = array(
'post__in' => $possible_ids,
'posts_per_page' => 4,
'category__in' => array(8),
'meta_query' => array(
@bordoni
bordoni / searchreplace.php
Created December 3, 2012 19:41
Search and Replace on WordPress Database
<?php
// Safe Search and Replace on Database with Serialized Data v1.0.1
// This script is to solve the problem of doing database search and replace
// when developers have only gone and used the non-relational concept of
// serializing PHP arrays into single database columns. It will search for all
// matching data on the database and change it, even if it's within a serialized
// PHP array.
@bordoni
bordoni / cropstring.php
Created December 12, 2012 05:23
A WordPress group of functions for Cropping strings based on some settings
<?php
/**
* Count the words in a string, remove all the html before counting
*
* @since 0.1a
* @access public
*
* @param string $text (required) Any kind of string works, even with html
* Default: 'null'.
* @param string $type (required) The kind of return that you want, could be just an int or an array
<?php
$_filter = function($title, $id) {
if (in_category('nome-da-category', $id) && strpos($title, 'Receita de ')!==false) {
return str_replace('Receita de ', '', $title);
}
return $title;
};
add_filter('the_title', $_filter);
@bordoni
bordoni / permalink-cursos.php
Last active December 18, 2015 17:29
WordPress Permalinks for a CPT called "cursos"
[qa.trii.com.br] Executing task 'deploy'
[qa.trii.com.br] sudo: git fetch --all --recurse-submodules-default=yes --quiet --prune
[qa.trii.com.br] sudo: git reset --hard origin/master && git submodule foreach git reset --hard origin/master
[qa.trii.com.br] out: HEAD is now at 393c4a2 NGINX whitelist
[qa.trii.com.br] out: Entering 'www/edumais'
[qa.trii.com.br] out: HEAD is now at 9583526 Adicionado a pasta uploads
[qa.trii.com.br] out: Entering 'www/institucional'
[qa.trii.com.br] out: HEAD is now at cef1df2 Mudança de endereços
[qa.trii.com.br] out: Entering 'www/plasticursos'
[qa.trii.com.br] out: HEAD is now at a4f8dc6 Ajustes de server
<?php
$role = 'subscriber';
if ( false === ( $userids = get_transient( "monthly_userids.{$role}" ) ) ) { // If the transient isn't set do it!
global $wpdb;
$start_date = date('Y-m-d H:i:s', strtotime('first day of this month'));
$end_date = date('Y-m-d H:i:s', strtotime('first day of next month'));
$userids = $wpdb->get_col( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS `user`.`ID` as `ID` FROM `{$wpdb->users}` AS `user`, `{$wpdb->usermeta}` AS `meta` WHERE 1=1 AND (`meta`.`user_id` = `user`.`ID` AND `meta`.`meta_key` = 'em_capabilities' AND `meta`.`meta_value` LIKE '%s') AND `user`.`user_registered` BETWEEN '%s' AND '%s' GROUP BY `user`.`ID`;", "%{$role}%", $start_date, $end_date ) );
set_transient( "monthly_userids.{$role}", $userids, 60*60*12 );
@bordoni
bordoni / wp-config-security.php
Created June 25, 2013 15:47
Some definitions for security on WordPress
<?php
/**
* WordPress Files Edition Security
* Nobody can be able to edit files within the admin it self
*/
define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', true );