function wpel_login_button($atts, $content = null) { extract(shortcode_atts(array('text' => __('Login with Envato')), $atts)); // Create url $url = WP_Envato_Login()->api->get_url(); $url = add_query_arg(array('response_type' => 'code', 'client_id' => WPEL_CLIENT_ID, 'redirect_uri' => WPEL_REDIRECT_URI), $url); $output = '<a href="' . $url . '">' . $text . '</a>'; return $output; }
/** * Call Envato api and request access token * * @uses grant_access() - returns an object containing refresh_token and access_token * @uses get_username() - pass access_token to the function * @return void */ public function load_access_token() { if (isset($_GET['envato_registration']) && isset($_GET['code'])) { // Get response of the api $api_response = $this->grant_access(); $username = $this->get_username($api_response->access_token); $email = $this->get_email($api_response->access_token); // Verify that the api returned something // if not - redirect to an error page if (empty($username) || empty($email)) { $error_url = add_query_arg(array('registration_error' => 'envato_offline'), wpum_get_core_page_url('register')); wp_redirect($error_url); exit; } // Do registration $new_user = WP_Envato_Login()->user->register($username, $email); // Finish registration process if (is_wp_error($new_user)) { WP_Envato_Login()->user->error_redirect($new_user->get_error_code()); } else { // Save refresh token WP_Envato_Login()->user->save_token($new_user, $api_response->refresh_token); do_action('wpel_after_registration', $new_user, $api_response); // Redirect user to successful page WP_Envato_Login()->user->success_redirect(); } } }
// Look in global /wp-content/languages/envato-login folder load_textdomain('envato-login', $mofile_global); } elseif (file_exists($mofile_local)) { // Look in local /wp-content/plugins/wp-user-manager/languages/ folder load_textdomain('envato-login', $mofile_local); } else { // Load the default language files load_plugin_textdomain('envato-login', false, $wpel_lang_dir); } } } } /** * The main function responsible for returning Envato_Login * Instance to functions everywhere. * * Use this function like you would a global variable, except without needing * to declare the global. * * Example: <?php $wpel = WP_Envato_Login(); ?> * * @since 1.0.0 * @return object Envato_Login Instance */ function WP_Envato_Login() { return Envato_Login::instance(); } // Get WP_Envato_Login Running WP_Envato_Login();