Skip to content

Instantly share code, notes, and snippets.

@iandunn
iandunn / programmatic_login.php
Last active March 7, 2023 18:18
Programmatically log in a WordPress user
/**
* Programmatically logs a user in
*
* @param string $username
* @return bool True if the login was successful; false if it wasn't
*/
function programmatic_login( $username ) {
if ( is_user_logged_in() ) {
wp_logout();
@stefthoen
stefthoen / Gruntfile.js
Last active December 31, 2015 05:39
Gruntfile.js for Paprika Patterns.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner:
'/*! <%= pkg.name %>.js v<%= pkg.version %>\n' +
' * http://<%= pkg.name %>.com/\n' +
' *\n' +
' * <%= pkg.description %>\n' +
@nternetinspired
nternetinspired / gist:7482445
Last active February 24, 2022 17:20
Load Disqus comments only on demand if you give a shit about page weight and your visitors. Even with no comments, i.e. an empty comment form, calling Disqus will load an extra 226Kb. If your page has comments this can be far higher. This Gist accompanies my blog post: http://internet-inspired.com/wrote/load-disqus-on-demand/
// Requires jQuery of course.
$(document).ready(function() {
$('.show-comments').on('click', function(){
var disqus_shortname = 'YOUR-DISQUS-USERNAME'; // Replace this value with *your* username.
// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
@lulalala
lulalala / banner.rb
Last active January 14, 2019 12:58 — forked from matheusvetor/banner.rb
Carrierwave image model validation on image dimensions/height/width.
class Banner < ActiveRecord::Base
attr_accessor :image_width, :image_height
mount_uploader :image, ImageUploader
validate :check_dimensions, :on => :create
def check_dimensions
if !image_cache.nil? && (image.width < 300 || image.height < 300)
errors.add :image, "Dimension too small."
end
end
@jrfnl
jrfnl / wp-config-debug.php
Last active April 5, 2024 18:16
Code to add to wp-config.php to enhance information available for debugging.
<?php
/**
* == About this Gist ==
*
* Code to add to wp-config.php to enhance information available for debugging.
*
* You would typically add this code below the database, language and salt settings
*
* Oh.. and *do* make sure you change the path to the log file to a proper file path on your server (make sure it exists).
*
@gaby-mg
gaby-mg / basic_install.sh
Last active February 19, 2016 16:57
WP: Basic Install Sript with wp-cli
#!/bin/bash
# Usage: basic-install [OPTIONS] file
#
# Index:
#
# 0.- Initial Setup and Functions
# 1.- Set your server correctly
# 2.- Install latest WordPress version
# 3.- Set up anti-spam and security measures
@Savjee
Savjee / s3-to-AWStat.sh
Created January 20, 2013 18:27
s3-to-AWStat is a bash script that downloads Amazon S3 access logs and makes them ready for AWStat.
#!/bin/bash
# s3-to-AWStat
# Copyright 2013 Xavier Decuyper
# http://www.savjee.be
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@rutger1140
rutger1140 / gist:4546397
Last active July 4, 2016 17:40
Run 2 copies of WordPress from the same database. Put this in your wp-config.php file above the line require_once(ABSPATH . 'wp-settings.php');
<?php
/** Run 2 copies of WordPress from the same Database
*
* source: http://codex.wordpress.org/Running_a_Development_Copy_of_WordPress#Run_2_Copies_of_WordPress_from_the_same_Database
*/
function WP_LOCATION () {
$script_path = realpath(dirname($_SERVER['SCRIPT_FILENAME']));
$wp_base_path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR);
$web_subfolder = substr( $script_path, strlen($wp_base_path));
$wp_path = $web_subfolder ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($web_subfolder) ) : dirname($_SERVER['SCRIPT_NAME']) ;
@reinier
reinier / backup-webapps
Created November 28, 2012 09:56
Tar remote dir and rsync it to backup dir
alias backup-webapps="ssh -t user@domain 'tar zcvf webapps.tar.gz webapps' && mkdir ~/Documents/Backups/webapps-`date +%Y%m%d` && rsync -avz user@domain:/home/user/webapps.tar.gz ~/Documents/Backups/webapps-`date +%Y%m%d`"
@cabans
cabans / fix_paged_homepage.php
Created September 27, 2012 09:34
Wordpress: Fix for loop pagination with Custom Post Type in homepage
<?php
//Fix homepage pagination
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}