Skip to content

Instantly share code, notes, and snippets.

@sillybean
sillybean / toolbar-buttons.php
Created Oct 16, 2016
Remove WP TinyMCE toolbar buttons
View toolbar-buttons.php
<?php
// Remove the underline and full-justify toolbar buttons
function scl_mce_buttons( $buttons ) {
$remove = array( 'underline', 'alignjustify' );
return array_diff( $buttons, $remove );
}
add_filter( 'mce_buttons_2', 'scl_mce_buttons' );
@sillybean
sillybean / ms-network-admin.php
Last active Oct 11, 2016
Multisite Network Administration functions
View ms-network-admin.php
<?php
/*
Plugin Name: Texas A&M Multisite Network Administration
Version: 0.4.2
Plugin URI: https://github.tamu.edu/COE-wordpress/coe-network-admin
Description: Adds columns to the Network Sites list screen; subsite user login redirects.
Author: Stephanie Leary
Author URI: http://stephanieleary.com
GitHub Plugin URI: https://github.tamu.edu/COE-wordpress/coe-network-admin
GitHub Enterprise: https://github.tamu.edu
@sillybean
sillybean / default-network-roles.php
Created Oct 11, 2016
Give new network users a default role on the main site
View default-network-roles.php
<?php
function tees_add_network_default_roles( $user_id ) {
if ( is_main_site() && !is_user_member_of_blog( $user_id ) )
add_user_to_blog( get_current_blog_id(), $user_id, 'subscriber' );
}
add_action( 'wpmu_activate_user', 'tees_add_network_default_roles', 10, 1 );
add_action( 'wpmu_new_user', 'tees_add_network_default_roles', 10, 1 );
add_action( 'user_register', 'tees_add_network_default_roles', 10, 1 );
@sillybean
sillybean / subsite-login-redirect.php
Last active Oct 10, 2016
Redirect user to primary blog dashboard if not superadmin or not allowed on this blog
View subsite-login-redirect.php
<?php
add_filter( 'login_redirect', 'tees_subsite_login_redirect', 100, 3 );
function tees_subsite_login_redirect( $redirect_to, $request_redirect_to, $user ) {
if ( !is_user_member_of_blog() || ( is_main_site() && !is_super_admin() ) ) {
$redirect_to = get_admin_url( get_userdata( $user->ID )->primary_blog );
}
return $redirect_to;
}
@sillybean
sillybean / functions.php
Last active Aug 26, 2016
Better Genesis a11y
View functions.php
<?php
// Replace primary navigation to remove unnecessary "Main navigation" heading, duplicated in ARIA label
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_after_header', 'scl_do_nav' );
function scl_do_nav() {
//* Do nothing if menu not supported
if ( ! genesis_nav_menu_supported( 'primary' ) || ! has_nav_menu( 'primary' ) )
return;
$class = 'menu genesis-nav-menu menu-primary';
@sillybean
sillybean / functions.php
Last active Aug 1, 2017
Change post excerpt meta box title and contents
View functions.php
<?php
remove_meta_box( 'postexcerpt', 'post', 'side' );
// use original box:
// add_meta_box('postexcerpt', __( 'Plain Text Summary' ), 'post_excerpt_meta_box', 'post', 'normal', 'high');
// replace box altogether:
add_meta_box( 'postexcerpt', __( 'Plain Text Summary' ), 'custom_post_excerpt_meta_box', 'post', 'normal', 'high' );
function custom_post_excerpt_meta_box( $post ) {
?>
@sillybean
sillybean / citation-importer-filters.php
Last active Aug 18, 2016
Example filters to add or edit custom fields for the Citation Importer plugin.
View citation-importer-filters.php
<?php
/*
Plugin Name: Citation Importer Filters
Plugin URI: http://stephanieleary.com/
Description: Add or edit fields for the Citation Importer.
Author: sillybean
Author URI: http://stephanieleary.com/
Version: 0.1
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
@sillybean
sillybean / html-importer.php
Created Aug 4, 2016
Add explicit categories to HTML Imported posts
View html-importer.php
<?php
// [file fragment]
// find this, around line 671
// ... and all the taxonomies...
$taxonomies = get_taxonomies( array( 'public' => true ), 'objects', 'and' );
foreach ( $taxonomies as $tax ) {
if ( isset( $options[$tax->name] ) )
wp_set_post_terms( $post_id, $options[$tax->name], $tax->name, false );
}
if ( isset( $customfieldtags ) )
@sillybean
sillybean / functions.php
Created Jul 21, 2016
Force Genesis Featured Page widget to use excerpts
View functions.php
<?php
//* Add excerpts to pages
add_post_type_support( 'page', 'excerpt' );
//* Use excerpts as Featured Page widget content
add_filter( 'get_the_content_limit', 'ebca_content_limit', 10, 4 );
function ebca_content_limit( $output, $content, $link, $max_characters ) {
$content = get_post_field( 'post_excerpt', get_the_ID() );
@sillybean
sillybean / searchwp-page.php
Created Jul 6, 2016
Feature requests for SearchWP Shortcodes extension
View searchwp-page.php
[searchwp_search_form engine="employee_directory" placeholder="Search for a name or custom field"] <!-- new -->
[searchwp_search_results_found] <!-- new -->
<div class="search-results-wrapper">
<h3>Search Results</h3>
[searchwp_search_results engine="employee_directory" posts_per_page=20]
<h4>[searchwp_search_result_link direct="true"]</h4>
[searchwp_search_result_excerpt]
[/searchwp_search_results]
</div>
You can’t perform that action at this time.