Create custom WordPress form and handle submission?

Standard
<?php

/**
 * Plugin Name: Custom Form
 * Plugin URI: http://https://tahiryasin.wordpress.com/
 * Description: Creates a custom form through shortcode and handles the submit event.
 * Version: 1.0
 * Author: Tahir Yasin
 * Author URI: https://tahiryasin.wordpress.com/about/
 * License: GPL2
 */

class CustomForm
{

    public function __construct()
    {
        add_action('init', array($this, 'init'));
        add_shortcode('custom_form', array($this, 'shortcode'));
    }

    public function init()
    {
        if (!empty($_POST['nonce_custom_form']))
        {
            if (!wp_verify_nonce($_POST['nonce_custom_form'], 'handle_custom_form'))
            {
                die('You are not authorized to perform this action.');
            } else
            {
                $error = null;
                if (empty($_POST['name']))
                {
                    $error = new WP_Error('empty_error', __('Please enter name.', 'tahiryasin'));
                    wp_die($error->get_error_message(), __('CustomForm Error', 'tahiryasin'));
                }
                else
                    die('Its safe to do further processing on submitted data.');
            }
        }
    }

    function shortcode($atts)
    {
        return "<form method='post' action=''>
    <input name='name' type='text' value='' />
    " . wp_nonce_field('handle_custom_form', 'nonce_custom_form') . "
        <input type='submit' value='Submit'/>
    </form>";
    }

}

$CustomForm = new CustomForm();
?>
Advertisements

WP Custom Query for meta search

Standard
SELECT * FROM wp_posts p, wp_postmeta m, wp_terms t, wp_term_relationships r, wp_term_taxonomy tt 
WHERE p.post_type='your-post-type' 
AND p.ID=m.post_id 
AND p.id=r.object_id 
AND r.term_taxonomy_id=tt.term_taxonomy_id 
AND tt.term_id = t.term_id 
AND ( t.name LIKE '%90036%' OR p.post_title LIKE '%90036%' 
OR ( (meta_key='Address 1' AND meta_value LIKE '%90036%') 
OR (meta_key ='Address 2' AND meta_value LIKE '%90036%') 
OR (meta_key='State' AND meta_value LIKE '%90036%') 
OR (meta_key='City' AND meta_value LIKE '%90036%') 
OR (meta_key='Zip' AND meta_value LIKE '%90036%') ) ) 
GROUP BY ID 
ORDER BY post_title

Add remove WordPress dashboard widgets

Standard
    function example_remove_dashboard_widgets() {
    // Globalize the metaboxes array, this holds all the widgets for wp-admin
    global $wp_meta_boxes;
     
    // Remove the incomming links widget
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
     
    // Remove right now
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
    }
     
    // Hoook into the 'wp_dashboard_setup' action to register our function
    add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets');
    add_action('wp_dashboard_setup', 'example_add_dashboard_widgets');
     
    function example_add_dashboard_widgets() {
    wp_add_dashboard_widget('example', 'Example', 'example_widget_callback');
    }
     
    function example_widget_callback() {
    echo 'testin widget';
    }