Built-in data validation function for URLs

Use esc_url( $url ) for URLs that should be displayed and esc_url_raw( $url ) if the URL should be sent to the database. The first will replace bare ampersands & with &. The second is a wrapper for the first; it will just suppress the escaping of ampersands. Both functions will check the protocol. See … Read more

How to update selective options on plugin settings page

First kick in your validation callback by changing the register_setting() to register_setting( ‘pluginname_options’, ‘pluginname-settings’, ‘pluginname_validate’ ); And then update your validation function to actually do something. Below it gets the current state of the options, and then only updates the pieces of the array that are submitted. When you are on a tab and click … Read more

Storing textbox values in Database

From PHP to WordPress If you are experienced in programming and in PHP, you know that saving data coming from a form basically involves these steps: validation sanitization connection to database store value in database even if “plain” PHP would work for all of them, WordPress has helpers and specific best practices for them. Validation … Read more

How to disable autocomplete for inputs in contact form 7? [closed]

Autocomplete tag in form settings does not work anymore (as today Contact Form 7 plugin version 5.1.3. The only solution which worked for me was to add custom attributes thanks to https://stackoverflow.com/a/46316728/1720476. E.g. if You have FirstName and LastName fields, where You want to disable autocomplete. Add this into functions.php file: add_filter( ‘wpcf7_form_elements’, ‘imp_wpcf7_form_elements’ ); … Read more

How to allow specific extensions and file size to wp_mail attachment?

Add the following condition before the file upload functionality – $allowedExts = array(“pdf”, “jpg”, “png”); $temp = explode(“.”, $_FILES[“attachment”][“name”]); $extension = end($temp); if ((($_FILES[“file”][“type”] == “image/pdf”) || ($_FILES[“file”][“type”] == “image/jpg”) || ($_FILES[“file”][“type”] == “image/png”)) && ($_FILES[“file”][“size”] < 1000000) && in_array($extension, $allowedExts)) { //your file upload code and other stuffs } else { echo “Invalid file”; … Read more

Trying to add admin file upload form plugin

Turns out the code is correct, the problem is the tutorial site I copy/pasted from was using weird, non standard space characters instead of normal spaces. I replaced the “fake spaces” with “normal spaces” and now everything works. In order to debug this I needed to look at the Apache error log rather than the … Read more

POST from jQuery to PHP

When you load your process.php file directly, it’s not within the context of the WordPress environment, so no WordPress functions are available. WordPress has a native AJAX API that should be used for this sort of thing. First, enqueue your javascript file, then use wp_localize_script to pass the location of admin-ajax.php, which will be processing … Read more

exclude category from WordPress Form function

What about using the exclude array key in your get_categories() call? e.g. change this: $massive_categories_obj = get_categories(‘hide_empty=0’); to this: $massive_categories_obj = get_categories(‘hide_empty=0&exclude=14’); Note that exclude expects a comma-separated string as a value. For your second function, what are you passing as $exclude? function retrieve_cat_data_sp( $exclude ){ $args = array( ‘hide_empty’ => ‘0’, ‘exclude’ => $exclude … Read more

Placeholders in Jetpack Contact Form [closed]

You can do this by means of jQuery (which means this is rather a jQuery/JavaScript question). Put the following in one of your (already included) JS files, or create a new JS file and enqueue it, or hard-code it in between <script>…</script> tags: jQuery(document).ready(function($) { $(‘#my-form-field’).attr(‘placeholder’, ‘Please enter your name…’); });

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