name = 'Manage Multiple Blogs'; $this->slug = 'manage-multiple-blogs'; $this->settings = get_option($this->slug); if (!$this->settings) { $this->settings = array( 'blogs' => array(), 'current_blog' => array('type' => null) ); } add_action('rightnow_end', array($this, 'add_right_now_info')); add_action('wp_footer', array('MMB_Stats', 'set_hit_count')); register_activation_hook($mmb_plugin_dir.'/init.php', array($this, 'install')); add_action('init', array($this, 'automatic_login')); } /** * Add an item into the Right Now Dashboard widget * to inform that the blog can be managed remotely * */ function add_right_now_info() { echo '
This site can be managed remotely.
Plugin could not be activated. Your PHP version must be 5.0 or higher.
"); } /** * Saves the (modified) options into the database * */ function _save_options() { if (get_option($this->slug)) { update_option($this->slug, $this->settings); } else { add_option($this->slug, $this->settings); } } /** * Deletes options for communication with master * */ function uninstall(){ delete_option('_worker_nossl_key'); delete_option('_worker_public_key'); delete_option('_action_message_id'); } /** * Constructs a url (for ajax purpose) * * @param mixed $base_page */ function _construct_url($params = array(), $base_page = 'index.php') { $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug); foreach ($params as $key => $value) { $url .= "&$key=$value"; } return $url; } /** * Worker update * */ function update_worker_plugin($params) { extract($params); if($download_url){ include_once(ABSPATH . 'wp-admin/includes/file.php'); include_once ABSPATH . 'wp-admin/includes/misc.php'; include_once ABSPATH . 'wp-admin/includes/template.php'; include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; ob_start(); @unlink(dirname(__FILE__)); $upgrader = new Plugin_Upgrader(); $result = $upgrader->run(array( 'package' => $download_url, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array( 'plugin' => 'worker/init.php' ))); ob_end_clean(); if(is_wp_error($result) || !$result){ return array('error' => 'ManageWP Worker could not been upgraded.'); } else{ return array('success' => 'ManageWP Worker plugin successfully upgraded.'); } } return array('error' => 'Bad download path for worker installation file.'); } /** * Automatically logs in when called from Master * */ function automatic_login(){ $where = ($_GET['mwp_goto']); if (!is_user_logged_in() && $_GET['auto_login']) { $signature = base64_decode($_GET['signature']); $message_id = trim($_GET['message_id']); $username = $_GET['username']; $auth = $this->_authenticate_message($where.$message_id, $signature, $message_id); if($auth === true){ $user = get_user_by('login', $username); $user_id = $user->ID; wp_set_current_user($user_id, $username); wp_set_auth_cookie( $user_id ); do_action('wp_login', $username); } else { wp_die($auth['error']); } } if($_GET['auto_login']){ wp_redirect(get_bloginfo('url')."/wp-admin/".$where); exit(); } } }