Skip to content

Instantly share code, notes, and snippets.

@brasofilo
brasofilo / code-snippets-shotcode.php
Last active August 26, 2023 23:48
Snippets Shortcode plugin. Add code snippets as a Custom Post Type. Display in regular posts and pages using a Shortcode. Rendered with Google Prettify in frontend.
<?php
/**
* Plugin Name: Snippets Shortcode
* Plugin URI: http://wordpress.stackexchange.com/q/116044/12615
* Description: Add code snippets as a Custom Post Type. Display in regular posts and pages using a Shortcode. Rendered with Google Prettify in frontend.
* Version: 1.0
* Author: Rodolfo Buaiz
* Author URI: http://brasofilo.com
* License: GPLv2 or later
*
@brasofilo
brasofilo / comments-2-excel.php
Last active April 1, 2018 06:54
Export WordPress Comments as Excel file. Uses PHPExcel, http://phpexcel.codeplex.com/. Place this file in the root of the WordPress installation. TODO: convert to plugin.
<?php
# Load slim WP
define( 'WP_USE_THEMES', false );
require( './wp-load.php' );
# http://phpexcel.codeplex.com/
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
global $wpdb;
$query = "SELECT * FROM $wpdb->comments
@brasofilo
brasofilo / widget-title-with-urls.php
Created October 1, 2013 19:19
Using URLs in Widget Titles. Using the format TITLE||URL||TARGET, being target optional. Nice article with many methods: http://www.rvamedia.com/wordpress/customize-wordpress-widget-title
<?php
add_filter( 'widget_title', function( $title )
{
$pieces = explode( '||', $title );
if( isset( $pieces[1] ) )
{
$target = isset( $pieces[2] ) ? "target='{$pieces[2]}'" : '';
$new_title = sprintf(
"<a href='%s' %s>%s</a>",
$pieces[1],
@brasofilo
brasofilo / paste-in-plugin.css
Created September 30, 2013 21:10
Admin Tweaks custom CSS
html, body {
min-height: 100%;
}
body {
background: #d8e0de;
background: -moz-linear-gradient(top, #d8e0de 0%, #aebfbc 22%, #99afab 33%, #8ea6a2 50%, #829d98 67%, #4e5c5a 82%, #0e0e0e 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#d8e0de), color-stop(22%,#aebfbc), color-stop(33%,#99afab), color-stop(50%,#8ea6a2), color-stop(67%,#829d98), color-stop(82%,#4e5c5a), color-stop(100%,#0e0e0e));
background: -webkit-linear-gradient(top, #d8e0de 0%,#aebfbc 22%,#99afab 33%,#8ea6a2 50%,#829d98 67%,#4e5c5a 82%,#0e0e0e 100%);
background: -o-linear-gradient(top, #d8e0de 0%,#aebfbc 22%,#99afab 33%,#8ea6a2 50%,#829d98 67%,#4e5c5a 82%,#0e0e0e 100%);
background: -ms-linear-gradient(top, #d8e0de 0%,#aebfbc 22%,#99afab 33%,#8ea6a2 50%,#829d98 67%,#4e5c5a 82%,#0e0e0e 100%);
@brasofilo
brasofilo / plugin.php
Last active April 6, 2020 01:13
Original code for Multisite Categories. At WordPress Answers http://wordpress.stackexchange.com/a/50936/12615
<?php
/**
* Plugin Name: Multisite Site Category
* Plugin URI: https://gist.github.com/brasofilo/6715423
* Description: Add a custom meta option when registering new sites in WordPress Multisite. Two columns will be added to the Sites listing screen: ID and Category. Based on http://wordpress.stackexchange.com/a/50936/12615
* Network: true
* Author: Rodolfo Buaiz
* Author URI: http://brasofilo.com/
* Version: 1.1
@brasofilo
brasofilo / folders-sizes-dashboard-widget.php
Last active December 23, 2015 19:08
WordPress Dashboard Widgets to calculate the size of the folders in root and wp-content. Used in the plugin Admin Tweaks.
<?php
/**
* Plugin Name: Calculate Folders Sizes
* Plugin URI: http://wordpress.org/extend/plugins/many-tips-together
* Description: Dashboard widgets to calculate the size of the folders in root and wp-content. Used in the plugin Admin Tweaks.
* Version: 1.0
* Author: Rodolfo Buaiz
* Author URI: http://brasofilo.com/
* Text Domain: mtt
* License: GPLv2 or later
<?php
/**
* Custom browser check
*
* Uses https://github.com/cbschuld/Browser.php
*/
function b5f_browser_check($what) {
global $browser, $browver;
switch ($what) {
@brasofilo
brasofilo / uid-settings.php
Last active December 3, 2016 16:26
Settings API based on User ID
<?php
/*
Plugin Name: Settings API based on User ID
*/
class MySettingsPage2
{
/**
* Holds the values to be used in the fields callbacks
*/
@brasofilo
brasofilo / language-cookie-wpse-113662.php
Last active August 29, 2018 19:02
WordPress plugin to deal with language cookies. Create one page for each language. Then a menu with them. Configure the arguments in the plugin file. Than do your thing in your theme with $_COOKIE[cookie_name].
<input type="text" name="my-theme-options[color]" id="color" />
<input type='button' class='pickcolor button-secondary' value='Select Color'>
<div id='colorpicker' style='z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;'></div>
// Color Picker for js file
$('.pickcolor').click( function(e) {
colorPicker = jQuery(this).next('div');
input = jQuery(this).prev('input');
$(colorPicker).farbtastic(input);
colorPicker.show();