function __construct() { // Can't do anything if Keyring is not available. // Prompt user to install Keyring (if they can), and bail if (!defined('KEYRING__VERSION') || version_compare(KEYRING__VERSION, static::KEYRING_VERSION, '<')) { if (current_user_can('install_plugins')) { add_thickbox(); wp_enqueue_script('plugin-install'); add_filter('admin_notices', array($this, 'require_keyring')); } return false; } // Populate options for this importer $this->options = get_option('keyring_' . static::SLUG . '_importer'); // Add a Keyring handler to push us to the next step of the importer once connected add_action('keyring_connection_verified', array($this, 'verified_connection'), 10, 2); // If a request is made for a new connection, pass it off to Keyring if (isset($_REQUEST['import']) && static::SLUG == $_REQUEST['import'] && (isset($_POST[static::SLUG . '_token']) && 'new' == $_POST[static::SLUG . '_token'] || isset($_POST['create_new']))) { $this->reset(); Keyring_Util::connect_to(static::SLUG, 'keyring-' . static::SLUG . '-importer'); exit; } // If we have a token set already, then load some details for it if ($this->get_option('token') && ($token = Keyring::get_token_store()->get_token(array('service' => static::SLUG, 'id' => $this->get_option('token'))))) { $this->service = call_user_func(array(static::KEYRING_SERVICE, 'init')); $this->service->set_token($token); } // Make sure the taxonomy entry is ready to go $this->taxonomy = null; $terms = get_terms('keyring_services', array('hide_empty' => false)); foreach ((array) $terms as $term) { if (static::LABEL == $term->name) { $this->taxonomy = $term; break; } } if (is_null($this->taxonomy)) { $term = wp_insert_term(static::LABEL, 'keyring_services', array('description' => sprintf(__('Posts imported from %s', 'keyring'), static::LABEL), 'slug' => static::SLUG)); $this->taxonomy = get_term($term['term_id'], 'keyring_services'); } // Make sure we have a scheduled job to handle auto-imports if enabled if ($this->get_option('auto_import') && !wp_get_schedule('keyring_' . static::SLUG . '_import_auto')) { wp_schedule_event(time(), 'hourly', 'keyring_' . static::SLUG . '_import_auto'); } // Form handling here, pre-output (in case we need to redirect etc) $this->handle_request(); }