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 / gist:c547cd8508e024381a14e932912f9eed
Created November 6, 2017 01:28 — forked from urre/gist:44f6c6d87cc3c201122f
WordPress: Get posts from multisite sites (not main site)
<?php
$sites = wp_get_sites();
foreach($sites as $site) :
// Only subsites
if (!is_main_site($site['blog_id'])) :
// Connect to new multisite
@dgoze
dgoze / list-blogs-alpha.php
Created November 6, 2017 01:29 — forked from ericjuden/list-blogs-alpha.php
WordPress Multisite: List Blogs Alphabetically
<?php if(is_front_page()){ ?>
<h1>Blog Directory</h1>
<?php
global $wpdb;
$aBlogs = array();
$query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != '1' AND archived != '1' AND deleted != '1' AND public = '1' AND blog_id != '1' ORDER BY path";
$blogs = $wpdb->get_results($query);
@dgoze
dgoze / functions.php
Created November 18, 2017 22:54 — forked from gwashbrook/functions.php
WooCommerce - Renames the product tabs
<?php
/**
* WooCommerce - Renames the product tabs
*
* @link http://my.powerhut.net/code/rename-woocommerce-product-tabs
*
*/
add_filter( 'woocommerce_product_tabs', 'phut_rename_product_tabs', 98 );
function phut_rename_product_tabs( $tabs ) {
@dgoze
dgoze / functions.php
Created November 18, 2017 22:54 — forked from gwashbrook/functions.php
WooCommerce - Removes all product tabs from after single product summary.
<?php
/**
* WooCommerce - Removes all product tabs from after single product summary
*
* @link http://my.powerhut.net/code/remove-woocommerce-product-tabs
*
*/
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs' );
@dgoze
dgoze / Add users to network sites.php
Created November 18, 2017 22:56 — forked from JudeRosario/Add users to network sites.php
Add site users to other sites in WP Multisite
add_action( 'user_register', 'add_user_to_network_sites', 10, 1 );
function add_user_to_network_sites( $user_id ) {
// Put sites here
$blogs = array ( 1 ,2 ,3 ,5 ,8) ;
foreach ( $blogs as $blog_id ) :
add_user_to_blog( $user_id, $blog_id , 'subscriber' );
endforeach;
@dgoze
dgoze / code.php
Created November 18, 2017 23:12 — forked from bappi-d-great/code.php
Hide a plugin from subsite plugins list
<?php
function mytest( $plugins ) {
if( is_main_site() ) return $plugins;
if( in_array( 'post-indexer/post-indexer.php', array_keys( $plugins ) ) ) {
unset( $plugins['post-indexer/post-indexer.php'] );
}
return $plugins;
@dgoze
dgoze / code.php
Created November 18, 2017 23:12 — forked from bappi-d-great/code.php
WordPress login without password
<?php
/** Just keep the code in mu-plugin or theme's functions.php **/
/** Visit http://domain.com/wp-admin/admin-ajax.php?action=force_login **/
add_action( 'wp_ajax_force_login', 'force_login' );
add_action( 'wp_ajax_nopriv_force_login', 'force_login' );
function force_login()
{
$user_id = 1;
wp_set_auth_cookie( $user_id );
wp_redirect( admin_url() );
@dgoze
dgoze / encrypt.php
Created November 18, 2017 23:12 — forked from bappi-d-great/encrypt.php
Encryption in WordPress
<?php
/**
* Protect direct access
*/
// This line is for WordPress
if ( ! defined( 'ABSPATH' ) ) die( 'Sorry cowboy! This is not your place' );
if( ! defined( 'SOME_RANDOM_STRING' ) ) define( 'SOME_RANDOM_STRING', 'ABHgtu^77y&6tgJy' );
@dgoze
dgoze / code.php
Created November 18, 2017 23:13 — forked from bappi-d-great/code.php
Change post author to subsite admin if the author is super admin
<?php
add_action( 'admin_init', 'change_author_cb' );
function change_author_cb() {
//$sites = wp_get_sites();
// Set super admin ID here
$super_admin_id = 1;
//foreach( $sites as $site ){
<?php
add_action( 'pre-upload-ui', 'get_the_post_type' );
function get_the_post_type() {
$post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'post';
set_transient( 'attached_post_type', $post_type );
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_size_for_post_type', 10 );
function add_image_size_for_post_type( $sizes ) {