0) { update_user_meta($user_ID, 'mm_github_connection_github_id', $data_array['github_internal_id']); return wp_redirect($current_url); } } if(isset($_GET['code']) && $_GET['code'] && isset($_GET['mm_github_login']) && $_GET['mm_github_login']=='true') { $data_array = mm_github_connection_get_data($_GET['code'], $current_url); $users_array = get_users(array('meta_key'=>'mm_github_connection_github_id', 'meta_value'=>$data_array['github_internal_id'])); if(is_array($users_array) && count($users_array)>0) { $user_to_auth_obj = $users_array[0]; if($user_to_auth_obj) { wp_set_current_user($user_to_auth_obj->ID, $user_to_auth_obj->user_login); wp_set_auth_cookie($user_to_auth_obj->ID); do_action('wp_login', $user_to_auth_obj->user_login); return wp_redirect(home_url('/')); } } } } } add_action('admin_init', 'mm_github_connection_register_setting_fields'); function mm_github_connection_register_setting_fields() { add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'mm_github_connection_plugins_bar_links'); add_settings_section('mm_connection_settings_section', ''.__('MM Connection Global Settings', 'marsminds'), 'mm_github_connection_global_settings_section', 'general'); register_setting('general', 'mm_connection_global_css', 'esc_attr'); add_settings_field('mm_connection_global_css', '' , 'mm_github_connection_print_global_css_field', 'mm_connection_settings_section'); add_settings_section('mm_github_connection_settings_section', ''.__('MM Github Connection Settings', 'marsminds'), 'mm_github_connection_settings_section', 'general'); register_setting('general', 'mm_github_connection_client_id', 'esc_attr'); register_setting('general', 'mm_github_connection_client_secret', 'esc_attr'); add_settings_field('mm_github_connection_client_id', '' , 'mm_github_connection_print_client_id_field', 'mm_github_connection_settings_section'); add_settings_field('mm_github_connection_client_secret', '' , 'mm_github_connection_print_client_secret_field', 'mm_github_connection_settings_section'); } function mm_github_connection_plugins_bar_links($links) { return array_merge( array( ''.__('CSS Settings', 'marsminds').'', ''.__('Github Connection Settings', 'marsminds').''), $links); } function mm_github_connection_print_global_css_field() { $global_css_default_value = ''."\n". ''."\n". ''; $global_css_value = get_option('mm_connection_global_css', $global_css_default_value); echo ''; } function mm_github_connection_print_client_id_field() { $client_id_value = get_option('mm_github_connection_client_id'); echo ''; } function mm_github_connection_print_client_secret_field() { $client_secret_value = get_option('mm_github_connection_client_secret'); echo ''; } function mm_github_connection_global_settings_section($args) { ?>
|
1 - Create a Github Application here https://github.com/settings/applications/new. 2 - Authorization callback URL needs to be this: 3 - Take the Client ID and Client Secret from your recent created App, and complete the fields below. |
|---|