public function initMenu() { if (class_exists('WP_APP_Collection')) { WP_APP_Collection::instance()->addOptionPage('手机登录', '手机登录', 'manage_options', 'phone-app-login', array($this, 'render_page')); } else { $hook = add_options_page('移动APP功能:手机登录', '移动APP:手机登录', 'manage_options', 'phone-app-login', array($this, 'render_page')); } }
echo "TODO:"; } public function addOptionPage($page_title, $menu_title, $capability, $menu_slug, $function = '') { add_submenu_page('app_collection', $page_title, $menu_title, $capability, $menu_slug, $function); } public static function instance() { static $instance = null; if (is_null($instance)) { $instance = new self(); } return $instance; } } WP_APP_Collection::instance(); function wp_app_sso_login($type, $id, $token) { global $wpdb; $uid = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} um WHERE um.meta_key='%s' AND um.meta_value='%s'", 'open_type_' . $type, $id)); if (is_wp_error($uid)) { return $uid; } if ($uid) { wp_set_auth_cookie($uid, true, false); wp_set_current_user($uid); if (isset($token)) { update_user_meta($uid, 'open_token_' . $type, $token); } } else { return new WP_Error('not_registered', '还没有注册。', array('status' => 404));