Skip to content

Instantly share code, notes, and snippets.

@un1ko85
un1ko85 / vklike.js
Created October 25, 2013 08:08
Как узнать количество lik'ов во ВКонтакте
VK.init({apiId:"...", onlyWidgets: false});
VK.Api.call('likes.getList', {type: "sitepage", owner_id: "...[apiId]",page_url:pageuri},
function(r) {
if(r.response && r.response.count) {
$.getJSON('...?rating=vk&ratingvalue=' + r.response.count);
}
});
@un1ko85
un1ko85 / new_gist_file.php
Created October 24, 2013 09:06
How can I de-register ALL styles all at once
function pm_remove_all_scripts() {
global $wp_scripts;
$wp_scripts->queue = array();
}
add_action('wp_print_scripts', 'pm_remove_all_scripts', 100);
function pm_remove_all_styles() {
global $wp_styles;
$wp_styles->queue = array();
}
add_action('wp_print_styles', 'pm_remove_all_styles', 100);
@un1ko85
un1ko85 / HTML Emails with wp_mail() .php
Created October 17, 2013 19:54
HTML Emails with wp_mail()
<?php
function mail_from() {
$emailaddress = 'contact@1stwebdesigner.com';
return $emailaddress;
}
function mail_from_name() {
$sendername = "1stWebDesigner.com - Dainis";
return $sendername;
}
@un1ko85
un1ko85 / new_gist_file.php
Created September 30, 2013 17:48
Showing subcategories on WordPress category pages
if (is_category()) {
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
echo "<h1>Subcategories</h1>";
echo "<ul>";
wp_list_categories('orderby=id&show_count=0&title_li=
&use_desc_for_title=1&child_of='.$this_category->cat_ID);
echo "</ul>";
}
}
@un1ko85
un1ko85 / new_gist_file.php
Created September 30, 2013 17:43
Get categories ordered by meta key on WordPress
get_categories('child_of=92&hide_empty=false&orderby=meta_value&meta_key=date&order=ASC');
//-----------------------------------------------------------------------
function category_custom_field_get_terms_orderby( $orderby, $args ){
if($args['orderby'] == 'category_custom_field' && isset($args['category_custom_field']))
return 'cv.field_value';
return $orderby;
}
function category_custom_field_get_terms_fields( $selects, $args ){
@un1ko85
un1ko85 / new_gist_file.php
Created September 17, 2013 16:29
force get_option to go back to the DB instead of cache
$GLOBALS['wp_object_cache']->delete( 'your_option_name', 'options' );
$value = get_option( 'your_option_name' );
@un1ko85
un1ko85 / new_gist_file.php
Created September 11, 2013 12:08
delete session file
<?php
session_start(); // start the current/old session (loads the $_SESSION variables)
$base_name = '/sess_'; // the base name for the session data files
$old_sessionid = session_id(); // get the current/old id
$_SESSION['test'] = 123; // some test data
session_regenerate_id(); // generate a new id and a new data file
$new_sessionid = session_id(); // get the new session id to store in the user table for the current visitor
@un1ko85
un1ko85 / new_gist_file.sh
Created August 26, 2013 08:05
Nginx WP AntiBrute + PHP CGI
location ~* /(wp-login\.php|administrator|admin\.php) {
set $humantest 0;
if ($http_cookie !~* "humans=fucking_love_cookies") {
set $humantest 1;
}
if ($args ~* (callback|logout|lostpassword)) {
set $humantest 0;
}
if ($humantest = 1) {
add_header Content-Type text/html;
@un1ko85
un1ko85 / get_posts_cached.php
Created July 4, 2013 11:27
Wrapper around get_posts that utilizes object caching
/**
* Wrapper around get_posts that utilizes object caching
*
* @access public
* @param mixed $args (default: NUL)
* @param bool $force_refresh (default: false)
* @return void
*/
function get_posts_cached( $args = NULL, $force_refresh = false ) {
$cache_incrementor = wp_cache_get( 'get_posts_cached', 'cache_incrementors' );
@un1ko85
un1ko85 / new_gist_file.sh
Created May 10, 2013 07:18
Starting and stopping NginX / MySQL / PHP-FPM on Mac OS X
#! /bin/bash
MYSQL="/opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper"
NGINX="/opt/local/sbin/nginx"
PHPFPM="/opt/local/sbin/php-fpm"
PIDPATH="/opt/local/var/run"
MEMCACHED="/opt/local/bin/memcached -m 24 -P /opt/local/var/run/memcached.pid -u root"
if [ $1 = "start" ]; then
sudo $MYSQL start
echo "Starting php-fpm ..."