Skip to content

Instantly share code, notes, and snippets.

View tcelestino's full-sized avatar
⛱️
Working from home

Tiago Celestino tcelestino

⛱️
Working from home
View GitHub Profile
@tcelestino
tcelestino / modify_theme.php
Created March 26, 2012 14:29
Modify your WordPress theme without modify a page published
<?php
if(isset($_GET["v2"])) :
include(dirname(__FILE__)."/v2/index.php");
exit;
endif;
get_header();
?>
@tcelestino
tcelestino / hexContraction.js
Created June 19, 2012 13:45
Hexdecimal Contraction
//authors: Diego Fleury and Diego Nunes
function hexContraction(color) {
var regexp = /#?([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3/i;
return '#'+ color.replace(regexp, '$1$2$3') || '#'+ color.replace('#', '');
}
hexContraction('aabbcc'); //#abc
hexContraction('#AD8634'); //'#AD8634
hexContraction('aaddc4'); //#aaddc4
@tcelestino
tcelestino / pagination_wordpress.php
Created June 26, 2012 12:35
pagination wordpress without plugin
<?php
function paglink($first=1,$last=1,$middle=10,$baseURL=false,$wp_query=false ) {
if(!$baseURL) $baseURL= get_bloginfo('url');
if(!$wp_query)global $wp_query;
$page = $wp_query->query_vars["paged"];
if ( !$page ) $page = 1;
$qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
if ( $wp_query->found_posts > $wp_query->query_vars["posts_per_page"] ) {
echo '<div class="box-paginacao">';
if ( $page > 1 ) {
@tcelestino
tcelestino / detect-support-console.js
Last active October 7, 2015 08:47
Detect browser support console
if(typeof(console) == 'undefined') console = { log : function(){} };
if(typeof(console.log) != 'function') console.log = function(){};
// color console.log
console.log("%c%s",
"color: red; background: yellow; font-size: 24px;",
"WARNING!");
@tcelestino
tcelestino / gist:3335352
Created August 12, 2012 23:35
Add caps Custom Post Type WordPress
<?php add_action( 'admin_init', 'cpt_add_caps');
function cpt_add_caps(){
$admin_role = get_role( 'administrator' );
$caps = array(
'publish_cpt',
'edit_cpt',
'edit_others_cpt',
'delete_estacionamentos',
'delete_others_cpt',
@tcelestino
tcelestino / facebook_page.php
Created September 4, 2012 00:09
Permissions app on page tab Facebook
<?php
require 'sdk/facebook.php';
$fb = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'SECRET_APP_ID',
));
$user = $fb->getUser();
if ($user) {
@tcelestino
tcelestino / permission.js
Created September 4, 2012 00:11
Permissions app on page tab facebook onload
var scope = ['user_about_me', 'user_groups', 'user_likes', 'user_photos', 'publish_stream', 'read_friendlists'];
var oauth_url = 'https://www.facebook.com/dialog/oauth/';
oauth_url += '?client_id=<?php echo $fb->getAppID() ?>';
oauth_url += '&redirect_uri=' + encodeURIComponent('https://www.facebook.com/pages/null/Página-de-Teste/503673046324840/?sk=app_<?php echo $fb->getAppID() ?>');
oauth_url += '&scope='+scope;
window.top.location = oauth_url;
@tcelestino
tcelestino / mailer.php
Last active October 11, 2015 07:37
Using PHPMailer to attachment WordPress files
<?php
define('WP_USE_THEMES', false);
require('../../../wp-load.php');
require_once("class.phpmailer.php");
if(isset($_POST)) {
$nome = $_POST["name"];
@tcelestino
tcelestino / gist:3886362
Created October 13, 2012 22:13 — forked from zenorocha/gist:3860568
Facebook Groups
@tcelestino
tcelestino / gist:4029038
Created November 7, 2012 01:43
Adiciona um novo usuário
<?php
// salva um usuario no wordpress
// return @interger
function save_user($avatar, $username, $name, $email) {
if(empty($username)) {
$username = "Guest_".rand(000000,999999).$username; // cria um usuario caso não tenha um nome de usuário
}
$userdata = array(