Skip to content

Instantly share code, notes, and snippets.

Nick Ohrn nickohrn

Block or report user

Report or block nickohrn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View wp-plugin-file-decoder.php
<?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));
@nickohrn
nickohrn / redirect-cpt-to-home.php
Last active Aug 29, 2015
Redirect custom post types that are defined to the home page before running any DB queries or anything.
View redirect-cpt-to-home.php
<?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)) {
@nickohrn
nickohrn / http-basic-cron-request.php
Created Jul 1, 2014
WP Cron with HTTP Basic Authentication
View http-basic-cron-request.php
<?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;
}
@nickohrn
nickohrn / force-cpt-template-for-search.php
Last active Aug 29, 2015
Force CPT template for search on CPT
View force-cpt-template-for-search.php
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');
View image-pagination-links.php
View remove-theme-name-from-at-a-glance.php
<?php
function at_a_glance_override() {
ob_start();
wp_dashboard_right_now();
$contents = ob_get_clean();
echo preg_replace('#.*themes\.php.*#', '', $contents);
}
View all-posts-status-review.php
<?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');
@nickohrn
nickohrn / dribbble-shot-embedder.php
Last active Nov 15, 2015
Automatically embed Dribbble shots into WordPress content
View dribbble-shot-embedder.php
<?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) {
@nickohrn
nickohrn / automatically-title-post.php
Created Mar 4, 2014
Automatically title a post based on its type and category
View automatically-title-post.php
<?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) {
@nickohrn
nickohrn / reassign-posts-on-delete-user.php
Created Mar 4, 2014
Reassign posts from user being deleted
View reassign-posts-on-delete-user.php
<?php
function reassign_post_on_delete_user($user_id) {
global $wpdb;
// Replace the following with whatever ID you want to reassign to
$replacement_id = 1;
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $user_id));
$wpdb->update($wpdb->posts, array('post_author' => $replacement_id), array('post_author' => $user_id));
You can’t perform that action at this time.