Skip to content

Instantly share code, notes, and snippets.

@Xilonz
Created February 29, 2020 15:03
Show Gist options
  • Save Xilonz/e66d1f1822faf9d2698aed0829778a9c to your computer and use it in GitHub Desktop.
Save Xilonz/e66d1f1822faf9d2698aed0829778a9c to your computer and use it in GitHub Desktop.
SatisPress Bedrock MU Plugin
<?php
/**
* Plugin Name: Bedrock StatisPress
* Plugin URI: https://steenbergen.design
* Description: An MU Plugin that ties Bedrock and SatisPress together. Allows for autoupdates and cleans up the admin dasboard.
* Version: 1.0.0
* Author: Steenbergen Design
* Author URI: https://steenbergen.design
* License: MIT License
*/
namespace BedrockSatisPress;
use SatisPress\Capabilities;
/**
* Always disable indexing
*/
add_action('pre_option_blog_public', '__return_zero');
/**
* WordPress enable the auto updater for everything except core
*/
add_filter( 'auto_update_core', '__return_false' );
add_filter( 'auto_update_plugin', '__return_true' );
add_filter( 'auto_update_theme', '__return_true' );
add_filter( 'auto_update_translation', '__return_true' );
add_filter( 'automatic_updater_disabled', '__return_false' );
/**
* Make an exception for file modification when auto updating
*/
add_filter('file_mod_allowed', function ( $allowed, $context) {
if( $context == 'automatic_updater' ) return true;
return $allowed;
}, 10, 2);
/**
* Set the URL to redirect to on login.
*
* @return string URL to redirect to on login. Must be absolute.
*/
add_filter( 'v_forcelogin_redirect', function (){
return get_admin_url();
});
/**
* Redirect all frontend urls to wp-admin
*/
add_action( 'template_redirect', function (){
if( !!is_admin() ) wp_safe_redirect( get_admin_url() );
});
/**
* Move SatisPress from settings to its own root menu item
*/
add_action( 'satispress_composed', function ( $satispress, $container ){
$settings = $container->get( 'screen.settings' );
// Remove original
remove_action('admin_menu', [ $settings, 'add_menu_item' ]);
// Add new
add_action( 'admin_menu', function () use ( $settings ) {
$page_hook = add_menu_page(
esc_html__( 'SatisPress', 'satispress' ),
esc_html__( 'SatisPress', 'satispress' ),
Capabilities::MANAGE_OPTIONS,
'satispress',
[ $settings, 'render_screen' ],
'dashicons-archive',
99
);
add_submenu_page(
'satispress',
esc_html__( 'Settings', 'satispress' ),
esc_html__( 'Settings', 'satispress' ),
Capabilities::MANAGE_OPTIONS,
'satispress',
[ $settings, 'render_screen' ]
);
add_submenu_page(
'satispress',
esc_html__( 'Packages', 'satispress' ),
esc_html__( 'Packages', 'satispress' ),
Capabilities::MANAGE_OPTIONS,
'satispress#satispress-packages',
[ $settings, 'render_screen' ]
);
add_action( 'load-' . $page_hook, [ $settings, 'load_screen' ] );
});
}, 10, 2);
/**
* Remove all unnessecairy roles
* And remove all post and page capabilities
*/
add_action( 'init', function () {
$roles = wp_roles();
foreach( array_keys( $roles->role_objects ) as $role ) {
if( $role == 'administrator' ) continue;
remove_role( $role );
}
$caps = array(
'edit_pages',
'edit_posts',
'delete_pages',
'delete_posts',
'edit_others_posts',
'edit_others_pages',
'delete_others_posts',
'delete_others_pages',
'manage_categories',
'manage_links',
'moderate_comments',
'publish_pages',
'publish_posts',
'upload_files',
'edit_theme_options',
);
foreach ( $roles->role_objects as $role ) {
foreach ( $caps as $cap ) {
$role->remove_cap( $cap );
}
}
});
/**
* Add Theme install menu item
*/
add_action( 'admin_menu', function () {
global $submenu;
$submenu['themes.php'][10] = array( _x( 'Add New', 'theme' ), 'install_themes', 'theme-install.php' );
});
add_filter( 'submenu_file', function( $submenu_file, $parent_file ){
global $self;
if($self == 'theme-install.php') $submenu_file = 'theme-install.php';
return $submenu_file;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment