Skip to content

Instantly share code, notes, and snippets.

View ihorvorotnov's full-sized avatar
🇺🇦
Working remotely since 1999

Ihor Vorotnov ihorvorotnov

🇺🇦
Working remotely since 1999
View GitHub Profile
@ihorvorotnov
ihorvorotnov / wp-show-rss
Created February 21, 2014 11:24
Display RSS feeds on your WordPress site
include_once(ABSPATH . WPINC . '/rss.php');
// Feed URL
$feed = 'http://example.com/feed/';
$rss = fetch_feed($feed);
if (!is_wp_error( $rss ) ) :
// Number of maximum items to get
$maxitems = $rss->get_item_quantity(3);
$rss_items = $rss->get_items(0, $maxitems);
@ihorvorotnov
ihorvorotnov / wp-custom-query-cache
Created February 21, 2014 11:28
WordPress: caching custom queries
// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$special_query_results = new WP_Query( '_YOUR_QUERY_ARGS_HERE_' );
set_transient( 'special_query_results', $special_query_results );
}
// Use the data like you would have normally...
@ihorvorotnov
ihorvorotnov / wp-twitter-followers-transient
Last active August 29, 2015 13:56
WordPress - Twitter followers and Facebook fans count with transients
/**
* Other transients stuff here http://www.catswhocode.com/blog/wordpress-transients-api-practical-examples
*/
function my_followers_count($screen_name = 'kovshenin'){
$key = 'my_followers_count_' . $screen_name;
// Let's see if we have a cached version
$followers_count = get_transient($key);
if ($followers_count !== false)
@ihorvorotnov
ihorvorotnov / wp-reposive-video
Created March 7, 2014 17:04
WordPress Resposive Videos (oEmbed + iframe/embed)
1. Add this to your functions.php or inc/templates-tags.php
/**
* Wrap videos embedded via oEmbed to make them responsive
*/
function p2_wrap_oembed( $html, $url, $attr, $post_id ) {
return '<div class="video-embed">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'p2_wrap_oembed', 99, 4 );

SSL certificates aren't cheap. You can create them on your own for private use. However for internet use you have to get a verified certificate.

Luckily there's https://www.startssl.com/

They offer you a class 1 SSL certificate for free. Their site might not look trustworthy, but I quite shure the'll do a greate job.

@ihorvorotnov
ihorvorotnov / gist:a306ceb7a4bbf64abb3a
Last active August 29, 2015 14:03
Custom pages without WordPress theme
/**
* This is one of the few WordPress constants that truly opens up a wide variety of possibilities for any developer.
* What it does is relatively simple, though: it tells WordPress whether or not to load the theme you’re using, which
* allows you to use all WordPress’s functionality for something that doesn’t look like WordPress at all!
* For example, you can create a file named index_non_wp.php and put this snippet in:
*/
// The next line is commented out to tell WP to not load theme
//define('WP_USE_THEMES', true);
@ihorvorotnov
ihorvorotnov / README.md
Last active August 29, 2015 14:07 — forked from oodavid/README.md
Deploy your site with git

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@ihorvorotnov
ihorvorotnov / my-plugin.php
Created October 15, 2014 04:45
Basic WordPress plugin, non-OOP
<?php
/**
* Plugin Name: My Custom Post Types
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: 1.0.0
* Author: My Name
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/
<?php
/*
Usage:
$frag = new CWS_Fragment_Cache( 'unique-key', 3600 ); // Second param is TTL
if ( !$frag->output() ) { // NOTE, testing for a return of false
functions_that_do_stuff_live();
these_should_echo();
// IMPORTANT
$frag->store();
// YOU CANNOT FORGET THIS. If you do, the site will break.
<?php
/*
Usage:
cache_fragment_output( 'unique-key', 3600, function () {
functions_that_do_stuff_live();
these_should_echo();
});
*/
function cache_fragment_output( $key, $ttl, $function ) {