我是wordpress的初学者,所以我的问题可能是愚蠢的,但我搜索各种方式,但找不到解决方案,所以写在这里。
我想创建一个wordpress插件,可以在word press中创建自定义用户注册页面。
首先我创建了页面模板并放置在主题目录中,然后我从创建的属性和页面创建了页面和选定的模板。没问题到此为止。
现在想通过插件在其他wordpress中创建相同的东西。
所以我在插件中添加了以下代码
$_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' ); }
如果在主题目录中复制模板文件但没有模板文件,它的工作正常。
我尝试了几种解决方案来使用插件目录中的模板,如
的add_filter( 'single_template', 'add_user_registration_page')
但它不起作用。
任何帮助或代码都会有所帮助。