Prevent invalid or empty values from being saved to the database and retain the form field values upon error

You’d do it something like this: function sanitize_number_callback ($input){ if( !preg_match( ‘/…regex for valid here…/’, $input ) ){ add_settings_error( ‘my_option’, esc_attr( ‘my_option’ ), //becomes part of id attribute of error message __( ‘Number must be a positive integer’, ‘wordpress’ ), //default text zone ‘error’ ); $input = get_option( ‘my_option’ ); //keep old value } return … Read more

remove_accents does not seem to work (when used inside sanitize_file_name filter)

I’ve just got an advice on Twitter from Daniel Střelec to simply use sanitize_title – which is a better solution anyway, as it removes whitespace and other non-ideal characters for filename. Use it this way: add_filter(‘sanitize_file_name’, ‘sanitize_title’); I’m keeping the question opened though, as what I’ve described above sounds like a WP bug to me. … Read more

Data sanitization for user registration and user login

You can check my tutorial for front-end user registration and login in WordPress: http://www.cozmoslabs.com/1012-wordpress-user-registration-template-and-custom-user-profile-fields/ As to the wp_signon, wp_insert_user, wp_create_user and wp_update_user they take care of all sanitation and validation of your content. Also you don’t need to use those filters in wp_create_user to create your users.

How to get rid of shortcodes in post content once and for all

Please backup your database before trying In your current theme, open the functions.php file and add the code below. In theshortcodeyouhate inform the shortcode you want to get rid of, note that even extended types works nicely! Once you added this code, hit F5 and you are done. add_action (‘init’,’remove_shortcode_from_db’); //you can choose any other … Read more

How to sanitize uploaded file filename from a plugin?

I found a way. Change the lines on wordpress-form-manager plugin direcoty -> types -> file.php (around line 109) From: if($fileNameFormat == “%filename%”){ $newFileName = $pathInfo[‘filename’]; } To: if($fileNameFormat == “%filename%”){ //Sanitize the filename (See note below) $remove_these = array(‘ ‘,’`’,'”‘,’\”,’\\’,”https://wordpress.stackexchange.com/”,’%’); $newFileName = str_replace($remove_these, ”, $pathInfo[‘filename’]); //Make the filename unique $newFileName = time().’-‘.$newFileName; }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)