Skip to content

Instantly share code, notes, and snippets.

View davebonds's full-sized avatar

Dave Bonds davebonds

View GitHub Profile
@retgef
retgef / wysiwyg-meta-box.php
Created September 10, 2011 02:06
How to add a Wordpress WYSIWYG editor to a meta box.
<?php
define('WYSIWYG_META_BOX_ID', 'my-editor');
define('WYSIWYG_EDITOR_ID', 'myeditor'); //Important for CSS that this is different
define('WYSIWYG_META_KEY', 'extra-content');
add_action('admin_init', 'wysiwyg_register_meta_box');
function wysiwyg_register_meta_box(){
add_meta_box(WYSIWYG_META_BOX_ID, __('WYSIWYG Meta Box', 'wysiwyg'), 'wysiwyg_render_meta_box', 'post');
}
@isGabe
isGabe / custom-menu-links-widget.php
Created October 12, 2012 23:50
WordPress Plugin - Custom Menu widget with link descriptions #snippet #WordPress
@eduardozulian
eduardozulian / wp-customize-image-reloaded.php
Last active November 16, 2023 02:50
Extend WP_Customize_Image_Control class allowing access to files uploaded within the same context.
<?php
/**
* Customize Image Reloaded Class
*
* Extend WP_Customize_Image_Control allowing access to uploads made within
* the same context
*/
class My_Customize_Image_Reloaded_Control extends WP_Customize_Image_Control {
/**
* Constructor.
@thenbrent
thenbrent / woocommerce-disable-paypal-for-subscriptions.md
Last active October 31, 2016 20:17
Using WooCommerce and want to disable PayPal for subscription purchases, but still offer it as an option for buying one-off products? Activate this plugin.

This gist has been migrated to a repo here.

<?php
/**
* Limit Primary Menu to Top Level Items
*
* @author Bill Erickson
* @link http://www.billerickson.net/customizing-menu-arguments/
*
* @param array @args
* @return array
<?php
/**
* Default Category Title
*
* @author Bill Erickson
* @url http://www.billerickson.net/default-category-and-tag-titles
*
* @param string $headline
* @param object $term
@chriscct7
chriscct7 / gist:d7d077afb01011b1839d
Last active January 24, 2024 04:20
Plugins that need to be updated to be ready for the move to PHP 5 constructors

Important Notice for WordPress Plugins Using PHP 4 Style Constructors

The ability to use PHP 4 style constructors is getting removed from PHP. Without an update, many plugins will eventually no longer work (this is PHP breaking this backwards compatibility, not WordPress)

One of the more common uses of the PHP 4 style constructor (as opposed to PHP 5 style __construct() ) are plugins with widgets calling WP_Widget::WP_Widget() and/or parent::WP_Widget() and/or {object}->WP_Widget()

Note: Starting in WordPress 4.3, regardless of the PHP version in use on a server, WordPress will throw a deprecated notice when one of the PHP 4 style constructors is called specifically for widgets.

Basically instead of doing these:

@frosit
frosit / infectedFiles.md
Created May 5, 2016 22:40
Some commands for finding and clearing infected PHP files

Finding infected files with following bash commands

** Command to list all infected files:

  • grep -lr --include=*.php "eval(base64_decode" /path/to/webroot
  • grep -lr --include=*.php "eval" .
  • grep -lr --include=*.php "base64" .

Command to remove malicious code:

  • grep -lr --include=*.php "eval(base64_decode" /path/to/webroot | xargs sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?php\n/g'
@davebonds
davebonds / managewp-update-mu-plugin-from-s3.php
Last active June 14, 2016 01:26
ManageWP: Update must use plugin from S3
<?php
function update_myplugin() {
// Get current version number
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$version = get_plugin_data(WPMU_PLUGIN_DIR .'/myplugin.php');
// Check if current version is latest
if($version['Version'] < 1.0) {
// Use wp_remote_get to fetch the data and store it to a file
$response = wp_remote_get('https://s3.amazonaws.com/path/to/zipfile/myplugin.zip', array( 'stream' => true, 'filename' => WPMU_PLUGIN_DIR . '/myplugin.zip') );
@tyxla
tyxla / insert-widget-in-sidebar.php
Created August 24, 2016 10:43
Insert a widget in a sidebar programmatically in WordPress
<?php
/**
* Insert a widget in a sidebar.
*
* @param string $widget_id ID of the widget (search, recent-posts, etc.)
* @param array $widget_data Widget settings.
* @param string $sidebar ID of the sidebar.
*/
function insert_widget_in_sidebar( $widget_id, $widget_data, $sidebar ) {