Can a page contain php code?

You can’t use PHP in the WordPress back-end editor. Maybe with a plugin you can, but not out of the box. The easiest solution for this is creating a shortcode. Then you can use something like [input type=”text” name”from”] in your editor. function input_func( $atts ) { extract( shortcode_atts( array( ‘type’ => ‘text’, ‘name’ => … Read more

How to handle forms from sidebar widgets – Processing $_POST variables using get_field_name()

WP doesn’t provide any helper methods for creating and processing forms in the front-end. To process your front-end form simply check for $_POST-ed data. I suggest you do this from within an action, and only if the widget is active. In your constructor – the someWidget() method (which you should rename to __construct, and call … Read more

Specify ABSPATH in jQuery url

If your JavaScript is running in the admin, you don’t need to set an explicit path to admin-ajax.php. It’s always available as a JS variable called “ajaxurl”. You can see an example of this in the Codex, under the heading “AJAX on the Administration Side” Ajaxurl is, unfortunately, not available on the frontend by default. … Read more

Uploading PDF files from the front-end

I have done a simple function for that, but i allow all types of media. So this could be a start: function insert_attachment( $file_handler, $post_id, $settpdf=”false” ) { // check to make sure its a successful upload if ( $_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK ) __return_false(); require_once( ABSPATH . ‘wp-admin’ . ‘/includes/image.php’ ); require_once( ABSPATH . ‘wp-admin’ … Read more

The Correct Way to Use Nonce Field without Settings API

This is a very basic nonce setup for a plugin: Create your nonce input in the form: wp_nonce_field( basename(__FILE__), $nonce_key ); Then check your nonce once submitted: if ( empty($_POST[$nonce_key]) || ! wp_verify_nonce( $_POST[$nonce_key], basename(__FILE__) ) ) return; basename(FILE) just uses the current filename (eg: plugin_options.php) to create the nonce string. You need to provide … Read more

how to add a custom form in a page

A basic example of inserting data into post meta fields. In your chosen template file you can do something similar to, <?php //this does not include data validation and sensitization but will check for the //existence of $_POST values being set. if ( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty( $_POST[‘action’] ) && $_POST[‘action’] == “add_meta”) { … Read more

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