Completed
Push — master ( b4d70b...56ad76 )
by Miled
02:58 queued 01:37
created

wsl.session.php ➔ wsl_init_php_session()   B

Complexity

Conditions 9
Paths 36

Size

Total Lines 29

Duplication

Lines 7
Ratio 24.14 %

Importance

Changes 0
Metric Value
cc 9
nc 36
nop 0
dl 7
loc 29
rs 8.0555
c 0
b 0
f 0
1
<?php
2
/*!
3
* WordPress Social Login
4
*
5
* https://miled.github.io/wordpress-social-login/ | https://github.com/miled/wordpress-social-login
6
*   (c) 2011-2020 Mohamed Mrassi and contributors | https://wordpress.org/plugins/wordpress-social-login/
7
*/
8
9
// --------------------------------------------------------------------
10
11
/**
12
* Attempts to initialize a PHP session when needed
13
*/
14
function wsl_init_php_session()
15
{
16
	// > check for wsl actions/page
17
	$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null;
18
	$page = isset( $_GET['page'] ) ? $_GET['page'] : null;
19
20 View Code Duplication
    if(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
        ! in_array( $action, array( "wordpress_social_authenticate", "wordpress_social_profile_completion", "wordpress_social_account_linking", "wordpress_social_authenticated" ) )
22
        && ! in_array( $page, array( "wordpress-social-login" ) )
23
    )
24
	{
25
		return false;
26
	}
27
28
    if ( headers_sent() )
29
    {
30
        wp_die( __( "HTTP headers already sent to browser and WSL won't be able to start/resume PHP session.", 'wordpress-social-login' ) );
31
    }
32
33
    if ( ! session_id() && ! defined( 'DOING_CRON' ) )
34
    {
35
        session_start();
36
    }
37
38
    if( session_id() )
39
    {
40
        wsl_init_php_session_storage();
41
    }
42
}
43
44
// --------------------------------------------------------------------
45
46
function wsl_init_php_session_storage()
47
{
48
    global $WORDPRESS_SOCIAL_LOGIN_VERSION;
49
50
    $_SESSION["wsl::plugin"] = "WordPress Social Login " . $WORDPRESS_SOCIAL_LOGIN_VERSION;
51
52
    if( defined( 'ABSPATH' ) )
53
    {
54
        $_SESSION['wsl:consts:ABSPATH'] = ABSPATH;
55
    }
56
}
57
58
// --------------------------------------------------------------------
59
60
function wsl_set_provider_config_in_session_storage($provider, $config)
61
{
62
	$provider = strtolower($provider);
63
64
	$_SESSION['wsl:' . $provider . ':config'] = (array) $config;
65
}
66
67
// --------------------------------------------------------------------
68
69
function wsl_get_provider_config_from_session_storage($provider)
70
{
71
	$provider = strtolower($provider);
72
73
    if(isset($_SESSION['wsl:' . $provider . ':config']))
74
    {
75
        return (array) $_SESSION['wsl:' . $provider . ':config'];
76
    }
77
}
78
79
// --------------------------------------------------------------------
80