Skip to content

Instantly share code, notes, and snippets.

View yllus's full-sized avatar

Sully Syed yllus

View GitHub Profile
// Disable WordPress's home page query (as much as we can).
function home_page_query_disable( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_home ) {
// Add a filter that effectively returns no results ever.
add_filter('posts_where', 'disable_query_filter');
}
}
return $query;

JavaScript:

nv.addGraph(function() {
  var chart = nv.models.pieChart()
      .x(function(d) { return d.label })
      .y(function(d) { return d.value })
      .color(['#d0212a', '#2f587f'])
      .showLabels(false)
      .donut(true)

.donutRatio(0.50)

@yllus
yllus / gist:38d55e30297ebe4f470d
Created July 10, 2014 21:44
Sportsnet.ca - Current Viafoura/Backplane code
<div class="viafoura">
<div class="vf-comments vf-widget" data-widget="comments"></div>
</div>
<script type="text/javascript">
var ViafouraSettings = {
Backplane: {
enable: true,
busName: "rogers-dev"
},
};
@yllus
yllus / gist:3009fda28a3644a77f41
Last active August 29, 2015 14:03
Sportsnet.ca - New Viafoura/Backplane code
<div class="viafoura">
<div class="vf-comments vf-widget" data-widget="comments"></div>
</div>
<script src="http://cdn.gigya.com/js/backplane2.js"></script>
<script>
Backplane(function(){
janrain.engage.signin.setBackplaneChannel(Backplane.getChannelID());
});
function getVideoContent() {
var metas = document.getElementsByTagName('meta');
for ( var i = 0; i < metas.length; i++ ) {
if ( metas[i].getAttribute("http-equiv") == 'Content-Language' ) {
return metas[i].getAttribute("content");
}
}
return '';
// Get term ID for the video category.
$video_category_term = get_term_by('slug', 'video-landing-page', 'video-categories');
$video_category_term_id = $video_category_term->term_id;
// Find the bc-video-strip post associated to that video category.
$strip_query = new WP_Query(
array(
'post_type' => 'bc-video-strip',
'tax_query' => array(
array(

SQL String Escaping

Here's an example of using grep to find all instances of the word "insert" (ignoring case):

ssyed@server:~$ cd /var/www/ 
ssyed@server:/var/www$ grep -Ri insert . 
... a whole bunch of results ...
./folder_button/jsinclude_server_com_ccare.php:$query = "INSERT INTO log VALUES(NULL, '$ip', '$hostname', '". $_SERVER['HTTP_REFERER'] ."', '". $data['queue_id'] ."', '". $data['status_id'] ."','". $_SERVER['HTTP_USER_AGENT'] ."');";	
... a whole bunch more results ...
@yllus
yllus / gist:9e179c589ff2179ab4c3
Created December 10, 2014 22:28
Permalink structure changing code
// Make the permalink structure for the Video post type match that of regular /YYYY/MM/DD/slug/ posts.
function bc_post_type_link( $url, $post ) {
if ( 'bc-video' == get_post_type( $post ) ) {
$url = home_url() . '/%year%/%monthnum%/%day%/%postname%/';
$post_date = strtotime( $post->post_date );
$url = str_replace(
array(
'%year%',
@yllus
yllus / gist:af420d24cbeab71aa4b7
Last active August 29, 2015 14:12
Adding an AJAX function/URL to WordPress (a three-step process)
// Put this function in your theme's functions.php (or even better, in an ajax.php file in the
// theme that is require'd in):
/* The function ajax_read_more() will be called when the following URL is requested
* from WordPress:
*
* http://www.yoursite.com/wp-admin/admin-ajax.php?action=read_more&limit=5
*/
function ajax_read_more() {
// Take in a few input parameters from $_GET or $_POST (depending on how you're passing the values) about
@yllus
yllus / gist:ebb21174e273efa4083a
Created January 19, 2015 19:30
Display a custom page template/view if a "rssa" GET parameter is placed in a post's URL
// If the query parameter is passed, use a different article template than the usual
// (this one has no header/footer).
function rssa_content_mobile_view() {
if ( isset( $_GET['rssa'] ) && is_singular() ) {
require '/some-path/article/view.article.mobile-view.php';
exit;
}
}
add_action( 'template_redirect', 'rssa_content_mobile_view' );