Esempio n. 1
0
 /**
  * Initiate the plugin
  */
 function init()
 {
     // Do actions before run the plugin
     // in case path is wrong (or unset), we still want to be able to access the admin panel
     add_action('wpphpbbu_changed', array($this, 'changed'));
     if (wpphpbbu\Path::is_path_ok() && wpphpbbu\Path::is_url_ok() && wpphpbbu\Proxy::is_cache_ok() && !defined('SHORT_INIT')) {
         try {
             $this->start();
             $this->phpbb_includes();
             $this->init_widget();
             // Do init actions
             add_action('init', array($this, 'start_integration'));
             // Start application integration
             //redirect pages
             add_action('init', function () {
                 if (wpphpbbu\User::is_user_logged_in() === false && wp_get_current_user()->ID !== 0) {
                     //We're logged_in by WP but not phpbb : you may have disconnected on phpbb
                     // //but it doesn't reflect here so we manually pull you out :)
                     wp_logout();
                 } else {
                     wpphpbbu\Path::login_page();
                 }
             });
             add_action('wp_logout', function () {
                 wpphpbbu\Path::logout_page();
             });
             add_action('add_meta_boxes', array($this, 'add_meta_box'));
             if (get_option('wpphpbbu_post_posts', false) === "yes") {
                 //
                 // // Check if our nonce is set.
                 // Call add_post when creating new WordPress post, to create a new forum topic
                 add_action('wp_insert_post', function ($post = null) {
                     $add_to_forums = [];
                     // Sanitize user input ?
                     $add_to_forums = isset($_POST['forum_id']) ? $_POST['forum_id'] : null;
                     if ($add_to_forums) {
                         wpphpbbu\Post::add_post($post, $add_to_forums);
                     }
                 });
             }
         } catch (Exception $e) {
             var_dump('DUH');
         }
     } else {
         if (wpphpbbu\Path::is_path_ok() && wpphpbbu\Path::is_url_ok()) {
             //set initial cache
             (new wpphpbbu\Proxy())->setCache();
         }
     }
     $this->admin_includes();
 }