I am beginner in wordpress so my question might be foolish but I searched various way but could not find the solution so that writing here.
I want to create a wordpress plugin that can create a custom user registration page in word press.
First I created page template and placed in theme directory, Then I created page and selected template from attribute and page created. No problem upto this.
Now want to create same thing in others wordpress by plugins.
So I added below code in plugin
$_p = array(); $_p['post_title'] = $the_page_title; $_p['post_content'] = "This text may be overridden by the plugin. You shouldn't edit it."; $_p['post_status'] = 'publish'; $_p['post_type'] = 'page'; $_p['comment_status'] = 'closed'; $_p['ping_status'] = 'closed'; $_p['post_category'] = array(1); // the default 'Uncatrgorised' // Insert the post into the database $the_page_id = wp_insert_post( $_p ); if ( !$the_page_id ) { wp_die( 'Error creating template page' ); } else { update_post_meta( $the_page_id, '_wp_page_template', 'page-userregistration.php' ); }
Its working fine if template file is copied in theme directory but not without it.
I tried several solutions to use template from plugin directory like
add_filter('single_template','add_user_registration_page')
But its not working.
Any help or code will be helpful.