Skip to content

Instantly share code, notes, and snippets.

View petenelson's full-sized avatar

Pete Nelson petenelson

View GitHub Profile
@petenelson
petenelson / pn-revisions-in-list-table.php
Last active August 29, 2015 14:18
WordPress: Display a list of post/page/custom post type revisions in the dashboard list tables
<?php
/*
Plugin Name: Revisions in List Table
Description: Allows a list of revisions to display in the dashboard list tables
Author: Pete Nelson
Version: 1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit( 'restricted access');
@petenelson
petenelson / timeline-express-filter-test.php
Created April 24, 2015 18:51
WordPress: Test the new Timeline Express filter
<?php
/*
Plugin Name: Timeline Express Custom Icon Filter Test
*/
add_filter( 'timeline-express-custom-icon-html', 'pn_timeline_express_custom_icon_html_test', 10, 3 );
function pn_timeline_express_custom_icon_html_test( $html, $post, $timeline_express_options ) {
$custom_png_icon = get_post_meta( $post->ID, '_custom_png_icon', true );
@petenelson
petenelson / add-featured-image-to-post.php
Created July 9, 2015 22:29
WordPress REST API: Add featured image link to posts
<?php
add_filter( 'rest_prepare_post', array( $this, 'add_featured_image_link' ), 10, 3 );
public function add_featured_image_link( $data, $post, $request ) {
if ( has_post_thumbnail( $post->ID ) ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$data->add_link( 'featured_image', $featured_image[0], array( 'width' => absint( $featured_image[1] ), 'height' => absint( $featured_image[2] ) ) );
}
@petenelson
petenelson / rest-api-disallow-non-ssl.php
Last active August 29, 2015 14:25
WordPress REST API: Disallow non-SSL
<?php
add_filter( 'rest_pre_dispatch', 'rest_api_disallow_non_ssl', 10, 3 );
function rest_api_disallow_non_ssl( $response, $server, $request ) {
if ( ! is_ssl() ) {
$response = new WP_Error( 'rest_forbidden', __( "SSL is required to access the REST API" ), array( 'status' => 403 ) );
}
@petenelson
petenelson / rest-api-force-link-header-https.php
Created July 24, 2015 01:03
WordPress REST API: Force Link rel header to https
@petenelson
petenelson / customized-wordpress-login-page.php
Last active October 7, 2015 18:48
WordPress: Customized Login Page
// customized login page CSS
// from http://www.wpsyntax.com/wordpress/7-functions-white-label-wordpress
add_action('login_head', 'my_theme_custom_login');
function my_theme_custom_login() {
echo '<style type="text/css">
h1 a { background-image:url('.get_stylesheet_directory_uri().'/img/logo-login-274-63.png) !important; }
</style>';
}
// link login page logo to the site's URL instead of wordpress.org
@petenelson
petenelson / remove_unwanted_menu_and_toolbar_items_wordpress.php
Created July 30, 2012 19:58 — forked from BronsonQuick/remove_unwanted_menu_and_toolbar_items_wordpress.php
WordPress: Remove unwanted menu items from the Menu Bar and Toolbar
<?php
/* Remove unwanted menus in WordPress e.g. Posts, Comments and Links */
/* Inspired by http://wordpress.org/extend/plugins/white-label-cms/ */
function ctm_remove_admin_menus() {
global $menu, $submenu;
$exclude[0] = '';
array_push($exclude,__('Posts','default'));
array_push($exclude,__('Comments','default'));
array_push($exclude,__('Links','default'));
unset($exclude[0]);
@petenelson
petenelson / wp-auth-cookie-expiration.php
Created August 8, 2012 15:45
WordPress filter to extend the expiration of the login auth cookie
@petenelson
petenelson / wordpress-body-classes.php
Last active October 8, 2015 18:38
WordPress: Add additional body classes based on the post meta
// extra body classes based on the post meta
add_filter('body_class','theme_body_class');
function theme_body_class($classes) {
$body_classes = get_post_meta(get_the_id(), 'body-class');
if (false !== $body_classes && count($body_classes) > 0)
$classes = array_merge($classes, $body_classes);
return $classes;
@petenelson
petenelson / document.php
Created November 16, 2012 15:50
WordPress: Custom post type (my-document) for docs (PDFs, etc)
<?php
/*
Plugin Name: My Document Permalink
Description: Custom post type (my-document) for docs (PDFs, etc)
Version: 1.0
Author: Pete Nelson
*/
add_action('init', 'my_register_document_post_type');