Skip to content

Instantly share code, notes, and snippets.

View nicholasohrn's full-sized avatar

Nicholas Ohrn nicholasohrn

  • OhrnVentures LLC
  • Las Vegas, NV
View GitHub Profile
<?php
if (defined('WP_CLI') && WP_CLI && is_callable('WP_CLI', 'add_command')) {
// BAT: Cache
\WP_CLI::add_command('insert-emoji-into-database', function() {
global $wpdb;
$result = $wpdb->query("INSERT INTO {$wpdb->prefix}gf_entry_meta (entry_id, form_id, meta_key, meta_value, item_index) VALUES (0, 0, 'x', '🎉', 0);");
echo "{$result}\n\n{$wpdb->last_error}";
<?php
$dirname = dirname(__FILE__);
$decoded = $dirname . '/' . 'decoded';
$files = glob("{$dirname}/*.cache");
foreach($files as $file) {
$decoded_filename = base64_decode(str_replace('.cache', '', basename($file))) . '.php';
$decoded_filecont = base64_decode(file_get_contents($file));
@nicholasohrn
nicholasohrn / redirect-cpt-to-home.php
Last active August 29, 2015 14:11
Redirect custom post types that are defined to the home page before running any DB queries or anything.
<?php
/**
* Hook in to the parse_request action to see if any custom post type
* variables are present. If so, redirect.
**/
function redirect_cpt_to_home($wp) {
$redirectable = array('book', 'movie', 'event');
if(in_array($wp->query_vars['post_type'], $redirectable)) {
@nicholasohrn
nicholasohrn / http-basic-cron-request.php
Created July 1, 2014 21:22
WP Cron with HTTP Basic Authentication
<?php
if(defined('WP_CRON_CUSTOM_HTTP_BASIC_USERNAME') && defined('WP_CRON_CUSTOM_HTTP_BASIC_PASSWORD')) {
function http_basic_cron_request($cron_request) {
$headers = array('Authorization' => sprintf('Basic %s', base64_encode(WP_CRON_CUSTOM_HTTP_BASIC_USERNAME . ':' . WP_CRON_CUSTOM_HTTP_BASIC_PASSWORD)));
$cron_request['args']['headers'] = isset($cron_request['args']['headers']) ? array_merge($cron_request['args']['headers'], $headers) : $headers;
return $cron_request;
}
@nicholasohrn
nicholasohrn / force-cpt-template-for-search.php
Last active August 29, 2015 14:01
Force CPT template for search on CPT
function force_cpt_template_for_search($template) {
if(is_search() && is_post_type_archive() && ($_template = get_post_type_archive_template())) {
$template = $_template;
}
return $template;
}
add_filter('template_include', 'force_cpt_template_for_search');
<?php
function at_a_glance_override() {
ob_start();
wp_dashboard_right_now();
$contents = ob_get_clean();
echo preg_replace('#.*themes\.php.*#', '', $contents);
}
<?php
function admin_menu_change_posts_link_to_pending_review() {
global $submenu;
$submenu['edit.php'][5][2] = 'edit.php?post_status=pending&post_type=post';
}
add_action('admin_menu', 'admin_menu_change_posts_link_to_pending_review');
@nicholasohrn
nicholasohrn / dribbble-shot-embedder.php
Last active July 30, 2020 16:55
Automatically embed Dribbble shots into WordPress content
<?php
/*
Plugin Name: Dribbble Shot Embed
Description: Automatically embed a shot into your WordPress site just by dropping the URL in place.
Version: 1.0.0.RC.1
Author: Nick Ohrn of Plugin-Developer.com
Author URI: http://plugin-developer.com/
*/
function dribbble_shot_embed_callback($matches, $attr, $url, $rawattr) {
@nicholasohrn
nicholasohrn / automatically-title-post.php
Created March 4, 2014 18:17
Automatically title a post based on its type and category
<?php
/*
Plugin Name: Automatically Title Post
Description: Automatically title post based on post type and taxonomy.
Version: 1.0.0.RC.1
Author: Nick Ohrn of Plugin-Developer.com
Author URI: http://plugin-developer.com/
*/
function automatically_title_post($post_id, $post, $update) {