Skip to content

Instantly share code, notes, and snippets.

@infn8
infn8 / force-login.php
Created December 9, 2014 21:26
Wordpress Force Login
<?php
if (!is_user_logged_in()) {
wp_login_form();
wp_die('you need to login' );
}
?>
@infn8
infn8 / README.md
Last active August 29, 2015 14:13
WP Livereload trigger

Add these files to your theme and ensure that your grunt or gulp or whatever is watching the php files in your theme folder for changes and triggering live reload.

Ensure that yoursite.dev has the live reload script at http://yoursite.dev:35729/livereload.js which it likely will if you're using grunt watch right. If Not edit the livereload-loader.js file to point to the right place where the file is.

@infn8
infn8 / functions.smtp.php
Created February 25, 2015 18:36
Use Mandrill SMTP for WordPress wp_mail() function
<?php
/* Add this to your functions.php or plugin file */
add_action( 'phpmailer_init', 'configure_mandrill_smtp' );
function configure_mandrill_smtp( PHPMailer $phpmailer ){
$phpmailer->isSMTP(); //switch to smtp
$phpmailer->Host = 'smtp.mandrillapp.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->Username = 'MAILCHIMP_USER';
$phpmailer->Password = 'MAILCHIMP_API_KEY';
@infn8
infn8 / NewWordpress.sh
Last active July 1, 2020 22:30
Wp CLI New Wordpress Install
#!/bin/bash
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "--dbname" ]
then ((i++))
dbname=${!i};
elif [ ${!i} = "--dbuser" ];
then ((i++))
@infn8
infn8 / functions.php
Last active April 5, 2018 11:11
Wordpress Bootstrap Image Sizes
function add_theme_features() {
// Add Image Sizes
$containerLG = 1170; // Change this if you have updated the largest bootstrap container width.
for ($i=1; $i <= 12; $i++) {
add_image_size(
'col-lg-'.$i,
ceil($containerLG / 12 * $i),
ceil($containerLG / 12 * $i) * 10,
false
);

Sublime Text Snippets and Keyboard shortcuts for working with Bootstrap

To install:

  • Toss all .sublime-snippet files into /Packages/User/ in your sublime install
  • Optional
    • Copy the lines from sample.sublime-keymap into your user keymap More Info Here

Tab Triggers

@infn8
infn8 / functions.php
Created February 11, 2016 17:24
Add uStream oEmbed support to WordPress.
<?php
// Add this to your plugin file or to functions.php
function my_add_oembed_providers() {
wp_oembed_add_provider( '#http://(www\.)?ustream.tv/*#i', 'http://www.ustream.tv/oembed', true );
}
add_action( 'init', 'my_add_oembed_providers' );
?>
@infn8
infn8 / gist:be3edaa79aa40693983a
Created March 4, 2016 20:50
WP CLI add post from lorem ipsum API with author of first administrator.
curl "http://loripsum.net/api/5/medium/decorate/link/ul/ol/dl/bq/code/headers/" | sed "s/<\/p>/<\/p>\<\!\-\-more\-\-\>/" | wp post generate --post_content --count=1 --post_author=$(wp user list --role=administrator --field=ID --format=json | sed "s/\[//" | sed "s/\]//" | sed "s/\,.*//")
@infn8
infn8 / cascade_values.fn.php
Last active July 28, 2016 05:42
Cascade Values
<?php
function cascade_values(){
for ($i = 0; $i < func_num_args(); $i++) {
$val = func_get_arg($i);
if(!empty($val)){
return $val;
}
}
return false;
}
@infn8
infn8 / functions.php
Created December 8, 2016 19:57
Remove Paragraph Formating in Wordpress on a per post basis
<?php
// knock out default filter
remove_filter('the_content','wpautop');
// add NEW filter
add_filter('the_content','post_custom_formatting');
function post_custom_formatting($content){
global $post;
// to remove the wpautop add a meta field to the post called 'wpautop' equal to 'false'
$nope = trim(get_post_meta( $post->ID, 'wpautop', true )) === 'false';
if($nope){