Skip to content

Instantly share code, notes, and snippets.

@brasofilo
brasofilo / download.php
Created June 3, 2012 12:55
Force File Download with PHP
<?php
/*
* Foce File Download
* Usage: http://example.com/download.php?file=./uploads/image.jpg
*
* There are a couple of *ninja* exit() as security guarantee, adapt as necessary
*
*/
// grab the requested file's name
@brasofilo
brasofilo / gist:3302470
Created August 9, 2012 08:56
5G Blacklist 2012 - Adapted to work with WordPress
# 5G BLACKLIST/FIREWALL
# @ http://perishablepress.com/5g-blacklist/
# 5G:[QUERY STRINGS]
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (localhost|mosconfig|scanner) [NC,OR]
# RewriteCond %{QUERY_STRING} (environ|localhost|mosconfig|scanner) [NC,OR]
# too many pieces of legitimate content with the word "environment" in the URL
@brasofilo
brasofilo / wpse_70758.php
Created November 19, 2012 14:08
WordPress plugin : Prevent Categories Deletion
<?php
/*
Plugin Name: Prevent Category Deletion
Plugin URI: http://wordpress.stackexchange.com/q/70758/12615
Description: Prevent deletion of categories. Modify the $undeletable array to suit your setup. Use Category SLUGS.
Author: brasofilo
Version: 1.0
Author URI: http://wordpress.stackexchange.com/users/12615/brasofilo
*/
@brasofilo
brasofilo / authorized-acf-access.php
Created December 8, 2012 18:53
Hide ACF Menu from Clients
/**
* A method to really block access to ACF menu
* http://www.advancedcustomfields.com/docs/tutorials/hide-acf-menu-from-clients/
*/
/**
* Remove ACF menu item from the admin menu
*/
add_action( 'admin_menu', 'acf_remove_menu_page', 15 );
@brasofilo
brasofilo / install.php
Last active September 3, 2023 20:24
WP Install Defaults - Dropin Plugin
<?php
!defined( 'ABSPATH' ) AND exit;
/*
Plugin Name: Custom Installation Script
Plugin URI: http://wordpress.stackexchange.com/q/75420/12615
Description: Create our own content on WP install
License: GPL
*/
@brasofilo
brasofilo / so_13646200.php
Created December 11, 2012 01:17
Repeatable upload field
add_action('admin_init', 'so_13646200_add_post_gallery');
add_action('save_post' , 'so_13646200_update_post_gallery');
function so_13646200_add_post_gallery() {
add_meta_box(
'post_gallery',
'Clients Logo Options',
'so_13646200_post_gallery_options',
'post',
'normal',
@brasofilo
brasofilo / wpse_76593.php
Last active August 17, 2017 11:38
Hide wp-content/themes path
<?php
// REMOVE WP-CONTENT
// Rewrites DO NOT happen for child themes
// Add .htaccess rewrite rules to convert urls
// like "http://example.com/wp-content/themes/theme-name/path" into "http://example.com/path"
/*
in case your wordpress is in a folder,
and you change the site_url to the root of the domain,
add the folder name in lines 29 to 34,
@brasofilo
brasofilo / gist:4367116
Last active December 10, 2015 02:19
Values in $wp_admin_bar
/**
* Value of $nodes in the following:
* global $wp_admin_bar;
* $nodes = $wp_admin_bar->get_nodes();
*/
Array
(
[user-actions] => stdClass Object
(
[id] => user-actions
@brasofilo
brasofilo / press-this-thickbox.php
Last active December 10, 2015 20:48
Dealing with PressThis inside an administrative thickbox
<?php
/**
Auxiliary menu and page with a button to open the thickbox
*/
add_action('admin_menu', 'add_auxiliary_menu');
function add_auxiliary_menu()
{
add_menu_page(
'TB',
@brasofilo
brasofilo / old-upload-method.php
Last active October 5, 2018 18:11
Replace the New WP 3.5 Uploader with the Old Thickbox
<?php
/**
* Plugin Name: Old Upload Method
* Plugin URI: http://wordpress.org/support/topic/is-there-a-way-to-disable-the-new-media-manager
* Description: Replace the new media upload with the old thickbox
* Author: A.Morita, brasofilo
* Version: 1.2
* License: GPLv2 or later
*