Skip to content

Instantly share code, notes, and snippets.

@smartdeal
smartdeal / yandex_map.js
Created June 29, 2018 16:12
[Lazy load and init Yandex Map] #YandexMap
/* Yandex Map
========================================================*/
var map_container = document.getElementById("map");
if (map_container) {
$(document).ready(function () {
get_map(map_container, map_contact);
});
}
function get_map(map_container, map_array){
@smartdeal
smartdeal / disable_hover_on_scroll.js
Created June 14, 2018 08:42
[Отключение ховера при прокрутке] #jQuery
var timer, // быстрая прокрутка, отключение ховера при прокрутке
classname = 'disable-hover',
$body = $('body');
$(window).scroll(function() {
clearTimeout(timer);
if (!$body.hasClass(classname)) {
$body.addClass(classname);
}
timer = setTimeout(function(){
@smartdeal
smartdeal / disable_hover_on_scroll.js
Created June 14, 2018 08:40
[Отключение ховера при прокрутке] #jQuery
var timer, // быстрая прокрутка, отключение ховера при прокрутке
classname = 'disable-hover',
$body = $('body');
$(window).scroll(function() {
clearTimeout(timer);
if (!$body.hasClass(classname)) {
$body.addClass(classname);
}
timer = setTimeout(function(){
@smartdeal
smartdeal / wp_send_notification.php
Last active June 13, 2018 13:08
[Отправка уведомлений при публикации поста] #WP #WP_functions
<?php
/**
* Отправка уведомлений при публикации поста
*/
function roomble_send_notification( $new_status, $old_status, $post ) {
if(
'publish' === $new_status &&
'publish' !== $old_status &&
'post' === $post->post_type
@smartdeal
smartdeal / git.cmd
Created June 13, 2018 12:35
[Перенести коммит в новую ветку из мастера] #GIT
# Вот дерьмо, git, я случайно закоммитил правки в мастер ветку вместо новой!
# Создаём новую ветку
git branch some-new-branch-name
# Удаляем коммит из мастер-ветки
git reset HEAD~ --hard
# Теперь ваш коммит живет в новой ветке
git checkout some-new-branch-name
@smartdeal
smartdeal / git.cmd
Created June 13, 2018 12:33
[Исправить последний коммит] #GIT
# Вот дерьмо, git, я закоммитил последние правки, но мне нужно там кое-что поменять!
# Вносим правку
git add . # или отдельный файл
git commit --amend
# Следуем подсказкам для изменения или сохранения последнего коммита
# Теперь ваш последний коммит содержит нужные вам правки
@smartdeal
smartdeal / git.cmd
Created June 13, 2018 12:32
[Машина времени] #GIT
# Смотрим список последних коммитов во всех ветках,
# каждый из которых имеет вид `index HEAD@{index}`.
# Выбираем первый коммит перед нашим косячным
git reflog
# Используем всю магию машины времени
git reset HEAD@{index}
@smartdeal
smartdeal / mihdan_shortcode.php
Last active June 13, 2018 13:08
[Способ подключения скриптов внутри шорткода] #WP #WP_functions
<?php
// Для начала зарегистрируйте ваш JavaScript-файл без подключения
function mihdan_wp_enqueue_scripts() {
wp_register_script( 'script-name', plugins_url( '/js/script.js' , __FILE__ ), array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'mihdan_wp_enqueue_scripts' );
/* *************** */
@smartdeal
smartdeal / disable_plugin_deactivation.php
Last active June 13, 2018 13:08
[Как запретить клиентам отключать важные плагины в WordPress] #WP #WP_functions
<?php
function mihdan_disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
// Удалить ссылку редактирования исходного кода
// для всех плагинов
if ( array_key_exists( 'edit', $actions ) ) {
unset( $actions[ 'edit' ] );
}
// Массив важных плагинов
@smartdeal
smartdeal / getFormData.js
Last active May 31, 2018 16:22
[Form data to array] Prepare form's data for send to server by AJAX #jQuery #Ajax
function getFormData($form){
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function(n, i){
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}