Skip to content

Instantly share code, notes, and snippets.

View wp-live's full-sized avatar

Wp Live wp-live

View GitHub Profile
<?php
function rgbc_slugify( $text ) {
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
<?php
add_action( 'wp_default_scripts', 'zl_remove_jquery_migrate' );
function zl_remove_jquery_migrate( $scripts ) {
if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
$script = $scripts->registered['jquery'];
if ( $script->deps ) {
$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
}
<?php
// Remove bookmakers from post type
add_filter( 'post_type_link', 'rgbc_remove_slug', 10, 2 );
function rgbc_remove_slug( $post_link, $post ) {
global $post;
if ( 'brand' !== $post->post_type || 'publish' !== $post->post_status ) {
return $post_link;
}
<?php
add_action( 'init', function(){
add_rewrite_rule( '^(users)/([^/]*)/?', 'index.php?page_name=$matches[1]&page_type=$matches[2]&user_id=$matches[3]', 'top' );
} );
function prefix_register_query_var( $vars ) {
$vars[] = 'page_type';
$vars[] = 'user_id';
$vars[] = 'page_name';
<?php
function format_bytes( $bytes, $precision = 2 ) {
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$bytes = max( $bytes, 0 );
$pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
$pow = min( $pow, count( $units ) - 1 );
$bytes /= pow( 1024, $pow );
<html>
<head>
<title>HTML RATING</title>
<style>
.rating {
display: inline-flex;
flex-direction: row-reverse;
}
/* Hiding elements in an accessible way */
const randomPerson = () => {
let randomNumber = Math.floor( Math.random() * people.length )
return randomNumber
}
class Select {
constructor(selector, options) {
this.$el = document.querySelector(selector)
this.options = options
this.selectedId = null
this.setup()
}
setup() {
this.clickHandler = this.clickHandler.bind(this)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#select * {
function urlGenerator(domain) {
return function(url){
return `https://${url}.${domain}`
}
}
const comUrl = urlGenerator('com')
const ruUrl = urlGenerator('ru')
console.log(comUrl('google'))