plugin-controls/plugin_controls.php

127 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2022-12-15 16:18:06 -05:00
<?php
2023-08-14 15:27:17 -04:00
/*
Plugin Name: Plugin Control
Plugin URI: https://cooini.com/services/dev/wordpress
Description: This plugin will disable access to the plugins and other pages
2024-11-12 17:13:52 -05:00
Version: 1.1.1
2023-08-14 15:27:17 -04:00
Author: sbyrd
Author URI: https://cooini.com/
License: MINE-all-mine
*/
2024-11-12 17:13:52 -05:00
function plugin_controls_isUserManagingService() : bool
{
$users = ['clpsupport','clsupport'];
$user = wp_get_current_user();
if (in_array($user->user_login, $users) )
return true;
elseif (preg_match("/courselauncher.io$/", $user->user_email ))
return true;
else
return false;
}
2023-08-14 15:27:17 -04:00
function plugin_controls_remove_menus()
{
$allow_plugin_file = plugin_dir_path(__FILE__)."/.allow_plugin_list";
if (isset($_GET['allow_plugin_list']) and $_GET['allow_plugin_list'] === "123letmesee")
{
touch( $allow_plugin_file );
}
2024-11-12 17:13:52 -05:00
else
{
if (file_exists($allow_plugin_file) and (time() - filectime($allow_plugin_file) >= 60 * 60 * 12 ))
{
// File is older than threshold, delete
unlink($allow_plugin_file);
}
}
$menus_to_hide = ['Plugins'=>'plugins.php',
'Updates'=>"update-core.php",
'Activity Log'=>'aryo-activity-log/aryo-activity-log.php'
];
2023-08-14 15:27:17 -04:00
2024-11-12 17:13:52 -05:00
if (plugin_controls_isUserManagingService() )
{
// This is us
add_action( 'admin_notices', function() use ($menus_to_hide) {
?>
<div class="notice notice-warning">
<h3>Wordpress Management</h3>
<p>Following menus are only visible to us</p>
<ul>
<?php
foreach ($menus_to_hide as $name => $value)
{
?><li><?php echo $name ?></li><?php
}
?>
</ul>
</div>
<?php
} );
return;
}
else
{
foreach($menus_to_hide as $name => $value)
{
remove_menu_page($value);
}
2023-08-14 15:27:17 -04:00
}
2024-11-12 17:13:52 -05:00
2023-08-14 15:27:17 -04:00
}
2024-11-12 17:13:52 -05:00
2023-08-14 15:27:17 -04:00
function plugin_page_control()
{
$allow_plugin_file = plugin_dir_path(__FILE__)."/.allow_updates";
if (isset($_GET['allow_updates']) and $_GET['allow_updates'] === "123letmeupdate")
{
touch( $allow_plugin_file );
}
else
{
if (file_exists($allow_plugin_file) and (time() - filectime($allow_plugin_file) >= 60 * 60 * 12 ))
{
// File is older than threshold, delete
unlink($allow_plugin_file);
}
}
//
2024-11-12 17:13:52 -05:00
if ( file_exists($allow_plugin_file))
2023-08-14 15:27:17 -04:00
{
define( 'DISALLOW_FILE_EDIT', false ); // allow
2024-11-12 17:13:52 -05:00
define( 'DISALLOW_FILE_MODS', false );
if (plugin_controls_isUserManagingService())
{
add_action( 'admin_notices', function() {
?>
<div class="notice notice-warning">
<p>Updates, file edits, are currently unlocked.</p>
</div>
<?php
} );
}
2023-08-14 15:27:17 -04:00
}
else
{
2024-11-12 17:13:52 -05:00
2023-08-14 15:27:17 -04:00
define( 'DISALLOW_FILE_EDIT', true ); // disable
define( 'DISALLOW_FILE_MODS', true);
}
2022-12-15 16:18:06 -05:00
}
2023-08-14 15:27:17 -04:00
2022-12-15 16:18:06 -05:00
add_action( 'admin_menu', 'plugin_controls_remove_menus' );
2023-08-14 15:27:17 -04:00
add_action( 'admin_menu', 'plugin_page_control' );
2022-12-15 16:18:06 -05:00