Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Created June 23, 2018 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/3923e856768a219fe0c17515f9f08124 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/3923e856768a219fe0c17515f9f08124 to your computer and use it in GitHub Desktop.
[Pro Sites] - Disable Free level access. Only admin can access Free sites that have no pro level
<?php
/**
* Plugin Name: [Pro Sites] - Disable Free level access[Pro Sites] - Disable Free level access
* Plugin URI: https://premium.wpmudev.org/
* Description: Only admin can access Free sites that have no pro level
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WPMUDEV_PS_Disable_Free_Front' ) ) {
class WPMUDEV_PS_Disable_Free_Front {
private static $_instance = null;
private $_page_to_redirect = 41;
public static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new WPMUDEV_PS_Disable_Free_Front();
}
return self::$_instance;
}
private function __construct() {
add_action( 'template_redirect', array( $this, 'maybe_disable_access' ), 20 );
}
public function maybe_disable_access() {
global $psts, $blog_id;
$main_site = get_network()->site_id;
if ( is_admin() || current_user_can( 'manage_options' ) || $main_site == $blog_id ) {
return;
}
if( ! $psts->is_pro_site( $blog_id ) ) {
switch_to_blog( $main_site );
wp_safe_redirect( get_permalink( $this->_page_to_redirect ) );
}
}
}
if ( ! function_exists( 'wpmudev_ps_disable_free_front' ) ) {
function wpmudev_ps_disable_free_front() {
return WPMUDEV_PS_Disable_Free_Front::get_instance();
}
add_action( 'plugins_loaded', 'wpmudev_ps_disable_free_front', 10 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment