Skip to content

Instantly share code, notes, and snippets.

View al5dy's full-sized avatar

Anton Lokotkov al5dy

View GitHub Profile
@al5dy
al5dy / settings.php
Created March 19, 2016 07:25
Add custom [_admin_mail] shortcode to CF7
if ( ! function_exists( 'add_cf7_shortcode' ) ) {
add_filter('wpcf7_special_mail_tags', 'add_cf7_shortcode', 20, 3);
function add_cf7_shortcode($output, $name, $html) {
$name = preg_replace('/^wpcf7\./', '_', $name);
if ('_admin_mail' == $name) {
if ( function_exists('get_option_tree') ) {
$email = ot_get_option('email'); // get OT value
$output = $email;
@al5dy
al5dy / acf.php
Created March 31, 2016 07:16
Кнопка "Добавить все" на определенном CPT в ACF Relationship
function acf_add_button( $field ) {
$screen = get_current_screen();
if( $screen->post_type === 'product' ) {
echo '<div class="acf-relationship-header"><a href="#" id="acf-add-all" class="button" title="">Добавить все</a></div>';
}
}
add_action('acf/render_field/type=relationship', 'acf_add_button', 10, 1);
@al5dy
al5dy / woocommerce.php
Created March 31, 2016 19:33
Метабокс цены для CPT, который позволяет добавить любую запись из CPT в WC корзину.
function gift_register_meta_box() {
add_meta_box(
'mdf_gift_meta_box',
__( 'Цена', 'tochkawp' ),
'mdf_gift_meta_box_handler',
'gift',
'normal',
'high'
);
}
@al5dy
al5dy / woocommerce.php
Last active April 5, 2016 09:12
Проверка и преобразование/создание вариативного товара в WooCommerce.
if ( ! function_exists( 'create_gift_variation' ) ) {
function create_gift_variation( $product_id, $price ) {
$product_variation = get_posts(
array(
'post_parent' => $product_id,
'post_title' => 'wfg_gift_product',
'post_type' => 'product_variation',
'posts_per_page' => 1
)
);
@al5dy
al5dy / app.scss
Created May 7, 2016 09:39
Убираем скачки fixed блоков в Chrome при использовании css scale
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
@al5dy
al5dy / app.scss
Created May 7, 2016 09:41
Сглаживаем шрифты и обнуляем hover tap для Android устройств.
html {
sx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
@al5dy
al5dy / single-project-settings.php
Last active July 2, 2016 10:43
Получаем массив мета поля и удаляем значение под индексом "1" и далее выводим новый массив с обновленными ключами.
$list_of_values = get_post_meta($post->ID, $this->meta . 'custom_field', true );
if (! empty ( $list_of_values )) {
unset($list_of_values[1]);
}
var_dump(array_combine(range(1, count($list_of_values)), array_values($list_of_values)));
@al5dy
al5dy / woocommerce.php
Last active July 7, 2016 07:47
Получить ID из любого YouTube видео URL (PHP)
function get_youtube_id( $url = '' ) {
$url = preg_replace('~https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/| youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*>| </a>))[?=&+%\w.-]*~ix', '$1', $url);
return $url;
}
@al5dy
al5dy / custom.js
Created July 8, 2016 08:59
"Размазываем" фоновое видео в зависимости от соотношения сторон
vimeoSettings : function () {
var wa = 16, // Соотношение сторон
ha = 9, // Соотношение сторон
$videoBlock = $('.vimeo-video'), // Блок внутри которого лежит iframe
od = $videoBlock.width()/$videoBlock.height(),
vd = wa/ha,
nvh = (od/vd)*100,
nvw = (vd/od)*100;
if (od>vd)
@al5dy
al5dy / functions.php
Created July 14, 2016 19:07
Yoast SEO - убираем теги <image:image> для Yandex
function yoast_clear_sitemap( $output, $url ) {
$timezone = new WPSEO_Sitemap_Timezone();
$date = null;
if ( ! empty( $url['mod'] ) ) {
$date = $timezone->format_date( $url['mod'] );
}