How to use esc_attr__() function properly to translate a variable that contains string?

If you have static text with dynamic content then you can use. printf( esc_attr___(‘static text goes here with %s’, ‘text-domain’ ), $title ); If you have only $title then no need to translate it. Just escape it. echo esc_attr( $title ); Note esc_attr, esc_attr__ and esc_attr_e used for escaping dynamic values from HTML element attributes. … Read more

Customizer sanitize_callback for input type number

Add a setting, specifying the sanitize_callback: $wp_customize->add_setting( ‘my_input’, array( ‘default’ => ‘100.00’, ‘sanitize_callback’ => ‘sanitize_float’, ) ); Add the control: $wp_customize->add_control( ‘my_input’, array( ‘label’ => ‘Please enter a number:’, ‘section’ => ‘my_section’, ‘type’ => ‘number’, ‘input_attrs’ => array( ‘min’ => ‘0.01’, ‘step’ => ‘0.01’, ‘max’ => ‘10000’, ), ) ); Create a function to perform … Read more

Data validation for inline javascript

You can use addslashes() and stripslashes() to prepare any data for database entry. These are native PHP functions, not wordpress functions, so they do not necessarily need to be hooked anywhere specific in the wordpress load to work.

Sanitizing a custom query’s clauses

I would suggest to think in this way: if I can not sanitize whole query (as you can not, what does sanitized mean? Is DELETE or DROP malicious or wanted query? Your plugin would have to be able to determinate the intended purpose of each query ant it is unreachable.), you can predict it’s content. … Read more

Notice: Undefined index: in options-framework.php

Most likely you have an undefined array index. You can check if the array index exists with isset() like this: if(isset($some_array[$some_index])){ } So check all your arrays in the options-framework.php file. You can try for example: if ( isset($option[‘type’]) && isset($input[$id]) && has_filter( ‘of_sanitize_’ . $option[‘type’] ) ) { $clean[$id] = apply_filters( ‘of_sanitize_’ . $option[‘type’], … Read more

Trouble creating custom sanitization function when uploading video files

validate_file doesn’t quite work the way you’re expecting it to – it checks if $file is in the allowed files array, not just its extension/mime type. You’re looking for wp_check_filetype. However, all that ultimately does is check the extension (i.e. it doesn’t read the headers of the file/ascertain the mime type otherwise). Unless you implement … Read more

Save selectlist value (taxonomy) in wp:wp_set_object_terms

solved it so: $part_brand = get_terms(‘brands’, ‘hide_empty=0′); <label for=”part_brand”>Бренд</label> <select name=”part_brand” id=’part_brand’> <option value=”” <?php **$brand_names = wp_get_object_terms($post->ID, ‘brands’);** if (!count($brand_names)) echo “selected”; ?>>None</option> <?php foreach($part_brand as $brand) { if (!is_wp_error($brand_names) && !empty($brand_names) && !strcmp($brand->slug, $brand_names[0]->slug)) echo “<option value=”” . $brand->slug . “” selected>” . $brand->name . “</option>\n”; else echo “<option value=”” . $brand->slug . … Read more