Skip to content

Instantly share code, notes, and snippets.

View joje47's full-sized avatar

George Bredberg joje47

View GitHub Profile
@joje47
joje47 / gist:98e11567db9780d64bf76c8106f3feab
Created October 5, 2017 07:18 — forked from gcatlin/gist:1847248
Install specific version of Homebrew formula
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
@joje47
joje47 / osx_install.sh
Created August 16, 2017 16:47 — forked from t-io/osx_install.sh
Install most of my Apps with homebrew & cask
#!/bin/sh
echo Install all AppStore Apps at first!
# no solution to automate AppStore installs
read -p "Press any key to continue... " -n1 -s
echo '\n'
echo Install and Set San Francisco as System Font
ruby -e "$(curl -fsSL https://raw.github.com/wellsriley/YosemiteSanFranciscoFont/master/install)"
echo Install Homebrew, Postgres, wget and cask
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@joje47
joje47 / lock-your-self-out.php
Created September 27, 2016 04:14
Show how you get locked out when using current_user_can in a plugin that get's network activated.
<?php
/*
* Plugin Name: Lock your self out
* Plugin URI: https://ngo-portal.org
* Description: Show how you get locked out when using current_user_can in a plugin that get's network activated.
* Just put this file in your plugins folder and go to plugins, network activate it, and you will get locked out.
* To get back in use ftp and rename this file (I use to add _ after filename like so lock-your-self-out.php_
* Reload your browser. Now your back in.
* Version: 0.0.1
* Author: George Bredberg
@joje47
joje47 / show_widgets.php
Last active July 24, 2016 07:43
Shows registered widgets in wordpress, so it's easier to get their names, and remove them at will.
add_action( 'wp_footer', function() // works best, but does not show up if the footer is removed..
// add_action( 'admin_menu', function() // Hides a bit, but copy and past to textfile to read
{
if ( empty ( $GLOBALS['wp_widget_factory'] ) )
return;
$widgets = array_keys( $GLOBALS['wp_widget_factory']->widgets );
print '<pre>$widgets = ' . esc_html( var_export( $widgets, TRUE ) ) . '</pre>';
});
@joje47
joje47 / activate_plugin_with_theme.php
Last active July 24, 2016 07:56
Snippet to activate a plugin that is required for a theme, and deactivate it when theme is deactivated.
<?php
// Wally-theme is dependant on wally-plugin, but we don't want site-admins to touch plugins, so we do this programatically.
// Enable Wally plugin when theme is activated
function ngo_activate_wally_plugin() {
//Get wally-plugin pathinfo
$wally_plugin = WP_PLUGIN_DIR . '/wally-plugin/index.php';
activate_plugins ( $wally_plugin, $redirect = '', false, true );
}
add_action( "after_switch_theme", "ngo_activate_wally_plugin" );
// Check if mother-plugins are installed and activated
// If not, deactivate this plugin and print an error message.
add_action( 'admin_init', 'child_plugin_has_parent_plugin' );
function child_plugin_has_parent_plugin() {
$req_plugins = array( 'multi-site-site-list-shortcode/multi-site-site-list-shortcode.php', 'link-manager/link-manager.php' );
foreach ($req_plugins as $req_plugin) {
if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( $req_plugin ) ) {
add_action( 'admin_notices', 'child_plugin_notice' );
deactivate_plugins( plugin_basename( __FILE__ ) );
@joje47
joje47 / check_mother_plugin.php
Created July 17, 2016 11:10
Gist that shows how to check for a "mother"-plugin being installed and activated. Script automatically disables plugin if mother-plugin gets disabled, or uninstalled. Could use array to check for several plugins, if your ad on is depending on more then one plugin being installed.
<?php
// Check if mother-plugin is installed and activated
// If not, deactivate this plugin and print an error message.
add_action( 'admin_init', 'eongo_plugin_has_parent_plugin' );
function eongo_plugin_has_parent_plugin() {
$req_plugin = 'event-organiser/event-organiser.php';
if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( $req_plugin ) ) {
add_action( 'admin_notices', 'eongo_plugin_notice' );
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( isset( $_GET['activate'] ) ) {
@joje47
joje47 / wp-config-debug.php
Last active July 16, 2016 07:52 — forked from jrfnl/wp-config-debug.php
Code to add to wp-config.php to enhance information available for debugging.
<?php
/**
* == About this Gist ==
* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* // This is a gist, copied here for convenience, but please see source down for the maintainer and give the credit to them. //
* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*
* 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