$size) {
$settings['max_limits'][$role] = (int) sanitize_text_field($size) * 1024 * 1024;
}
}
// ⏱ Execution time
if (isset($_POST['max_execution_time_field'])) {
$settings['max_execution_time'] = (int) sanitize_text_field($_POST['max_execution_time_field']);
}
// 💾 Memory limit
if (isset($_POST['max_memory_limit_field'])) {
$settings['max_memory_limit'] = (int) sanitize_text_field($_POST['max_memory_limit_field']) * 1024 * 1024;
}
update_option('wmufs_settings', $settings);
set_transient('wmufs_settings_updated', 'Settings saved successfully.', 30);
wp_safe_redirect(admin_url('admin.php?page=easy_media'));
exit;
}
/**
* AJAX handler for restoring default settings
*/
static function restore_default_settings_ajax() {
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'wmufs_restore_defaults')) {
wp_send_json_error(array('message' => __('Security check failed.', 'wp-maximum-upload-file-size')));
}
// Check user capabilities
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => __('You do not have permission to perform this action.', 'wp-maximum-upload-file-size')));
}
try {
// Delete main plugin settings (this is the primary setting)
delete_option('wmufs_settings');
// Delete legacy settings only if they exist (for backward compatibility)
if (get_option('wmufs_maximum_execution_time') !== false) {
delete_option('wmufs_maximum_execution_time');
}
if (get_option('wmufs_memory_limit') !== false) {
delete_option('wmufs_memory_limit');
}
if (get_option('wmufs_notice_disable_time') !== false) {
delete_option('wmufs_notice_disable_time');
}
// Clear any transients (safe to call even if they don't exist)
delete_transient('wmufs_settings_updated');
delete_transient('codepopular_promo_data');
delete_transient('codepopular_blog_posts');
// Also clear any Appsero tracking settings if they exist
$appsero_options = array(
'wp_maximum_upload_file_size_allow_tracking',
'wp_maximum_upload_file_size_tracking_notice',
'wp_maximum_upload_file_size_tracking_last_send',
'wp_maximum_upload_file_size_tracking_skipped'
);
foreach ($appsero_options as $option) {
if (get_option($option) !== false) {
delete_option($option);
}
}
wp_send_json_success(array(
'message' => __('Settings have been restored to default values successfully.', 'wp-maximum-upload-file-size')
));
} catch (Exception $e) {
wp_send_json_error(array(
'message' => __('An error occurred while restoring settings: ', 'wp-maximum-upload-file-size') . $e->getMessage()
));
}
}
static function show_admin_notice() {
if ( $message = get_transient('wmufs_settings_updated') ) {
echo '
' . esc_html($message) . '
';
delete_transient('wmufs_settings_updated');
}
}
static function wmufs_style_and_script() {
wp_enqueue_style('wmufs-admin-style', WMUFS_PLUGIN_URL . 'assets/css/wmufs.css', array(), WMUFS_PLUGIN_VERSION);
// Ensure jQuery is loaded
wp_enqueue_script('jquery');
// Enqueue your script with explicit dependency on jQuery
wp_enqueue_script('wmufs-admin', WMUFS_PLUGIN_URL . 'assets/js/admin.js', array('jquery'), WMUFS_PLUGIN_VERSION, true);
wp_localize_script(
'wmufs-admin',
'wmufs_admin_notice_ajax_object',
array(
'wmufs_admin_notice_ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('wmufs_notice_status'),
'plugin_url' => WMUFS_PLUGIN_URL,
'active_tab' => isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'general',
)
);
// Add ajaxurl for inline scripts
wp_add_inline_script('wmufs-admin', 'var ajaxurl = "' . admin_url('admin-ajax.php') . '";', 'before');
}
static function get_plugin_version() {
$plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
return $plugin_data['version'];
}
static function is_plugin_page() {
$current_screen = get_current_screen();
return ($current_screen->id === 'media_page_easy_media');
}
/**
* Add plugin action links (Settings + Upgrade to Pro).
*
* @param array $links Existing plugin action links.
* @return array Modified plugin action links.
*/
public static function plugin_action_links( $links ) {
// Settings link (always show).
$settings_link = sprintf(
'%s',
esc_url( admin_url( 'admin.php?page=easy_media' ) ),
esc_html__( 'Settings', 'easy-media' )
);
// Add the Settings link first.
array_unshift( $links, $settings_link );
// Only show "Upgrade to Pro" if premium is NOT active.
if ( ! WMUFS_Helper::is_premium_active() ) {
$upgrade_link = sprintf(
'%s',
esc_url( 'https://codepopular.com/product/easymedia/?utm_source=upgrade-pro-button' ),
esc_html__( 'Upgrade to Pro', 'easy-media' )
);
array_unshift( $links, $upgrade_link );
}
return $links;
}
/**
* Add plugin meta links (Support, etc.) under plugin name in Plugins list.
*
* @param array $links Existing plugin meta links.
* @param string $file Plugin file path.
* @return array Modified plugin meta links.
*/
public static function plugin_meta_links( $links, $file ) {
if ( $file === plugin_basename( __FILE__ ) ) {
$links[] = sprintf(
'%s',
esc_url( 'https://wordpress.org/support/plugin/wp-maximum-upload-file-size/' ),
esc_html__( 'Support', 'easy-media' )
);
}
return $links;
}
static function admin_footer_text( $text ) {
if ( ! self::is_plugin_page() ) {
return $text;
}
return '';
}
static function upload_max_file_size_add_pages() {
add_submenu_page(
'upload.php', // Parent Slug.
'EasyMedia - Increase Max Upload File Size',
'EasyMedia',
'manage_options',
'easy_media',
array( __CLASS__, 'upload_max_file_size_dash' )
);
}
static function upload_max_file_size_dash() {
$active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'general';
$tabs = array(
'general' => __('General', 'wp-maximum-upload-file-size'),
'system_status' => __('System Status', 'wp-maximum-upload-file-size')
);
if (!WMUFS_Helper::is_premium_active()) {
$tabs['upload_logs'] = __('Pro PRO', 'wp-maximum-upload-file-size');
}
$tabs = apply_filters('wmufs_admin_tabs', $tabs);
?>
0 && function_exists('set_time_limit')) {
@set_time_limit($max_execution_time);
}
// Apply memory limit setting
$memory_limit = (int) (isset($settings['max_memory_limit']) ? $settings['max_memory_limit'] : get_option('wmufs_memory_limit'));
if ($memory_limit > 0) {
$memory_limit_mb = round($memory_limit / 1048576);
@ini_set('memory_limit', $memory_limit_mb . 'M');
}
// Apply upload size limits based on a limit type
if ($limit_type === 'global') {
// Global limit for all users
$global_limit = (int) (isset($max_limits['all']) ? $max_limits['all'] : 0);
if ($global_limit > 0) {
add_filter('upload_size_limit', function ($size) use ($global_limit) {
return $global_limit;
});
}
} elseif ($limit_type === 'role_based') {
$role_limits = $max_limits;
add_filter('upload_size_limit', function ($size) use ($role_limits) {
if (is_user_logged_in()) {
$user = wp_get_current_user();
foreach ($user->roles as $role) {
if (isset($role_limits[$role]) && $role_limits[$role] > 0) {
return (int) $role_limits[$role];
}
}
}
return $size;
});
}
}
}
add_action('init', array( 'MaxUploader_Admin', 'init' ));