Skip to content

Instantly share code, notes, and snippets.

@leurdo
leurdo / img-link-tooltip.js
Last active July 17, 2023 22:09
Gutenberg Rich Editor button for tooltip
@leurdo
leurdo / gist:bfbcac57ee963f3874268421b509409c
Created October 17, 2022 15:53
gutenberg: make srset from media object
import { get } from 'lodash';
import { select, useSelect } from '@wordpress/data';
const image = useSelect( () => select( 'core' ).getMedia( id ) );
const thumbnail = get( image, [ 'media_details', 'sizes', 'medium', 'source_url' ] );
@leurdo
leurdo / gist:65c51612e73129191ae88d637b738d34
Created December 10, 2020 07:22
Get taxonomy by term and keep it in transient
public function get_tax_by_term($use_var) {
if ( ! $this->all_terms ) {
$this->all_terms = get_transient('all_terms_' . $this->post_type );
if ( ! $this->all_terms ) {
$taxonomy_names = get_object_taxonomies( $this->post_type );
$this->all_terms = [];
foreach ( $taxonomy_names as $taxonomy_name ) {
$terms = get_terms( [
'taxonomy' => $taxonomy_name,
# Do not edit this file
# It will be overwritten each time nginx-rc upgrade
# Editing this file manually might break RunCloud System
# If you think there is a bug, contact us at bug@runcloud.io
worker_processes auto;
worker_rlimit_nofile 65535;
user runcloud-www runcloud-www;
pid /run/nginx-rc.pid;
pcre_jit on;
@leurdo
leurdo / gist:1ac870c84f51124e08cf54686630405d
Created May 15, 2019 11:01
/etc/nginx-rc/rocket-nginx/default.conf
###################################################################################################
# Rocket-Nginx
#
# Rocket-Nginx is a NGINX configuration to speedup your WordPress
# website with the cache plugin WP-Rocket (http://wp-rocket.me)
#
# Author: Maxime Jobin
# URL: https://github.com/maximejobin/rocket-nginx
#
# Tested with WP-Rocket version: 3.0.5.1
@leurdo
leurdo / gist:c81f10472cfdd403cf608068b0f054d7
Last active September 9, 2018 14:03
wiki post type and taxonomy registration, gives permalink structure http://site.ru/wiki/category/subcategory/post
<?php
// don't load directly
if (!defined('ABSPATH')) die('-1');
class CreditznatokAddwiki
{
private static $_instance;
static function getInstance()
function move_term_to_top( $orderby, $query_vars, $taxonomies ) {
if ( 'my_taxonomy' === reset( $taxonomies ) ) {
$orderby = "(CASE WHEN t.name = 'My Top Term' THEN 1 ELSE t.name END)";
}
return $orderby;
}
add_filter( 'get_terms_orderby', 'move_term_to_top', 10, 3 );
@leurdo
leurdo / gist:92e89a3247b2cdf06f5e80e8af6eea7e
Created February 27, 2017 08:03
Как разрешить загрузку svg в вордпресс 4.7.1
/**
*
* SVG upload fix for wp 4.7.1
*
* @link https://wordpress.org/support/topic/wp-4-7-1-kills-svg/page/4/
*
*/
add_filter('wp_check_filetype_and_ext', 'ignore_upload_ext', 10, 4);
function ignore_upload_ext($checked, $file, $filename, $mimes)
{
@leurdo
leurdo / gist:09dcb8488019cd57e4aa91eafd234c24
Created January 15, 2017 11:41
SVG fix for WP 4.7.1+
add_filter('wp_check_filetype_and_ext', 'ignore_upload_ext', 10, 4);
function ignore_upload_ext($checked, $file, $filename, $mimes){
//we only need to worry if WP failed the first pass
if(!$checked['type']){
//rebuild the type info
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
$proper_filename = $filename;
@leurdo
leurdo / gist:9ac640e275a22ab0f9f8738704cc3727
Created August 11, 2016 16:56
Задание на подготовку к курсу PHP
<!DOCTYPE html>
<html lang="ru-RU">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width">
<title>Вводное ДЗ по курсу PHP</title>
</head>
<body>
<?php