lundi 4 avril 2016

Unsure how to link a form to a plugin in WordPress. What's the form's "action"?

I'm trying to create my very first very own plugin to upload posts into WordPress.

I'm learning by looking at another post uploader plugin out there, but I was really confused about the "action=" of the html form.

In the plugin I was looking at for reference the action of the form uses this link:

http://ift.tt/23cgwMY

When I create a plugin (to upload posts) myself, I'm not sure to which "url" I need to set the "action" in my form. I want it to execute the following php (this is how my plug in fire looks like now):

if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "upload_post") {

    if($_POST["editindication"] == 'newpost'){
        $post_array = array(
            'post_title'    => $_POST["post_title"],
            'post_content'  => '',
        );
    $post_id = wp_insert_post( $post_array, true );
    }
    $link = "http://ift.tt/25HNWFz";
    wp_redirect( $link );
}
do_action('wp_insert_post', 'wp_insert_post');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire