Skip to content

Instantly share code, notes, and snippets.

View azanebrain's full-sized avatar
🤖
Jamming with the console cowboys in cyberspace

AJ Zane azanebrain

🤖
Jamming with the console cowboys in cyberspace
View GitHub Profile
@azanebrain
azanebrain / Create WordPress Users
Created June 29, 2013 23:16
Create WordPress Users with a function
//This would be good for setting up a stock dev environment. So instead of dumping in a DB, you would run an initializer with options
$users[0] = array(
'first_name' => 'Daniel',
'last_name' => 'Pataki',
'user_login' => 'danielpataki',
'user_pass' => 'mysupersecretpass',
'user_email' => 'mysupermail@mymail.com',
'display_name' => 'Daniel',
'description' => 'Guitar-wielding Web developer',
@azanebrain
azanebrain / disable-admin-bar
Created December 11, 2013 05:43
Don't allow subscribers to view the admin panels or the admin bar
/**
* Disable admin bar on the frontend of your website
* for subscribers.
*/
function themeblvd_disable_admin_bar() {
if( ! current_user_can('edit_posts') )
add_filter('show_admin_bar', '__return_false');
}
add_action( 'after_setup_theme', 'themeblvd_disable_admin_bar' );
@azanebrain
azanebrain / wp-plugin-add-template
Created January 8, 2014 03:23
Add template files to wordpress plugin
//Template fallback
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
global $wp;
$plugindir = dirname( __FILE__ );
//A Specific Custom Post Type
if ($wp->query_vars["post_type"] == 'product') {
$templatefilename = 'single-product.php';
@azanebrain
azanebrain / hover-sprite
Last active January 3, 2016 19:48
Hover sprite icon with css
.hoverSpriteVert,
.hoverSpriteHoriz
background-position: 0 0
.hoverSpriteHoriz:hover
background-position: 100% 0
.hoverSpriteVert:hover
background-position: 0 100%
@azanebrain
azanebrain / php-read-dir
Created January 19, 2014 20:18
A PHP snippet that reads the files of a folder and returns the filename as an array
<?php
//vvvvvvvvvv *INCLUDE_FUNCTIONS vvvvvvvvvv
/* phpReadDir v0.1
* This function gets the contents of a directory.
* It returns an array ($contentsArr) of strings for each item in the target directory
* $dir : The path of the directory to search in
* Attributes:
ignoreSystemFiles: Do not include system files in the array
Such as: ., .., DS_Store
num: How many entries to return. 0 will return all
@azanebrain
azanebrain / get-contents-of-dir
Created January 19, 2014 20:19
A PHP Function to get an array of files within a directory
/* getContentsofDir v0.1
* This function gets the contents of a directory.
* It returns an array ($contentsArr) of strings for each item in the target directory
* $dir : The path of the directory to search in
* Attributes:
ignoreSystemFiles: Do not include system files in the array
Such as: ., .., DS_Store
num: How many entries to return. 0 will return all
ignore: Ignore this file(s)
ignoreType: Ignore this file type(s)
@azanebrain
azanebrain / hide-wp-plugins
Created January 23, 2014 00:24
Hide plugins and settings panels from the WordPress admin panels to make sure certain users don't deactivate them, or change settings.
add_filter( 'all_plugins', 'hide_plugin_list' );
function hide_plugin_list( $plugins ) {
if ( is_admin() ) {
//Only run this if we're in the Admin panels
unset( $plugins[ 'advanced-custom-fields/acf.php'] );
//Admin only plugins
if ( ! current_user_can( 'administrator' ) ) {
unset( $plugins[ 'better-wp-security/better-wp-security.php'] );
@azanebrain
azanebrain / multisite-upload-path.php
Created January 27, 2014 20:20
Set a unique upload path for each site on a multisite network (MU Plugin)
<?php
add_filter('upload_dir', 'mu_media_upload_dir');
function mu_media_upload_dir($upload) {
$site_title=str_replace( ' ' , '_' , get_bloginfo('name','raw') );
$upload['path'] = ABSPATH . '/shared/' . $site_title;
switch_to_blog(1);
$upload['url'] = site_url() . '/shared/' . $site_title;
restore_current_blog();
$upload['subdir'] = "";
$upload['basedir'] = $upload['path'];
@azanebrain
azanebrain / change_user_lang.php
Last active July 15, 2016 15:59
Change the user language depending on the username. This example defaults to Japanese, unless you are me
<?php
/**
* Plugin Name: Change User Language
* Description: Change the language depending on the user
* Version: 0.1
* Author: AJ Zane
* Author URI: http://AJZane.com
* License: GPL2
*/
@azanebrain
azanebrain / terminal-bulkchangefiles
Created December 5, 2015 14:59
Bulk change the file extension of all files in a directory
for old in path/to/files/*.txt; do mv $old path/to/files/`basename $old .text`.md; done