Skip to content

Instantly share code, notes, and snippets.

View 5A5K1A's full-sized avatar
🦄

Saskia Bouten 5A5K1A

🦄
View GitHub Profile
@5A5K1A
5A5K1A / wordpress-hooks-admin.php
Created February 27, 2017 01:06
WordPress Remove Dashboard sections for "simple users"
<?php
/* Hide certain admin sections for "simple users"
/* -------------------------------------------------- */
add_action('wp_dashboard_setup', function() {
if( current_user_can('editor') ) {
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); //Quick Press widget
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); //Recent Drafts
remove_meta_box('dashboard_primary', 'dashboard', 'side'); //WordPress.com Blog
remove_meta_box('dashboard_secondary', 'dashboard', 'side'); //Other WordPress News
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); //Incoming Links
@5A5K1A
5A5K1A / wordpress-hooks-admin.php
Created February 27, 2017 01:06
WordPress Rename WP standard 'Berichten' to 'Nieuws'
<?php
/* rename WP standard 'Berichten' to 'Nieuws'
/* ------------------------------------ */
add_action( 'admin_menu', function() {
global $menu;
global $submenu;
$menu[5][0] = 'Nieuws';
$submenu['edit.php'][5][0] = 'Nieuws';
$submenu['edit.php'][10][0] = 'Nieuw nieuws';
$submenu['edit.php'][16][0] = 'Nieuws Tags';
@5A5K1A
5A5K1A / wordpress-hooks-metabox.php
Created February 27, 2017 01:04
WordPress Change 'Featured Image' metabox
<?php
/* Featured Image Metabox : change the text in the current metaboxes
/* -------------------------------------------------- */
add_filter( 'admin_post_thumbnail_html', function( $content ) {
if(get_post_type() == 'post') {
$content = str_replace('Uitgelichte afbeelding', 'Nieuws foto', $content);
// $content .= '<p>Een extra uitlegtekst.</p>';
} elseif(get_post_type() == 'page') {
$content = str_replace('Uitgelichte afbeelding', 'Header foto', $content);
@5A5K1A
5A5K1A / wordpress-hooks-metabox.php
Last active February 27, 2017 01:03
WordPress Change custom taxonomy metabox (checkboxes to radios, in order to force one)
<?php
/* Custom Tax Metabox : remove the current custom taxonomy metabox
/* -------------------------------------------------- */
add_action( 'admin_menu', function(){
remove_meta_box('customtaxdiv', 'posttype', 'normal');
});
/* Custom Tax Metabox : add a new & improved custom taxonomy metabox (select-one)
/* -------------------------------------------------- */
add_action( 'add_meta_boxes', function() {
@5A5K1A
5A5K1A / wordpress-hook-admin-dashboard.php
Last active February 27, 2017 01:01
WordPress Add all CPT (& tax) to WP Dashboard Right Now Widget
<?php
/* ------------------------------------ */
/* Add Custom Post Type to WP-ADMIN Right Now Widget
/* ------------------------------------ */
add_action( 'dashboard_glance_items', function() { ?>
<style>
#dashboard_right_now a.post_type_name-count:before { content: "\f473"; }
</style>
<?php
$args = array(
@5A5K1A
5A5K1A / wordpress-hooks-admin-save.php
Last active February 4, 2017 21:16
WordPress Make "in-site" URL's relative
<?php
/* ------------------------------------ */
/* Convert absolute URLs in content to site relative ones
/* Inspired by http://thisismyurl.com/6166/replace-wordpress-static-urls-dynamic-urls/
/* ------------------------------------ */
add_filter('content_save_pre', function( $content ) {
$site_url = get_bloginfo('url');
return str_replace(' href=\"'.$site_url, ' href=\"', str_replace(' src=\"'.$site_url, ' src=\"', $content));
}, 10, 1);