Skip to content

Instantly share code, notes, and snippets.

View lenivene's full-sized avatar
🖖
Full-stack dev

Lenivene Bezerra lenivene

🖖
Full-stack dev
View GitHub Profile
@lenivene
lenivene / functions.php
Last active July 1, 2016 16:08
Escape json
<?php
function esc_json( $json ) {
/**
* @var string $safe_json replace escapers
* @var array escapers
* @var array replacements
*
*/
$safe_json = str_replace(
array( "\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c" ),
@lenivene
lenivene / functions.php
Last active July 12, 2016 09:15
Get platform and browser user WordPress
<?php
/**
* Example <html <?php html_class( 'no-js' ); ?>>
*/
function html_class( $class = '' ){
echo 'class="' . join( ' ', get_html_class( $class ) ) . '"';
}
function get_html_class( $class = '' ){
$useragent = $_SERVER['HTTP_USER_AGENT'];
$useragent = isset( $useragent ) ? $useragent : '';
@lenivene
lenivene / readme.md
Last active September 10, 2019 02:08
Get YouTube url ID

Example code

$link = "https://www.youtube.com/watch?v=sOnqjkJTMaA";
$youtube_ID = get_youtube_ID( $link );

echo $youtube_ID;
@lenivene
lenivene / functions.php
Created July 22, 2016 20:19
Upload image by url
<?php
function wp_upload_image_by_url( $url, $post_ID = 0 ) {
require_once( ABSPATH . 'wp-admin/includes/media.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
if ( '' == $post_id )
return new WP_Error( 'upload_image_by_url_failed', __( 'Invalid post ID' ) );
@lenivene
lenivene / functions.php
Last active August 14, 2016 16:30
List all user by date WordPress
<?php
/**
* Add user date register in column
*
* @author Lenivene Bezerra
* @return columns and filter orderby date user registered
*/
add_filter( 'manage_users_columns', 'column_user_registered' );
function column_user_registered( $columns ) {
$columns[ 'user_registered' ] = __( 'Date' );
@lenivene
lenivene / .htaccess
Created August 18, 2016 00:39
All Files "aspx" redirecting to file "html".
RewriteCond %{THE_REQUEST} \ /(.+)\.aspx
RewriteRule ^ /%1.html [L,R=301]
@lenivene
lenivene / jquery.fleetmenu.js
Last active December 19, 2016 19:41
Push Menu jQuery
/*!
* jQuery FleetMenu Plugin v1.0.0
* https://www.soufleet.com
*
* Copyright 2016, Lenivene Bezerra
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD (Register as an anonymous module)
@lenivene
lenivene / functions.php
Created February 5, 2017 10:59
First character uppercase
<?php
if( ! function_exists( 'mb_ucfirst' ) ){
function mb_ucfirst( $string = '', $encoding = "UTF-8" ){
if( empty( $string ) )
return false;
$strlen = mb_strlen( $string, $encoding );
$firstChar = mb_substr( $string, 0, 1, $encoding );
$end_Char = mb_substr( $string, 1, $strlen - 1, $encoding );
@lenivene
lenivene / functions.php
Created February 5, 2017 11:38
Encode 256 bytes and 10 bytes
<?php
function b256_to_b10_encode( $string, $encoding = "UTF-8" ) {
bcscale( 0 );
$result = "0";
for ($i = mb_strlen( $string, $encoding )-1; $i >= 0; $i--) {
$result = bcadd( $result, bcmul( ord( $string[$i] ), bcpow( 256, $i ) ) );
}
@lenivene
lenivene / functions.php
Created August 2, 2017 19:58
Using an array as needles in mb_strpos
<?php
if( ! function_exists( 'mb_strpos' ) ){
function mb_strpos( $haystack, $needles, $offset=0 ){
return strpos( $haystack, $needle, $offset );
}
}
function mb_strposa( $haystack, $needles = array(), $offset=0 ) {
$chr = array();
foreach( $needles as $needle ){