Skip to content

Instantly share code, notes, and snippets.

View mihdan's full-sized avatar
:octocat:
Code is poetry

Mikhail Kobzarev mihdan

:octocat:
Code is poetry
View GitHub Profile
@lilumi
lilumi / hooks.php
Created April 8, 2023 14:42
Disable WPML String Translations for Gutenberg Blocks
<?php
/*
WPML checks for gutenberg like this:
\WPML_Page_Builders_Defined->has()
```
if ( 'gutenberg' === $page_builder ) {
if ( version_compare( $wp_version, '5.0-beta1', '>=' ) ) {
return true;
}
}
@Dreamer0x01
Dreamer0x01 / composer_beget.txt
Last active November 27, 2023 17:11
Команды composer на хостинге beget
На некторых хостингах, в том числе хостинге beget, требуется явно указывать версию php для композера, так как версия php в консоли часто отличается от версии, заданной в контрольной панели для сайта.
(Текущую версию php для консоли можно узнать командой php -v)
Например, для версии 7.4 команда будет такая:
composer-php7.4 install
Для других версий php алиасы соответствующих версий будут такими:
composer-php5.3
composer-php5.4
composer-php5.5
composer-php5.6
@amurrell
amurrell / custom-post-hierarchy.php
Last active May 5, 2024 04:52
Allow wordpress posts to have hierarchy - figures out slugs
<?php
add_action('registered_post_type', 'make_posts_hierarchical', 99, 2);
/**
* Ensure posts post type is hierarchal and allows page attributes
*
* Initial Setup - Runs after each post type is registered
*/
function make_posts_hierarchical($post_type, $pto)
@kagg-design
kagg-design / uasort
Created November 12, 2021 18:25
uasort example
<?php
$arr = [
[ 'foo' => 1, 'bar' => 7, 'den' => 9 ],
[ 'foo' => 11, 'bar' => 4, 'den' => 0 ],
[ 'foo' => 1, 'bar' => 12, 'den' => 6 ],
[ 'foo' => 1, 'bar' => 10, 'den' => 6 ],
];
uasort( $arr, 'cmp' );
@kagg-design
kagg-design / fix-authors-bug-5.7.php
Created March 22, 2021 08:28
MU-Plugin to temporary fix the problem with the list of authors on post edit page with Block Editor.
<?php
/**
* MU-Plugin to temporary fix the problem with the list of authors on post edit page with Block Editor.
* With WP 5.7, user with the Editor role is unable to search across long list of authors in Author combobox.
*
* @package kagg-design
*/
/**
* Fixes bug in WP 5.7 with author selection on post edit in admin.
@jchristopher
jchristopher / searchwp-customizations.php
Created March 2, 2021 13:11
Limit SearchWP results to Category that has 'foobar' slug
<?php
// Limit SearchWP results to Category that has 'foobar' slug.
$search = new \SWP_Query( [
's' => 'coffee', // Search string.
'tax_query' => [ [
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'foobar',
] ],
@wppunk
wppunk / elementor-default-editor.php
Created February 27, 2021 16:25
Make the Elementor as default editor
<?php
/**
* Make the Elementor as default editor.
*
* @since 1.0.0
* @author wppunk
* @link https://github.com/wppunk/
*/
namespace wppunk\Elementor;
@cliffordp
cliffordp / local-lightning-xdebug-phpstorm.md
Last active November 6, 2020 09:36
Local (Lightning) Xdebug setup with PhpStorm

1) Local Lightning

Local Lightning works differently than the previous version of Local. This guide is for Lightning.

Install and activate the "Xdebug + PhpStorm" Local add-on. You'll need to restart Local app to complete installation.

Whenever a new site is added click its "Utilities" tab, then click "Add Run Configuration to PhpStorm" to insert "Local" with your site's URL as a "PHP Web Page > Server" in the Configurations, then specify its root location via Path Mappings.

2 min video walk-through (requires the following to be completed already... so continue below before trying to trigger an Xdebug breakpoint...)

<?php
add_filter(
'render_block',
function ( $block_content, $block ) {
if ( 'core/image' === $block['blockName'] ) {
$block_content = str_replace(
array( '<figure ', '</figure>' ),
array( '<p ', '</p>' ),
$block_content
);
@seojacky
seojacky / alt.php
Last active July 28, 2020 08:24
Дописывание автоматически alt
/* Делаем alt для Превью поста
* Функция автозаполнения alt должна быть отключена в плагинах типа
* Webcraftic Clearfy или любом другом, который устанавливает alt автоматически, так как там всегда генерирует на основе заголовка
* В некоторых темах, например OceanWP alt прописан как заголовок статьи в самой теме, и там нужно дополнительно кодить
* в Astra всё нормально работает
*/
add_filter( 'wp_get_attachment_image_attributes', 'add_best_alt_attachment_image', 90, 2 );
function add_best_alt_attachment_image( $attr, $attachment ) {
//проверяем не заполнен ли уже alt