diff --git a/mu/aspireupdate-mu-loader.php b/mu/aspireupdate-mu-loader.php new file mode 100644 index 0000000..16e88c3 --- /dev/null +++ b/mu/aspireupdate-mu-loader.php @@ -0,0 +1,129 @@ +load_hooks( $plugin_file ); + } + } + add_filter( 'option_active_plugins', array( $this, 'set_as_active' ) ); + } + + /** + * Load action and filter hooks. + * + * Remove links and disable checkbox from Plugins page so user can't delete main plugin. + * Ensure plugin shows as active. + * + * @param string $plugin_file Plugin file. + * @return void + */ + public function load_hooks( $plugin_file ) { + add_filter( 'network_admin_plugin_action_links_' . $plugin_file, array( $this, 'mu_plugin_active' ) ); + add_filter( 'plugin_action_links_' . $plugin_file, array( $this, 'mu_plugin_active' ) ); + add_action( 'after_plugin_row_' . $plugin_file, array( $this, 'after_plugin_row_updates' ) ); + add_action( 'after_plugin_row_meta', array( $this, 'display_as_mu_plugin' ), 10, 1 ); + } + + /** + * Make plugin row active and disable checkbox. + * + * @param string $plugin_file Plugin file. + * @return void + */ + public function after_plugin_row_updates( $plugin_file ) { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + print ""; + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + print ""; + } + + /** + * Add 'Activated as mu-plugin' to plugin row meta. + * + * @param string $plugin_file Plugin file. + * @return void + */ + public function display_as_mu_plugin( $plugin_file ) { + if ( in_array( $plugin_file, (array) static::$plugin_files, true ) ) { + printf( + '
%s', + esc_html__( 'Activated as Must-Use plugin', 'mu-loader' ) + ); + } + } + + /** + * Unset action links. + * + * @param array $actions Link actions. + * @return array + */ + public function mu_plugin_active( $actions ) { + unset( $actions['activate'], $actions['delete'], $actions['deactivate'] ); + + return $actions; + } + + /** + * Set mu-plugins as active. + * + * @param array $active_plugins Array of active plugins. + * @return array + */ + public function set_as_active( $active_plugins ) { + $active_plugins = array_merge( $active_plugins, static::$plugin_files ); + + return array_unique( $active_plugins ); + } +} + +( new MU_Loader() )->run(); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index af33bc2..7bc7c64 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -45,6 +45,9 @@ /languages/* + + /mu/* +