Example #1
0
 function WPPHPBBU_SettingsPage()
 {
     do_action('wpphpbbu_before_admin_settings');
     if (isset($_POST['action']) && $_POST['action'] == 'update') {
         $e = new WP_Error();
         if (!wp_verify_nonce($_POST['_wpnonce'], 'wpphpbbu_settings_page')) {
             $e->add('access_denied', __('You submition does not meet the WordPress security level.', 'wpphpbbu'));
         } else {
             $wpphpbbu_path = stripslashes($_POST['wpphpbbu_path']);
             $wpphpbbu_url = stripslashes($_POST['wpphpbbu_url']);
             $wpphpbbu_post_posts = isset($_POST['wpphpbbu_post_posts']) ? 'yes' : 'no';
             $wpphpbbu_post_locked = isset($_POST['wpphpbbu_post_locked']) ? 'yes' : 'no';
             update_option('wpphpbbu_path', $wpphpbbu_path);
             $is_path = wpphpbbu\Path::is_path_ok();
             if (!$is_path) {
                 $e->add('file_not_exists', __('The file config.php does not exists in the path you have enter', 'wpphpbbu'));
             }
             update_option('wpphpbbu_path_ok', $is_path);
             update_option('wpphpbbu_url', $wpphpbbu_url);
             do_action('wpphpbbu_changed');
             update_option('wpphpbbu_post_posts', $wpphpbbu_post_posts);
             update_option('wpphpbbu_post_locked', $wpphpbbu_post_locked);
         }
     }
     $wpphpbbu_path = trim(get_option('wpphpbbu_path', ABSPATH . 'phpbb3/config.php'));
     $wpphpbbu_url = trim(get_option('wpphpbbu_url', ''));
     $wpphpbbu_post_posts = trim(get_option('wpphpbbu_post_posts', 'yes'));
     $wpphpbbu_post_locked = trim(get_option('wpphpbbu_post_locked', 'yes'));
     require_once __DIR__ . '/admin/settings.php';
     do_action('wpphpbbu_after_admin_settings');
 }
 /**
  * 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\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 () {
                 wpphpbbu\Path::login_page();
             });
             add_action('init', array($this, 'add_permissions'));
             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()) {
             //set initial cache
             (new wpphpbbu\Proxy())->setCache();
         }
     }
     $this->admin_includes();
 }