Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / get_current_post_type.php
Created October 13, 2017 20:58 — forked from bradvin/get_current_post_type.php
Get the current post_type context in the WordPress admin.
<?php
/**
* gets the current post type in the WordPress Admin
*/
function get_current_post_type() {
global $post, $typenow, $current_screen;
//we have a post so we can just get the post type from that
if ( $post && $post->post_type )
return $post->post_type;
@dgoze
dgoze / add_body_class_wpmu.php
Created November 6, 2017 01:08 — forked from celsofabri/add_body_class_wpmu.php
Add Class Body Multisite / Adicionando Classe Body para Multisite
<?php
// Apply filter
add_filter('body_class', 'multisite_body_classes');
function multisite_body_classes($classes) {
$id = get_current_blog_id();
$slug = strtolower(str_replace(' ', '-', trim(get_bloginfo('name'))));
$classes[] = sanitize_title('site-'.$slug);
return $classes;
}
@dgoze
dgoze / functions.php
Created November 6, 2017 01:09 — forked from qutek/functions.php
[Wordpress] [Multisite] Get latest post from wordpress multisite blog
/* Get Latest post from all blogs */
function recent_mu_posts( $howMany = 10 ) {
global $wpdb;
global $table_prefix;
// get an array of the table names that our posts will be in
// we do this by first getting all of our blog ids and then forming the name of the
// table and putting it into an array
$rows = $wpdb->get_results( "SELECT blog_id from $wpdb->blogs WHERE
public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0';" );
@dgoze
dgoze / multisite_functions.php
Created November 6, 2017 01:09 — forked from freekrai/multisite_functions.php
Some handy wordpress multisite functions
<?php
$posts = multisite_latest_post( array(
"how_many"=>10,
"how_long_days"=>30,
"how_many_words"=>50,
"more_text"=>"[...]",
"remove_html"=>true,
"sort_by"=>"post_date",
// if paginating:
"paginate"=>true,
@dgoze
dgoze / wordpress_multisite_save_page.php
Created November 6, 2017 01:10 — forked from mihaiiro/wordpress_multisite_save_page.php
wordpress_multisite_save_page.php
<?php
// See full article here http://www.wpriders.com/snippets/multisite-create-page-on-all-sites/
$args = array(
'post_content' => $page_content,
'post_name' => $page_slug,
'post_title' => $page_title,
'post_status' => 'publish',
'post_type' => 'page'
);
$post_id = wp_insert_post( $args, true );
@dgoze
dgoze / display-site-ids.php
Created November 6, 2017 01:26 — forked from ninnypants/display-site-ids.php
Show ID column in multisite Sites list table
<?php
/*
Plugin Name: Show Multisite IDs
Plugin URI: http://ninnypants.com
Description: Adds table column to show site ID
Version: 1.0
Author: ninnypants
Author URI: http://ninnypants.com
License: GPL2
@dgoze
dgoze / auto-activate-plugins.php
Created November 6, 2017 01:26
Automatically enable plugins in new WordPress Multisite blogs
<?php
// There are three options (that I know of) for automatically enabling a plugin
// in new sites.
// 1. Move the plugin from wp-content/plugins/ to wp-content/mu-plugins/ (MU =
// Must Use). But then it cannot be deactivated for any site.
// 2. Click "Network Activate" instead of "Activate" to enable it for all sites.
// I didn't want to use this though because I didn't want to affect existing
@dgoze
dgoze / network-shared-media.php
Created November 6, 2017 01:26 — forked from aaroneaton/network-shared-media.php
WP:Share WP media libraries across multisite network
<?php
// Add filter that inserts our new tab
function nsm_menu($tabs) {
$newtab = array('shared_media' => __('Network Shared Media', 'networksharedmedia'));
return array_merge($tabs, $newtab);
}
add_filter('media_upload_tabs', 'nsm_menu');
// Load media_nsm_process() into the existing iframe
function nsm_menu_handle() {
@dgoze
dgoze / unused-plugins.php
Created November 6, 2017 01:27 — forked from superjinjo/unused-plugins.php
Check which WordPress plugins are unused in your multisite network
<?php
//This is a quick and dirty script to see which WordPress plugins aren't being used by ANY of the sites in a multisite network.
/** Load WordPress Bootstrap */
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
@dgoze
dgoze / rkv-multi-crosspost.php
Created November 6, 2017 01:28 — forked from norcross/rkv-multi-crosspost.php
cross post (syndicate) posts on a WP multisite install
<?php
/*
Plugin Name: Multisite Cross Post
Description: Cross post content between a WP multisite installation
Author: Andrew Norcross
Version: 0.1
Author URI: http://andrewnorcross.com
*/
class RKV_Multi_CrossPost {