'; echo '

Add Prefix on File Upload

'; echo '

Visit our website to see our plugins

'; echo '
'; settings_fields('add-prefix-file-upload-settings-group'); do_settings_sections('add-prefix-file-upload'); // Table for the form fields echo ''; // Table row for the file prefix field echo ''; echo ''; echo ''; echo ''; // End of the table echo '
New File Name Prefix
'; // Submit button submit_button(); // End of the form echo '
'; echo ''; } /** * Registers the settings used by the plugin. */ function add_prefix_file_upload_register_settings() { register_setting( 'add-prefix-file-upload-settings-group', // Option Group 'new_file_name_prefix', // Option Name 'sanitize_text_field' // Sanitize user input ); } add_action('admin_init', 'add_prefix_file_upload_register_settings'); /** * Renames the uploaded file using the custom prefix. */ function add_prefix_file_upload_rename_uploaded_file($file) { $prefix = get_option('new_file_name_prefix'); $prefix = sanitize_text_field(get_option('new_file_name_prefix')); $file['name'] = $prefix . '-' . $file['name']; return $file; } add_filter('wp_handle_upload_prefilter', 'add_prefix_file_upload_rename_uploaded_file'); ?>