Commit 900dc439 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Combine MU plugins into one

parent 788b87f8
Loading
Loading
Loading
Loading
+111 −0
Original line number Diff line number Diff line
<?php
/**
 * Plugin Name: Media URL Fix
 * Copyright 2019-2021 Dominik Sekotill <dom.sekotill@kodo.org.uk>
 *
 * Plugin Name: Docker Image Integration
 * Plugin URI: https://code.kodo.org.uk/singing-chimes.co.uk/wordpress/tree/master/plugins
 * Description: Adjusts the media URL path base to /media, where the Nginx instance is hosting it.
 * Description: Hooks in behaviour for operating cleanly in a Docker environment
 * Licence: MPL-2.0
 * Licence URI: https://www.mozilla.org/en-US/MPL/2.0/
 * Author: Dominik Sekotill
 * Author URI: https://code.kodo.org.uk/dom
 */


// Media URL Fix

add_action( 'plugins_loaded', function() {
	add_filter( 'upload_dir', function( $paths ) {
		$baseurl = parse_url( $paths['baseurl'] );
@@ -25,6 +30,72 @@ add_action( 'plugins_loaded', function() {
	});
});


// Block File Modification

add_filter(
	'file_mod_allowed',

	function( $setting, $context ) {
		if ( $context == 'automatic_updater' ) {
			return true;
		}
		return $setting;
	},

	10, 2
);


// Disable Plugins & Themes

add_filter(
	'user_has_cap',

	function( $allcaps, $caps, $args ) {
		switch ($args[0]) {
		case 'delete_plugins':
		case 'delete_themes':
		case 'edit_plugins':
		case 'edit_themes':
		case 'install_plugins':
		case 'install_themes':
		case 'update_plugins':
		case 'update_themes':
			$allcaps[$caps[0]] = false;
		}
		return $allcaps;
	},

	10, 3
);


// S3-Uploads Integration

if ( defined( 'S3_UPLOADS_ENDPOINT_URL' ) || defined( 'WP_CLI' ) ):

add_filter(
	's3_uploads_s3_client_params',

	function ( $params ) {
		$params['endpoint'] = S3_UPLOADS_ENDPOINT_URL;
		$params['bucket_endpoint'] = true;
		$params['disable_host_prefix_injection'] = true;
		$params['use_path_style_endpoint'] = true;
		$params['debug'] = WP_DEBUG && WP_DEBUG_DISPLAY;
		$params['region'] = '';
		return $params;
	}
);

require WPMU_PLUGIN_DIR . '/s3-uploads/s3-uploads.php';

endif;


// Functions

function unparse_url( array $parts ) {
	return (
		(isset($parts['scheme'])   ?  "{$parts['scheme']}://" : '') .

plugins/override_file_mod.php

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
<?php
/**
 * Plugin Name: File Modification Blocker
 * Plugin URI: https://wordpress.stackexchange.com/a/300718
 * Description: Block file modification except for security updates.
 * Licence: CC BY-SA 3.0
 * Licence URI: https://creativecommons.org/licenses/by-sa/3.0/
 * Author: Marc Guay
 * Author URI: https://wordpress.stackexchange.com/users/69982/marcguay
 */

add_filter( 'file_mod_allowed', 'override_file_mod_allowed', 10, 2 );

function override_file_mod_allowed( $setting, $context ) {
	if ( $context == 'automatic_updater' ) {
		return true;
	}
	return $setting;
}
+0 −27
Original line number Diff line number Diff line
<?php
/**
 * Plugin Name: Disable Plugins & Theme Management
 * Plugin URI: https://code.kodo.org.uk/singing-chimes.co.uk/wordpress/tree/master/plugins
 * Description: Prevents changes to installed code from the admin dashboard.  All such changes should be managed through deployment configuration.
 * Licence: MPL-2.0
 * Licence URI: https://www.mozilla.org/en-US/MPL/2.0/
 * Author: Dominik Sekotill
 * Author URI: https://code.kodo.org.uk/dom
 */

add_filter( 'user_has_cap', 'override_plugin_install', 10, 3 );

function override_plugin_install( $allcaps, $caps, $args ) {
	switch ($args[0]) {
	case 'delete_plugins':
	case 'delete_themes':
	case 'edit_plugins':
	case 'edit_themes':
	case 'install_plugins':
	case 'install_themes':
	case 'update_plugins':
	case 'update_themes':
		$allcaps[$caps[0]] = false;
	}
	return $allcaps;
}

plugins/s3-uploads.php

deleted100644 → 0
+0 −26
Original line number Diff line number Diff line
<?php
/**
 * Plugin Name: S3-Uploads
 * Plugin URI: https://github.com/humanmade/S3-Uploads
 * Description: S3-Uploads with custom endpoint configuration
 * Licence: GPL-2.0+
 * Licence URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * Author: Human Made Limited
 * Author URI: http://hmn.md/
 **/

if ( defined( 'S3_UPLOADS_ENDPOINT_URL' ) || defined( 'WP_CLI' ) ):

add_filter( 's3_uploads_s3_client_params', function ( $params ) {
	$params['endpoint'] = S3_UPLOADS_ENDPOINT_URL;
	$params['bucket_endpoint'] = true;
	$params['disable_host_prefix_injection'] = true;
	$params['use_path_style_endpoint'] = true;
	$params['debug'] = WP_DEBUG && WP_DEBUG_DISPLAY;
	$params['region'] = '';
	return $params;
} );

require WPMU_PLUGIN_DIR . '/s3-uploads/s3-uploads.php';

endif;