Skip to content

Instantly share code, notes, and snippets.

View jimboobrien's full-sized avatar

Jimobrien jimboobrien

View GitHub Profile
@jimboobrien
jimboobrien / wp-plugin-settings-link.php
Created September 20, 2017 23:33 — forked from wpscholar/wp-plugin-settings-link.php
Add a settings link to your WordPress plugin
@jimboobrien
jimboobrien / wp-snapshot-shortcode.php
Created September 20, 2017 23:33 — forked from wpscholar/wp-snapshot-shortcode.php
Shortcode displays snapshots of remote sites on your WordPress site.
<?php
/**
* This shortcode will allow you to create a snapshot of a remote website and post it
* on your WordPress site.
*
* [snapshot url="http://www.wordpress.org" alt="WordPress.org" width="400" height="300"]
*/
add_shortcode( 'snapshot', function ( $atts ) {
$atts = shortcode_atts( array(
@jimboobrien
jimboobrien / remove-admin-menu-items.php
Created September 20, 2017 23:32 — forked from wpscholar/remove-admin-menu-items.php
Remove unwanted pages from the WordPress admin menu
<?php
/**
* Remove unwanted pages from the WordPress admin menu
*/
function my_admin_menu() {
remove_menu_page('link-manager.php');
}
add_action( 'admin_menu', 'my_admin_menu' );
@jimboobrien
jimboobrien / members-only-shortcode.php
Created September 20, 2017 23:32 — forked from wpscholar/members-only-shortcode.php
WordPress shortcode will only display content to registered users.
<?php
/**
* WordPress shortcode only displays content to registered users. Could be improved by
* passing role as an attribute to only allow certain types of users.
*
* Example: [member]This text will be only displayed to registered users.[/member]
*/
function members_only_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
@jimboobrien
jimboobrien / load-pdf.php
Created September 20, 2017 23:32 — forked from wpscholar/load-pdf.php
WordPress shortcode loads a PDF file on your site in an iframe using Google Docs
<?php
/**
* WordPress shortcode loads a PDF file on your site in an iframe using Google Docs.
*
* Example: [embed_pdf width="600px" height="500px"]http://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf]
*/
function embed_pdf($attr, $url) {
return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>';
}
@jimboobrien
jimboobrien / rss-shortcode.php
Created September 20, 2017 23:32 — forked from wpscholar/rss-shortcode.php
WordPress shortcode allows you to create content that is visible only in your RSS feeds.
<?php
/**
* WordPress shortcode allows you to create content that is visible only in your RSS feeds.
*
* Example: [feedonly]Dear RSS readers...[/feedonly]
*/
function feedonly_shortcode( $atts, $content = null) {
if (!is_feed()) return "";
return $content;
@jimboobrien
jimboobrien / append-nav-items.php
Created September 20, 2017 23:30 — forked from wpscholar/append-nav-items.php
Add a custom link to the end of a menu that uses the wp_nav_menu() function
<?php
/**
* Add a custom link to the end of a specific menu that uses the wp_nav_menu() function
*/
add_filter('wp_nav_menu_items', 'add_admin_link', 10, 2);
function add_admin_link($items, $args){
if( $args->theme_location == 'footer_menu' ){
$items .= '<li><a title="Admin" href="'. esc_url( admin_url() ) .'">' . __( 'Admin' ) . '</a></li>';
}
@jimboobrien
jimboobrien / generate-list.php
Created September 20, 2017 23:30 — forked from wpscholar/generate-list.php
Take a multi-dimensional array in $_POST format and convert into an unordered list.
<?php
/**
*
* Take a multi-dimensional array in $_POST format and convert into an unordered list.
*
* @param $data
* @param array $args
* @return string
*/
@jimboobrien
jimboobrien / wp-redirect.php
Created September 20, 2017 23:30 — forked from wpscholar/wp-redirect.php
WordPress function for redirecting users on login based on user role
<?php
/**
* WordPress function for redirecting users on login based on user role
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
@jimboobrien
jimboobrien / force-ssl.php
Created September 20, 2017 23:30 — forked from wpscholar/force-ssl.php
Force SSL on pages in WordPress
<?php
/**
* Force SSL on pages in WordPress
*/
function force_ssl(){
if( !is_ssl() ){
$url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
wp_redirect( $url, 301);
exit();