创建帖子和论坛的插件,然后选择类别和父论坛

时间:2013-06-12 作者:Downloadtaky

我需要为客户创建一个插件,帮助他创建帖子和论坛,并将它们放在一个类别中,然后选择是父论坛还是子论坛。

Just created a GitHub Repo for my files : https://github.com/maisdesign/MDPostEforumsCreator

我当前的安装是:WordPress + BBPress + BuddyPress.

我希望它是这样工作的:

It creates Articles and Forum with same name

正如您所看到的,有一个简单的表单,用户必须编写帖子的标题并选择类别。

点击提交后,插件将创建一个带有该标题的帖子,以及一个带有该标题的论坛。

这是我的代码,在@s\\u ha\\u dum(谢谢)的帮助下,现在可以部分工作了。

下一步是添加选择父论坛的可能性,以便刚创建的论坛是父论坛还是子论坛。

我找不到有关BBPress函数的任何文档。

除了BBPress,是否有任何与wp\\U dropdown\\U categories(wp\\U dropdown\\U类别)等价的内容?

有人能帮我吗?

File index.php

 <?php
/*
Plugin Name: Post And Forum Creator by MaisDesign & Stestaz
Plugin URI: http://maisdesign.it
Description: You give it a title and it automatically create a blank post and forum with that title, that\'s it!
Version: 1.0.0
Author: MaisDesign & Stestaz
Author URI: http://maisdesign.it
License: 
License URI: 
*/
/* Documentazione:
    Quello che sto cercando di ottenere è di svolgere tutto in una sola pagina, sono certo che non serva richiamare BBHOST e compagnia bella per inserire un cavolo di articolo ma sono le 2.20 AM e non so più che pesci pigliare!
    In fondo a questa pagina troverai del codice commentato, se ci sono bestemmie nei commenti lasciale dove stanno, sono di buon auspicio :-P
*/
/* Definiamo la versione */

