Skip to content

Instantly share code, notes, and snippets.

View camaleaun's full-sized avatar

Gilberto Tavares camaleaun

  • Yogh
  • Joinville SC, Brazil
  • 00:28 (UTC -03:00)
View GitHub Profile
{
"require": {
"composer/installers": "^1.6"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"wp-coding-standards/wpcs": "^2.0"
},
"scripts": {
"php:lint": "composer install && vendor/bin/phpcs -p"
@camaleaun
camaleaun / functions.php
Last active August 13, 2019 22:52
Funcions Utils
<?php
add_filter( 'themename_twbs_bootstrap_defaults', 'themename_twbs_bootstrap_defaults' );
function themename_twbs_bootstrap_defaults( $defaults ) {
$defaults['version'] = '3.3.7';
$defaults['files'] = 'both';
$defaults['cdn'] = 'maxcdn';
$defaults['css_path'] = get_theme_file_uri( 'assets/css' );
$defaults['js_path'] = get_theme_file_uri( 'assets/js' );
return $defaults;
@camaleaun
camaleaun / comma.sql
Created August 2, 2019 01:45
Comma group contact mysql select join
CREATE TABLE images (
meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
post_id bigint(20) unsigned NOT NULL DEFAULT '0',
image longtext,
PRIMARY KEY (meta_id),
KEY post_id (post_id)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
INSERT INTO images (post_id, image) VALUES (2,'image1.jpg'),(2,'image2.jpg');
@camaleaun
camaleaun / upload.php
Last active June 28, 2019 16:15
Tests file upload in server
<?php
/**
* Uploads tests.
*/
if ( $_POST && isset( $_POST['upload'] ) && ! empty( $_FILES ) ) {
/** Define ABSPATH as this file's directory */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}
@camaleaun
camaleaun / formatting.php
Last active January 26, 2019 13:31
Formatting functions
/**
* Extract full name to first and last name.
*
* @version 1.0.1
* @link https://gist.github.com/camaleaun/a9ab8de21dd9830708f927b6db69c021
* @param string $name Full name.
* @param string $object Optional. If true return as OBJECT (with 'first' and 'last' as properties) (Default ARRAY_N).
* @return array|object First and last names.
*/
function pluginname_split_name( $name, $object = false ) {
@camaleaun
camaleaun / pluginname.php
Created November 20, 2018 13:32
Register commands to run through WP-CLI
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_hook( 'after_wp_load', 'pluginname_cli_runner' );
}
function pluginname_test() {
WP_CLI::success( 'Command works.' );
}
function pluginname_cli_runner() {
WP_CLI::add_command( 'pluginname test', 'pluginname_test' );
}
@camaleaun
camaleaun / genpwd
Last active November 10, 2018 19:59
Generate password like in wp
#!/bin/bash
rand() {
RANGE=$2
rand=$RANDOM
let "rand %= $RANGE"
}
generate_password() {
chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
@camaleaun
camaleaun / tab-trigger.js
Created September 13, 2018 14:58 — forked from wesbos/tab-trigger.js
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
@camaleaun
camaleaun / chat.html
Created July 31, 2018 18:23
Hsform hack to redirects to HypnoBx chat
<!--[if lte IE 8]>
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
portalId: "PORTAL_ID_HERE",
formId: "FORM_ID_HERE"
});
var chatData = {};
add_action( 'init', 'short_aliases' );
add_filter( 'short_aliases', 'shorts_redirect' ) );
function short_aliases() {
$aliases = apply_filters( 'short_aliases', array() );
if ( ! is_array( $aliases ) ) {
$aliases = array();
}
foreach ( $aliases as $alias => $redirects ) {
add_rewrite_rule( "^$alias/?", $redirects, 'top' );