Skip to content

Instantly share code, notes, and snippets.

@Otto42
Otto42 / allow-private-parents.php
Last active April 6, 2022 02:21
Allow Private Pages to be parents of other pages
<?php
/*
Plugin Name: Allow Private Parents
Author: Otto
Author URI: http://ottopress.com
*/
add_filter('page_attributes_dropdown_pages_args', 'allow_private_page_parents');
function allow_private_page_parents($args) {
$args['post_status'] = array( 'publish', 'private' );
@Otto42
Otto42 / spamcrap.txt
Created April 26, 2013 13:33
Somewhat more complete version of a spam template
{
{I have|I’ve} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It’s|It is} pretty worth enough for me.
{In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as you did, the
{internet|net|web} will be {much more|a lot more} useful than ever before.
|
I {couldn’t|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I’ll} {right away|immediately} {take hold
of|grab|clutch|grasp|seize|snatch} your {rss|rss feed} as I {can not|can’t} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you’ve} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe.
@Otto42
Otto42 / gist:5853020
Created June 24, 2013 19:54
mlb.tv embed code for a WordPress plugin
<?php
function mlbtv_embed_register_handler() {
wp_embed_register_handler( 'mlbtv', '|https?://wapc.mlb.com/play/\?content_id=([0-9]*)?#?|i', 'mlbtv_embed_handler' );
}
add_action( 'init', 'mlbtv_embed_register_handler' );
function mlbtv_embed_handler( $matches, $attr, $url, $rawattr ) {
if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
@Otto42
Otto42 / gist:5854277
Last active December 18, 2015 22:28
WordPress embed handler for shows from cbs.com
<?php
function cbscom_embed_register_handler() {
wp_embed_register_handler( 'cbscom', '|https?://www.cbs.com/shows/.*|i', 'cbscom_embed_handler' );
}
add_action( 'init', 'cbscom_embed_register_handler' );
function cbscom_embed_handler( $matches, $attr, $url, $rawattr ) {
global $post, $wp_embed;
@Otto42
Otto42 / instagram-embed.php
Last active December 22, 2015 16:49
Instagram embed override code for WordPress, to use the embed iframe instead of Instagram's own oEmbed API endpoint.
<?php
/*
Plugin Name: Instagram Frame Embedder
Author: Otto
*/
wp_embed_register_handler( 'instagram', '#https?://instagr(\.am|am\.com)/p/([^/]+)#i', 'custom_embed_handler_instagram' );
function custom_embed_handler_instagram( $matches, $attr, $url, $rawattr ) {
if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
@Otto42
Otto42 / time-shortcode.php
Created September 13, 2013 15:50
Time shortcode used for make p2's
<?php
/**
* Plugin: Time Shortcode
* Author: Otto
*
* Usage: [time]any-valid-time-string-here[/time]
* Will attempt to parse the time string and create a format that shows it in the viewers local time zone
* Note that times should be complete with year, month, day, and hour and minute.. something strtotime can parse meaningfully
* Conversion happens via Javascript and will depend on the users browser.
**/
@Otto42
Otto42 / gist:6639477
Created September 20, 2013 15:40
How to set the color picker and the control in the customizer via JS
control = wp.customize.control.instance('header_textcolor');
picker = control.container.find('.color-picker-hex');
control.setting.set('#FFFFFF');
picker.wpColorPicker('color', control.setting() );
@Otto42
Otto42 / metabox.php
Created January 13, 2014 05:12
Simple meta box plugin
<?php
/*
Plugin Name: Demo of a Metabox
*/
add_action('add_meta_boxes','my_meta_box_add');
function my_meta_box_add() {
add_meta_box( 'my-meta-box', 'My Meta Box', 'my_meta_box', 'post', 'side');
}

Keybase proof

I hereby claim:

  • I am Otto42 on github.
  • I am otto42 (https://keybase.io/otto42) on keybase.
  • I have a public key whose fingerprint is 270B 9CC6 F8C3 4F82 5AAE 92A5 2D65 34DE 7063 B5B2

To claim this, I am signing this object:

@Otto42
Otto42 / gist:b79ff5428993fcff45bb
Last active November 2, 2018 19:48
disable emojis in wp 4.2
add_action( 'init', 'disable_emoji', 1 );
function disable_emoji() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_tinymce_emoji' );