if (!defined(\'MD_POSTFORUM_CREATOR_VERSION_KEY\'))
    define(\'MD_POSTFORUM_CREATOR_VERSION_KEY\', \'md_postforum_creator_version\');

if (!defined(\'MD_POSTFORUM_CREATOR_VERSION_NUM\'))
    define(\'MD_POSTFORUM_CREATOR_VERSION_NUM\', \'1.0.0\');

add_option(MD_POSTFORUM_CREATOR_VERSION_KEY, MD_POSTFORUM_CREATOR_VERSION_NUM);

/*
    * This example will work at least on WordPress 2.6.3, 
    * but maybe on older versions too.
    */
   add_action( \'admin_init\', \'md_postforum_creator_init\' );
   add_action( \'admin_menu\', \'md_postforum_creator_menu\' );

   function md_postforum_creator_init() {
       /* Register our stylesheet. */
       wp_register_style( \'mdPostforumCreatorStyle\', plugins_url(\'css/mdpostforumstyle.css\', __FILE__) );
           wp_register_script( \'mdPostforumCreatorScript\', plugins_url( \'/js/alajax-1.2.js\', __FILE__ ) );
   };   
   function md_postforum_creator_menu() {
       /* Register our plugin page */
       $page = add_submenu_page( \'options.php\', 
                                 __( \'MDPFC Plugin\', \'md-postforum-creator\' ), 
                                 __( \'MDPFC Plugin\', \'md-postforum-creator\' ),
                                 \'administrator\',
                                 __FILE__, 
                                 \'md_postforum_creator_manage_menu\' );

       /* Using registered $page handle to hook stylesheet loading */
       add_action( \'admin_print_styles-\' . $page, \'md_postforum_creator_styles\' );
        add_action(\'admin_print_scripts-\' . $page, \'md_postforum_creator_scripts\');
   };   
   function md_postforum_creator_styles() {
       /*
        * It will be called only on your plugin admin page, enqueue our stylesheet here
        */
       wp_enqueue_style( \'mdPostforumCreatorStyle\' );
   };
   function md_postforum_creator_scripts() {
        /* Link our already registered script to a page */
        wp_enqueue_script( \'mdPostforumCreatorScript\' );
    };
   /*function md_postforum_creator_manage_menu() {
   };*/
   add_action(\'admin_menu\', \'register_md_postforum_creator_menu\');
function register_md_postforum_creator_menu() {
   add_menu_page( \'MDPFC Options\', // $page_title
                  \'MDPFC Options\', // $menu_title
                  \'manage_options\', // $capability
                  \'md-postforum-creator-menu-page-slug\', // $menu_slug
                  \'md_postforum_creator_menu_page\', // $function
                  plugins_url( \'md-postforum-creator/images/mdpostforum.png\' ), /* $icon_url*/
                  3 ); /* $position*/
};

function md_postforum_creator_menu_page() {
   /* Does the user have the right permissions?*/
   if (!current_user_can(\'manage_options\')) {
      wp_die( \'Sorry, you do not have permission to access this page.\');
   };
  if(isset($_POST[\'new_post\']) == \'1\') {
    $post_title = $_POST[\'post_title\'];
    $post_category = $_POST[\'cat\'];
    $post_content = $_POST[\'post_content\'];

    $new_post = array(
          \'ID\' => \'\',
          \'post_author\' => $user->ID, 
          \'post_category\' => array($post_category),
          \'post_content\' => \'\', 
          \'post_title\' => wp_strip_all_tags($post_title),
          \'post_status\' => \'draft\'
        );
    $post_id = wp_insert_post($new_post);
    if (is_plugin_active(\'bbpress/bbpress.php\')) {
    $forum_id = bbp_insert_forum( array(
                /*\'post_parent\'  => bbp_get_group_forums_root_id(),*/
                \'post_title\'   => $post_title,
                /*\'post_content\' => $group->description,*/
                \'post_status\'  => \'draft\'
            ) );
    /*$default_forum = array(   
        $_POST[\'post_title\']     => array($post_category),
    );


    $forum = bbp_insert_forum( $default_forum );*/
    };
};          
echo \'
<form action="\'.admin_url(\'admin.php?page=md-postforum-creator-menu-page-slug\').\'" method="post">
    <input type="text" name="post_title" size="45" id="input-title"/>
    <input type="hidden" name="new_post" value="1"/>\';

    wp_dropdown_categories(\'orderby=name&hide_empty=0&exclude=1&hierarchical=1\');

    echo \'<input class="subput round" type="submit" name="submit" value="Post"/>
</form>\';
};?>

1 个回复
SO网友:s_ha_dum

如果这是完整的代码ste.php 然后,在没有任何WordPress上下文的情况下加载它,这意味着wp_insert_post 不会被定义。如果检查服务器日志,可能会看到类似的错误。

解决这一问题的最简单也是最好的方法是在提交表单时使用的页面上处理表单。该页面注册为WordPress菜单页面,以便加载WordPress核心。

function md_postforum_creator_menu_page() {
   /* Does the user have the right permissions?*/
   if (!current_user_can(\'manage_options\')) {
      wp_die( \'Sorry, you do not have permission to access this page.\');
   };
   if (!empty($_POST)) {
     md_post_creator_inserimento_post();
   }
   _e(\'<h3>Generates Posts and Forums</h3>\',\'md_postforum_creator\');
   echo \'<h3>My Custom Menu Page</h3>\';
   echo \'<div class="mdpostform container">
            <form action="\'.admin_url(\'admin.php?page=md-postforum-creator-menu-page-slug\').\'" method="post">
            <div class="descmdpost"><p>\';
        _e(\'Nome Clan\',\'md_postforum_creator\');
    echo \'</p></div>
            <div class="imputpost"><input name="name" type="text" id="name" value="\'.$_POST[\'name\'].\'"></div>
            <div class="clickmdpost"><input name="button" type="submit" value="Invia"></div>
        </form>
    </div>\';
};
我应该补充一点,我注意到notices 在测试时,您应该清理这些内容。使可能debugging 你会看到的。我会在这方面做得更好$_POST 数据也一样,如果是我的话。

结束

相关推荐

访问前3天帖子的wpdb查询问题

我正试图通过作者id 2获取所有已发布帖子的标题,最近一次是通过最近几天的发布日期。以下是我的疑问:\"SELECT post_title FROM $wpdb->posts WHERE post_status = \'publish\' AND post_author = 2 ORDER BY post_date DESC LIMIT 3 \" 这将显示最近的3篇帖子,而不是最近3天的帖子。如何正确查询?