Skip to content

Instantly share code, notes, and snippets.

Avatar

Kovalenko Anton kovalenko-anton

  • Ukraine, Kharkiv
View GitHub Profile
View getNested.js
function getNested(obj, deepKey, delimiter = '.') {
let args = deepKey.split(delimiter);
for (let i = 0; i < args.length; i++) {
if (!obj || !obj.hasOwnProperty(args[i])) {
return undefined;
}
obj = obj[args[i]];
}
return obj;
View checkNested.js
function checkNested(obj /*, level1, level2, ... levelN*/) {
var args = Array.prototype.slice.call(arguments, 1);
for (var i = 0; i < args.length; i++) {
if (!obj || !obj.hasOwnProperty(args[i])) {
return false;
}
obj = obj[args[i]];
}
return true;
View Simple accordion
$('li.menu-item-has-children').click( function(){
subMenu = $('ul', this);
if( subMenu.is(":visible") )
{
subMenu.slideUp();
}
else
{
View add custom fields to comment
/**
* Add our field to the comment form
*/
add_action( 'comment_form_logged_in_after', 'pmg_comment_tut_fields' );
add_action( 'comment_form_after_fields', 'pmg_comment_tut_fields' );
function pmg_comment_tut_fields()
{
?>
<p class="comment-form-title">
<label for="pmg_comment_title"><?php _e( 'Title' ); ?></label>
View post duplicate link
<?php
/*
* Function creates post duplicate as a draft and redirects then to the edit post screen
*/
function rd_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
View склонение количества комментариев
<?php // склонение количества комментариев
function plural_form( $number, $after) {
$cases = array (2, 0, 1, 1, 1, 2);
echo $number.' '.$after[ ($number%100>4 && $number%100<20) ? 2: $cases[min($number%10, 5)] ];
}
?>
View create page in admin area Wordpress
add_action( 'admin_menu', function(){
add_menu_page( 'Empty Page', // The text to be displayed in the title tags of the page when the menu is selected.
'New Page', // The text to be used for the menu.
'manage_options', // The capability required for this menu to be displayed to the user.
'site-options', // The slug name to refer to this menu by (should be unique for this menu).
'add_my_setting', // The function to be called to output the content for this page.
'', // The URL to the icon to be used for this menu.
4 ); // The position in the menu order this one should appear.