Completed
Pull Request — develop (#1713)
by Zack
17:42
created
future/loader.php 3 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 /** If this file is called directly, abort. */
9 9
 if (!defined('GRAVITYVIEW_DIR')) {
10
-    exit();
10
+	exit();
11 11
 }
12 12
 
13 13
 /**
@@ -16,37 +16,37 @@  discard block
 block discarded – undo
16 16
 register_activation_hook(GRAVITYVIEW_DIR.'gravityview.php', 'gravityview_lock_version');
17 17
 function gravityview_lock_version()
18 18
 {
19
-    $version = phpversion();
20
-    if (version_compare($version, '5.3', '<')) {
21
-        if (php_sapi_name() == 'cli') {
22
-            printf(
23
-                __("GravityView requires PHP Version %s or newer. You're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview'),
24
-                GV_MIN_PHP_VERSION,
25
-                phpversion()
26
-            );
27
-        } else {
28
-            printf('<body style="padding: 0; margin: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">');
29
-            printf('<img src="'.plugins_url('assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE).'" alt="The GravityView Astronaut Says:" style="float: left; height: 60px; margin-right : 10px;" />');
30
-            printf(
31
-                __("%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview'),
32
-                '<h3 style="font-size:16px; margin: 0 0 8px 0;">',
33
-                GV_MIN_PHP_VERSION,
34
-                "</h3>\n\n",
35
-                $version
36
-            );
37
-            printf('</body>');
38
-        }
19
+	$version = phpversion();
20
+	if (version_compare($version, '5.3', '<')) {
21
+		if (php_sapi_name() == 'cli') {
22
+			printf(
23
+				__("GravityView requires PHP Version %s or newer. You're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview'),
24
+				GV_MIN_PHP_VERSION,
25
+				phpversion()
26
+			);
27
+		} else {
28
+			printf('<body style="padding: 0; margin: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">');
29
+			printf('<img src="'.plugins_url('assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE).'" alt="The GravityView Astronaut Says:" style="float: left; height: 60px; margin-right : 10px;" />');
30
+			printf(
31
+				__("%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview'),
32
+				'<h3 style="font-size:16px; margin: 0 0 8px 0;">',
33
+				GV_MIN_PHP_VERSION,
34
+				"</h3>\n\n",
35
+				$version
36
+			);
37
+			printf('</body>');
38
+		}
39 39
 
40
-        exit; /** Die without activating. Sorry. */
41
-    }
40
+		exit; /** Die without activating. Sorry. */
41
+	}
42 42
 }
43 43
 
44 44
 /** The future branch of GravityView requires PHP 5.3+ namespaces and SPL. */
45 45
 if (version_compare(phpversion(), '5.3.0', '<')) {
46
-    require GRAVITYVIEW_DIR.'future/_stubs.php';
46
+	require GRAVITYVIEW_DIR.'future/_stubs.php';
47 47
 
48 48
 /** All looks fine. */
49 49
 } else {
50
-    /** @define "GRAVITYVIEW_DIR" "../" */
51
-    require GRAVITYVIEW_DIR.'future/gravityview.php';
50
+	/** @define "GRAVITYVIEW_DIR" "../" */
51
+	require GRAVITYVIEW_DIR.'future/gravityview.php';
52 52
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -6,35 +6,35 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 /** If this file is called directly, abort. */
9
-if (!defined('GRAVITYVIEW_DIR')) {
9
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
10 10
     exit();
11 11
 }
12 12
 
13 13
 /**
14 14
  * Do not allow activation if PHP version is lower than 5.3.
15 15
  */
16
-register_activation_hook(GRAVITYVIEW_DIR.'gravityview.php', 'gravityview_lock_version');
16
+register_activation_hook( GRAVITYVIEW_DIR . 'gravityview.php', 'gravityview_lock_version' );
17 17
 function gravityview_lock_version()
18 18
 {
19 19
     $version = phpversion();
20
-    if (version_compare($version, '5.3', '<')) {
21
-        if (php_sapi_name() == 'cli') {
20
+    if ( version_compare( $version, '5.3', '<' ) ) {
21
+        if ( php_sapi_name() == 'cli' ) {
22 22
             printf(
23
-                __("GravityView requires PHP Version %s or newer. You're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview'),
23
+                __( "GravityView requires PHP Version %s or newer. You're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ),
24 24
                 GV_MIN_PHP_VERSION,
25 25
                 phpversion()
26 26
             );
27 27
         } else {
28
-            printf('<body style="padding: 0; margin: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">');
29
-            printf('<img src="'.plugins_url('assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE).'" alt="The GravityView Astronaut Says:" style="float: left; height: 60px; margin-right : 10px;" />');
28
+            printf( '<body style="padding: 0; margin: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">' );
29
+            printf( '<img src="' . plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ) . '" alt="The GravityView Astronaut Says:" style="float: left; height: 60px; margin-right : 10px;" />' );
30 30
             printf(
31
-                __("%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview'),
31
+                __( "%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ),
32 32
                 '<h3 style="font-size:16px; margin: 0 0 8px 0;">',
33 33
                 GV_MIN_PHP_VERSION,
34 34
                 "</h3>\n\n",
35 35
                 $version
36 36
             );
37
-            printf('</body>');
37
+            printf( '</body>' );
38 38
         }
39 39
 
40 40
         exit; /** Die without activating. Sorry. */
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 }
43 43
 
44 44
 /** The future branch of GravityView requires PHP 5.3+ namespaces and SPL. */
45
-if (version_compare(phpversion(), '5.3.0', '<')) {
46
-    require GRAVITYVIEW_DIR.'future/_stubs.php';
45
+if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
46
+    require GRAVITYVIEW_DIR . 'future/_stubs.php';
47 47
 
48 48
 /** All looks fine. */
49 49
 } else {
50 50
     /** @define "GRAVITYVIEW_DIR" "../" */
51
-    require GRAVITYVIEW_DIR.'future/gravityview.php';
51
+    require GRAVITYVIEW_DIR . 'future/gravityview.php';
52 52
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@
 block discarded – undo
14 14
  * Do not allow activation if PHP version is lower than 5.3.
15 15
  */
16 16
 register_activation_hook(GRAVITYVIEW_DIR.'gravityview.php', 'gravityview_lock_version');
17
-function gravityview_lock_version()
18
-{
17
+function gravityview_lock_version() {
19 18
     $version = phpversion();
20 19
     if (version_compare($version, '5.3', '<')) {
21 20
         if (php_sapi_name() == 'cli') {
Please login to merge, or discard this patch.
future/_mocks.timesort.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class GF_Query_Call_TIMESORT extends \GF_Query_Call
11 11
 {
12
-    public function timesort_sql($query)
13
-    {
14
-        global $wpdb;
12
+	public function timesort_sql($query)
13
+	{
14
+		global $wpdb;
15 15
 
16
-        list($column, $sql) = $this->parameters;
17
-        $meta_table = \GFFormsModel::get_entry_meta_table_name();
16
+		list($column, $sql) = $this->parameters;
17
+		$meta_table = \GFFormsModel::get_entry_meta_table_name();
18 18
 
19
-        $alias = $query->_alias($column->field_id, $column->source, 'm');
19
+		$alias = $query->_alias($column->field_id, $column->source, 'm');
20 20
 
21
-        /*
21
+		/*
22 22
         SELECT v,
23 23
         IF(
24 24
         POSITION('pm' IN v) > 0,
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
         FROM meta;
40 40
         */
41 41
 
42
-        // Detect if 'pm' is in the time field
43
-        $pm_exists = "POSITION('pm' IN $alias.`meta_value`)";
42
+		// Detect if 'pm' is in the time field
43
+		$pm_exists = "POSITION('pm' IN $alias.`meta_value`)";
44 44
 
45
-        // Transform a pm time into minutes ((hour + (12 if hour > 12 else 0)) * 60)
46
-        $minutes_12 = "(SUBSTRING_INDEX($alias.`meta_value`, ':', 1) + IF(SUBSTRING_INDEX($alias.`meta_value`, ':', 1) < 12, 12, 0)) * 60";
45
+		// Transform a pm time into minutes ((hour + (12 if hour > 12 else 0)) * 60)
46
+		$minutes_12 = "(SUBSTRING_INDEX($alias.`meta_value`, ':', 1) + IF(SUBSTRING_INDEX($alias.`meta_value`, ':', 1) < 12, 12, 0)) * 60";
47 47
 
48
-        // Transform a 24-hour time into minutes (hour * 60), maybe compensate 12 am = 0
49
-        $minutes_24 = "(SUBSTRING_INDEX($alias.`meta_value`, ':', 1) - IF(POSITION('am' IN $alias.`meta_value`) AND SUBSTRING_INDEX($alias.`meta_value`, ':', 1) = '12', 12, 0)) * 60";
48
+		// Transform a 24-hour time into minutes (hour * 60), maybe compensate 12 am = 0
49
+		$minutes_24 = "(SUBSTRING_INDEX($alias.`meta_value`, ':', 1) - IF(POSITION('am' IN $alias.`meta_value`) AND SUBSTRING_INDEX($alias.`meta_value`, ':', 1) = '12', 12, 0)) * 60";
50 50
 
51
-        // Minutes
52
-        $minutes = "RIGHT(IF(POSITION('m' IN $alias.`meta_value`), SUBSTRING_INDEX($alias.`meta_value`, ' ', 1), $alias.`meta_value`), 2)";
51
+		// Minutes
52
+		$minutes = "RIGHT(IF(POSITION('m' IN $alias.`meta_value`), SUBSTRING_INDEX($alias.`meta_value`, ' ', 1), $alias.`meta_value`), 2)";
53 53
 
54
-        // Combine the insanity :)
55
-        $condition = "IF($pm_exists, $minutes_12, $minutes_24) + $minutes";
54
+		// Combine the insanity :)
55
+		$condition = "IF($pm_exists, $minutes_12, $minutes_24) + $minutes";
56 56
 
57
-        return "(SELECT $condition)";
58
-    }
57
+		return "(SELECT $condition)";
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@
 block discarded – undo
9 9
  */
10 10
 class GF_Query_Call_TIMESORT extends \GF_Query_Call
11 11
 {
12
-    public function timesort_sql($query)
12
+    public function timesort_sql( $query )
13 13
     {
14 14
         global $wpdb;
15 15
 
16
-        list($column, $sql) = $this->parameters;
16
+        list( $column, $sql ) = $this->parameters;
17 17
         $meta_table = \GFFormsModel::get_entry_meta_table_name();
18 18
 
19
-        $alias = $query->_alias($column->field_id, $column->source, 'm');
19
+        $alias = $query->_alias( $column->field_id, $column->source, 'm' );
20 20
 
21 21
         /*
22 22
         SELECT v,
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,7 @@
 block discarded – undo
9 9
  */
10 10
 class GF_Query_Call_TIMESORT extends \GF_Query_Call
11 11
 {
12
-    public function timesort_sql($query)
13
-    {
12
+    public function timesort_sql($query) {
14 13
         global $wpdb;
15 14
 
16 15
         list($column, $sql) = $this->parameters;
Please login to merge, or discard this patch.
future/_mocks.isnull.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@
 block discarded – undo
9 9
  */
10 10
 class GF_Query_Condition_IS_NULL extends \GF_Query_Condition
11 11
 {
12
-    private $override_placeholder = '{GF_Query_Condition_IS_NULL_override}';
12
+	private $override_placeholder = '{GF_Query_Condition_IS_NULL_override}';
13 13
 
14
-    public function __construct($left = null, $operator = null, $right = null)
15
-    {
16
-        parent::__construct($left, self::EQ, new \GF_Query_Literal($this->override_placeholder));
17
-    }
14
+	public function __construct($left = null, $operator = null, $right = null)
15
+	{
16
+		parent::__construct($left, self::EQ, new \GF_Query_Literal($this->override_placeholder));
17
+	}
18 18
 
19
-    public function sql($query)
20
-    {
21
-        return str_replace("= '{$this->override_placeholder}'", 'IS NULL', parent::sql($query));
22
-    }
19
+	public function sql($query)
20
+	{
21
+		return str_replace("= '{$this->override_placeholder}'", 'IS NULL', parent::sql($query));
22
+	}
23 23
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
 {
12 12
     private $override_placeholder = '{GF_Query_Condition_IS_NULL_override}';
13 13
 
14
-    public function __construct($left = null, $operator = null, $right = null)
14
+    public function __construct( $left = null, $operator = null, $right = null )
15 15
     {
16
-        parent::__construct($left, self::EQ, new \GF_Query_Literal($this->override_placeholder));
16
+        parent::__construct( $left, self::EQ, new \GF_Query_Literal( $this->override_placeholder ) );
17 17
     }
18 18
 
19
-    public function sql($query)
19
+    public function sql( $query )
20 20
     {
21
-        return str_replace("= '{$this->override_placeholder}'", 'IS NULL', parent::sql($query));
21
+        return str_replace( "= '{$this->override_placeholder}'", 'IS NULL', parent::sql( $query ) );
22 22
     }
23 23
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,13 +11,11 @@
 block discarded – undo
11 11
 {
12 12
     private $override_placeholder = '{GF_Query_Condition_IS_NULL_override}';
13 13
 
14
-    public function __construct($left = null, $operator = null, $right = null)
15
-    {
14
+    public function __construct($left = null, $operator = null, $right = null) {
16 15
         parent::__construct($left, self::EQ, new \GF_Query_Literal($this->override_placeholder));
17 16
     }
18 17
 
19
-    public function sql($query)
20
-    {
18
+    public function sql($query) {
21 19
         return str_replace("= '{$this->override_placeholder}'", 'IS NULL', parent::sql($query));
22 20
     }
23 21
 }
Please login to merge, or discard this patch.
future/_mocks.php 3 patches
Indentation   +685 added lines, -685 removed lines patch added patch discarded remove patch
@@ -17,51 +17,51 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function GravityView_View_Data_add_view($view_id, $atts, $_this)
19 19
 {
20
-    /** Handle array of IDs. */
21
-    if (is_array($view_id)) {
22
-        foreach ($view_id as $id) {
23
-            call_user_func(__FUNCTION__, $id, $atts, $_this);
24
-        }
20
+	/** Handle array of IDs. */
21
+	if (is_array($view_id)) {
22
+		foreach ($view_id as $id) {
23
+			call_user_func(__FUNCTION__, $id, $atts, $_this);
24
+		}
25 25
 
26
-        if (!$_this->views->count()) {
27
-            return [];
28
-        }
26
+		if (!$_this->views->count()) {
27
+			return [];
28
+		}
29 29
 
30
-        return array_combine(
31
-            array_map(function ($view) { return $view->ID; }, $_this->views->all()),
32
-            array_map(function ($view) { return $view->as_data(); }, $_this->views->all())
33
-        );
34
-    }
30
+		return array_combine(
31
+			array_map(function ($view) { return $view->ID; }, $_this->views->all()),
32
+			array_map(function ($view) { return $view->as_data(); }, $_this->views->all())
33
+		);
34
+	}
35 35
 
36
-    /** View has been set already. */
37
-    if ($view = $_this->views->get($view_id)) {
38
-        do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id));
36
+	/** View has been set already. */
37
+	if ($view = $_this->views->get($view_id)) {
38
+		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id));
39 39
 
40
-        return $view->as_data();
41
-    }
40
+		return $view->as_data();
41
+	}
42 42
 
43
-    $view = \GV\View::by_id($view_id);
44
-    if (!$view) {
45
-        do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id));
43
+	$view = \GV\View::by_id($view_id);
44
+	if (!$view) {
45
+		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id));
46 46
 
47
-        return false;
48
-    }
47
+		return false;
48
+	}
49 49
 
50
-    /** Doesn't have a connected form. */
51
-    if (!$view->form) {
52
-        do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id));
50
+	/** Doesn't have a connected form. */
51
+	if (!$view->form) {
52
+		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id));
53 53
 
54
-        return false;
55
-    }
54
+		return false;
55
+	}
56 56
 
57
-    /** Update the settings */
58
-    if (is_array($atts)) {
59
-        $view->settings->update($atts);
60
-    }
57
+	/** Update the settings */
58
+	if (is_array($atts)) {
59
+		$view->settings->update($atts);
60
+	}
61 61
 
62
-    $_this->views->add($view);
62
+	$_this->views->add($view);
63 63
 
64
-    return $view->as_data();
64
+	return $view->as_data();
65 65
 }
66 66
 
67 67
 /**
@@ -77,64 +77,64 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count)
79 79
 {
80
-    $form = \GV\GF_Form::by_id($form_id);
81
-
82
-    /**
83
-     * Kick off all advanced filters.
84
-     *
85
-     * Parameters and criteria are pretty much the same thing here, just
86
-     *  different naming, where `$parameters` are the initial parameters
87
-     *  calculated for hte view, and `$criteria` are the filtered ones
88
-     *  retrieved via \GVCommon::calculate_get_entries_criteria()
89
-     */
90
-    $criteria = \GVCommon::calculate_get_entries_criteria($parameters, $form->ID);
91
-
92
-    do_action('gravityview_log_debug', '[gravityview_get_entries] Final Parameters', $criteria);
93
-
94
-    /** ...and all the (now deprecated) filters that usually follow `gravityview_get_entries` */
95
-
96
-    /**
97
-     * @deprecated
98
-     * Do not use this filter anymore.
99
-     */
100
-    $entries = apply_filters_ref_array('gravityview_before_get_entries', [null, $criteria, $parameters, &$count]);
101
-
102
-    if (!is_null($entries)) {
103
-        /**
104
-         * We've been given an entries result that we can return,
105
-         *  just set the paging and we're good to go.
106
-         */
107
-        $paging = \GV\Utils::get($parameters, 'paging');
108
-    } else {
109
-        $entries = new \GV\Entry_Collection();
110
-        if ($view = \GV\View::by_id(\GV\Utils::get($args, 'id'))) {
111
-            $view->settings->update($args);
112
-            $entries = $view->get_entries(gravityview()->request);
113
-        }
114
-
115
-        $page = \GV\Utils::get($parameters['paging'], 'current_page') ?: ((($parameters['paging']['offset'] - $view->settings->get('offset')) / $parameters['paging']['page_size']) + 1);
116
-
117
-        /** Set paging, count and unwrap the entries. */
118
-        $paging = [
119
-            'offset'    => ($page - 1) * $view->settings->get('page_size'),
120
-            'page_size' => $view->settings->get('page_size'),
121
-        ];
122
-        /**
123
-         * GF_Query does not subtract the offset, we have to subtract it ourselves.
124
-         */
125
-        $count = $entries->total() - (gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY) ? $view->settings->get('offset') : 0);
126
-        $entries = array_map(function ($e) { return $e->as_entry(); }, $entries->all());
127
-    }
128
-
129
-    /** Just one more filter, for compatibility's sake! */
130
-
131
-    /**
132
-     * @deprecated
133
-     * Do not use this filter anymore.
134
-     */
135
-    $entries = apply_filters_ref_array('gravityview_entries', [$entries, $criteria, $parameters, &$count]);
136
-
137
-    return [$entries, $paging, $count];
80
+	$form = \GV\GF_Form::by_id($form_id);
81
+
82
+	/**
83
+	 * Kick off all advanced filters.
84
+	 *
85
+	 * Parameters and criteria are pretty much the same thing here, just
86
+	 *  different naming, where `$parameters` are the initial parameters
87
+	 *  calculated for hte view, and `$criteria` are the filtered ones
88
+	 *  retrieved via \GVCommon::calculate_get_entries_criteria()
89
+	 */
90
+	$criteria = \GVCommon::calculate_get_entries_criteria($parameters, $form->ID);
91
+
92
+	do_action('gravityview_log_debug', '[gravityview_get_entries] Final Parameters', $criteria);
93
+
94
+	/** ...and all the (now deprecated) filters that usually follow `gravityview_get_entries` */
95
+
96
+	/**
97
+	 * @deprecated
98
+	 * Do not use this filter anymore.
99
+	 */
100
+	$entries = apply_filters_ref_array('gravityview_before_get_entries', [null, $criteria, $parameters, &$count]);
101
+
102
+	if (!is_null($entries)) {
103
+		/**
104
+		 * We've been given an entries result that we can return,
105
+		 *  just set the paging and we're good to go.
106
+		 */
107
+		$paging = \GV\Utils::get($parameters, 'paging');
108
+	} else {
109
+		$entries = new \GV\Entry_Collection();
110
+		if ($view = \GV\View::by_id(\GV\Utils::get($args, 'id'))) {
111
+			$view->settings->update($args);
112
+			$entries = $view->get_entries(gravityview()->request);
113
+		}
114
+
115
+		$page = \GV\Utils::get($parameters['paging'], 'current_page') ?: ((($parameters['paging']['offset'] - $view->settings->get('offset')) / $parameters['paging']['page_size']) + 1);
116
+
117
+		/** Set paging, count and unwrap the entries. */
118
+		$paging = [
119
+			'offset'    => ($page - 1) * $view->settings->get('page_size'),
120
+			'page_size' => $view->settings->get('page_size'),
121
+		];
122
+		/**
123
+		 * GF_Query does not subtract the offset, we have to subtract it ourselves.
124
+		 */
125
+		$count = $entries->total() - (gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY) ? $view->settings->get('offset') : 0);
126
+		$entries = array_map(function ($e) { return $e->as_entry(); }, $entries->all());
127
+	}
128
+
129
+	/** Just one more filter, for compatibility's sake! */
130
+
131
+	/**
132
+	 * @deprecated
133
+	 * Do not use this filter anymore.
134
+	 */
135
+	$entries = apply_filters_ref_array('gravityview_entries', [$entries, $criteria, $parameters, &$count]);
136
+
137
+	return [$entries, $paging, $count];
138 138
 }
139 139
 
140 140
 /**
@@ -154,67 +154,67 @@  discard block
 block discarded – undo
154 154
  */
155 155
 function GravityView_API_field_value($entry, $field_settings, $format)
156 156
 {
157
-    if (empty($entry['form_id']) || empty($field_settings['id'])) {
158
-        gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
157
+	if (empty($entry['form_id']) || empty($field_settings['id'])) {
158
+		gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
159 159
 
160
-        return null;
161
-    }
160
+		return null;
161
+	}
162 162
 
163
-    if (!empty($entry['_multi']) && !empty($field_settings['form_id']) && !empty($entry['_multi'][$field_settings['form_id']])) {
164
-        $multientry = \GV\Multi_Entry::from_entries(array_map('\GV\GF_Entry::from_entry', $entry['_multi']));
165
-        $entry = $entry['_multi'][$field_settings['form_id']];
166
-    }
163
+	if (!empty($entry['_multi']) && !empty($field_settings['form_id']) && !empty($entry['_multi'][$field_settings['form_id']])) {
164
+		$multientry = \GV\Multi_Entry::from_entries(array_map('\GV\GF_Entry::from_entry', $entry['_multi']));
165
+		$entry = $entry['_multi'][$field_settings['form_id']];
166
+	}
167 167
 
168
-    if (empty($entry['id']) || !$entry = \GV\GF_Entry::by_id($entry['id'])) {
169
-        gravityview()->log->error('Invalid \GV\GF_Entry supplied', ['data' => $entry]);
168
+	if (empty($entry['id']) || !$entry = \GV\GF_Entry::by_id($entry['id'])) {
169
+		gravityview()->log->error('Invalid \GV\GF_Entry supplied', ['data' => $entry]);
170 170
 
171
-        return null;
172
-    }
171
+		return null;
172
+	}
173 173
 
174
-    /**
175
-     * Determine the source backend.
176
-     *
177
-     * Fields with a numeric ID are Gravity Forms ones.
178
-     */
179
-    $source = is_numeric($field_settings['id']) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
174
+	/**
175
+	 * Determine the source backend.
176
+	 *
177
+	 * Fields with a numeric ID are Gravity Forms ones.
178
+	 */
179
+	$source = is_numeric($field_settings['id']) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
180 180
 
181
-    /** Initialize the future field. */
182
-    switch ($source) {
183
-        /** The Gravity Forms backend. */
184
-        case \GV\Source::BACKEND_GRAVITYFORMS:
185
-            if (!$form = \GV\GF_Form::by_id($entry['form_id'])) {
186
-                gravityview()->log->error('No form Gravity Form found for entry', ['data' => $entry]);
181
+	/** Initialize the future field. */
182
+	switch ($source) {
183
+		/** The Gravity Forms backend. */
184
+		case \GV\Source::BACKEND_GRAVITYFORMS:
185
+			if (!$form = \GV\GF_Form::by_id($entry['form_id'])) {
186
+				gravityview()->log->error('No form Gravity Form found for entry', ['data' => $entry]);
187 187
 
188
-                return null;
189
-            }
188
+				return null;
189
+			}
190 190
 
191
-            if (!$field = $form::get_field($form, $field_settings['id'])) {
192
-                return null;
193
-            }
191
+			if (!$field = $form::get_field($form, $field_settings['id'])) {
192
+				return null;
193
+			}
194 194
 
195
-            break;
195
+			break;
196 196
 
197
-        /** Our internal backend. */
198
-        case \GV\Source::BACKEND_INTERNAL:
199
-            if (!$field = \GV\Internal_Source::get_field($field_settings['id'])) {
200
-                return null;
201
-            }
197
+		/** Our internal backend. */
198
+		case \GV\Source::BACKEND_INTERNAL:
199
+			if (!$field = \GV\Internal_Source::get_field($field_settings['id'])) {
200
+				return null;
201
+			}
202 202
 
203
-            break;
203
+			break;
204 204
 
205
-        /** An unidentified backend. */
206
-        default:
207
-            gravityview()->log->error('Could not determine source for entry', ['data' => [func_get_args()]]);
205
+		/** An unidentified backend. */
206
+		default:
207
+			gravityview()->log->error('Could not determine source for entry', ['data' => [func_get_args()]]);
208 208
 
209
-            return null;
210
-    }
209
+			return null;
210
+	}
211 211
 
212
-    /** Add the field settings. */
213
-    $field->update_configuration($field_settings);
212
+	/** Add the field settings. */
213
+	$field->update_configuration($field_settings);
214 214
 
215
-    $renderer = new \GV\Field_Renderer();
215
+	$renderer = new \GV\Field_Renderer();
216 216
 
217
-    return $renderer->render($field, gravityview()->views->get(), $source == \GV\Source::BACKEND_GRAVITYFORMS ? $form : null, isset($multientry) ? $multientry : $entry, gravityview()->request);
217
+	return $renderer->render($field, gravityview()->views->get(), $source == \GV\Source::BACKEND_GRAVITYFORMS ? $form : null, isset($multientry) ? $multientry : $entry, gravityview()->request);
218 218
 }
219 219
 
220 220
 /**
@@ -233,136 +233,136 @@  discard block
 block discarded – undo
233 233
 function GravityView_API_field_label($form, $field_settings, $entry, $force_show_label = false)
234 234
 {
235 235
 
236
-    /** A bail condition. */
237
-    $bail = function ($label, $field_settings, $entry, $force_show_label, $form) {
238
-        if (!empty($field_settings['show_label']) || $force_show_label) {
239
-            $label = isset($field_settings['label']) ? $field_settings['label'] : '';
240
-
241
-            // Use Gravity Forms label by default, but if a custom label is defined in GV, use it.
242
-            if (!empty($field_settings['custom_label'])) {
243
-                $label = \GravityView_API::replace_variables($field_settings['custom_label'], $form, $entry);
244
-            }
245
-
246
-            /**
247
-             * @filter `gravityview_render_after_label` Append content to a field label
248
-             *
249
-             * @param string $appended_content Content you can add after a label. Empty by default.
250
-             * @param array  $field            GravityView field array
251
-             */
252
-            $label .= apply_filters('gravityview_render_after_label', '', $field_settings);
253
-        }
254
-
255
-        /**
256
-         * @filter `gravityview/template/field_label` Modify field label output
257
-         *
258
-         * @since 1.7
259
-         *
260
-         * @param string $label Field label HTML
261
-         * @param array  $field GravityView field array
262
-         * @param array  $form  Gravity Forms form array
263
-         * @param array  $entry Gravity Forms entry array
264
-         */
265
-        $label = apply_filters('gravityview/template/field_label', $label, $field_settings, $form, $entry);
266
-
267
-        return $label;
268
-    };
269
-
270
-    $label = '';
271
-
272
-    if (!empty($entry['_multi']) && !empty($field_settings['form_id']) && !empty($entry['_multi'][$field_settings['form_id']])) {
273
-        $entry = $entry['_multi'][$field_settings['form_id']];
274
-        if ($_form = \GV\GF_Form::by_id($field_settings['form_id'])) {
275
-            $form = $_form->form;
276
-        }
277
-    }
278
-
279
-    if (empty($entry['form_id']) || empty($field_settings['id'])) {
280
-        gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
281
-
282
-        return $bail($label, $field_settings, $entry, $force_show_label, $form);
283
-    }
284
-
285
-    if (empty($entry['id']) || !$gv_entry = \GV\GF_Entry::by_id($entry['id'])) {
286
-        gravityview()->log->error('Invalid \GV\GF_Entry supplied', ['data' => $entry]);
287
-
288
-        return $bail($label, $field_settings, $entry, $force_show_label, $form);
289
-    }
290
-
291
-    $entry = $gv_entry;
292
-
293
-    /**
294
-     * Determine the source backend.
295
-     *
296
-     * Fields with a numeric ID are Gravity Forms ones.
297
-     */
298
-    $source = is_numeric($field_settings['id']) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
299
-
300
-    /** Initialize the future field. */
301
-    switch ($source) {
302
-        /** The Gravity Forms backend. */
303
-        case \GV\Source::BACKEND_GRAVITYFORMS:
304
-            if (!$gf_form = \GV\GF_Form::by_id($entry['form_id'])) {
305
-                gravityview()->log->error('No form Gravity Form found for entry', ['data' => $entry]);
306
-
307
-                return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $form);
308
-            }
309
-
310
-            if (!$field = $gf_form::get_field($gf_form, $field_settings['id'])) {
311
-                gravityview()->log->error('No field found for specified form and field ID #{field_id}', ['field_id' => $field_settings['id'], 'data' => $form]);
312
-
313
-                return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $gf_form->form);
314
-            }
315
-            if (empty($field_settings['show_label'])) {
316
-                /** The label never wins... */
317
-                $field_settings['label'] = '';
318
-            }
319
-
320
-            break;
321
-
322
-        /** Our internal backend. */
323
-        case \GV\Source::BACKEND_INTERNAL:
324
-            if (!$field = \GV\Internal_Source::get_field($field_settings['id'])) {
325
-                return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $form);
326
-            }
327
-            break;
328
-
329
-        /** An unidentified backend. */
330
-        default:
331
-            gravityview()->log->error('Could not determine source for entry. Using empty field.', ['data' => [func_get_args()]]);
332
-            $field = new \GV\Field();
333
-            break;
334
-    }
335
-
336
-    if ($force_show_label) {
337
-        $field_settings['show_label'] = '1';
338
-    }
339
-
340
-    /** Add the field settings. */
341
-    $field->update_configuration($field_settings);
342
-
343
-    if (!empty($field->show_label)) {
344
-        $label = $field->get_label(null, isset($gf_form) ? $gf_form : null, $entry);
345
-
346
-        /**
347
-         * @filter `gravityview_render_after_label` Append content to a field label
348
-         *
349
-         * @param string $appended_content Content you can add after a label. Empty by default.
350
-         * @param array  $field            GravityView field array
351
-         */
352
-        $label .= apply_filters('gravityview_render_after_label', '', $field->as_configuration());
353
-    }
354
-
355
-    /**
356
-     * @filter `gravityview/template/field_label` Modify field label output
357
-     *
358
-     * @since 1.7
359
-     *
360
-     * @param string $label Field label HTML
361
-     * @param array  $field GravityView field array
362
-     * @param array  $form  Gravity Forms form array
363
-     * @param array  $entry Gravity Forms entry array
364
-     */
365
-    return apply_filters('gravityview/template/field_label', $label, $field->as_configuration(), isset($gf_form) ? $gf_form->form : $form, $entry->as_entry());
236
+	/** A bail condition. */
237
+	$bail = function ($label, $field_settings, $entry, $force_show_label, $form) {
238
+		if (!empty($field_settings['show_label']) || $force_show_label) {
239
+			$label = isset($field_settings['label']) ? $field_settings['label'] : '';
240
+
241
+			// Use Gravity Forms label by default, but if a custom label is defined in GV, use it.
242
+			if (!empty($field_settings['custom_label'])) {
243
+				$label = \GravityView_API::replace_variables($field_settings['custom_label'], $form, $entry);
244
+			}
245
+
246
+			/**
247
+			 * @filter `gravityview_render_after_label` Append content to a field label
248
+			 *
249
+			 * @param string $appended_content Content you can add after a label. Empty by default.
250
+			 * @param array  $field            GravityView field array
251
+			 */
252
+			$label .= apply_filters('gravityview_render_after_label', '', $field_settings);
253
+		}
254
+
255
+		/**
256
+		 * @filter `gravityview/template/field_label` Modify field label output
257
+		 *
258
+		 * @since 1.7
259
+		 *
260
+		 * @param string $label Field label HTML
261
+		 * @param array  $field GravityView field array
262
+		 * @param array  $form  Gravity Forms form array
263
+		 * @param array  $entry Gravity Forms entry array
264
+		 */
265
+		$label = apply_filters('gravityview/template/field_label', $label, $field_settings, $form, $entry);
266
+
267
+		return $label;
268
+	};
269
+
270
+	$label = '';
271
+
272
+	if (!empty($entry['_multi']) && !empty($field_settings['form_id']) && !empty($entry['_multi'][$field_settings['form_id']])) {
273
+		$entry = $entry['_multi'][$field_settings['form_id']];
274
+		if ($_form = \GV\GF_Form::by_id($field_settings['form_id'])) {
275
+			$form = $_form->form;
276
+		}
277
+	}
278
+
279
+	if (empty($entry['form_id']) || empty($field_settings['id'])) {
280
+		gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
281
+
282
+		return $bail($label, $field_settings, $entry, $force_show_label, $form);
283
+	}
284
+
285
+	if (empty($entry['id']) || !$gv_entry = \GV\GF_Entry::by_id($entry['id'])) {
286
+		gravityview()->log->error('Invalid \GV\GF_Entry supplied', ['data' => $entry]);
287
+
288
+		return $bail($label, $field_settings, $entry, $force_show_label, $form);
289
+	}
290
+
291
+	$entry = $gv_entry;
292
+
293
+	/**
294
+	 * Determine the source backend.
295
+	 *
296
+	 * Fields with a numeric ID are Gravity Forms ones.
297
+	 */
298
+	$source = is_numeric($field_settings['id']) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
299
+
300
+	/** Initialize the future field. */
301
+	switch ($source) {
302
+		/** The Gravity Forms backend. */
303
+		case \GV\Source::BACKEND_GRAVITYFORMS:
304
+			if (!$gf_form = \GV\GF_Form::by_id($entry['form_id'])) {
305
+				gravityview()->log->error('No form Gravity Form found for entry', ['data' => $entry]);
306
+
307
+				return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $form);
308
+			}
309
+
310
+			if (!$field = $gf_form::get_field($gf_form, $field_settings['id'])) {
311
+				gravityview()->log->error('No field found for specified form and field ID #{field_id}', ['field_id' => $field_settings['id'], 'data' => $form]);
312
+
313
+				return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $gf_form->form);
314
+			}
315
+			if (empty($field_settings['show_label'])) {
316
+				/** The label never wins... */
317
+				$field_settings['label'] = '';
318
+			}
319
+
320
+			break;
321
+
322
+		/** Our internal backend. */
323
+		case \GV\Source::BACKEND_INTERNAL:
324
+			if (!$field = \GV\Internal_Source::get_field($field_settings['id'])) {
325
+				return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $form);
326
+			}
327
+			break;
328
+
329
+		/** An unidentified backend. */
330
+		default:
331
+			gravityview()->log->error('Could not determine source for entry. Using empty field.', ['data' => [func_get_args()]]);
332
+			$field = new \GV\Field();
333
+			break;
334
+	}
335
+
336
+	if ($force_show_label) {
337
+		$field_settings['show_label'] = '1';
338
+	}
339
+
340
+	/** Add the field settings. */
341
+	$field->update_configuration($field_settings);
342
+
343
+	if (!empty($field->show_label)) {
344
+		$label = $field->get_label(null, isset($gf_form) ? $gf_form : null, $entry);
345
+
346
+		/**
347
+		 * @filter `gravityview_render_after_label` Append content to a field label
348
+		 *
349
+		 * @param string $appended_content Content you can add after a label. Empty by default.
350
+		 * @param array  $field            GravityView field array
351
+		 */
352
+		$label .= apply_filters('gravityview_render_after_label', '', $field->as_configuration());
353
+	}
354
+
355
+	/**
356
+	 * @filter `gravityview/template/field_label` Modify field label output
357
+	 *
358
+	 * @since 1.7
359
+	 *
360
+	 * @param string $label Field label HTML
361
+	 * @param array  $field GravityView field array
362
+	 * @param array  $form  Gravity Forms form array
363
+	 * @param array  $entry Gravity Forms entry array
364
+	 */
365
+	return apply_filters('gravityview/template/field_label', $label, $field->as_configuration(), isset($gf_form) ? $gf_form->form : $form, $entry->as_entry());
366 366
 }
367 367
 
368 368
 /**
@@ -382,438 +382,438 @@  discard block
 block discarded – undo
382 382
  */
383 383
 final class Legacy_Context
384 384
 {
385
-    private static $stack = [];
386
-
387
-    /**
388
-     * Set the state depending on the provided configuration.
389
-     *
390
-     * Saves current global state and context.
391
-     *
392
-     * Configuration keys:
393
-     *
394
-     * - \GV\View	view:		sets \GravityView_View::atts, \GravityView_View::view_id,
395
-     *								 \GravityView_View::back_link_label
396
-     *								 \GravityView_frontend::context_view_id,
397
-     *								 \GravityView_View::form, \GravityView_View::form_id
398
-     * - \GV\Field	field:		sets \GravityView_View::_current_field, \GravityView_View::field_data,
399
-     * - \GV\Entry	entry:		sets \GravityView_View::_current_entry, \GravityView_frontend::single_entry,
400
-     *								 \GravityView_frontend::entry
401
-     * - \WP_Post	post:		sets \GravityView_View::post_id, \GravityView_frontend::post_id,
402
-     *								 \GravityView_frontend::is_gravityview_post_type,
403
-     *								 \GravityView_frontend::post_has_shortcode
404
-     * - array		paging:		sets \GravityView_View::paging
405
-     * - array		sorting:	sets \GravityView_View::sorting
406
-     * - array		template:	sets \GravityView_View::template_part_slug, \GravityView_View::template_part_name
407
-     *
408
-     * - boolean	in_the_loop sets $wp_actions['loop_start'] and $wp_query::in_the_loop
409
-     *
410
-     * also:
411
-     *
412
-     * - \GV\Request	request:	sets \GravityView_frontend::is_search, \GravityView_frontend::single_entry,
413
-     *									 \GravityView_View::context, \GravityView_frontend::entry
414
-     *
415
-     * - \GV\View_Collection	views:		sets \GravityView_View_Data::views
416
-     * - \GV\Field_Collection	fields:		sets \GravityView_View::fields
417
-     * - \GV\Entry_Collection	entries:	sets \GravityView_View::entries, \GravityView_View::total_entries
418
-     *
419
-     * and automagically:
420
-     *
421
-     * - \GravityView_View		data:		sets \GravityView_frontend::gv_output_data
422
-     *
423
-     * @param array $configuration The configuration.
424
-     *
425
-     * @return void
426
-     */
427
-    public static function push($configuration)
428
-    {
429
-        array_push(self::$stack, self::freeze());
430
-        self::load($configuration);
431
-    }
432
-
433
-    /**
434
-     * Restores last saved state and context.
435
-     *
436
-     * @return void
437
-     */
438
-    public static function pop()
439
-    {
440
-        self::thaw(array_pop(self::$stack));
441
-    }
442
-
443
-    /**
444
-     * Serializes the current configuration as needed.
445
-     *
446
-     * @return array The configuration.
447
-     */
448
-    public static function freeze()
449
-    {
450
-        global $wp_actions, $wp_query;
451
-
452
-        return [
453
-            '\GravityView_View::atts'                         => \GravityView_View::getInstance()->getAtts(),
454
-            '\GravityView_View::view_id'                      => \GravityView_View::getInstance()->getViewId(),
455
-            '\GravityView_View::back_link_label'              => \GravityView_View::getInstance()->getBackLinkLabel(false),
456
-            '\GravityView_View_Data::views'                   => \GravityView_View_Data::getInstance()->views,
457
-            '\GravityView_View::entries'                      => \GravityView_View::getInstance()->getEntries(),
458
-            '\GravityView_View::form'                         => \GravityView_View::getInstance()->getForm(),
459
-            '\GravityView_View::form_id'                      => \GravityView_View::getInstance()->getFormId(),
460
-            '\GravityView_View::context'                      => \GravityView_View::getInstance()->getContext(),
461
-            '\GravityView_View::total_entries'                => \GravityView_View::getInstance()->getTotalEntries(),
462
-            '\GravityView_View::post_id'                      => \GravityView_View::getInstance()->getPostId(),
463
-            '\GravityView_View::hide_until_searched'          => \GravityView_View::getInstance()->isHideUntilSearched(),
464
-            '\GravityView_frontend::post_id'                  => \GravityView_frontend::getInstance()->getPostId(),
465
-            '\GravityView_frontend::context_view_id'          => \GravityView_frontend::getInstance()->get_context_view_id(),
466
-            '\GravityView_frontend::is_gravityview_post_type' => \GravityView_frontend::getInstance()->isGravityviewPostType(),
467
-            '\GravityView_frontend::post_has_shortcode'       => \GravityView_frontend::getInstance()->isPostHasShortcode(),
468
-            '\GravityView_frontend::gv_output_data'           => \GravityView_frontend::getInstance()->getGvOutputData(),
469
-            '\GravityView_View::paging'                       => \GravityView_View::getInstance()->getPaging(),
470
-            '\GravityView_View::sorting'                      => \GravityView_View::getInstance()->getSorting(),
471
-            '\GravityView_frontend::is_search'                => \GravityView_frontend::getInstance()->isSearch(),
472
-            '\GravityView_frontend::single_entry'             => \GravityView_frontend::getInstance()->getSingleEntry(),
473
-            '\GravityView_frontend::entry'                    => \GravityView_frontend::getInstance()->getEntry(),
474
-            '\GravityView_View::_current_entry'               => \GravityView_View::getInstance()->getCurrentEntry(),
475
-            '\GravityView_View::fields'                       => \GravityView_View::getInstance()->getFields(),
476
-            '\GravityView_View::_current_field'               => \GravityView_View::getInstance()->getCurrentField(),
477
-            'wp_actions[loop_start]'                          => empty($wp_actions['loop_start']) ? 0 : $wp_actions['loop_start'],
478
-            'wp_query::in_the_loop'                           => $wp_query->in_the_loop,
479
-        ];
480
-    }
481
-
482
-    /**
483
-     * Deserializes a saved configuration. Modifies the global state.
484
-     *
485
-     * @param array $data Saved configuration from self::freeze()
486
-     */
487
-    public static function thaw($data)
488
-    {
489
-        foreach ((array) $data as $key => $value) {
490
-            switch ($key) {
491
-                case '\GravityView_View::atts':
492
-                    \GravityView_View::getInstance()->setAtts($value);
493
-                    break;
494
-                case '\GravityView_View::view_id':
495
-                    \GravityView_View::getInstance()->setViewId($value);
496
-                    break;
497
-                case '\GravityView_View::back_link_label':
498
-                    \GravityView_View::getInstance()->setBackLinkLabel($value);
499
-                    break;
500
-                case '\GravityView_View_Data::views':
501
-                    \GravityView_View_Data::getInstance()->views = $value;
502
-                    break;
503
-                case '\GravityView_View::entries':
504
-                    \GravityView_View::getInstance()->setEntries($value);
505
-                    break;
506
-                case '\GravityView_View::form':
507
-                    \GravityView_View::getInstance()->setForm($value);
508
-                    break;
509
-                case '\GravityView_View::form_id':
510
-                    \GravityView_View::getInstance()->setFormId($value);
511
-                    break;
512
-                case '\GravityView_View::context':
513
-                    \GravityView_View::getInstance()->setContext($value);
514
-                    break;
515
-                case '\GravityView_View::total_entries':
516
-                    \GravityView_View::getInstance()->setTotalEntries($value);
517
-                    break;
518
-                case '\GravityView_View::post_id':
519
-                    \GravityView_View::getInstance()->setPostId($value);
520
-                    break;
521
-                case '\GravityView_View::is_hide_until_searched':
522
-                    \GravityView_View::getInstance()->setHideUntilSearched($value);
523
-                    break;
524
-                case '\GravityView_frontend::post_id':
525
-                    \GravityView_frontend::getInstance()->setPostId($value);
526
-                    break;
527
-                case '\GravityView_frontend::context_view_id':
528
-                    $frontend = \GravityView_frontend::getInstance();
529
-                    $frontend->context_view_id = $value;
530
-                    break;
531
-                case '\GravityView_frontend::is_gravityview_post_type':
532
-                    \GravityView_frontend::getInstance()->setIsGravityviewPostType($value);
533
-                    break;
534
-                case '\GravityView_frontend::post_has_shortcode':
535
-                    \GravityView_frontend::getInstance()->setPostHasShortcode($value);
536
-                    break;
537
-                case '\GravityView_frontend::gv_output_data':
538
-                    \GravityView_frontend::getInstance()->setGvOutputData($value);
539
-                    break;
540
-                case '\GravityView_View::paging':
541
-                    \GravityView_View::getInstance()->setPaging($value);
542
-                    break;
543
-                case '\GravityView_View::sorting':
544
-                    \GravityView_View::getInstance()->setSorting($value);
545
-                    break;
546
-                case '\GravityView_frontend::is_search':
547
-                    \GravityView_frontend::getInstance()->setIsSearch($value);
548
-                    break;
549
-                case '\GravityView_frontend::single_entry':
550
-                    \GravityView_frontend::getInstance()->setSingleEntry($value);
551
-                    break;
552
-                case '\GravityView_frontend::entry':
553
-                    \GravityView_frontend::getInstance()->setEntry($value);
554
-                    break;
555
-                case '\GravityView_View::_current_entry':
556
-                    \GravityView_View::getInstance()->setCurrentEntry($value);
557
-                    break;
558
-                case '\GravityView_View::fields':
559
-                    \GravityView_View::getInstance()->setFields($value);
560
-                    break;
561
-                case '\GravityView_View::_current_field':
562
-                    \GravityView_View::getInstance()->setCurrentField($value);
563
-                    break;
564
-                case 'wp_actions[loop_start]':
565
-                    global $wp_actions;
566
-                    $wp_actions['loop_start'] = $value;
567
-                    break;
568
-                case 'wp_query::in_the_loop':
569
-                    global $wp_query;
570
-                    $wp_query->in_the_loop = $value;
571
-                    break;
572
-            }
573
-        }
574
-    }
575
-
576
-    /**
577
-     * Hydrates the legacy context globals as needed.
578
-     *
579
-     * @see Legacy_Context::push() for format.
580
-     *
581
-     * @return void
582
-     */
583
-    public static function load($configuration)
584
-    {
585
-        foreach ((array) $configuration as $key => $value) {
586
-            switch ($key) {
587
-                case 'view':
588
-                    $views = new \GV\View_Collection();
589
-                    $views->add($value);
590
-
591
-                    self::thaw([
592
-                        '\GravityView_View::atts'                   => $value->settings->as_atts(),
593
-                        '\GravityView_View::view_id'                => $value->ID,
594
-                        '\GravityView_View::back_link_label'        => $value->settings->get('back_link_label', null),
595
-                        '\GravityView_View::form'                   => $value->form ? $value->form->form : null,
596
-                        '\GravityView_View::form_id'                => $value->form ? $value->form->ID : null,
597
-                        '\GravityView_View::is_hide_until_searched' => $value->settings->get('hide_until_searched', null) && !gravityview()->request->is_search(),
598
-
599
-                        '\GravityView_View_Data::views'          => $views,
600
-                        '\GravityView_frontend::gv_output_data'  => \GravityView_View_Data::getInstance(),
601
-                        '\GravityView_frontend::context_view_id' => $value->ID,
602
-                    ]);
603
-                    break;
604
-                case 'post':
605
-                    $has_shortcode = false;
606
-                    foreach (\GV\Shortcode::parse($value->post_content) as $shortcode) {
607
-                        if ($shortcode->name == 'gravityview') {
608
-                            $has_shortcode = true;
609
-                            break;
610
-                        }
611
-                    }
612
-                    self::thaw([
613
-                        '\GravityView_View::post_id'                      => $value->ID,
614
-                        '\GravityView_frontend::post_id'                  => $value->ID,
615
-                        '\GravityView_frontend::is_gravityview_post_type' => $value->post_type == 'gravityview',
616
-                        '\GravityView_frontend::post_has_shortcode'       => $has_shortcode,
617
-                    ]);
618
-                    break;
619
-                case 'views':
620
-                    self::thaw([
621
-                        '\GravityView_View_Data::views'         => $value,
622
-                        '\GravityView_frontend::gv_output_data' => \GravityView_View_Data::getInstance(),
623
-                    ]);
624
-                    break;
625
-                case 'entries':
626
-                    self::thaw([
627
-                        '\GravityView_View::entries' => array_map(function ($e) { return $e->as_entry(); }, $value->all()),
628
-                        '\GravityView_View::total_entries' => $value->total(),
629
-                    ]);
630
-                    break;
631
-                case 'entry':
632
-                    self::thaw([
633
-                        '\GravityView_frontend::single_entry' => $value->ID,
634
-                        '\GravityView_frontend::entry'        => $value->as_entry(),
635
-                        '\GravityView_View::_current_entry'   => $value->as_entry(),
636
-                    ]);
637
-                    break;
638
-                case 'fields':
639
-                    self::thaw([
640
-                        '\GravityView_View::fields' => $value->as_configuration(),
641
-                    ]);
642
-                    break;
643
-                case 'field':
644
-                    self::thaw([
645
-                        '\GravityView_View::_current_field' => [
646
-                            'field_id'       => $value->ID,
647
-                            'field'          => $value->field,
648
-                            'field_settings' => $value->as_configuration(),
649
-                            'form'           => \GravityView_View::getInstance()->getForm(),
650
-                            'field_type'     => $value->type, /** {@since 1.6} */
651
-                            'entry'          => \GravityView_View::getInstance()->getCurrentEntry(),
652
-                            'UID'            => $value->UID,
653
-
654
-                            // 'field_path' => $field_path, /** {@since 1.16} */
655
-                            // 'value' => $value,
656
-                            // 'display_value' => $display_value,
657
-                            // 'format' => $format,
658
-                        ],
659
-                    ]);
660
-                    break;
661
-                case 'request':
662
-                    self::thaw([
663
-                        '\GravityView_View::context' => (
664
-                            $value->is_entry() ? 'single' :
665
-                            (
666
-                                $value->is_edit_entry() ? 'edit' :
667
-                                    ($value->is_view() ? 'directory' : null)
668
-                            )
669
-                        ),
670
-                        '\GravityView_frontend::is_search' => $value->is_search(),
671
-                    ]);
672
-
673
-                    if (!$value->is_entry()) {
674
-                        self::thaw([
675
-                            '\GravityView_frontend::single_entry' => 0,
676
-                            '\GravityView_frontend::entry'        => 0,
677
-                        ]);
678
-                    }
679
-                    break;
680
-                case 'paging':
681
-                    self::thaw([
682
-                        '\GravityView_View::paging' => $value,
683
-                    ]);
684
-                    break;
685
-                case 'sorting':
686
-                    self::thaw([
687
-                        '\GravityView_View::sorting' => $value,
688
-                    ]);
689
-                    break;
690
-                case 'in_the_loop':
691
-                    self::thaw([
692
-                        'wp_query::in_the_loop'  => $value,
693
-                        'wp_actions[loop_start]' => $value ? 1 : 0,
694
-                    ]);
695
-                    break;
696
-            }
697
-        }
698
-
699
-        global $gravityview_view;
700
-        $gravityview_view = \GravityView_View::getInstance();
701
-    }
702
-
703
-    /**
704
-     * Resets the global state completely.
705
-     *
706
-     * Use with utmost care, as filter and action callbacks
707
-     *  may be added again.
708
-     *
709
-     * Does not touch the context stack.
710
-     *
711
-     * @return void
712
-     */
713
-    public static function reset()
714
-    {
715
-        \GravityView_View::$instance = null;
716
-        \GravityView_frontend::$instance = null;
717
-        \GravityView_View_Data::$instance = null;
718
-
719
-        global $wp_query, $wp_actions;
720
-
721
-        $wp_query->in_the_loop = false;
722
-        $wp_actions['loop_start'] = 0;
723
-    }
385
+	private static $stack = [];
386
+
387
+	/**
388
+	 * Set the state depending on the provided configuration.
389
+	 *
390
+	 * Saves current global state and context.
391
+	 *
392
+	 * Configuration keys:
393
+	 *
394
+	 * - \GV\View	view:		sets \GravityView_View::atts, \GravityView_View::view_id,
395
+	 *								 \GravityView_View::back_link_label
396
+	 *								 \GravityView_frontend::context_view_id,
397
+	 *								 \GravityView_View::form, \GravityView_View::form_id
398
+	 * - \GV\Field	field:		sets \GravityView_View::_current_field, \GravityView_View::field_data,
399
+	 * - \GV\Entry	entry:		sets \GravityView_View::_current_entry, \GravityView_frontend::single_entry,
400
+	 *								 \GravityView_frontend::entry
401
+	 * - \WP_Post	post:		sets \GravityView_View::post_id, \GravityView_frontend::post_id,
402
+	 *								 \GravityView_frontend::is_gravityview_post_type,
403
+	 *								 \GravityView_frontend::post_has_shortcode
404
+	 * - array		paging:		sets \GravityView_View::paging
405
+	 * - array		sorting:	sets \GravityView_View::sorting
406
+	 * - array		template:	sets \GravityView_View::template_part_slug, \GravityView_View::template_part_name
407
+	 *
408
+	 * - boolean	in_the_loop sets $wp_actions['loop_start'] and $wp_query::in_the_loop
409
+	 *
410
+	 * also:
411
+	 *
412
+	 * - \GV\Request	request:	sets \GravityView_frontend::is_search, \GravityView_frontend::single_entry,
413
+	 *									 \GravityView_View::context, \GravityView_frontend::entry
414
+	 *
415
+	 * - \GV\View_Collection	views:		sets \GravityView_View_Data::views
416
+	 * - \GV\Field_Collection	fields:		sets \GravityView_View::fields
417
+	 * - \GV\Entry_Collection	entries:	sets \GravityView_View::entries, \GravityView_View::total_entries
418
+	 *
419
+	 * and automagically:
420
+	 *
421
+	 * - \GravityView_View		data:		sets \GravityView_frontend::gv_output_data
422
+	 *
423
+	 * @param array $configuration The configuration.
424
+	 *
425
+	 * @return void
426
+	 */
427
+	public static function push($configuration)
428
+	{
429
+		array_push(self::$stack, self::freeze());
430
+		self::load($configuration);
431
+	}
432
+
433
+	/**
434
+	 * Restores last saved state and context.
435
+	 *
436
+	 * @return void
437
+	 */
438
+	public static function pop()
439
+	{
440
+		self::thaw(array_pop(self::$stack));
441
+	}
442
+
443
+	/**
444
+	 * Serializes the current configuration as needed.
445
+	 *
446
+	 * @return array The configuration.
447
+	 */
448
+	public static function freeze()
449
+	{
450
+		global $wp_actions, $wp_query;
451
+
452
+		return [
453
+			'\GravityView_View::atts'                         => \GravityView_View::getInstance()->getAtts(),
454
+			'\GravityView_View::view_id'                      => \GravityView_View::getInstance()->getViewId(),
455
+			'\GravityView_View::back_link_label'              => \GravityView_View::getInstance()->getBackLinkLabel(false),
456
+			'\GravityView_View_Data::views'                   => \GravityView_View_Data::getInstance()->views,
457
+			'\GravityView_View::entries'                      => \GravityView_View::getInstance()->getEntries(),
458
+			'\GravityView_View::form'                         => \GravityView_View::getInstance()->getForm(),
459
+			'\GravityView_View::form_id'                      => \GravityView_View::getInstance()->getFormId(),
460
+			'\GravityView_View::context'                      => \GravityView_View::getInstance()->getContext(),
461
+			'\GravityView_View::total_entries'                => \GravityView_View::getInstance()->getTotalEntries(),
462
+			'\GravityView_View::post_id'                      => \GravityView_View::getInstance()->getPostId(),
463
+			'\GravityView_View::hide_until_searched'          => \GravityView_View::getInstance()->isHideUntilSearched(),
464
+			'\GravityView_frontend::post_id'                  => \GravityView_frontend::getInstance()->getPostId(),
465
+			'\GravityView_frontend::context_view_id'          => \GravityView_frontend::getInstance()->get_context_view_id(),
466
+			'\GravityView_frontend::is_gravityview_post_type' => \GravityView_frontend::getInstance()->isGravityviewPostType(),
467
+			'\GravityView_frontend::post_has_shortcode'       => \GravityView_frontend::getInstance()->isPostHasShortcode(),
468
+			'\GravityView_frontend::gv_output_data'           => \GravityView_frontend::getInstance()->getGvOutputData(),
469
+			'\GravityView_View::paging'                       => \GravityView_View::getInstance()->getPaging(),
470
+			'\GravityView_View::sorting'                      => \GravityView_View::getInstance()->getSorting(),
471
+			'\GravityView_frontend::is_search'                => \GravityView_frontend::getInstance()->isSearch(),
472
+			'\GravityView_frontend::single_entry'             => \GravityView_frontend::getInstance()->getSingleEntry(),
473
+			'\GravityView_frontend::entry'                    => \GravityView_frontend::getInstance()->getEntry(),
474
+			'\GravityView_View::_current_entry'               => \GravityView_View::getInstance()->getCurrentEntry(),
475
+			'\GravityView_View::fields'                       => \GravityView_View::getInstance()->getFields(),
476
+			'\GravityView_View::_current_field'               => \GravityView_View::getInstance()->getCurrentField(),
477
+			'wp_actions[loop_start]'                          => empty($wp_actions['loop_start']) ? 0 : $wp_actions['loop_start'],
478
+			'wp_query::in_the_loop'                           => $wp_query->in_the_loop,
479
+		];
480
+	}
481
+
482
+	/**
483
+	 * Deserializes a saved configuration. Modifies the global state.
484
+	 *
485
+	 * @param array $data Saved configuration from self::freeze()
486
+	 */
487
+	public static function thaw($data)
488
+	{
489
+		foreach ((array) $data as $key => $value) {
490
+			switch ($key) {
491
+				case '\GravityView_View::atts':
492
+					\GravityView_View::getInstance()->setAtts($value);
493
+					break;
494
+				case '\GravityView_View::view_id':
495
+					\GravityView_View::getInstance()->setViewId($value);
496
+					break;
497
+				case '\GravityView_View::back_link_label':
498
+					\GravityView_View::getInstance()->setBackLinkLabel($value);
499
+					break;
500
+				case '\GravityView_View_Data::views':
501
+					\GravityView_View_Data::getInstance()->views = $value;
502
+					break;
503
+				case '\GravityView_View::entries':
504
+					\GravityView_View::getInstance()->setEntries($value);
505
+					break;
506
+				case '\GravityView_View::form':
507
+					\GravityView_View::getInstance()->setForm($value);
508
+					break;
509
+				case '\GravityView_View::form_id':
510
+					\GravityView_View::getInstance()->setFormId($value);
511
+					break;
512
+				case '\GravityView_View::context':
513
+					\GravityView_View::getInstance()->setContext($value);
514
+					break;
515
+				case '\GravityView_View::total_entries':
516
+					\GravityView_View::getInstance()->setTotalEntries($value);
517
+					break;
518
+				case '\GravityView_View::post_id':
519
+					\GravityView_View::getInstance()->setPostId($value);
520
+					break;
521
+				case '\GravityView_View::is_hide_until_searched':
522
+					\GravityView_View::getInstance()->setHideUntilSearched($value);
523
+					break;
524
+				case '\GravityView_frontend::post_id':
525
+					\GravityView_frontend::getInstance()->setPostId($value);
526
+					break;
527
+				case '\GravityView_frontend::context_view_id':
528
+					$frontend = \GravityView_frontend::getInstance();
529
+					$frontend->context_view_id = $value;
530
+					break;
531
+				case '\GravityView_frontend::is_gravityview_post_type':
532
+					\GravityView_frontend::getInstance()->setIsGravityviewPostType($value);
533
+					break;
534
+				case '\GravityView_frontend::post_has_shortcode':
535
+					\GravityView_frontend::getInstance()->setPostHasShortcode($value);
536
+					break;
537
+				case '\GravityView_frontend::gv_output_data':
538
+					\GravityView_frontend::getInstance()->setGvOutputData($value);
539
+					break;
540
+				case '\GravityView_View::paging':
541
+					\GravityView_View::getInstance()->setPaging($value);
542
+					break;
543
+				case '\GravityView_View::sorting':
544
+					\GravityView_View::getInstance()->setSorting($value);
545
+					break;
546
+				case '\GravityView_frontend::is_search':
547
+					\GravityView_frontend::getInstance()->setIsSearch($value);
548
+					break;
549
+				case '\GravityView_frontend::single_entry':
550
+					\GravityView_frontend::getInstance()->setSingleEntry($value);
551
+					break;
552
+				case '\GravityView_frontend::entry':
553
+					\GravityView_frontend::getInstance()->setEntry($value);
554
+					break;
555
+				case '\GravityView_View::_current_entry':
556
+					\GravityView_View::getInstance()->setCurrentEntry($value);
557
+					break;
558
+				case '\GravityView_View::fields':
559
+					\GravityView_View::getInstance()->setFields($value);
560
+					break;
561
+				case '\GravityView_View::_current_field':
562
+					\GravityView_View::getInstance()->setCurrentField($value);
563
+					break;
564
+				case 'wp_actions[loop_start]':
565
+					global $wp_actions;
566
+					$wp_actions['loop_start'] = $value;
567
+					break;
568
+				case 'wp_query::in_the_loop':
569
+					global $wp_query;
570
+					$wp_query->in_the_loop = $value;
571
+					break;
572
+			}
573
+		}
574
+	}
575
+
576
+	/**
577
+	 * Hydrates the legacy context globals as needed.
578
+	 *
579
+	 * @see Legacy_Context::push() for format.
580
+	 *
581
+	 * @return void
582
+	 */
583
+	public static function load($configuration)
584
+	{
585
+		foreach ((array) $configuration as $key => $value) {
586
+			switch ($key) {
587
+				case 'view':
588
+					$views = new \GV\View_Collection();
589
+					$views->add($value);
590
+
591
+					self::thaw([
592
+						'\GravityView_View::atts'                   => $value->settings->as_atts(),
593
+						'\GravityView_View::view_id'                => $value->ID,
594
+						'\GravityView_View::back_link_label'        => $value->settings->get('back_link_label', null),
595
+						'\GravityView_View::form'                   => $value->form ? $value->form->form : null,
596
+						'\GravityView_View::form_id'                => $value->form ? $value->form->ID : null,
597
+						'\GravityView_View::is_hide_until_searched' => $value->settings->get('hide_until_searched', null) && !gravityview()->request->is_search(),
598
+
599
+						'\GravityView_View_Data::views'          => $views,
600
+						'\GravityView_frontend::gv_output_data'  => \GravityView_View_Data::getInstance(),
601
+						'\GravityView_frontend::context_view_id' => $value->ID,
602
+					]);
603
+					break;
604
+				case 'post':
605
+					$has_shortcode = false;
606
+					foreach (\GV\Shortcode::parse($value->post_content) as $shortcode) {
607
+						if ($shortcode->name == 'gravityview') {
608
+							$has_shortcode = true;
609
+							break;
610
+						}
611
+					}
612
+					self::thaw([
613
+						'\GravityView_View::post_id'                      => $value->ID,
614
+						'\GravityView_frontend::post_id'                  => $value->ID,
615
+						'\GravityView_frontend::is_gravityview_post_type' => $value->post_type == 'gravityview',
616
+						'\GravityView_frontend::post_has_shortcode'       => $has_shortcode,
617
+					]);
618
+					break;
619
+				case 'views':
620
+					self::thaw([
621
+						'\GravityView_View_Data::views'         => $value,
622
+						'\GravityView_frontend::gv_output_data' => \GravityView_View_Data::getInstance(),
623
+					]);
624
+					break;
625
+				case 'entries':
626
+					self::thaw([
627
+						'\GravityView_View::entries' => array_map(function ($e) { return $e->as_entry(); }, $value->all()),
628
+						'\GravityView_View::total_entries' => $value->total(),
629
+					]);
630
+					break;
631
+				case 'entry':
632
+					self::thaw([
633
+						'\GravityView_frontend::single_entry' => $value->ID,
634
+						'\GravityView_frontend::entry'        => $value->as_entry(),
635
+						'\GravityView_View::_current_entry'   => $value->as_entry(),
636
+					]);
637
+					break;
638
+				case 'fields':
639
+					self::thaw([
640
+						'\GravityView_View::fields' => $value->as_configuration(),
641
+					]);
642
+					break;
643
+				case 'field':
644
+					self::thaw([
645
+						'\GravityView_View::_current_field' => [
646
+							'field_id'       => $value->ID,
647
+							'field'          => $value->field,
648
+							'field_settings' => $value->as_configuration(),
649
+							'form'           => \GravityView_View::getInstance()->getForm(),
650
+							'field_type'     => $value->type, /** {@since 1.6} */
651
+							'entry'          => \GravityView_View::getInstance()->getCurrentEntry(),
652
+							'UID'            => $value->UID,
653
+
654
+							// 'field_path' => $field_path, /** {@since 1.16} */
655
+							// 'value' => $value,
656
+							// 'display_value' => $display_value,
657
+							// 'format' => $format,
658
+						],
659
+					]);
660
+					break;
661
+				case 'request':
662
+					self::thaw([
663
+						'\GravityView_View::context' => (
664
+							$value->is_entry() ? 'single' :
665
+							(
666
+								$value->is_edit_entry() ? 'edit' :
667
+									($value->is_view() ? 'directory' : null)
668
+							)
669
+						),
670
+						'\GravityView_frontend::is_search' => $value->is_search(),
671
+					]);
672
+
673
+					if (!$value->is_entry()) {
674
+						self::thaw([
675
+							'\GravityView_frontend::single_entry' => 0,
676
+							'\GravityView_frontend::entry'        => 0,
677
+						]);
678
+					}
679
+					break;
680
+				case 'paging':
681
+					self::thaw([
682
+						'\GravityView_View::paging' => $value,
683
+					]);
684
+					break;
685
+				case 'sorting':
686
+					self::thaw([
687
+						'\GravityView_View::sorting' => $value,
688
+					]);
689
+					break;
690
+				case 'in_the_loop':
691
+					self::thaw([
692
+						'wp_query::in_the_loop'  => $value,
693
+						'wp_actions[loop_start]' => $value ? 1 : 0,
694
+					]);
695
+					break;
696
+			}
697
+		}
698
+
699
+		global $gravityview_view;
700
+		$gravityview_view = \GravityView_View::getInstance();
701
+	}
702
+
703
+	/**
704
+	 * Resets the global state completely.
705
+	 *
706
+	 * Use with utmost care, as filter and action callbacks
707
+	 *  may be added again.
708
+	 *
709
+	 * Does not touch the context stack.
710
+	 *
711
+	 * @return void
712
+	 */
713
+	public static function reset()
714
+	{
715
+		\GravityView_View::$instance = null;
716
+		\GravityView_frontend::$instance = null;
717
+		\GravityView_View_Data::$instance = null;
718
+
719
+		global $wp_query, $wp_actions;
720
+
721
+		$wp_query->in_the_loop = false;
722
+		$wp_actions['loop_start'] = 0;
723
+	}
724 724
 }
725 725
 
726 726
 /** Add some global fix for field capability discrepancies. */
727 727
 add_filter('gravityview/configuration/fields', function ($fields) {
728
-    if (empty($fields)) {
729
-        return $fields;
730
-    }
731
-
732
-    /**
733
-     * Each view field is saved in a weird capability state by default.
734
-     *
735
-     * With loggedin set to false, but a capability of 'read' it introduces
736
-     *  some logical issues and is not robust. Fix this behavior throughout
737
-     *  core by making sure capability is '' if log in is not required.
738
-     *
739
-     * Perhaps in the UI a fix would be to unite the two fields (as our new
740
-     *  \GV\Field class already does) into one dropdown:
741
-     *
742
-     * Anyone, Logged In Only, ... etc. etc.
743
-     *
744
-     * The two "settings" should be as tightly coupled as possible to avoid
745
-     *  split logic scenarios. Uniting them into one field is the way to go.
746
-     */
747
-    foreach ($fields as $position => &$_fields) {
748
-        if (empty($_fields) || !is_array($_fields)) {
749
-            continue;
750
-        }
751
-
752
-        foreach ($_fields as $uid => &$_field) {
753
-            if (!isset($_field['only_loggedin'])) {
754
-                continue;
755
-            }
756
-            /** If we do not require login, we don't require a cap. */
757
-            $_field['only_loggedin'] != '1' && ($_field['only_loggedin_cap'] = '');
758
-        }
759
-    }
760
-
761
-    return $fields;
728
+	if (empty($fields)) {
729
+		return $fields;
730
+	}
731
+
732
+	/**
733
+	 * Each view field is saved in a weird capability state by default.
734
+	 *
735
+	 * With loggedin set to false, but a capability of 'read' it introduces
736
+	 *  some logical issues and is not robust. Fix this behavior throughout
737
+	 *  core by making sure capability is '' if log in is not required.
738
+	 *
739
+	 * Perhaps in the UI a fix would be to unite the two fields (as our new
740
+	 *  \GV\Field class already does) into one dropdown:
741
+	 *
742
+	 * Anyone, Logged In Only, ... etc. etc.
743
+	 *
744
+	 * The two "settings" should be as tightly coupled as possible to avoid
745
+	 *  split logic scenarios. Uniting them into one field is the way to go.
746
+	 */
747
+	foreach ($fields as $position => &$_fields) {
748
+		if (empty($_fields) || !is_array($_fields)) {
749
+			continue;
750
+		}
751
+
752
+		foreach ($_fields as $uid => &$_field) {
753
+			if (!isset($_field['only_loggedin'])) {
754
+				continue;
755
+			}
756
+			/** If we do not require login, we don't require a cap. */
757
+			$_field['only_loggedin'] != '1' && ($_field['only_loggedin_cap'] = '');
758
+		}
759
+	}
760
+
761
+	return $fields;
762 762
 });
763 763
 
764 764
 /** Add a future fix to make sure field configurations include the form ID. */
765 765
 add_filter('gravityview/view/configuration/fields', function ($fields, $view) {
766
-    if (!$view || empty($fields)) {
767
-        return $fields;
768
-    }
769
-
770
-    if (!$view->form || !$view->form->ID) {
771
-        return $fields;
772
-    }
773
-
774
-    /**
775
-     * In order to instantiate the correct \GV\Field implementation
776
-     *  we need to provide a form_id inside the configuration.
777
-     *
778
-     * @todo Make sure this actually happens in the admin side
779
-     *  when saving the views.
780
-     */
781
-    foreach ($fields as $position => &$_fields) {
782
-        if (empty($_fields) || !is_array($_fields)) {
783
-            continue;
784
-        }
785
-
786
-        foreach ($_fields as $uid => &$_field) {
787
-            if (!empty($_field['id']) && is_numeric($_field['id']) && empty($_field['form_id'])) {
788
-                $_field['form_id'] = $view->form->ID;
789
-            }
790
-        }
791
-    }
792
-
793
-    return $fields;
766
+	if (!$view || empty($fields)) {
767
+		return $fields;
768
+	}
769
+
770
+	if (!$view->form || !$view->form->ID) {
771
+		return $fields;
772
+	}
773
+
774
+	/**
775
+	 * In order to instantiate the correct \GV\Field implementation
776
+	 *  we need to provide a form_id inside the configuration.
777
+	 *
778
+	 * @todo Make sure this actually happens in the admin side
779
+	 *  when saving the views.
780
+	 */
781
+	foreach ($fields as $position => &$_fields) {
782
+		if (empty($_fields) || !is_array($_fields)) {
783
+			continue;
784
+		}
785
+
786
+		foreach ($_fields as $uid => &$_field) {
787
+			if (!empty($_field['id']) && is_numeric($_field['id']) && empty($_field['form_id'])) {
788
+				$_field['form_id'] = $view->form->ID;
789
+			}
790
+		}
791
+	}
792
+
793
+	return $fields;
794 794
 }, 10, 2);
795 795
 
796 796
 /** Make sure the non-configured notice is not output twice. */
797 797
 add_action('gravityview/template/after', function ($gravityview = null) {
798
-    if (class_exists('\GravityView_frontend')) {
799
-        global $wp_filter;
800
-
801
-        if (empty($wp_filter['gravityview_after'])) {
802
-            return;
803
-        }
804
-
805
-        foreach ($wp_filter['gravityview_after']->callbacks[10] as $function_key => $callback) {
806
-            if (strpos($function_key, 'context_not_configured_warning')) {
807
-                unset($wp_filter['gravityview_after']->callbacks[10][$function_key]);
808
-            }
809
-        }
810
-    }
798
+	if (class_exists('\GravityView_frontend')) {
799
+		global $wp_filter;
800
+
801
+		if (empty($wp_filter['gravityview_after'])) {
802
+			return;
803
+		}
804
+
805
+		foreach ($wp_filter['gravityview_after']->callbacks[10] as $function_key => $callback) {
806
+			if (strpos($function_key, 'context_not_configured_warning')) {
807
+				unset($wp_filter['gravityview_after']->callbacks[10][$function_key]);
808
+			}
809
+		}
810
+	}
811 811
 });
812 812
 
813 813
 add_filter('gravityview/query/is_null_condition', function () {
814
-    if (!class_exists($class = '\GV\Mocks\GF_Query_Condition_IS_NULL')) {
815
-        require_once gravityview()->plugin->dir('future/_mocks.isnull.php');
816
-    }
814
+	if (!class_exists($class = '\GV\Mocks\GF_Query_Condition_IS_NULL')) {
815
+		require_once gravityview()->plugin->dir('future/_mocks.isnull.php');
816
+	}
817 817
 
818
-    return $class;
818
+	return $class;
819 819
 });
Please login to merge, or discard this patch.
Spacing   +184 added lines, -186 removed lines patch added patch discarded remove patch
@@ -15,51 +15,51 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return array|false The old array data, or false on error.
17 17
  */
18
-function GravityView_View_Data_add_view($view_id, $atts, $_this)
18
+function GravityView_View_Data_add_view( $view_id, $atts, $_this )
19 19
 {
20 20
     /** Handle array of IDs. */
21
-    if (is_array($view_id)) {
22
-        foreach ($view_id as $id) {
23
-            call_user_func(__FUNCTION__, $id, $atts, $_this);
21
+    if ( is_array( $view_id ) ) {
22
+        foreach ( $view_id as $id ) {
23
+            call_user_func( __FUNCTION__, $id, $atts, $_this );
24 24
         }
25 25
 
26
-        if (!$_this->views->count()) {
27
-            return [];
26
+        if ( ! $_this->views->count() ) {
27
+            return [ ];
28 28
         }
29 29
 
30 30
         return array_combine(
31
-            array_map(function ($view) { return $view->ID; }, $_this->views->all()),
32
-            array_map(function ($view) { return $view->as_data(); }, $_this->views->all())
31
+            array_map( function( $view ) { return $view->ID; }, $_this->views->all() ),
32
+            array_map( function( $view ) { return $view->as_data(); }, $_this->views->all() )
33 33
         );
34 34
     }
35 35
 
36 36
     /** View has been set already. */
37
-    if ($view = $_this->views->get($view_id)) {
38
-        do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id));
37
+    if ( $view = $_this->views->get( $view_id ) ) {
38
+        do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id ) );
39 39
 
40 40
         return $view->as_data();
41 41
     }
42 42
 
43
-    $view = \GV\View::by_id($view_id);
44
-    if (!$view) {
45
-        do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id));
43
+    $view = \GV\View::by_id( $view_id );
44
+    if ( ! $view ) {
45
+        do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id ) );
46 46
 
47 47
         return false;
48 48
     }
49 49
 
50 50
     /** Doesn't have a connected form. */
51
-    if (!$view->form) {
52
-        do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id));
51
+    if ( ! $view->form ) {
52
+        do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id ) );
53 53
 
54 54
         return false;
55 55
     }
56 56
 
57 57
     /** Update the settings */
58
-    if (is_array($atts)) {
59
-        $view->settings->update($atts);
58
+    if ( is_array( $atts ) ) {
59
+        $view->settings->update( $atts );
60 60
     }
61 61
 
62
-    $_this->views->add($view);
62
+    $_this->views->add( $view );
63 63
 
64 64
     return $view->as_data();
65 65
 }
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
  *               \GravityView_frontend::get_view_entries(), the paging parameters
76 76
  *               and a total count of all entries.
77 77
  */
78
-function GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count)
78
+function GravityView_frontend_get_view_entries( $args, $form_id, $parameters, $count )
79 79
 {
80
-    $form = \GV\GF_Form::by_id($form_id);
80
+    $form = \GV\GF_Form::by_id( $form_id );
81 81
 
82 82
     /**
83 83
      * Kick off all advanced filters.
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
      *  calculated for hte view, and `$criteria` are the filtered ones
88 88
      *  retrieved via \GVCommon::calculate_get_entries_criteria()
89 89
      */
90
-    $criteria = \GVCommon::calculate_get_entries_criteria($parameters, $form->ID);
90
+    $criteria = \GVCommon::calculate_get_entries_criteria( $parameters, $form->ID );
91 91
 
92
-    do_action('gravityview_log_debug', '[gravityview_get_entries] Final Parameters', $criteria);
92
+    do_action( 'gravityview_log_debug', '[gravityview_get_entries] Final Parameters', $criteria );
93 93
 
94 94
     /** ...and all the (now deprecated) filters that usually follow `gravityview_get_entries` */
95 95
 
@@ -97,33 +97,33 @@  discard block
 block discarded – undo
97 97
      * @deprecated
98 98
      * Do not use this filter anymore.
99 99
      */
100
-    $entries = apply_filters_ref_array('gravityview_before_get_entries', [null, $criteria, $parameters, &$count]);
100
+    $entries = apply_filters_ref_array( 'gravityview_before_get_entries', [ null, $criteria, $parameters, &$count ] );
101 101
 
102
-    if (!is_null($entries)) {
102
+    if ( ! is_null( $entries ) ) {
103 103
         /**
104 104
          * We've been given an entries result that we can return,
105 105
          *  just set the paging and we're good to go.
106 106
          */
107
-        $paging = \GV\Utils::get($parameters, 'paging');
107
+        $paging = \GV\Utils::get( $parameters, 'paging' );
108 108
     } else {
109 109
         $entries = new \GV\Entry_Collection();
110
-        if ($view = \GV\View::by_id(\GV\Utils::get($args, 'id'))) {
111
-            $view->settings->update($args);
112
-            $entries = $view->get_entries(gravityview()->request);
110
+        if ( $view = \GV\View::by_id( \GV\Utils::get( $args, 'id' ) ) ) {
111
+            $view->settings->update( $args );
112
+            $entries = $view->get_entries( gravityview()->request );
113 113
         }
114 114
 
115
-        $page = \GV\Utils::get($parameters['paging'], 'current_page') ?: ((($parameters['paging']['offset'] - $view->settings->get('offset')) / $parameters['paging']['page_size']) + 1);
115
+        $page = \GV\Utils::get( $parameters[ 'paging' ], 'current_page' ) ?: ( ( ( $parameters[ 'paging' ][ 'offset' ] - $view->settings->get( 'offset' ) ) / $parameters[ 'paging' ][ 'page_size' ] ) + 1 );
116 116
 
117 117
         /** Set paging, count and unwrap the entries. */
118 118
         $paging = [
119
-            'offset'    => ($page - 1) * $view->settings->get('page_size'),
120
-            'page_size' => $view->settings->get('page_size'),
119
+            'offset'    => ( $page - 1 ) * $view->settings->get( 'page_size' ),
120
+            'page_size' => $view->settings->get( 'page_size' ),
121 121
         ];
122 122
         /**
123 123
          * GF_Query does not subtract the offset, we have to subtract it ourselves.
124 124
          */
125
-        $count = $entries->total() - (gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY) ? $view->settings->get('offset') : 0);
126
-        $entries = array_map(function ($e) { return $e->as_entry(); }, $entries->all());
125
+        $count = $entries->total() - ( gravityview()->plugin->supports( \GV\Plugin::FEATURE_GFQUERY ) ? $view->settings->get( 'offset' ) : 0 );
126
+        $entries = array_map( function( $e ) { return $e->as_entry(); }, $entries->all() );
127 127
     }
128 128
 
129 129
     /** Just one more filter, for compatibility's sake! */
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
      * @deprecated
133 133
      * Do not use this filter anymore.
134 134
      */
135
-    $entries = apply_filters_ref_array('gravityview_entries', [$entries, $criteria, $parameters, &$count]);
135
+    $entries = apply_filters_ref_array( 'gravityview_entries', [ $entries, $criteria, $parameters, &$count ] );
136 136
 
137
-    return [$entries, $paging, $count];
137
+    return [ $entries, $paging, $count ];
138 138
 }
139 139
 
140 140
 /**
@@ -152,21 +152,21 @@  discard block
 block discarded – undo
152 152
  *
153 153
  * @return null|string The value of a field in an entry.
154 154
  */
155
-function GravityView_API_field_value($entry, $field_settings, $format)
155
+function GravityView_API_field_value( $entry, $field_settings, $format )
156 156
 {
157
-    if (empty($entry['form_id']) || empty($field_settings['id'])) {
158
-        gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
157
+    if ( empty( $entry[ 'form_id' ] ) || empty( $field_settings[ 'id' ] ) ) {
158
+        gravityview()->log->error( 'No entry or field_settings[id] supplied', [ 'data' => [ func_get_args() ] ] );
159 159
 
160 160
         return null;
161 161
     }
162 162
 
163
-    if (!empty($entry['_multi']) && !empty($field_settings['form_id']) && !empty($entry['_multi'][$field_settings['form_id']])) {
164
-        $multientry = \GV\Multi_Entry::from_entries(array_map('\GV\GF_Entry::from_entry', $entry['_multi']));
165
-        $entry = $entry['_multi'][$field_settings['form_id']];
163
+    if ( ! empty( $entry[ '_multi' ] ) && ! empty( $field_settings[ 'form_id' ] ) && ! empty( $entry[ '_multi' ][ $field_settings[ 'form_id' ] ] ) ) {
164
+        $multientry = \GV\Multi_Entry::from_entries( array_map( '\GV\GF_Entry::from_entry', $entry[ '_multi' ] ) );
165
+        $entry = $entry[ '_multi' ][ $field_settings[ 'form_id' ] ];
166 166
     }
167 167
 
168
-    if (empty($entry['id']) || !$entry = \GV\GF_Entry::by_id($entry['id'])) {
169
-        gravityview()->log->error('Invalid \GV\GF_Entry supplied', ['data' => $entry]);
168
+    if ( empty( $entry[ 'id' ] ) || ! $entry = \GV\GF_Entry::by_id( $entry[ 'id' ] ) ) {
169
+        gravityview()->log->error( 'Invalid \GV\GF_Entry supplied', [ 'data' => $entry ] );
170 170
 
171 171
         return null;
172 172
     }
@@ -176,19 +176,19 @@  discard block
 block discarded – undo
176 176
      *
177 177
      * Fields with a numeric ID are Gravity Forms ones.
178 178
      */
179
-    $source = is_numeric($field_settings['id']) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
179
+    $source = is_numeric( $field_settings[ 'id' ] ) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
180 180
 
181 181
     /** Initialize the future field. */
182
-    switch ($source) {
182
+    switch ( $source ) {
183 183
         /** The Gravity Forms backend. */
184 184
         case \GV\Source::BACKEND_GRAVITYFORMS:
185
-            if (!$form = \GV\GF_Form::by_id($entry['form_id'])) {
186
-                gravityview()->log->error('No form Gravity Form found for entry', ['data' => $entry]);
185
+            if ( ! $form = \GV\GF_Form::by_id( $entry[ 'form_id' ] ) ) {
186
+                gravityview()->log->error( 'No form Gravity Form found for entry', [ 'data' => $entry ] );
187 187
 
188 188
                 return null;
189 189
             }
190 190
 
191
-            if (!$field = $form::get_field($form, $field_settings['id'])) {
191
+            if ( ! $field = $form::get_field( $form, $field_settings[ 'id' ] ) ) {
192 192
                 return null;
193 193
             }
194 194
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
         /** Our internal backend. */
198 198
         case \GV\Source::BACKEND_INTERNAL:
199
-            if (!$field = \GV\Internal_Source::get_field($field_settings['id'])) {
199
+            if ( ! $field = \GV\Internal_Source::get_field( $field_settings[ 'id' ] ) ) {
200 200
                 return null;
201 201
             }
202 202
 
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
 
205 205
         /** An unidentified backend. */
206 206
         default:
207
-            gravityview()->log->error('Could not determine source for entry', ['data' => [func_get_args()]]);
207
+            gravityview()->log->error( 'Could not determine source for entry', [ 'data' => [ func_get_args() ] ] );
208 208
 
209 209
             return null;
210 210
     }
211 211
 
212 212
     /** Add the field settings. */
213
-    $field->update_configuration($field_settings);
213
+    $field->update_configuration( $field_settings );
214 214
 
215 215
     $renderer = new \GV\Field_Renderer();
216 216
 
217
-    return $renderer->render($field, gravityview()->views->get(), $source == \GV\Source::BACKEND_GRAVITYFORMS ? $form : null, isset($multientry) ? $multientry : $entry, gravityview()->request);
217
+    return $renderer->render( $field, gravityview()->views->get(), $source == \GV\Source::BACKEND_GRAVITYFORMS ? $form : null, isset( $multientry ) ? $multientry : $entry, gravityview()->request );
218 218
 }
219 219
 
220 220
 /**
@@ -230,17 +230,17 @@  discard block
 block discarded – undo
230 230
  *
231 231
  * @return string The label of a field in an entry.
232 232
  */
233
-function GravityView_API_field_label($form, $field_settings, $entry, $force_show_label = false)
233
+function GravityView_API_field_label( $form, $field_settings, $entry, $force_show_label = false )
234 234
 {
235 235
 
236 236
     /** A bail condition. */
237
-    $bail = function ($label, $field_settings, $entry, $force_show_label, $form) {
238
-        if (!empty($field_settings['show_label']) || $force_show_label) {
239
-            $label = isset($field_settings['label']) ? $field_settings['label'] : '';
237
+    $bail = function( $label, $field_settings, $entry, $force_show_label, $form ) {
238
+        if ( ! empty( $field_settings[ 'show_label' ] ) || $force_show_label ) {
239
+            $label = isset( $field_settings[ 'label' ] ) ? $field_settings[ 'label' ] : '';
240 240
 
241 241
             // Use Gravity Forms label by default, but if a custom label is defined in GV, use it.
242
-            if (!empty($field_settings['custom_label'])) {
243
-                $label = \GravityView_API::replace_variables($field_settings['custom_label'], $form, $entry);
242
+            if ( ! empty( $field_settings[ 'custom_label' ] ) ) {
243
+                $label = \GravityView_API::replace_variables( $field_settings[ 'custom_label' ], $form, $entry );
244 244
             }
245 245
 
246 246
             /**
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
              * @param string $appended_content Content you can add after a label. Empty by default.
250 250
              * @param array  $field            GravityView field array
251 251
              */
252
-            $label .= apply_filters('gravityview_render_after_label', '', $field_settings);
252
+            $label .= apply_filters( 'gravityview_render_after_label', '', $field_settings );
253 253
         }
254 254
 
255 255
         /**
@@ -262,30 +262,30 @@  discard block
 block discarded – undo
262 262
          * @param array  $form  Gravity Forms form array
263 263
          * @param array  $entry Gravity Forms entry array
264 264
          */
265
-        $label = apply_filters('gravityview/template/field_label', $label, $field_settings, $form, $entry);
265
+        $label = apply_filters( 'gravityview/template/field_label', $label, $field_settings, $form, $entry );
266 266
 
267 267
         return $label;
268 268
     };
269 269
 
270 270
     $label = '';
271 271
 
272
-    if (!empty($entry['_multi']) && !empty($field_settings['form_id']) && !empty($entry['_multi'][$field_settings['form_id']])) {
273
-        $entry = $entry['_multi'][$field_settings['form_id']];
274
-        if ($_form = \GV\GF_Form::by_id($field_settings['form_id'])) {
272
+    if ( ! empty( $entry[ '_multi' ] ) && ! empty( $field_settings[ 'form_id' ] ) && ! empty( $entry[ '_multi' ][ $field_settings[ 'form_id' ] ] ) ) {
273
+        $entry = $entry[ '_multi' ][ $field_settings[ 'form_id' ] ];
274
+        if ( $_form = \GV\GF_Form::by_id( $field_settings[ 'form_id' ] ) ) {
275 275
             $form = $_form->form;
276 276
         }
277 277
     }
278 278
 
279
-    if (empty($entry['form_id']) || empty($field_settings['id'])) {
280
-        gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
279
+    if ( empty( $entry[ 'form_id' ] ) || empty( $field_settings[ 'id' ] ) ) {
280
+        gravityview()->log->error( 'No entry or field_settings[id] supplied', [ 'data' => [ func_get_args() ] ] );
281 281
 
282
-        return $bail($label, $field_settings, $entry, $force_show_label, $form);
282
+        return $bail( $label, $field_settings, $entry, $force_show_label, $form );
283 283
     }
284 284
 
285
-    if (empty($entry['id']) || !$gv_entry = \GV\GF_Entry::by_id($entry['id'])) {
286
-        gravityview()->log->error('Invalid \GV\GF_Entry supplied', ['data' => $entry]);
285
+    if ( empty( $entry[ 'id' ] ) || ! $gv_entry = \GV\GF_Entry::by_id( $entry[ 'id' ] ) ) {
286
+        gravityview()->log->error( 'Invalid \GV\GF_Entry supplied', [ 'data' => $entry ] );
287 287
 
288
-        return $bail($label, $field_settings, $entry, $force_show_label, $form);
288
+        return $bail( $label, $field_settings, $entry, $force_show_label, $form );
289 289
     }
290 290
 
291 291
     $entry = $gv_entry;
@@ -295,53 +295,53 @@  discard block
 block discarded – undo
295 295
      *
296 296
      * Fields with a numeric ID are Gravity Forms ones.
297 297
      */
298
-    $source = is_numeric($field_settings['id']) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
298
+    $source = is_numeric( $field_settings[ 'id' ] ) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
299 299
 
300 300
     /** Initialize the future field. */
301
-    switch ($source) {
301
+    switch ( $source ) {
302 302
         /** The Gravity Forms backend. */
303 303
         case \GV\Source::BACKEND_GRAVITYFORMS:
304
-            if (!$gf_form = \GV\GF_Form::by_id($entry['form_id'])) {
305
-                gravityview()->log->error('No form Gravity Form found for entry', ['data' => $entry]);
304
+            if ( ! $gf_form = \GV\GF_Form::by_id( $entry[ 'form_id' ] ) ) {
305
+                gravityview()->log->error( 'No form Gravity Form found for entry', [ 'data' => $entry ] );
306 306
 
307
-                return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $form);
307
+                return $bail( $label, $field_settings, $entry->as_entry(), $force_show_label, $form );
308 308
             }
309 309
 
310
-            if (!$field = $gf_form::get_field($gf_form, $field_settings['id'])) {
311
-                gravityview()->log->error('No field found for specified form and field ID #{field_id}', ['field_id' => $field_settings['id'], 'data' => $form]);
310
+            if ( ! $field = $gf_form::get_field( $gf_form, $field_settings[ 'id' ] ) ) {
311
+                gravityview()->log->error( 'No field found for specified form and field ID #{field_id}', [ 'field_id' => $field_settings[ 'id' ], 'data' => $form ] );
312 312
 
313
-                return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $gf_form->form);
313
+                return $bail( $label, $field_settings, $entry->as_entry(), $force_show_label, $gf_form->form );
314 314
             }
315
-            if (empty($field_settings['show_label'])) {
315
+            if ( empty( $field_settings[ 'show_label' ] ) ) {
316 316
                 /** The label never wins... */
317
-                $field_settings['label'] = '';
317
+                $field_settings[ 'label' ] = '';
318 318
             }
319 319
 
320 320
             break;
321 321
 
322 322
         /** Our internal backend. */
323 323
         case \GV\Source::BACKEND_INTERNAL:
324
-            if (!$field = \GV\Internal_Source::get_field($field_settings['id'])) {
325
-                return $bail($label, $field_settings, $entry->as_entry(), $force_show_label, $form);
324
+            if ( ! $field = \GV\Internal_Source::get_field( $field_settings[ 'id' ] ) ) {
325
+                return $bail( $label, $field_settings, $entry->as_entry(), $force_show_label, $form );
326 326
             }
327 327
             break;
328 328
 
329 329
         /** An unidentified backend. */
330 330
         default:
331
-            gravityview()->log->error('Could not determine source for entry. Using empty field.', ['data' => [func_get_args()]]);
331
+            gravityview()->log->error( 'Could not determine source for entry. Using empty field.', [ 'data' => [ func_get_args() ] ] );
332 332
             $field = new \GV\Field();
333 333
             break;
334 334
     }
335 335
 
336
-    if ($force_show_label) {
337
-        $field_settings['show_label'] = '1';
336
+    if ( $force_show_label ) {
337
+        $field_settings[ 'show_label' ] = '1';
338 338
     }
339 339
 
340 340
     /** Add the field settings. */
341
-    $field->update_configuration($field_settings);
341
+    $field->update_configuration( $field_settings );
342 342
 
343
-    if (!empty($field->show_label)) {
344
-        $label = $field->get_label(null, isset($gf_form) ? $gf_form : null, $entry);
343
+    if ( ! empty( $field->show_label ) ) {
344
+        $label = $field->get_label( null, isset( $gf_form ) ? $gf_form : null, $entry );
345 345
 
346 346
         /**
347 347
          * @filter `gravityview_render_after_label` Append content to a field label
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
          * @param string $appended_content Content you can add after a label. Empty by default.
350 350
          * @param array  $field            GravityView field array
351 351
          */
352
-        $label .= apply_filters('gravityview_render_after_label', '', $field->as_configuration());
352
+        $label .= apply_filters( 'gravityview_render_after_label', '', $field->as_configuration() );
353 353
     }
354 354
 
355 355
     /**
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * @param array  $form  Gravity Forms form array
363 363
      * @param array  $entry Gravity Forms entry array
364 364
      */
365
-    return apply_filters('gravityview/template/field_label', $label, $field->as_configuration(), isset($gf_form) ? $gf_form->form : $form, $entry->as_entry());
365
+    return apply_filters( 'gravityview/template/field_label', $label, $field->as_configuration(), isset( $gf_form ) ? $gf_form->form : $form, $entry->as_entry() );
366 366
 }
367 367
 
368 368
 /**
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
  */
383 383
 final class Legacy_Context
384 384
 {
385
-    private static $stack = [];
385
+    private static $stack = [ ];
386 386
 
387 387
     /**
388 388
      * Set the state depending on the provided configuration.
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
      *
425 425
      * @return void
426 426
      */
427
-    public static function push($configuration)
427
+    public static function push( $configuration )
428 428
     {
429
-        array_push(self::$stack, self::freeze());
430
-        self::load($configuration);
429
+        array_push( self::$stack, self::freeze() );
430
+        self::load( $configuration );
431 431
     }
432 432
 
433 433
     /**
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
      */
438 438
     public static function pop()
439 439
     {
440
-        self::thaw(array_pop(self::$stack));
440
+        self::thaw( array_pop( self::$stack ) );
441 441
     }
442 442
 
443 443
     /**
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         return [
453 453
             '\GravityView_View::atts'                         => \GravityView_View::getInstance()->getAtts(),
454 454
             '\GravityView_View::view_id'                      => \GravityView_View::getInstance()->getViewId(),
455
-            '\GravityView_View::back_link_label'              => \GravityView_View::getInstance()->getBackLinkLabel(false),
455
+            '\GravityView_View::back_link_label'              => \GravityView_View::getInstance()->getBackLinkLabel( false ),
456 456
             '\GravityView_View_Data::views'                   => \GravityView_View_Data::getInstance()->views,
457 457
             '\GravityView_View::entries'                      => \GravityView_View::getInstance()->getEntries(),
458 458
             '\GravityView_View::form'                         => \GravityView_View::getInstance()->getForm(),
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
             '\GravityView_View::_current_entry'               => \GravityView_View::getInstance()->getCurrentEntry(),
475 475
             '\GravityView_View::fields'                       => \GravityView_View::getInstance()->getFields(),
476 476
             '\GravityView_View::_current_field'               => \GravityView_View::getInstance()->getCurrentField(),
477
-            'wp_actions[loop_start]'                          => empty($wp_actions['loop_start']) ? 0 : $wp_actions['loop_start'],
477
+            'wp_actions[loop_start]'                          => empty( $wp_actions[ 'loop_start' ] ) ? 0 : $wp_actions[ 'loop_start' ],
478 478
             'wp_query::in_the_loop'                           => $wp_query->in_the_loop,
479 479
         ];
480 480
     }
@@ -484,86 +484,86 @@  discard block
 block discarded – undo
484 484
      *
485 485
      * @param array $data Saved configuration from self::freeze()
486 486
      */
487
-    public static function thaw($data)
487
+    public static function thaw( $data )
488 488
     {
489
-        foreach ((array) $data as $key => $value) {
490
-            switch ($key) {
489
+        foreach ( (array)$data as $key => $value ) {
490
+            switch ( $key ) {
491 491
                 case '\GravityView_View::atts':
492
-                    \GravityView_View::getInstance()->setAtts($value);
492
+                    \GravityView_View::getInstance()->setAtts( $value );
493 493
                     break;
494 494
                 case '\GravityView_View::view_id':
495
-                    \GravityView_View::getInstance()->setViewId($value);
495
+                    \GravityView_View::getInstance()->setViewId( $value );
496 496
                     break;
497 497
                 case '\GravityView_View::back_link_label':
498
-                    \GravityView_View::getInstance()->setBackLinkLabel($value);
498
+                    \GravityView_View::getInstance()->setBackLinkLabel( $value );
499 499
                     break;
500 500
                 case '\GravityView_View_Data::views':
501 501
                     \GravityView_View_Data::getInstance()->views = $value;
502 502
                     break;
503 503
                 case '\GravityView_View::entries':
504
-                    \GravityView_View::getInstance()->setEntries($value);
504
+                    \GravityView_View::getInstance()->setEntries( $value );
505 505
                     break;
506 506
                 case '\GravityView_View::form':
507
-                    \GravityView_View::getInstance()->setForm($value);
507
+                    \GravityView_View::getInstance()->setForm( $value );
508 508
                     break;
509 509
                 case '\GravityView_View::form_id':
510
-                    \GravityView_View::getInstance()->setFormId($value);
510
+                    \GravityView_View::getInstance()->setFormId( $value );
511 511
                     break;
512 512
                 case '\GravityView_View::context':
513
-                    \GravityView_View::getInstance()->setContext($value);
513
+                    \GravityView_View::getInstance()->setContext( $value );
514 514
                     break;
515 515
                 case '\GravityView_View::total_entries':
516
-                    \GravityView_View::getInstance()->setTotalEntries($value);
516
+                    \GravityView_View::getInstance()->setTotalEntries( $value );
517 517
                     break;
518 518
                 case '\GravityView_View::post_id':
519
-                    \GravityView_View::getInstance()->setPostId($value);
519
+                    \GravityView_View::getInstance()->setPostId( $value );
520 520
                     break;
521 521
                 case '\GravityView_View::is_hide_until_searched':
522
-                    \GravityView_View::getInstance()->setHideUntilSearched($value);
522
+                    \GravityView_View::getInstance()->setHideUntilSearched( $value );
523 523
                     break;
524 524
                 case '\GravityView_frontend::post_id':
525
-                    \GravityView_frontend::getInstance()->setPostId($value);
525
+                    \GravityView_frontend::getInstance()->setPostId( $value );
526 526
                     break;
527 527
                 case '\GravityView_frontend::context_view_id':
528 528
                     $frontend = \GravityView_frontend::getInstance();
529 529
                     $frontend->context_view_id = $value;
530 530
                     break;
531 531
                 case '\GravityView_frontend::is_gravityview_post_type':
532
-                    \GravityView_frontend::getInstance()->setIsGravityviewPostType($value);
532
+                    \GravityView_frontend::getInstance()->setIsGravityviewPostType( $value );
533 533
                     break;
534 534
                 case '\GravityView_frontend::post_has_shortcode':
535
-                    \GravityView_frontend::getInstance()->setPostHasShortcode($value);
535
+                    \GravityView_frontend::getInstance()->setPostHasShortcode( $value );
536 536
                     break;
537 537
                 case '\GravityView_frontend::gv_output_data':
538
-                    \GravityView_frontend::getInstance()->setGvOutputData($value);
538
+                    \GravityView_frontend::getInstance()->setGvOutputData( $value );
539 539
                     break;
540 540
                 case '\GravityView_View::paging':
541
-                    \GravityView_View::getInstance()->setPaging($value);
541
+                    \GravityView_View::getInstance()->setPaging( $value );
542 542
                     break;
543 543
                 case '\GravityView_View::sorting':
544
-                    \GravityView_View::getInstance()->setSorting($value);
544
+                    \GravityView_View::getInstance()->setSorting( $value );
545 545
                     break;
546 546
                 case '\GravityView_frontend::is_search':
547
-                    \GravityView_frontend::getInstance()->setIsSearch($value);
547
+                    \GravityView_frontend::getInstance()->setIsSearch( $value );
548 548
                     break;
549 549
                 case '\GravityView_frontend::single_entry':
550
-                    \GravityView_frontend::getInstance()->setSingleEntry($value);
550
+                    \GravityView_frontend::getInstance()->setSingleEntry( $value );
551 551
                     break;
552 552
                 case '\GravityView_frontend::entry':
553
-                    \GravityView_frontend::getInstance()->setEntry($value);
553
+                    \GravityView_frontend::getInstance()->setEntry( $value );
554 554
                     break;
555 555
                 case '\GravityView_View::_current_entry':
556
-                    \GravityView_View::getInstance()->setCurrentEntry($value);
556
+                    \GravityView_View::getInstance()->setCurrentEntry( $value );
557 557
                     break;
558 558
                 case '\GravityView_View::fields':
559
-                    \GravityView_View::getInstance()->setFields($value);
559
+                    \GravityView_View::getInstance()->setFields( $value );
560 560
                     break;
561 561
                 case '\GravityView_View::_current_field':
562
-                    \GravityView_View::getInstance()->setCurrentField($value);
562
+                    \GravityView_View::getInstance()->setCurrentField( $value );
563 563
                     break;
564 564
                 case 'wp_actions[loop_start]':
565 565
                     global $wp_actions;
566
-                    $wp_actions['loop_start'] = $value;
566
+                    $wp_actions[ 'loop_start' ] = $value;
567 567
                     break;
568 568
                 case 'wp_query::in_the_loop':
569 569
                     global $wp_query;
@@ -580,68 +580,68 @@  discard block
 block discarded – undo
580 580
      *
581 581
      * @return void
582 582
      */
583
-    public static function load($configuration)
583
+    public static function load( $configuration )
584 584
     {
585
-        foreach ((array) $configuration as $key => $value) {
586
-            switch ($key) {
585
+        foreach ( (array)$configuration as $key => $value ) {
586
+            switch ( $key ) {
587 587
                 case 'view':
588 588
                     $views = new \GV\View_Collection();
589
-                    $views->add($value);
589
+                    $views->add( $value );
590 590
 
591
-                    self::thaw([
591
+                    self::thaw( [
592 592
                         '\GravityView_View::atts'                   => $value->settings->as_atts(),
593 593
                         '\GravityView_View::view_id'                => $value->ID,
594
-                        '\GravityView_View::back_link_label'        => $value->settings->get('back_link_label', null),
594
+                        '\GravityView_View::back_link_label'        => $value->settings->get( 'back_link_label', null ),
595 595
                         '\GravityView_View::form'                   => $value->form ? $value->form->form : null,
596 596
                         '\GravityView_View::form_id'                => $value->form ? $value->form->ID : null,
597
-                        '\GravityView_View::is_hide_until_searched' => $value->settings->get('hide_until_searched', null) && !gravityview()->request->is_search(),
597
+                        '\GravityView_View::is_hide_until_searched' => $value->settings->get( 'hide_until_searched', null ) && ! gravityview()->request->is_search(),
598 598
 
599 599
                         '\GravityView_View_Data::views'          => $views,
600 600
                         '\GravityView_frontend::gv_output_data'  => \GravityView_View_Data::getInstance(),
601 601
                         '\GravityView_frontend::context_view_id' => $value->ID,
602
-                    ]);
602
+                    ] );
603 603
                     break;
604 604
                 case 'post':
605 605
                     $has_shortcode = false;
606
-                    foreach (\GV\Shortcode::parse($value->post_content) as $shortcode) {
607
-                        if ($shortcode->name == 'gravityview') {
606
+                    foreach ( \GV\Shortcode::parse( $value->post_content ) as $shortcode ) {
607
+                        if ( $shortcode->name == 'gravityview' ) {
608 608
                             $has_shortcode = true;
609 609
                             break;
610 610
                         }
611 611
                     }
612
-                    self::thaw([
612
+                    self::thaw( [
613 613
                         '\GravityView_View::post_id'                      => $value->ID,
614 614
                         '\GravityView_frontend::post_id'                  => $value->ID,
615 615
                         '\GravityView_frontend::is_gravityview_post_type' => $value->post_type == 'gravityview',
616 616
                         '\GravityView_frontend::post_has_shortcode'       => $has_shortcode,
617
-                    ]);
617
+                    ] );
618 618
                     break;
619 619
                 case 'views':
620
-                    self::thaw([
620
+                    self::thaw( [
621 621
                         '\GravityView_View_Data::views'         => $value,
622 622
                         '\GravityView_frontend::gv_output_data' => \GravityView_View_Data::getInstance(),
623
-                    ]);
623
+                    ] );
624 624
                     break;
625 625
                 case 'entries':
626
-                    self::thaw([
627
-                        '\GravityView_View::entries' => array_map(function ($e) { return $e->as_entry(); }, $value->all()),
626
+                    self::thaw( [
627
+                        '\GravityView_View::entries' => array_map( function( $e ) { return $e->as_entry(); }, $value->all() ),
628 628
                         '\GravityView_View::total_entries' => $value->total(),
629
-                    ]);
629
+                    ] );
630 630
                     break;
631 631
                 case 'entry':
632
-                    self::thaw([
632
+                    self::thaw( [
633 633
                         '\GravityView_frontend::single_entry' => $value->ID,
634 634
                         '\GravityView_frontend::entry'        => $value->as_entry(),
635 635
                         '\GravityView_View::_current_entry'   => $value->as_entry(),
636
-                    ]);
636
+                    ] );
637 637
                     break;
638 638
                 case 'fields':
639
-                    self::thaw([
639
+                    self::thaw( [
640 640
                         '\GravityView_View::fields' => $value->as_configuration(),
641
-                    ]);
641
+                    ] );
642 642
                     break;
643 643
                 case 'field':
644
-                    self::thaw([
644
+                    self::thaw( [
645 645
                         '\GravityView_View::_current_field' => [
646 646
                             'field_id'       => $value->ID,
647 647
                             'field'          => $value->field,
@@ -656,42 +656,40 @@  discard block
 block discarded – undo
656 656
                             // 'display_value' => $display_value,
657 657
                             // 'format' => $format,
658 658
                         ],
659
-                    ]);
659
+                    ] );
660 660
                     break;
661 661
                 case 'request':
662
-                    self::thaw([
662
+                    self::thaw( [
663 663
                         '\GravityView_View::context' => (
664
-                            $value->is_entry() ? 'single' :
665
-                            (
666
-                                $value->is_edit_entry() ? 'edit' :
667
-                                    ($value->is_view() ? 'directory' : null)
664
+                            $value->is_entry() ? 'single' : (
665
+                                $value->is_edit_entry() ? 'edit' : ( $value->is_view() ? 'directory' : null )
668 666
                             )
669 667
                         ),
670 668
                         '\GravityView_frontend::is_search' => $value->is_search(),
671
-                    ]);
669
+                    ] );
672 670
 
673
-                    if (!$value->is_entry()) {
674
-                        self::thaw([
671
+                    if ( ! $value->is_entry() ) {
672
+                        self::thaw( [
675 673
                             '\GravityView_frontend::single_entry' => 0,
676 674
                             '\GravityView_frontend::entry'        => 0,
677
-                        ]);
675
+                        ] );
678 676
                     }
679 677
                     break;
680 678
                 case 'paging':
681
-                    self::thaw([
679
+                    self::thaw( [
682 680
                         '\GravityView_View::paging' => $value,
683
-                    ]);
681
+                    ] );
684 682
                     break;
685 683
                 case 'sorting':
686
-                    self::thaw([
684
+                    self::thaw( [
687 685
                         '\GravityView_View::sorting' => $value,
688
-                    ]);
686
+                    ] );
689 687
                     break;
690 688
                 case 'in_the_loop':
691
-                    self::thaw([
689
+                    self::thaw( [
692 690
                         'wp_query::in_the_loop'  => $value,
693 691
                         'wp_actions[loop_start]' => $value ? 1 : 0,
694
-                    ]);
692
+                    ] );
695 693
                     break;
696 694
             }
697 695
         }
@@ -719,13 +717,13 @@  discard block
 block discarded – undo
719 717
         global $wp_query, $wp_actions;
720 718
 
721 719
         $wp_query->in_the_loop = false;
722
-        $wp_actions['loop_start'] = 0;
720
+        $wp_actions[ 'loop_start' ] = 0;
723 721
     }
724 722
 }
725 723
 
726 724
 /** Add some global fix for field capability discrepancies. */
727
-add_filter('gravityview/configuration/fields', function ($fields) {
728
-    if (empty($fields)) {
725
+add_filter( 'gravityview/configuration/fields', function( $fields ) {
726
+    if ( empty( $fields ) ) {
729 727
         return $fields;
730 728
     }
731 729
 
@@ -744,17 +742,17 @@  discard block
 block discarded – undo
744 742
      * The two "settings" should be as tightly coupled as possible to avoid
745 743
      *  split logic scenarios. Uniting them into one field is the way to go.
746 744
      */
747
-    foreach ($fields as $position => &$_fields) {
748
-        if (empty($_fields) || !is_array($_fields)) {
745
+    foreach ( $fields as $position => &$_fields ) {
746
+        if ( empty( $_fields ) || ! is_array( $_fields ) ) {
749 747
             continue;
750 748
         }
751 749
 
752
-        foreach ($_fields as $uid => &$_field) {
753
-            if (!isset($_field['only_loggedin'])) {
750
+        foreach ( $_fields as $uid => &$_field ) {
751
+            if ( ! isset( $_field[ 'only_loggedin' ] ) ) {
754 752
                 continue;
755 753
             }
756 754
             /** If we do not require login, we don't require a cap. */
757
-            $_field['only_loggedin'] != '1' && ($_field['only_loggedin_cap'] = '');
755
+            $_field[ 'only_loggedin' ] != '1' && ( $_field[ 'only_loggedin_cap' ] = '' );
758 756
         }
759 757
     }
760 758
 
@@ -762,12 +760,12 @@  discard block
 block discarded – undo
762 760
 });
763 761
 
764 762
 /** Add a future fix to make sure field configurations include the form ID. */
765
-add_filter('gravityview/view/configuration/fields', function ($fields, $view) {
766
-    if (!$view || empty($fields)) {
763
+add_filter( 'gravityview/view/configuration/fields', function( $fields, $view ) {
764
+    if ( ! $view || empty( $fields ) ) {
767 765
         return $fields;
768 766
     }
769 767
 
770
-    if (!$view->form || !$view->form->ID) {
768
+    if ( ! $view->form || ! $view->form->ID ) {
771 769
         return $fields;
772 770
     }
773 771
 
@@ -778,41 +776,41 @@  discard block
 block discarded – undo
778 776
      * @todo Make sure this actually happens in the admin side
779 777
      *  when saving the views.
780 778
      */
781
-    foreach ($fields as $position => &$_fields) {
782
-        if (empty($_fields) || !is_array($_fields)) {
779
+    foreach ( $fields as $position => &$_fields ) {
780
+        if ( empty( $_fields ) || ! is_array( $_fields ) ) {
783 781
             continue;
784 782
         }
785 783
 
786
-        foreach ($_fields as $uid => &$_field) {
787
-            if (!empty($_field['id']) && is_numeric($_field['id']) && empty($_field['form_id'])) {
788
-                $_field['form_id'] = $view->form->ID;
784
+        foreach ( $_fields as $uid => &$_field ) {
785
+            if ( ! empty( $_field[ 'id' ] ) && is_numeric( $_field[ 'id' ] ) && empty( $_field[ 'form_id' ] ) ) {
786
+                $_field[ 'form_id' ] = $view->form->ID;
789 787
             }
790 788
         }
791 789
     }
792 790
 
793 791
     return $fields;
794
-}, 10, 2);
792
+}, 10, 2 );
795 793
 
796 794
 /** Make sure the non-configured notice is not output twice. */
797
-add_action('gravityview/template/after', function ($gravityview = null) {
798
-    if (class_exists('\GravityView_frontend')) {
795
+add_action( 'gravityview/template/after', function( $gravityview = null ) {
796
+    if ( class_exists( '\GravityView_frontend' ) ) {
799 797
         global $wp_filter;
800 798
 
801
-        if (empty($wp_filter['gravityview_after'])) {
799
+        if ( empty( $wp_filter[ 'gravityview_after' ] ) ) {
802 800
             return;
803 801
         }
804 802
 
805
-        foreach ($wp_filter['gravityview_after']->callbacks[10] as $function_key => $callback) {
806
-            if (strpos($function_key, 'context_not_configured_warning')) {
807
-                unset($wp_filter['gravityview_after']->callbacks[10][$function_key]);
803
+        foreach ( $wp_filter[ 'gravityview_after' ]->callbacks[ 10 ] as $function_key => $callback ) {
804
+            if ( strpos( $function_key, 'context_not_configured_warning' ) ) {
805
+                unset( $wp_filter[ 'gravityview_after' ]->callbacks[ 10 ][ $function_key ] );
808 806
             }
809 807
         }
810 808
     }
811 809
 });
812 810
 
813
-add_filter('gravityview/query/is_null_condition', function () {
814
-    if (!class_exists($class = '\GV\Mocks\GF_Query_Condition_IS_NULL')) {
815
-        require_once gravityview()->plugin->dir('future/_mocks.isnull.php');
811
+add_filter( 'gravityview/query/is_null_condition', function() {
812
+    if ( ! class_exists( $class = '\GV\Mocks\GF_Query_Condition_IS_NULL' ) ) {
813
+        require_once gravityview()->plugin->dir( 'future/_mocks.isnull.php' );
816 814
     }
817 815
 
818 816
     return $class;
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return array|false The old array data, or false on error.
17 17
  */
18
-function GravityView_View_Data_add_view($view_id, $atts, $_this)
19
-{
18
+function GravityView_View_Data_add_view($view_id, $atts, $_this) {
20 19
     /** Handle array of IDs. */
21 20
     if (is_array($view_id)) {
22 21
         foreach ($view_id as $id) {
@@ -75,8 +74,7 @@  discard block
 block discarded – undo
75 74
  *               \GravityView_frontend::get_view_entries(), the paging parameters
76 75
  *               and a total count of all entries.
77 76
  */
78
-function GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count)
79
-{
77
+function GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count) {
80 78
     $form = \GV\GF_Form::by_id($form_id);
81 79
 
82 80
     /**
@@ -152,8 +150,7 @@  discard block
 block discarded – undo
152 150
  *
153 151
  * @return null|string The value of a field in an entry.
154 152
  */
155
-function GravityView_API_field_value($entry, $field_settings, $format)
156
-{
153
+function GravityView_API_field_value($entry, $field_settings, $format) {
157 154
     if (empty($entry['form_id']) || empty($field_settings['id'])) {
158 155
         gravityview()->log->error('No entry or field_settings[id] supplied', ['data' => [func_get_args()]]);
159 156
 
@@ -230,8 +227,7 @@  discard block
 block discarded – undo
230 227
  *
231 228
  * @return string The label of a field in an entry.
232 229
  */
233
-function GravityView_API_field_label($form, $field_settings, $entry, $force_show_label = false)
234
-{
230
+function GravityView_API_field_label($form, $field_settings, $entry, $force_show_label = false) {
235 231
 
236 232
     /** A bail condition. */
237 233
     $bail = function ($label, $field_settings, $entry, $force_show_label, $form) {
@@ -380,8 +376,7 @@  discard block
 block discarded – undo
380 376
  * Some examples right now include template files, utility functions,
381 377
  *  some actions and filters that expect the old contexts to be set.
382 378
  */
383
-final class Legacy_Context
384
-{
379
+final class Legacy_Context {
385 380
     private static $stack = [];
386 381
 
387 382
     /**
@@ -424,8 +419,7 @@  discard block
 block discarded – undo
424 419
      *
425 420
      * @return void
426 421
      */
427
-    public static function push($configuration)
428
-    {
422
+    public static function push($configuration) {
429 423
         array_push(self::$stack, self::freeze());
430 424
         self::load($configuration);
431 425
     }
@@ -435,8 +429,7 @@  discard block
 block discarded – undo
435 429
      *
436 430
      * @return void
437 431
      */
438
-    public static function pop()
439
-    {
432
+    public static function pop() {
440 433
         self::thaw(array_pop(self::$stack));
441 434
     }
442 435
 
@@ -445,8 +438,7 @@  discard block
 block discarded – undo
445 438
      *
446 439
      * @return array The configuration.
447 440
      */
448
-    public static function freeze()
449
-    {
441
+    public static function freeze() {
450 442
         global $wp_actions, $wp_query;
451 443
 
452 444
         return [
@@ -484,8 +476,7 @@  discard block
 block discarded – undo
484 476
      *
485 477
      * @param array $data Saved configuration from self::freeze()
486 478
      */
487
-    public static function thaw($data)
488
-    {
479
+    public static function thaw($data) {
489 480
         foreach ((array) $data as $key => $value) {
490 481
             switch ($key) {
491 482
                 case '\GravityView_View::atts':
@@ -580,8 +571,7 @@  discard block
 block discarded – undo
580 571
      *
581 572
      * @return void
582 573
      */
583
-    public static function load($configuration)
584
-    {
574
+    public static function load($configuration) {
585 575
         foreach ((array) $configuration as $key => $value) {
586 576
             switch ($key) {
587 577
                 case 'view':
@@ -710,8 +700,7 @@  discard block
 block discarded – undo
710 700
      *
711 701
      * @return void
712 702
      */
713
-    public static function reset()
714
-    {
703
+    public static function reset() {
715 704
         \GravityView_View::$instance = null;
716 705
         \GravityView_frontend::$instance = null;
717 706
         \GravityView_View_Data::$instance = null;
Please login to merge, or discard this patch.
future/lib/EDD_SL_Plugin_Updater.php 3 patches
Indentation   +632 added lines, -632 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 // Exit if accessed directly
14 14
 if (!defined('ABSPATH')) {
15
-    exit;
15
+	exit;
16 16
 }
17 17
 
18 18
 /**
@@ -24,638 +24,638 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class EDD_SL_Plugin_Updater
26 26
 {
27
-    private $api_url = '';
28
-    private $api_data = [];
29
-    private $plugin_file = '';
30
-    private $name = '';
31
-    private $slug = '';
32
-    private $version = '';
33
-    private $wp_override = false;
34
-    private $beta = false;
35
-    private $failed_request_cache_key;
36
-
37
-    /**
38
-     * Class constructor.
39
-     *
40
-     * @uses plugin_basename()
41
-     * @uses hook()
42
-     *
43
-     * @param string $_api_url     The URL pointing to the custom API endpoint.
44
-     * @param string $_plugin_file Path to the plugin file.
45
-     * @param array  $_api_data    Optional data to send with API calls.
46
-     */
47
-    public function __construct($_api_url, $_plugin_file, $_api_data = null)
48
-    {
49
-        global $edd_plugin_data;
50
-
51
-        $this->api_url = trailingslashit($_api_url);
52
-        $this->api_data = $_api_data;
53
-        $this->plugin_file = $_plugin_file;
54
-        $this->name = plugin_basename($_plugin_file);
55
-        $this->slug = basename($_plugin_file, '.php');
56
-        $this->version = $_api_data['version'];
57
-        $this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false;
58
-        $this->beta = !empty($this->api_data['beta']) ? true : false;
59
-        $this->failed_request_cache_key = 'edd_sl_failed_http_'.md5($this->api_url);
60
-
61
-        $edd_plugin_data[$this->slug] = $this->api_data;
62
-
63
-        /**
64
-         * Fires after the $edd_plugin_data is setup.
65
-         *
66
-         * @since x.x.x
67
-         *
68
-         * @param array $edd_plugin_data Array of EDD SL plugin data.
69
-         */
70
-        do_action('post_edd_sl_plugin_updater_setup', $edd_plugin_data);
71
-
72
-        // Set up hooks.
73
-        $this->init();
74
-    }
75
-
76
-    /**
77
-     * Set up WordPress filters to hook into WP's update process.
78
-     *
79
-     * @uses add_filter()
80
-     *
81
-     * @return void
82
-     */
83
-    public function init()
84
-    {
85
-        add_filter('pre_set_site_transient_update_plugins', [$this, 'check_update']);
86
-        add_filter('plugins_api', [$this, 'plugins_api_filter'], 10, 3);
87
-        add_action('after_plugin_row', [$this, 'show_update_notification'], 10, 2);
88
-        add_action('admin_init', [$this, 'show_changelog']);
89
-    }
90
-
91
-    /**
92
-     * Check for Updates at the defined API endpoint and modify the update array.
93
-     *
94
-     * This function dives into the update API just when WordPress creates its update array,
95
-     * then adds a custom API call and injects the custom plugin data retrieved from the API.
96
-     * It is reassembled from parts of the native WordPress plugin update code.
97
-     * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
98
-     *
99
-     * @uses api_request()
100
-     *
101
-     * @param array $_transient_data Update array build by WordPress.
102
-     *
103
-     * @return array Modified update array with custom plugin data.
104
-     */
105
-    public function check_update($_transient_data)
106
-    {
107
-        global $pagenow;
108
-
109
-        if (!is_object($_transient_data)) {
110
-            $_transient_data = new stdClass();
111
-        }
112
-
113
-        if (!empty($_transient_data->response) && !empty($_transient_data->response[$this->name]) && false === $this->wp_override) {
114
-            return $_transient_data;
115
-        }
116
-
117
-        $current = $this->get_repo_api_data();
118
-        if (false !== $current && is_object($current) && isset($current->new_version)) {
119
-            if (version_compare($this->version, $current->new_version, '<')) {
120
-                $_transient_data->response[$this->name] = $current;
121
-            } else {
122
-                // Populating the no_update information is required to support auto-updates in WordPress 5.5.
123
-                $_transient_data->no_update[$this->name] = $current;
124
-            }
125
-        }
126
-        $_transient_data->last_checked = time();
127
-        $_transient_data->checked[$this->name] = $this->version;
128
-
129
-        return $_transient_data;
130
-    }
131
-
132
-    /**
133
-     * Get repo API data from store.
134
-     * Save to cache.
135
-     *
136
-     * @return \stdClass
137
-     */
138
-    public function get_repo_api_data()
139
-    {
140
-        $version_info = $this->get_cached_version_info();
141
-
142
-        if (false === $version_info) {
143
-            $version_info = $this->api_request(
144
-                'plugin_latest_version',
145
-                [
146
-                    'slug' => $this->slug,
147
-                    'beta' => $this->beta,
148
-                ]
149
-            );
150
-            if (!$version_info) {
151
-                return false;
152
-            }
153
-
154
-            // This is required for your plugin to support auto-updates in WordPress 5.5.
155
-            $version_info->plugin = $this->name;
156
-            $version_info->id = $this->name;
157
-
158
-            $this->set_version_info_cache($version_info);
159
-        }
160
-
161
-        return $version_info;
162
-    }
163
-
164
-    /**
165
-     * Show the update notification on multisite subsites.
166
-     *
167
-     * @param string $file
168
-     * @param array  $plugin
169
-     */
170
-    public function show_update_notification($file, $plugin)
171
-    {
172
-
173
-        // Return early if in the network admin, or if this is not a multisite install.
174
-        if (is_network_admin() || !is_multisite()) {
175
-            return;
176
-        }
177
-
178
-        // Allow single site admins to see that an update is available.
179
-        if (!current_user_can('activate_plugins')) {
180
-            return;
181
-        }
182
-
183
-        if ($this->name !== $file) {
184
-            return;
185
-        }
186
-
187
-        // Do not print any message if update does not exist.
188
-        $update_cache = get_site_transient('update_plugins');
189
-
190
-        if (!isset($update_cache->response[$this->name])) {
191
-            if (!is_object($update_cache)) {
192
-                $update_cache = new stdClass();
193
-            }
194
-            $update_cache->response[$this->name] = $this->get_repo_api_data();
195
-        }
196
-
197
-        // Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
198
-        if (empty($update_cache->response[$this->name]) || version_compare($this->version, $update_cache->response[$this->name]->new_version, '>=')) {
199
-            return;
200
-        }
201
-
202
-        printf(
203
-            '<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
204
-            $this->slug,
205
-            $file,
206
-            in_array($this->name, $this->get_active_plugins(), true) ? 'active' : 'inactive'
207
-        );
208
-
209
-        echo '<td colspan="3" class="plugin-update colspanchange">';
210
-        echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
211
-
212
-        $changelog_link = '';
213
-        if (!empty($update_cache->response[$this->name]->sections->changelog)) {
214
-            $changelog_link = add_query_arg(
215
-                [
216
-                    'edd_sl_action' => 'view_plugin_changelog',
217
-                    'plugin'        => urlencode($this->name),
218
-                    'slug'          => urlencode($this->slug),
219
-                    'TB_iframe'     => 'true',
220
-                    'width'         => 77,
221
-                    'height'        => 911,
222
-                ],
223
-                self_admin_url('index.php')
224
-            );
225
-        }
226
-        $update_link = add_query_arg(
227
-            [
228
-                'action' => 'upgrade-plugin',
229
-                'plugin' => urlencode($this->name),
230
-            ],
231
-            self_admin_url('update.php')
232
-        );
233
-
234
-        printf(
235
-        /* translators: the plugin name. */
236
-            esc_html__('There is a new version of %1$s available.', 'gravityview'),
237
-            esc_html($plugin['Name'])
238
-        );
239
-
240
-        if (!current_user_can('update_plugins')) {
241
-            echo ' ';
242
-            esc_html_e('Contact your network administrator to install the update.', 'gravityview');
243
-        } elseif (empty($update_cache->response[$this->name]->package) && !empty($changelog_link)) {
244
-            echo ' ';
245
-            printf(
246
-            /* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
247
-                __('%1$sView version %2$s details%3$s.', 'gravityview'),
248
-                '<a target="_blank" class="thickbox open-plugin-details-modal" href="'.esc_url($changelog_link).'">',
249
-                esc_html($update_cache->response[$this->name]->new_version),
250
-                '</a>'
251
-            );
252
-        } elseif (!empty($changelog_link)) {
253
-            echo ' ';
254
-            printf(
255
-                __('%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'gravityview'),
256
-                '<a target="_blank" class="thickbox open-plugin-details-modal" href="'.esc_url($changelog_link).'">',
257
-                esc_html($update_cache->response[$this->name]->new_version),
258
-                '</a>',
259
-                '<a target="_blank" class="update-link" href="'.esc_url(wp_nonce_url($update_link, 'upgrade-plugin_'.$file)).'">',
260
-                '</a>'
261
-            );
262
-        } else {
263
-            printf(
264
-                ' %1$s%2$s%3$s',
265
-                '<a target="_blank" class="update-link" href="'.esc_url(wp_nonce_url($update_link, 'upgrade-plugin_'.$file)).'">',
266
-                esc_html__('Update now.', 'gravityview'),
267
-                '</a>'
268
-            );
269
-        }
270
-
271
-        do_action("in_plugin_update_message-{$file}", $plugin, $plugin);
272
-
273
-        echo '</p></div></td></tr>';
274
-    }
275
-
276
-    /**
277
-     * Gets the plugins active in a multisite network.
278
-     *
279
-     * @return array
280
-     */
281
-    private function get_active_plugins()
282
-    {
283
-        $active_plugins = (array) get_option('active_plugins');
284
-        $active_network_plugins = (array) get_site_option('active_sitewide_plugins');
285
-
286
-        return array_merge($active_plugins, array_keys($active_network_plugins));
287
-    }
288
-
289
-    /**
290
-     * Updates information on the "View version x.x details" page with custom data.
291
-     *
292
-     * @uses api_request()
293
-     *
294
-     * @param mixed  $_data
295
-     * @param string $_action
296
-     * @param object $_args
297
-     *
298
-     * @return object $_data
299
-     */
300
-    public function plugins_api_filter($_data, $_action = '', $_args = null)
301
-    {
302
-        if ('plugin_information' !== $_action) {
303
-            return $_data;
304
-        }
305
-
306
-        if (!isset($_args->slug) || ($_args->slug !== $this->slug)) {
307
-            return $_data;
308
-        }
309
-
310
-        $to_send = [
311
-            'slug'   => $this->slug,
312
-            'is_ssl' => is_ssl(),
313
-            'fields' => [
314
-                'banners' => [],
315
-                'reviews' => false,
316
-                'icons'   => [],
317
-            ],
318
-        ];
319
-
320
-        // Get the transient where we store the api request for this plugin for 24 hours
321
-        $edd_api_request_transient = $this->get_cached_version_info();
322
-
323
-        //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
324
-        if (empty($edd_api_request_transient)) {
325
-            $api_response = $this->api_request('plugin_information', $to_send);
326
-
327
-            // Expires in 3 hours
328
-            $this->set_version_info_cache($api_response);
329
-
330
-            if (false !== $api_response) {
331
-                $_data = $api_response;
332
-            }
333
-        } else {
334
-            $_data = $edd_api_request_transient;
335
-        }
336
-
337
-        // Convert sections into an associative array, since we're getting an object, but Core expects an array.
338
-        if (isset($_data->sections) && !is_array($_data->sections)) {
339
-            $_data->sections = $this->convert_object_to_array($_data->sections);
340
-        }
341
-
342
-        // Convert banners into an associative array, since we're getting an object, but Core expects an array.
343
-        if (isset($_data->banners) && !is_array($_data->banners)) {
344
-            $_data->banners = $this->convert_object_to_array($_data->banners);
345
-        }
346
-
347
-        // Convert icons into an associative array, since we're getting an object, but Core expects an array.
348
-        if (isset($_data->icons) && !is_array($_data->icons)) {
349
-            $_data->icons = $this->convert_object_to_array($_data->icons);
350
-        }
351
-
352
-        // Convert contributors into an associative array, since we're getting an object, but Core expects an array.
353
-        if (isset($_data->contributors) && !is_array($_data->contributors)) {
354
-            $_data->contributors = $this->convert_object_to_array($_data->contributors);
355
-        }
356
-
357
-        if (!isset($_data->plugin)) {
358
-            $_data->plugin = $this->name;
359
-        }
360
-
361
-        return $_data;
362
-    }
363
-
364
-    /**
365
-     * Convert some objects to arrays when injecting data into the update API.
366
-     *
367
-     * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
368
-     * decoding, they are objects. This method allows us to pass in the object and return an associative array.
369
-     *
370
-     * @since 3.6.5
371
-     *
372
-     * @param stdClass $data
373
-     *
374
-     * @return array
375
-     */
376
-    private function convert_object_to_array($data)
377
-    {
378
-        if (!is_array($data) && !is_object($data)) {
379
-            return [];
380
-        }
381
-        $new_data = [];
382
-        foreach ($data as $key => $value) {
383
-            $new_data[$key] = is_object($value) ? $this->convert_object_to_array($value) : $value;
384
-        }
385
-
386
-        return $new_data;
387
-    }
388
-
389
-    /**
390
-     * Disable SSL verification in order to prevent download update failures.
391
-     *
392
-     * @param array  $args
393
-     * @param string $url
394
-     *
395
-     * @return object $array
396
-     */
397
-    public function http_request_args($args, $url)
398
-    {
399
-        if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) {
400
-            $args['sslverify'] = $this->verify_ssl();
401
-        }
402
-
403
-        return $args;
404
-    }
405
-
406
-    /**
407
-     * Calls the API and, if successfull, returns the object delivered by the API.
408
-     *
409
-     * @uses get_bloginfo()
410
-     * @uses wp_remote_post()
411
-     * @uses is_wp_error()
412
-     *
413
-     * @param string $_action The requested action.
414
-     * @param array  $_data   Parameters for the API action.
415
-     *
416
-     * @return false|object|void
417
-     */
418
-    private function api_request($_action, $_data)
419
-    {
420
-        $data = array_merge($this->api_data, $_data);
421
-
422
-        if ($data['slug'] !== $this->slug) {
423
-            return;
424
-        }
425
-
426
-        // Don't allow a plugin to ping itself
427
-        if (trailingslashit(home_url()) === $this->api_url) {
428
-            return false;
429
-        }
430
-
431
-        if ($this->request_recently_failed()) {
432
-            return false;
433
-        }
434
-
435
-        return $this->get_version_from_remote();
436
-    }
437
-
438
-    /**
439
-     * Determines if a request has recently failed.
440
-     *
441
-     * @since 1.9.1
442
-     *
443
-     * @return bool
444
-     */
445
-    private function request_recently_failed()
446
-    {
447
-        $failed_request_details = get_option($this->failed_request_cache_key);
448
-
449
-        // Request has never failed.
450
-        if (empty($failed_request_details) || !is_numeric($failed_request_details)) {
451
-            return false;
452
-        }
453
-
454
-        /*
27
+	private $api_url = '';
28
+	private $api_data = [];
29
+	private $plugin_file = '';
30
+	private $name = '';
31
+	private $slug = '';
32
+	private $version = '';
33
+	private $wp_override = false;
34
+	private $beta = false;
35
+	private $failed_request_cache_key;
36
+
37
+	/**
38
+	 * Class constructor.
39
+	 *
40
+	 * @uses plugin_basename()
41
+	 * @uses hook()
42
+	 *
43
+	 * @param string $_api_url     The URL pointing to the custom API endpoint.
44
+	 * @param string $_plugin_file Path to the plugin file.
45
+	 * @param array  $_api_data    Optional data to send with API calls.
46
+	 */
47
+	public function __construct($_api_url, $_plugin_file, $_api_data = null)
48
+	{
49
+		global $edd_plugin_data;
50
+
51
+		$this->api_url = trailingslashit($_api_url);
52
+		$this->api_data = $_api_data;
53
+		$this->plugin_file = $_plugin_file;
54
+		$this->name = plugin_basename($_plugin_file);
55
+		$this->slug = basename($_plugin_file, '.php');
56
+		$this->version = $_api_data['version'];
57
+		$this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false;
58
+		$this->beta = !empty($this->api_data['beta']) ? true : false;
59
+		$this->failed_request_cache_key = 'edd_sl_failed_http_'.md5($this->api_url);
60
+
61
+		$edd_plugin_data[$this->slug] = $this->api_data;
62
+
63
+		/**
64
+		 * Fires after the $edd_plugin_data is setup.
65
+		 *
66
+		 * @since x.x.x
67
+		 *
68
+		 * @param array $edd_plugin_data Array of EDD SL plugin data.
69
+		 */
70
+		do_action('post_edd_sl_plugin_updater_setup', $edd_plugin_data);
71
+
72
+		// Set up hooks.
73
+		$this->init();
74
+	}
75
+
76
+	/**
77
+	 * Set up WordPress filters to hook into WP's update process.
78
+	 *
79
+	 * @uses add_filter()
80
+	 *
81
+	 * @return void
82
+	 */
83
+	public function init()
84
+	{
85
+		add_filter('pre_set_site_transient_update_plugins', [$this, 'check_update']);
86
+		add_filter('plugins_api', [$this, 'plugins_api_filter'], 10, 3);
87
+		add_action('after_plugin_row', [$this, 'show_update_notification'], 10, 2);
88
+		add_action('admin_init', [$this, 'show_changelog']);
89
+	}
90
+
91
+	/**
92
+	 * Check for Updates at the defined API endpoint and modify the update array.
93
+	 *
94
+	 * This function dives into the update API just when WordPress creates its update array,
95
+	 * then adds a custom API call and injects the custom plugin data retrieved from the API.
96
+	 * It is reassembled from parts of the native WordPress plugin update code.
97
+	 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
98
+	 *
99
+	 * @uses api_request()
100
+	 *
101
+	 * @param array $_transient_data Update array build by WordPress.
102
+	 *
103
+	 * @return array Modified update array with custom plugin data.
104
+	 */
105
+	public function check_update($_transient_data)
106
+	{
107
+		global $pagenow;
108
+
109
+		if (!is_object($_transient_data)) {
110
+			$_transient_data = new stdClass();
111
+		}
112
+
113
+		if (!empty($_transient_data->response) && !empty($_transient_data->response[$this->name]) && false === $this->wp_override) {
114
+			return $_transient_data;
115
+		}
116
+
117
+		$current = $this->get_repo_api_data();
118
+		if (false !== $current && is_object($current) && isset($current->new_version)) {
119
+			if (version_compare($this->version, $current->new_version, '<')) {
120
+				$_transient_data->response[$this->name] = $current;
121
+			} else {
122
+				// Populating the no_update information is required to support auto-updates in WordPress 5.5.
123
+				$_transient_data->no_update[$this->name] = $current;
124
+			}
125
+		}
126
+		$_transient_data->last_checked = time();
127
+		$_transient_data->checked[$this->name] = $this->version;
128
+
129
+		return $_transient_data;
130
+	}
131
+
132
+	/**
133
+	 * Get repo API data from store.
134
+	 * Save to cache.
135
+	 *
136
+	 * @return \stdClass
137
+	 */
138
+	public function get_repo_api_data()
139
+	{
140
+		$version_info = $this->get_cached_version_info();
141
+
142
+		if (false === $version_info) {
143
+			$version_info = $this->api_request(
144
+				'plugin_latest_version',
145
+				[
146
+					'slug' => $this->slug,
147
+					'beta' => $this->beta,
148
+				]
149
+			);
150
+			if (!$version_info) {
151
+				return false;
152
+			}
153
+
154
+			// This is required for your plugin to support auto-updates in WordPress 5.5.
155
+			$version_info->plugin = $this->name;
156
+			$version_info->id = $this->name;
157
+
158
+			$this->set_version_info_cache($version_info);
159
+		}
160
+
161
+		return $version_info;
162
+	}
163
+
164
+	/**
165
+	 * Show the update notification on multisite subsites.
166
+	 *
167
+	 * @param string $file
168
+	 * @param array  $plugin
169
+	 */
170
+	public function show_update_notification($file, $plugin)
171
+	{
172
+
173
+		// Return early if in the network admin, or if this is not a multisite install.
174
+		if (is_network_admin() || !is_multisite()) {
175
+			return;
176
+		}
177
+
178
+		// Allow single site admins to see that an update is available.
179
+		if (!current_user_can('activate_plugins')) {
180
+			return;
181
+		}
182
+
183
+		if ($this->name !== $file) {
184
+			return;
185
+		}
186
+
187
+		// Do not print any message if update does not exist.
188
+		$update_cache = get_site_transient('update_plugins');
189
+
190
+		if (!isset($update_cache->response[$this->name])) {
191
+			if (!is_object($update_cache)) {
192
+				$update_cache = new stdClass();
193
+			}
194
+			$update_cache->response[$this->name] = $this->get_repo_api_data();
195
+		}
196
+
197
+		// Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
198
+		if (empty($update_cache->response[$this->name]) || version_compare($this->version, $update_cache->response[$this->name]->new_version, '>=')) {
199
+			return;
200
+		}
201
+
202
+		printf(
203
+			'<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
204
+			$this->slug,
205
+			$file,
206
+			in_array($this->name, $this->get_active_plugins(), true) ? 'active' : 'inactive'
207
+		);
208
+
209
+		echo '<td colspan="3" class="plugin-update colspanchange">';
210
+		echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
211
+
212
+		$changelog_link = '';
213
+		if (!empty($update_cache->response[$this->name]->sections->changelog)) {
214
+			$changelog_link = add_query_arg(
215
+				[
216
+					'edd_sl_action' => 'view_plugin_changelog',
217
+					'plugin'        => urlencode($this->name),
218
+					'slug'          => urlencode($this->slug),
219
+					'TB_iframe'     => 'true',
220
+					'width'         => 77,
221
+					'height'        => 911,
222
+				],
223
+				self_admin_url('index.php')
224
+			);
225
+		}
226
+		$update_link = add_query_arg(
227
+			[
228
+				'action' => 'upgrade-plugin',
229
+				'plugin' => urlencode($this->name),
230
+			],
231
+			self_admin_url('update.php')
232
+		);
233
+
234
+		printf(
235
+		/* translators: the plugin name. */
236
+			esc_html__('There is a new version of %1$s available.', 'gravityview'),
237
+			esc_html($plugin['Name'])
238
+		);
239
+
240
+		if (!current_user_can('update_plugins')) {
241
+			echo ' ';
242
+			esc_html_e('Contact your network administrator to install the update.', 'gravityview');
243
+		} elseif (empty($update_cache->response[$this->name]->package) && !empty($changelog_link)) {
244
+			echo ' ';
245
+			printf(
246
+			/* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
247
+				__('%1$sView version %2$s details%3$s.', 'gravityview'),
248
+				'<a target="_blank" class="thickbox open-plugin-details-modal" href="'.esc_url($changelog_link).'">',
249
+				esc_html($update_cache->response[$this->name]->new_version),
250
+				'</a>'
251
+			);
252
+		} elseif (!empty($changelog_link)) {
253
+			echo ' ';
254
+			printf(
255
+				__('%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'gravityview'),
256
+				'<a target="_blank" class="thickbox open-plugin-details-modal" href="'.esc_url($changelog_link).'">',
257
+				esc_html($update_cache->response[$this->name]->new_version),
258
+				'</a>',
259
+				'<a target="_blank" class="update-link" href="'.esc_url(wp_nonce_url($update_link, 'upgrade-plugin_'.$file)).'">',
260
+				'</a>'
261
+			);
262
+		} else {
263
+			printf(
264
+				' %1$s%2$s%3$s',
265
+				'<a target="_blank" class="update-link" href="'.esc_url(wp_nonce_url($update_link, 'upgrade-plugin_'.$file)).'">',
266
+				esc_html__('Update now.', 'gravityview'),
267
+				'</a>'
268
+			);
269
+		}
270
+
271
+		do_action("in_plugin_update_message-{$file}", $plugin, $plugin);
272
+
273
+		echo '</p></div></td></tr>';
274
+	}
275
+
276
+	/**
277
+	 * Gets the plugins active in a multisite network.
278
+	 *
279
+	 * @return array
280
+	 */
281
+	private function get_active_plugins()
282
+	{
283
+		$active_plugins = (array) get_option('active_plugins');
284
+		$active_network_plugins = (array) get_site_option('active_sitewide_plugins');
285
+
286
+		return array_merge($active_plugins, array_keys($active_network_plugins));
287
+	}
288
+
289
+	/**
290
+	 * Updates information on the "View version x.x details" page with custom data.
291
+	 *
292
+	 * @uses api_request()
293
+	 *
294
+	 * @param mixed  $_data
295
+	 * @param string $_action
296
+	 * @param object $_args
297
+	 *
298
+	 * @return object $_data
299
+	 */
300
+	public function plugins_api_filter($_data, $_action = '', $_args = null)
301
+	{
302
+		if ('plugin_information' !== $_action) {
303
+			return $_data;
304
+		}
305
+
306
+		if (!isset($_args->slug) || ($_args->slug !== $this->slug)) {
307
+			return $_data;
308
+		}
309
+
310
+		$to_send = [
311
+			'slug'   => $this->slug,
312
+			'is_ssl' => is_ssl(),
313
+			'fields' => [
314
+				'banners' => [],
315
+				'reviews' => false,
316
+				'icons'   => [],
317
+			],
318
+		];
319
+
320
+		// Get the transient where we store the api request for this plugin for 24 hours
321
+		$edd_api_request_transient = $this->get_cached_version_info();
322
+
323
+		//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
324
+		if (empty($edd_api_request_transient)) {
325
+			$api_response = $this->api_request('plugin_information', $to_send);
326
+
327
+			// Expires in 3 hours
328
+			$this->set_version_info_cache($api_response);
329
+
330
+			if (false !== $api_response) {
331
+				$_data = $api_response;
332
+			}
333
+		} else {
334
+			$_data = $edd_api_request_transient;
335
+		}
336
+
337
+		// Convert sections into an associative array, since we're getting an object, but Core expects an array.
338
+		if (isset($_data->sections) && !is_array($_data->sections)) {
339
+			$_data->sections = $this->convert_object_to_array($_data->sections);
340
+		}
341
+
342
+		// Convert banners into an associative array, since we're getting an object, but Core expects an array.
343
+		if (isset($_data->banners) && !is_array($_data->banners)) {
344
+			$_data->banners = $this->convert_object_to_array($_data->banners);
345
+		}
346
+
347
+		// Convert icons into an associative array, since we're getting an object, but Core expects an array.
348
+		if (isset($_data->icons) && !is_array($_data->icons)) {
349
+			$_data->icons = $this->convert_object_to_array($_data->icons);
350
+		}
351
+
352
+		// Convert contributors into an associative array, since we're getting an object, but Core expects an array.
353
+		if (isset($_data->contributors) && !is_array($_data->contributors)) {
354
+			$_data->contributors = $this->convert_object_to_array($_data->contributors);
355
+		}
356
+
357
+		if (!isset($_data->plugin)) {
358
+			$_data->plugin = $this->name;
359
+		}
360
+
361
+		return $_data;
362
+	}
363
+
364
+	/**
365
+	 * Convert some objects to arrays when injecting data into the update API.
366
+	 *
367
+	 * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
368
+	 * decoding, they are objects. This method allows us to pass in the object and return an associative array.
369
+	 *
370
+	 * @since 3.6.5
371
+	 *
372
+	 * @param stdClass $data
373
+	 *
374
+	 * @return array
375
+	 */
376
+	private function convert_object_to_array($data)
377
+	{
378
+		if (!is_array($data) && !is_object($data)) {
379
+			return [];
380
+		}
381
+		$new_data = [];
382
+		foreach ($data as $key => $value) {
383
+			$new_data[$key] = is_object($value) ? $this->convert_object_to_array($value) : $value;
384
+		}
385
+
386
+		return $new_data;
387
+	}
388
+
389
+	/**
390
+	 * Disable SSL verification in order to prevent download update failures.
391
+	 *
392
+	 * @param array  $args
393
+	 * @param string $url
394
+	 *
395
+	 * @return object $array
396
+	 */
397
+	public function http_request_args($args, $url)
398
+	{
399
+		if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) {
400
+			$args['sslverify'] = $this->verify_ssl();
401
+		}
402
+
403
+		return $args;
404
+	}
405
+
406
+	/**
407
+	 * Calls the API and, if successfull, returns the object delivered by the API.
408
+	 *
409
+	 * @uses get_bloginfo()
410
+	 * @uses wp_remote_post()
411
+	 * @uses is_wp_error()
412
+	 *
413
+	 * @param string $_action The requested action.
414
+	 * @param array  $_data   Parameters for the API action.
415
+	 *
416
+	 * @return false|object|void
417
+	 */
418
+	private function api_request($_action, $_data)
419
+	{
420
+		$data = array_merge($this->api_data, $_data);
421
+
422
+		if ($data['slug'] !== $this->slug) {
423
+			return;
424
+		}
425
+
426
+		// Don't allow a plugin to ping itself
427
+		if (trailingslashit(home_url()) === $this->api_url) {
428
+			return false;
429
+		}
430
+
431
+		if ($this->request_recently_failed()) {
432
+			return false;
433
+		}
434
+
435
+		return $this->get_version_from_remote();
436
+	}
437
+
438
+	/**
439
+	 * Determines if a request has recently failed.
440
+	 *
441
+	 * @since 1.9.1
442
+	 *
443
+	 * @return bool
444
+	 */
445
+	private function request_recently_failed()
446
+	{
447
+		$failed_request_details = get_option($this->failed_request_cache_key);
448
+
449
+		// Request has never failed.
450
+		if (empty($failed_request_details) || !is_numeric($failed_request_details)) {
451
+			return false;
452
+		}
453
+
454
+		/*
455 455
          * Request previously failed, but the timeout has expired.
456 456
          * This means we're allowed to try again.
457 457
          */
458
-        if (time() > $failed_request_details) {
459
-            delete_option($this->failed_request_cache_key);
460
-
461
-            return false;
462
-        }
463
-
464
-        return true;
465
-    }
466
-
467
-    /**
468
-     * Logs a failed HTTP request for this API URL.
469
-     * We set a timestamp for 1 hour from now. This prevents future API requests from being
470
-     * made to this domain for 1 hour. Once the timestamp is in the past, API requests
471
-     * will be allowed again. This way if the site is down for some reason we don't bombard
472
-     * it with failed API requests.
473
-     *
474
-     * @see EDD_SL_Plugin_Updater::request_recently_failed
475
-     * @since 1.9.1
476
-     */
477
-    private function log_failed_request()
478
-    {
479
-        update_option($this->failed_request_cache_key, strtotime('+1 hour'));
480
-    }
481
-
482
-    /**
483
-     * If available, show the changelog for sites in a multisite install.
484
-     */
485
-    public function show_changelog()
486
-    {
487
-        if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action']) {
488
-            return;
489
-        }
490
-
491
-        if (empty($_REQUEST['plugin'])) {
492
-            return;
493
-        }
494
-
495
-        if (empty($_REQUEST['slug']) || $this->slug !== $_REQUEST['slug']) {
496
-            return;
497
-        }
498
-
499
-        if (!current_user_can('update_plugins')) {
500
-            wp_die(esc_html__('You do not have permission to install plugin updates', 'gravityview'), esc_html__('Error', 'gravityview'), ['response' => 403]);
501
-        }
502
-
503
-        $version_info = $this->get_repo_api_data();
504
-        if (isset($version_info->sections)) {
505
-            $sections = $this->convert_object_to_array($version_info->sections);
506
-            if (!empty($sections['changelog'])) {
507
-                echo '<div style="background:#fff;padding:10px;">'.wp_kses_post($sections['changelog']).'</div>';
508
-            }
509
-        }
510
-
511
-        exit;
512
-    }
513
-
514
-    /**
515
-     * Gets the current version information from the remote site.
516
-     *
517
-     * @return array|false
518
-     */
519
-    private function get_version_from_remote()
520
-    {
521
-        $api_params = [
522
-            'edd_action'  => 'get_version',
523
-            'license'     => !empty($this->api_data['license']) ? $this->api_data['license'] : '',
524
-            'item_name'   => isset($this->api_data['item_name']) ? $this->api_data['item_name'] : false,
525
-            'item_id'     => isset($this->api_data['item_id']) ? $this->api_data['item_id'] : false,
526
-            'version'     => isset($this->api_data['version']) ? $this->api_data['version'] : false,
527
-            'slug'        => $this->slug,
528
-            'author'      => $this->api_data['author'],
529
-            'url'         => home_url(),
530
-            'beta'        => $this->beta,
531
-            'php_version' => phpversion(),
532
-            'wp_version'  => get_bloginfo('version'),
533
-        ];
534
-
535
-        /**
536
-         * Filters the parameters sent in the API request.
537
-         *
538
-         * @param array  $api_params        The array of data sent in the request.
539
-         * @param array  $this->api_data    The array of data set up in the class constructor.
540
-         * @param string $this->plugin_file The full path and filename of the file.
541
-         */
542
-        $api_params = apply_filters('edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file);
543
-
544
-        $request = wp_remote_post(
545
-            $this->api_url,
546
-            [
547
-                'timeout'   => 15,
548
-                'sslverify' => $this->verify_ssl(),
549
-                'body'      => $api_params,
550
-            ]
551
-        );
552
-
553
-        if (is_wp_error($request) || (200 !== wp_remote_retrieve_response_code($request))) {
554
-            $this->log_failed_request();
555
-
556
-            return false;
557
-        }
558
-
559
-        $request = json_decode(wp_remote_retrieve_body($request));
560
-
561
-        if ($request && isset($request->sections)) {
562
-            $request->sections = maybe_unserialize($request->sections);
563
-        } else {
564
-            $request = false;
565
-        }
566
-
567
-        if ($request && isset($request->banners)) {
568
-            $request->banners = maybe_unserialize($request->banners);
569
-        }
570
-
571
-        if ($request && isset($request->icons)) {
572
-            $request->icons = maybe_unserialize($request->icons);
573
-        }
574
-
575
-        if (!empty($request->sections)) {
576
-            foreach ($request->sections as $key => $section) {
577
-                $request->$key = (array) $section;
578
-            }
579
-        }
580
-
581
-        return $request;
582
-    }
583
-
584
-    /**
585
-     * Get the version info from the cache, if it exists.
586
-     *
587
-     * @param string $cache_key
588
-     *
589
-     * @return object
590
-     */
591
-    public function get_cached_version_info($cache_key = '')
592
-    {
593
-        if (empty($cache_key)) {
594
-            $cache_key = $this->get_cache_key();
595
-        }
596
-
597
-        $cache = get_option($cache_key);
598
-
599
-        // Cache is expired
600
-        if (empty($cache['timeout']) || time() > $cache['timeout']) {
601
-            return false;
602
-        }
603
-
604
-        // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
605
-        $cache['value'] = json_decode($cache['value']);
606
-        if (!empty($cache['value']->icons)) {
607
-            $cache['value']->icons = (array) $cache['value']->icons;
608
-        }
609
-
610
-        return $cache['value'];
611
-    }
612
-
613
-    /**
614
-     * Adds the plugin version information to the database.
615
-     *
616
-     * @param string $value
617
-     * @param string $cache_key
618
-     */
619
-    public function set_version_info_cache($value = '', $cache_key = '')
620
-    {
621
-        if (empty($cache_key)) {
622
-            $cache_key = $this->get_cache_key();
623
-        }
624
-
625
-        $data = [
626
-            'timeout' => strtotime('+3 hours', time()),
627
-            'value'   => wp_json_encode($value),
628
-        ];
629
-
630
-        update_option($cache_key, $data, 'no');
631
-
632
-        // Delete the duplicate option
633
-        delete_option('edd_api_request_'.md5(serialize($this->slug.$this->api_data['license'].$this->beta)));
634
-    }
635
-
636
-    /**
637
-     * Returns if the SSL of the store should be verified.
638
-     *
639
-     * @since  1.6.13
640
-     *
641
-     * @return bool
642
-     */
643
-    private function verify_ssl()
644
-    {
645
-        return (bool) apply_filters('edd_sl_api_request_verify_ssl', true, $this);
646
-    }
647
-
648
-    /**
649
-     * Gets the unique key (option name) for a plugin.
650
-     *
651
-     * @since 1.9.0
652
-     *
653
-     * @return string
654
-     */
655
-    private function get_cache_key()
656
-    {
657
-        $string = $this->slug.$this->api_data['license'].$this->beta;
658
-
659
-        return 'edd_sl_'.md5(serialize($string));
660
-    }
458
+		if (time() > $failed_request_details) {
459
+			delete_option($this->failed_request_cache_key);
460
+
461
+			return false;
462
+		}
463
+
464
+		return true;
465
+	}
466
+
467
+	/**
468
+	 * Logs a failed HTTP request for this API URL.
469
+	 * We set a timestamp for 1 hour from now. This prevents future API requests from being
470
+	 * made to this domain for 1 hour. Once the timestamp is in the past, API requests
471
+	 * will be allowed again. This way if the site is down for some reason we don't bombard
472
+	 * it with failed API requests.
473
+	 *
474
+	 * @see EDD_SL_Plugin_Updater::request_recently_failed
475
+	 * @since 1.9.1
476
+	 */
477
+	private function log_failed_request()
478
+	{
479
+		update_option($this->failed_request_cache_key, strtotime('+1 hour'));
480
+	}
481
+
482
+	/**
483
+	 * If available, show the changelog for sites in a multisite install.
484
+	 */
485
+	public function show_changelog()
486
+	{
487
+		if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action']) {
488
+			return;
489
+		}
490
+
491
+		if (empty($_REQUEST['plugin'])) {
492
+			return;
493
+		}
494
+
495
+		if (empty($_REQUEST['slug']) || $this->slug !== $_REQUEST['slug']) {
496
+			return;
497
+		}
498
+
499
+		if (!current_user_can('update_plugins')) {
500
+			wp_die(esc_html__('You do not have permission to install plugin updates', 'gravityview'), esc_html__('Error', 'gravityview'), ['response' => 403]);
501
+		}
502
+
503
+		$version_info = $this->get_repo_api_data();
504
+		if (isset($version_info->sections)) {
505
+			$sections = $this->convert_object_to_array($version_info->sections);
506
+			if (!empty($sections['changelog'])) {
507
+				echo '<div style="background:#fff;padding:10px;">'.wp_kses_post($sections['changelog']).'</div>';
508
+			}
509
+		}
510
+
511
+		exit;
512
+	}
513
+
514
+	/**
515
+	 * Gets the current version information from the remote site.
516
+	 *
517
+	 * @return array|false
518
+	 */
519
+	private function get_version_from_remote()
520
+	{
521
+		$api_params = [
522
+			'edd_action'  => 'get_version',
523
+			'license'     => !empty($this->api_data['license']) ? $this->api_data['license'] : '',
524
+			'item_name'   => isset($this->api_data['item_name']) ? $this->api_data['item_name'] : false,
525
+			'item_id'     => isset($this->api_data['item_id']) ? $this->api_data['item_id'] : false,
526
+			'version'     => isset($this->api_data['version']) ? $this->api_data['version'] : false,
527
+			'slug'        => $this->slug,
528
+			'author'      => $this->api_data['author'],
529
+			'url'         => home_url(),
530
+			'beta'        => $this->beta,
531
+			'php_version' => phpversion(),
532
+			'wp_version'  => get_bloginfo('version'),
533
+		];
534
+
535
+		/**
536
+		 * Filters the parameters sent in the API request.
537
+		 *
538
+		 * @param array  $api_params        The array of data sent in the request.
539
+		 * @param array  $this->api_data    The array of data set up in the class constructor.
540
+		 * @param string $this->plugin_file The full path and filename of the file.
541
+		 */
542
+		$api_params = apply_filters('edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file);
543
+
544
+		$request = wp_remote_post(
545
+			$this->api_url,
546
+			[
547
+				'timeout'   => 15,
548
+				'sslverify' => $this->verify_ssl(),
549
+				'body'      => $api_params,
550
+			]
551
+		);
552
+
553
+		if (is_wp_error($request) || (200 !== wp_remote_retrieve_response_code($request))) {
554
+			$this->log_failed_request();
555
+
556
+			return false;
557
+		}
558
+
559
+		$request = json_decode(wp_remote_retrieve_body($request));
560
+
561
+		if ($request && isset($request->sections)) {
562
+			$request->sections = maybe_unserialize($request->sections);
563
+		} else {
564
+			$request = false;
565
+		}
566
+
567
+		if ($request && isset($request->banners)) {
568
+			$request->banners = maybe_unserialize($request->banners);
569
+		}
570
+
571
+		if ($request && isset($request->icons)) {
572
+			$request->icons = maybe_unserialize($request->icons);
573
+		}
574
+
575
+		if (!empty($request->sections)) {
576
+			foreach ($request->sections as $key => $section) {
577
+				$request->$key = (array) $section;
578
+			}
579
+		}
580
+
581
+		return $request;
582
+	}
583
+
584
+	/**
585
+	 * Get the version info from the cache, if it exists.
586
+	 *
587
+	 * @param string $cache_key
588
+	 *
589
+	 * @return object
590
+	 */
591
+	public function get_cached_version_info($cache_key = '')
592
+	{
593
+		if (empty($cache_key)) {
594
+			$cache_key = $this->get_cache_key();
595
+		}
596
+
597
+		$cache = get_option($cache_key);
598
+
599
+		// Cache is expired
600
+		if (empty($cache['timeout']) || time() > $cache['timeout']) {
601
+			return false;
602
+		}
603
+
604
+		// We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
605
+		$cache['value'] = json_decode($cache['value']);
606
+		if (!empty($cache['value']->icons)) {
607
+			$cache['value']->icons = (array) $cache['value']->icons;
608
+		}
609
+
610
+		return $cache['value'];
611
+	}
612
+
613
+	/**
614
+	 * Adds the plugin version information to the database.
615
+	 *
616
+	 * @param string $value
617
+	 * @param string $cache_key
618
+	 */
619
+	public function set_version_info_cache($value = '', $cache_key = '')
620
+	{
621
+		if (empty($cache_key)) {
622
+			$cache_key = $this->get_cache_key();
623
+		}
624
+
625
+		$data = [
626
+			'timeout' => strtotime('+3 hours', time()),
627
+			'value'   => wp_json_encode($value),
628
+		];
629
+
630
+		update_option($cache_key, $data, 'no');
631
+
632
+		// Delete the duplicate option
633
+		delete_option('edd_api_request_'.md5(serialize($this->slug.$this->api_data['license'].$this->beta)));
634
+	}
635
+
636
+	/**
637
+	 * Returns if the SSL of the store should be verified.
638
+	 *
639
+	 * @since  1.6.13
640
+	 *
641
+	 * @return bool
642
+	 */
643
+	private function verify_ssl()
644
+	{
645
+		return (bool) apply_filters('edd_sl_api_request_verify_ssl', true, $this);
646
+	}
647
+
648
+	/**
649
+	 * Gets the unique key (option name) for a plugin.
650
+	 *
651
+	 * @since 1.9.0
652
+	 *
653
+	 * @return string
654
+	 */
655
+	private function get_cache_key()
656
+	{
657
+		$string = $this->slug.$this->api_data['license'].$this->beta;
658
+
659
+		return 'edd_sl_'.md5(serialize($string));
660
+	}
661 661
 }
Please login to merge, or discard this patch.
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly
14
-if (!defined('ABSPATH')) {
14
+if ( ! defined( 'ABSPATH' ) ) {
15 15
     exit;
16 16
 }
17 17
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 class EDD_SL_Plugin_Updater
26 26
 {
27 27
     private $api_url = '';
28
-    private $api_data = [];
28
+    private $api_data = [ ];
29 29
     private $plugin_file = '';
30 30
     private $name = '';
31 31
     private $slug = '';
@@ -44,21 +44,21 @@  discard block
 block discarded – undo
44 44
      * @param string $_plugin_file Path to the plugin file.
45 45
      * @param array  $_api_data    Optional data to send with API calls.
46 46
      */
47
-    public function __construct($_api_url, $_plugin_file, $_api_data = null)
47
+    public function __construct( $_api_url, $_plugin_file, $_api_data = null )
48 48
     {
49 49
         global $edd_plugin_data;
50 50
 
51
-        $this->api_url = trailingslashit($_api_url);
51
+        $this->api_url = trailingslashit( $_api_url );
52 52
         $this->api_data = $_api_data;
53 53
         $this->plugin_file = $_plugin_file;
54
-        $this->name = plugin_basename($_plugin_file);
55
-        $this->slug = basename($_plugin_file, '.php');
56
-        $this->version = $_api_data['version'];
57
-        $this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false;
58
-        $this->beta = !empty($this->api_data['beta']) ? true : false;
59
-        $this->failed_request_cache_key = 'edd_sl_failed_http_'.md5($this->api_url);
54
+        $this->name = plugin_basename( $_plugin_file );
55
+        $this->slug = basename( $_plugin_file, '.php' );
56
+        $this->version = $_api_data[ 'version' ];
57
+        $this->wp_override = isset( $_api_data[ 'wp_override' ] ) ? (bool)$_api_data[ 'wp_override' ] : false;
58
+        $this->beta = ! empty( $this->api_data[ 'beta' ] ) ? true : false;
59
+        $this->failed_request_cache_key = 'edd_sl_failed_http_' . md5( $this->api_url );
60 60
 
61
-        $edd_plugin_data[$this->slug] = $this->api_data;
61
+        $edd_plugin_data[ $this->slug ] = $this->api_data;
62 62
 
63 63
         /**
64 64
          * Fires after the $edd_plugin_data is setup.
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param array $edd_plugin_data Array of EDD SL plugin data.
69 69
          */
70
-        do_action('post_edd_sl_plugin_updater_setup', $edd_plugin_data);
70
+        do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
71 71
 
72 72
         // Set up hooks.
73 73
         $this->init();
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function init()
84 84
     {
85
-        add_filter('pre_set_site_transient_update_plugins', [$this, 'check_update']);
86
-        add_filter('plugins_api', [$this, 'plugins_api_filter'], 10, 3);
87
-        add_action('after_plugin_row', [$this, 'show_update_notification'], 10, 2);
88
-        add_action('admin_init', [$this, 'show_changelog']);
85
+        add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'check_update' ] );
86
+        add_filter( 'plugins_api', [ $this, 'plugins_api_filter' ], 10, 3 );
87
+        add_action( 'after_plugin_row', [ $this, 'show_update_notification' ], 10, 2 );
88
+        add_action( 'admin_init', [ $this, 'show_changelog' ] );
89 89
     }
90 90
 
91 91
     /**
@@ -102,29 +102,29 @@  discard block
 block discarded – undo
102 102
      *
103 103
      * @return array Modified update array with custom plugin data.
104 104
      */
105
-    public function check_update($_transient_data)
105
+    public function check_update( $_transient_data )
106 106
     {
107 107
         global $pagenow;
108 108
 
109
-        if (!is_object($_transient_data)) {
109
+        if ( ! is_object( $_transient_data ) ) {
110 110
             $_transient_data = new stdClass();
111 111
         }
112 112
 
113
-        if (!empty($_transient_data->response) && !empty($_transient_data->response[$this->name]) && false === $this->wp_override) {
113
+        if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
114 114
             return $_transient_data;
115 115
         }
116 116
 
117 117
         $current = $this->get_repo_api_data();
118
-        if (false !== $current && is_object($current) && isset($current->new_version)) {
119
-            if (version_compare($this->version, $current->new_version, '<')) {
120
-                $_transient_data->response[$this->name] = $current;
118
+        if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
119
+            if ( version_compare( $this->version, $current->new_version, '<' ) ) {
120
+                $_transient_data->response[ $this->name ] = $current;
121 121
             } else {
122 122
                 // Populating the no_update information is required to support auto-updates in WordPress 5.5.
123
-                $_transient_data->no_update[$this->name] = $current;
123
+                $_transient_data->no_update[ $this->name ] = $current;
124 124
             }
125 125
         }
126 126
         $_transient_data->last_checked = time();
127
-        $_transient_data->checked[$this->name] = $this->version;
127
+        $_transient_data->checked[ $this->name ] = $this->version;
128 128
 
129 129
         return $_transient_data;
130 130
     }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
     {
140 140
         $version_info = $this->get_cached_version_info();
141 141
 
142
-        if (false === $version_info) {
142
+        if ( false === $version_info ) {
143 143
             $version_info = $this->api_request(
144 144
                 'plugin_latest_version',
145 145
                 [
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                     'beta' => $this->beta,
148 148
                 ]
149 149
             );
150
-            if (!$version_info) {
150
+            if ( ! $version_info ) {
151 151
                 return false;
152 152
             }
153 153
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $version_info->plugin = $this->name;
156 156
             $version_info->id = $this->name;
157 157
 
158
-            $this->set_version_info_cache($version_info);
158
+            $this->set_version_info_cache( $version_info );
159 159
         }
160 160
 
161 161
         return $version_info;
@@ -167,35 +167,35 @@  discard block
 block discarded – undo
167 167
      * @param string $file
168 168
      * @param array  $plugin
169 169
      */
170
-    public function show_update_notification($file, $plugin)
170
+    public function show_update_notification( $file, $plugin )
171 171
     {
172 172
 
173 173
         // Return early if in the network admin, or if this is not a multisite install.
174
-        if (is_network_admin() || !is_multisite()) {
174
+        if ( is_network_admin() || ! is_multisite() ) {
175 175
             return;
176 176
         }
177 177
 
178 178
         // Allow single site admins to see that an update is available.
179
-        if (!current_user_can('activate_plugins')) {
179
+        if ( ! current_user_can( 'activate_plugins' ) ) {
180 180
             return;
181 181
         }
182 182
 
183
-        if ($this->name !== $file) {
183
+        if ( $this->name !== $file ) {
184 184
             return;
185 185
         }
186 186
 
187 187
         // Do not print any message if update does not exist.
188
-        $update_cache = get_site_transient('update_plugins');
188
+        $update_cache = get_site_transient( 'update_plugins' );
189 189
 
190
-        if (!isset($update_cache->response[$this->name])) {
191
-            if (!is_object($update_cache)) {
190
+        if ( ! isset( $update_cache->response[ $this->name ] ) ) {
191
+            if ( ! is_object( $update_cache ) ) {
192 192
                 $update_cache = new stdClass();
193 193
             }
194
-            $update_cache->response[$this->name] = $this->get_repo_api_data();
194
+            $update_cache->response[ $this->name ] = $this->get_repo_api_data();
195 195
         }
196 196
 
197 197
         // Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
198
-        if (empty($update_cache->response[$this->name]) || version_compare($this->version, $update_cache->response[$this->name]->new_version, '>=')) {
198
+        if ( empty( $update_cache->response[ $this->name ] ) || version_compare( $this->version, $update_cache->response[ $this->name ]->new_version, '>=' ) ) {
199 199
             return;
200 200
         }
201 201
 
@@ -203,72 +203,72 @@  discard block
 block discarded – undo
203 203
             '<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
204 204
             $this->slug,
205 205
             $file,
206
-            in_array($this->name, $this->get_active_plugins(), true) ? 'active' : 'inactive'
206
+            in_array( $this->name, $this->get_active_plugins(), true ) ? 'active' : 'inactive'
207 207
         );
208 208
 
209 209
         echo '<td colspan="3" class="plugin-update colspanchange">';
210 210
         echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
211 211
 
212 212
         $changelog_link = '';
213
-        if (!empty($update_cache->response[$this->name]->sections->changelog)) {
213
+        if ( ! empty( $update_cache->response[ $this->name ]->sections->changelog ) ) {
214 214
             $changelog_link = add_query_arg(
215 215
                 [
216 216
                     'edd_sl_action' => 'view_plugin_changelog',
217
-                    'plugin'        => urlencode($this->name),
218
-                    'slug'          => urlencode($this->slug),
217
+                    'plugin'        => urlencode( $this->name ),
218
+                    'slug'          => urlencode( $this->slug ),
219 219
                     'TB_iframe'     => 'true',
220 220
                     'width'         => 77,
221 221
                     'height'        => 911,
222 222
                 ],
223
-                self_admin_url('index.php')
223
+                self_admin_url( 'index.php' )
224 224
             );
225 225
         }
226 226
         $update_link = add_query_arg(
227 227
             [
228 228
                 'action' => 'upgrade-plugin',
229
-                'plugin' => urlencode($this->name),
229
+                'plugin' => urlencode( $this->name ),
230 230
             ],
231
-            self_admin_url('update.php')
231
+            self_admin_url( 'update.php' )
232 232
         );
233 233
 
234 234
         printf(
235 235
         /* translators: the plugin name. */
236
-            esc_html__('There is a new version of %1$s available.', 'gravityview'),
237
-            esc_html($plugin['Name'])
236
+            esc_html__( 'There is a new version of %1$s available.', 'gravityview' ),
237
+            esc_html( $plugin[ 'Name' ] )
238 238
         );
239 239
 
240
-        if (!current_user_can('update_plugins')) {
240
+        if ( ! current_user_can( 'update_plugins' ) ) {
241 241
             echo ' ';
242
-            esc_html_e('Contact your network administrator to install the update.', 'gravityview');
243
-        } elseif (empty($update_cache->response[$this->name]->package) && !empty($changelog_link)) {
242
+            esc_html_e( 'Contact your network administrator to install the update.', 'gravityview' );
243
+        } elseif ( empty( $update_cache->response[ $this->name ]->package ) && ! empty( $changelog_link ) ) {
244 244
             echo ' ';
245 245
             printf(
246 246
             /* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
247
-                __('%1$sView version %2$s details%3$s.', 'gravityview'),
248
-                '<a target="_blank" class="thickbox open-plugin-details-modal" href="'.esc_url($changelog_link).'">',
249
-                esc_html($update_cache->response[$this->name]->new_version),
247
+                __( '%1$sView version %2$s details%3$s.', 'gravityview' ),
248
+                '<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
249
+                esc_html( $update_cache->response[ $this->name ]->new_version ),
250 250
                 '</a>'
251 251
             );
252
-        } elseif (!empty($changelog_link)) {
252
+        } elseif ( ! empty( $changelog_link ) ) {
253 253
             echo ' ';
254 254
             printf(
255
-                __('%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'gravityview'),
256
-                '<a target="_blank" class="thickbox open-plugin-details-modal" href="'.esc_url($changelog_link).'">',
257
-                esc_html($update_cache->response[$this->name]->new_version),
255
+                __( '%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'gravityview' ),
256
+                '<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
257
+                esc_html( $update_cache->response[ $this->name ]->new_version ),
258 258
                 '</a>',
259
-                '<a target="_blank" class="update-link" href="'.esc_url(wp_nonce_url($update_link, 'upgrade-plugin_'.$file)).'">',
259
+                '<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
260 260
                 '</a>'
261 261
             );
262 262
         } else {
263 263
             printf(
264 264
                 ' %1$s%2$s%3$s',
265
-                '<a target="_blank" class="update-link" href="'.esc_url(wp_nonce_url($update_link, 'upgrade-plugin_'.$file)).'">',
266
-                esc_html__('Update now.', 'gravityview'),
265
+                '<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
266
+                esc_html__( 'Update now.', 'gravityview' ),
267 267
                 '</a>'
268 268
             );
269 269
         }
270 270
 
271
-        do_action("in_plugin_update_message-{$file}", $plugin, $plugin);
271
+        do_action( "in_plugin_update_message-{$file}", $plugin, $plugin );
272 272
 
273 273
         echo '</p></div></td></tr>';
274 274
     }
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
      */
281 281
     private function get_active_plugins()
282 282
     {
283
-        $active_plugins = (array) get_option('active_plugins');
284
-        $active_network_plugins = (array) get_site_option('active_sitewide_plugins');
283
+        $active_plugins = (array)get_option( 'active_plugins' );
284
+        $active_network_plugins = (array)get_site_option( 'active_sitewide_plugins' );
285 285
 
286
-        return array_merge($active_plugins, array_keys($active_network_plugins));
286
+        return array_merge( $active_plugins, array_keys( $active_network_plugins ) );
287 287
     }
288 288
 
289 289
     /**
@@ -297,13 +297,13 @@  discard block
 block discarded – undo
297 297
      *
298 298
      * @return object $_data
299 299
      */
300
-    public function plugins_api_filter($_data, $_action = '', $_args = null)
300
+    public function plugins_api_filter( $_data, $_action = '', $_args = null )
301 301
     {
302
-        if ('plugin_information' !== $_action) {
302
+        if ( 'plugin_information' !== $_action ) {
303 303
             return $_data;
304 304
         }
305 305
 
306
-        if (!isset($_args->slug) || ($_args->slug !== $this->slug)) {
306
+        if ( ! isset( $_args->slug ) || ( $_args->slug !== $this->slug ) ) {
307 307
             return $_data;
308 308
         }
309 309
 
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
             'slug'   => $this->slug,
312 312
             'is_ssl' => is_ssl(),
313 313
             'fields' => [
314
-                'banners' => [],
314
+                'banners' => [ ],
315 315
                 'reviews' => false,
316
-                'icons'   => [],
316
+                'icons'   => [ ],
317 317
             ],
318 318
         ];
319 319
 
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
         $edd_api_request_transient = $this->get_cached_version_info();
322 322
 
323 323
         //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
324
-        if (empty($edd_api_request_transient)) {
325
-            $api_response = $this->api_request('plugin_information', $to_send);
324
+        if ( empty( $edd_api_request_transient ) ) {
325
+            $api_response = $this->api_request( 'plugin_information', $to_send );
326 326
 
327 327
             // Expires in 3 hours
328
-            $this->set_version_info_cache($api_response);
328
+            $this->set_version_info_cache( $api_response );
329 329
 
330
-            if (false !== $api_response) {
330
+            if ( false !== $api_response ) {
331 331
                 $_data = $api_response;
332 332
             }
333 333
         } else {
@@ -335,26 +335,26 @@  discard block
 block discarded – undo
335 335
         }
336 336
 
337 337
         // Convert sections into an associative array, since we're getting an object, but Core expects an array.
338
-        if (isset($_data->sections) && !is_array($_data->sections)) {
339
-            $_data->sections = $this->convert_object_to_array($_data->sections);
338
+        if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
339
+            $_data->sections = $this->convert_object_to_array( $_data->sections );
340 340
         }
341 341
 
342 342
         // Convert banners into an associative array, since we're getting an object, but Core expects an array.
343
-        if (isset($_data->banners) && !is_array($_data->banners)) {
344
-            $_data->banners = $this->convert_object_to_array($_data->banners);
343
+        if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
344
+            $_data->banners = $this->convert_object_to_array( $_data->banners );
345 345
         }
346 346
 
347 347
         // Convert icons into an associative array, since we're getting an object, but Core expects an array.
348
-        if (isset($_data->icons) && !is_array($_data->icons)) {
349
-            $_data->icons = $this->convert_object_to_array($_data->icons);
348
+        if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
349
+            $_data->icons = $this->convert_object_to_array( $_data->icons );
350 350
         }
351 351
 
352 352
         // Convert contributors into an associative array, since we're getting an object, but Core expects an array.
353
-        if (isset($_data->contributors) && !is_array($_data->contributors)) {
354
-            $_data->contributors = $this->convert_object_to_array($_data->contributors);
353
+        if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
354
+            $_data->contributors = $this->convert_object_to_array( $_data->contributors );
355 355
         }
356 356
 
357
-        if (!isset($_data->plugin)) {
357
+        if ( ! isset( $_data->plugin ) ) {
358 358
             $_data->plugin = $this->name;
359 359
         }
360 360
 
@@ -373,14 +373,14 @@  discard block
 block discarded – undo
373 373
      *
374 374
      * @return array
375 375
      */
376
-    private function convert_object_to_array($data)
376
+    private function convert_object_to_array( $data )
377 377
     {
378
-        if (!is_array($data) && !is_object($data)) {
379
-            return [];
378
+        if ( ! is_array( $data ) && ! is_object( $data ) ) {
379
+            return [ ];
380 380
         }
381
-        $new_data = [];
382
-        foreach ($data as $key => $value) {
383
-            $new_data[$key] = is_object($value) ? $this->convert_object_to_array($value) : $value;
381
+        $new_data = [ ];
382
+        foreach ( $data as $key => $value ) {
383
+            $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
384 384
         }
385 385
 
386 386
         return $new_data;
@@ -394,10 +394,10 @@  discard block
 block discarded – undo
394 394
      *
395 395
      * @return object $array
396 396
      */
397
-    public function http_request_args($args, $url)
397
+    public function http_request_args( $args, $url )
398 398
     {
399
-        if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) {
400
-            $args['sslverify'] = $this->verify_ssl();
399
+        if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
400
+            $args[ 'sslverify' ] = $this->verify_ssl();
401 401
         }
402 402
 
403 403
         return $args;
@@ -415,20 +415,20 @@  discard block
 block discarded – undo
415 415
      *
416 416
      * @return false|object|void
417 417
      */
418
-    private function api_request($_action, $_data)
418
+    private function api_request( $_action, $_data )
419 419
     {
420
-        $data = array_merge($this->api_data, $_data);
420
+        $data = array_merge( $this->api_data, $_data );
421 421
 
422
-        if ($data['slug'] !== $this->slug) {
422
+        if ( $data[ 'slug' ] !== $this->slug ) {
423 423
             return;
424 424
         }
425 425
 
426 426
         // Don't allow a plugin to ping itself
427
-        if (trailingslashit(home_url()) === $this->api_url) {
427
+        if ( trailingslashit( home_url() ) === $this->api_url ) {
428 428
             return false;
429 429
         }
430 430
 
431
-        if ($this->request_recently_failed()) {
431
+        if ( $this->request_recently_failed() ) {
432 432
             return false;
433 433
         }
434 434
 
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
      */
445 445
     private function request_recently_failed()
446 446
     {
447
-        $failed_request_details = get_option($this->failed_request_cache_key);
447
+        $failed_request_details = get_option( $this->failed_request_cache_key );
448 448
 
449 449
         // Request has never failed.
450
-        if (empty($failed_request_details) || !is_numeric($failed_request_details)) {
450
+        if ( empty( $failed_request_details ) || ! is_numeric( $failed_request_details ) ) {
451 451
             return false;
452 452
         }
453 453
 
@@ -455,8 +455,8 @@  discard block
 block discarded – undo
455 455
          * Request previously failed, but the timeout has expired.
456 456
          * This means we're allowed to try again.
457 457
          */
458
-        if (time() > $failed_request_details) {
459
-            delete_option($this->failed_request_cache_key);
458
+        if ( time() > $failed_request_details ) {
459
+            delete_option( $this->failed_request_cache_key );
460 460
 
461 461
             return false;
462 462
         }
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
      */
477 477
     private function log_failed_request()
478 478
     {
479
-        update_option($this->failed_request_cache_key, strtotime('+1 hour'));
479
+        update_option( $this->failed_request_cache_key, strtotime( '+1 hour' ) );
480 480
     }
481 481
 
482 482
     /**
@@ -484,27 +484,27 @@  discard block
 block discarded – undo
484 484
      */
485 485
     public function show_changelog()
486 486
     {
487
-        if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action']) {
487
+        if ( empty( $_REQUEST[ 'edd_sl_action' ] ) || 'view_plugin_changelog' !== $_REQUEST[ 'edd_sl_action' ] ) {
488 488
             return;
489 489
         }
490 490
 
491
-        if (empty($_REQUEST['plugin'])) {
491
+        if ( empty( $_REQUEST[ 'plugin' ] ) ) {
492 492
             return;
493 493
         }
494 494
 
495
-        if (empty($_REQUEST['slug']) || $this->slug !== $_REQUEST['slug']) {
495
+        if ( empty( $_REQUEST[ 'slug' ] ) || $this->slug !== $_REQUEST[ 'slug' ] ) {
496 496
             return;
497 497
         }
498 498
 
499
-        if (!current_user_can('update_plugins')) {
500
-            wp_die(esc_html__('You do not have permission to install plugin updates', 'gravityview'), esc_html__('Error', 'gravityview'), ['response' => 403]);
499
+        if ( ! current_user_can( 'update_plugins' ) ) {
500
+            wp_die( esc_html__( 'You do not have permission to install plugin updates', 'gravityview' ), esc_html__( 'Error', 'gravityview' ), [ 'response' => 403 ] );
501 501
         }
502 502
 
503 503
         $version_info = $this->get_repo_api_data();
504
-        if (isset($version_info->sections)) {
505
-            $sections = $this->convert_object_to_array($version_info->sections);
506
-            if (!empty($sections['changelog'])) {
507
-                echo '<div style="background:#fff;padding:10px;">'.wp_kses_post($sections['changelog']).'</div>';
504
+        if ( isset( $version_info->sections ) ) {
505
+            $sections = $this->convert_object_to_array( $version_info->sections );
506
+            if ( ! empty( $sections[ 'changelog' ] ) ) {
507
+                echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections[ 'changelog' ] ) . '</div>';
508 508
             }
509 509
         }
510 510
 
@@ -520,16 +520,16 @@  discard block
 block discarded – undo
520 520
     {
521 521
         $api_params = [
522 522
             'edd_action'  => 'get_version',
523
-            'license'     => !empty($this->api_data['license']) ? $this->api_data['license'] : '',
524
-            'item_name'   => isset($this->api_data['item_name']) ? $this->api_data['item_name'] : false,
525
-            'item_id'     => isset($this->api_data['item_id']) ? $this->api_data['item_id'] : false,
526
-            'version'     => isset($this->api_data['version']) ? $this->api_data['version'] : false,
523
+            'license'     => ! empty( $this->api_data[ 'license' ] ) ? $this->api_data[ 'license' ] : '',
524
+            'item_name'   => isset( $this->api_data[ 'item_name' ] ) ? $this->api_data[ 'item_name' ] : false,
525
+            'item_id'     => isset( $this->api_data[ 'item_id' ] ) ? $this->api_data[ 'item_id' ] : false,
526
+            'version'     => isset( $this->api_data[ 'version' ] ) ? $this->api_data[ 'version' ] : false,
527 527
             'slug'        => $this->slug,
528
-            'author'      => $this->api_data['author'],
528
+            'author'      => $this->api_data[ 'author' ],
529 529
             'url'         => home_url(),
530 530
             'beta'        => $this->beta,
531 531
             'php_version' => phpversion(),
532
-            'wp_version'  => get_bloginfo('version'),
532
+            'wp_version'  => get_bloginfo( 'version' ),
533 533
         ];
534 534
 
535 535
         /**
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
          * @param array  $this->api_data    The array of data set up in the class constructor.
540 540
          * @param string $this->plugin_file The full path and filename of the file.
541 541
          */
542
-        $api_params = apply_filters('edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file);
542
+        $api_params = apply_filters( 'edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file );
543 543
 
544 544
         $request = wp_remote_post(
545 545
             $this->api_url,
@@ -550,31 +550,31 @@  discard block
 block discarded – undo
550 550
             ]
551 551
         );
552 552
 
553
-        if (is_wp_error($request) || (200 !== wp_remote_retrieve_response_code($request))) {
553
+        if ( is_wp_error( $request ) || ( 200 !== wp_remote_retrieve_response_code( $request ) ) ) {
554 554
             $this->log_failed_request();
555 555
 
556 556
             return false;
557 557
         }
558 558
 
559
-        $request = json_decode(wp_remote_retrieve_body($request));
559
+        $request = json_decode( wp_remote_retrieve_body( $request ) );
560 560
 
561
-        if ($request && isset($request->sections)) {
562
-            $request->sections = maybe_unserialize($request->sections);
561
+        if ( $request && isset( $request->sections ) ) {
562
+            $request->sections = maybe_unserialize( $request->sections );
563 563
         } else {
564 564
             $request = false;
565 565
         }
566 566
 
567
-        if ($request && isset($request->banners)) {
568
-            $request->banners = maybe_unserialize($request->banners);
567
+        if ( $request && isset( $request->banners ) ) {
568
+            $request->banners = maybe_unserialize( $request->banners );
569 569
         }
570 570
 
571
-        if ($request && isset($request->icons)) {
572
-            $request->icons = maybe_unserialize($request->icons);
571
+        if ( $request && isset( $request->icons ) ) {
572
+            $request->icons = maybe_unserialize( $request->icons );
573 573
         }
574 574
 
575
-        if (!empty($request->sections)) {
576
-            foreach ($request->sections as $key => $section) {
577
-                $request->$key = (array) $section;
575
+        if ( ! empty( $request->sections ) ) {
576
+            foreach ( $request->sections as $key => $section ) {
577
+                $request->$key = (array)$section;
578 578
             }
579 579
         }
580 580
 
@@ -588,26 +588,26 @@  discard block
 block discarded – undo
588 588
      *
589 589
      * @return object
590 590
      */
591
-    public function get_cached_version_info($cache_key = '')
591
+    public function get_cached_version_info( $cache_key = '' )
592 592
     {
593
-        if (empty($cache_key)) {
593
+        if ( empty( $cache_key ) ) {
594 594
             $cache_key = $this->get_cache_key();
595 595
         }
596 596
 
597
-        $cache = get_option($cache_key);
597
+        $cache = get_option( $cache_key );
598 598
 
599 599
         // Cache is expired
600
-        if (empty($cache['timeout']) || time() > $cache['timeout']) {
600
+        if ( empty( $cache[ 'timeout' ] ) || time() > $cache[ 'timeout' ] ) {
601 601
             return false;
602 602
         }
603 603
 
604 604
         // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
605
-        $cache['value'] = json_decode($cache['value']);
606
-        if (!empty($cache['value']->icons)) {
607
-            $cache['value']->icons = (array) $cache['value']->icons;
605
+        $cache[ 'value' ] = json_decode( $cache[ 'value' ] );
606
+        if ( ! empty( $cache[ 'value' ]->icons ) ) {
607
+            $cache[ 'value' ]->icons = (array)$cache[ 'value' ]->icons;
608 608
         }
609 609
 
610
-        return $cache['value'];
610
+        return $cache[ 'value' ];
611 611
     }
612 612
 
613 613
     /**
@@ -616,21 +616,21 @@  discard block
 block discarded – undo
616 616
      * @param string $value
617 617
      * @param string $cache_key
618 618
      */
619
-    public function set_version_info_cache($value = '', $cache_key = '')
619
+    public function set_version_info_cache( $value = '', $cache_key = '' )
620 620
     {
621
-        if (empty($cache_key)) {
621
+        if ( empty( $cache_key ) ) {
622 622
             $cache_key = $this->get_cache_key();
623 623
         }
624 624
 
625 625
         $data = [
626
-            'timeout' => strtotime('+3 hours', time()),
627
-            'value'   => wp_json_encode($value),
626
+            'timeout' => strtotime( '+3 hours', time() ),
627
+            'value'   => wp_json_encode( $value ),
628 628
         ];
629 629
 
630
-        update_option($cache_key, $data, 'no');
630
+        update_option( $cache_key, $data, 'no' );
631 631
 
632 632
         // Delete the duplicate option
633
-        delete_option('edd_api_request_'.md5(serialize($this->slug.$this->api_data['license'].$this->beta)));
633
+        delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data[ 'license' ] . $this->beta ) ) );
634 634
     }
635 635
 
636 636
     /**
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
      */
643 643
     private function verify_ssl()
644 644
     {
645
-        return (bool) apply_filters('edd_sl_api_request_verify_ssl', true, $this);
645
+        return (bool)apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
646 646
     }
647 647
 
648 648
     /**
@@ -654,8 +654,8 @@  discard block
 block discarded – undo
654 654
      */
655 655
     private function get_cache_key()
656 656
     {
657
-        $string = $this->slug.$this->api_data['license'].$this->beta;
657
+        $string = $this->slug . $this->api_data[ 'license' ] . $this->beta;
658 658
 
659
-        return 'edd_sl_'.md5(serialize($string));
659
+        return 'edd_sl_' . md5( serialize( $string ) );
660 660
     }
661 661
 }
Please login to merge, or discard this patch.
Braces   +19 added lines, -38 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@  discard block
 block discarded – undo
22 22
  *
23 23
  * @version 1.9.1
24 24
  */
25
-class EDD_SL_Plugin_Updater
26
-{
25
+class EDD_SL_Plugin_Updater {
27 26
     private $api_url = '';
28 27
     private $api_data = [];
29 28
     private $plugin_file = '';
@@ -44,8 +43,7 @@  discard block
 block discarded – undo
44 43
      * @param string $_plugin_file Path to the plugin file.
45 44
      * @param array  $_api_data    Optional data to send with API calls.
46 45
      */
47
-    public function __construct($_api_url, $_plugin_file, $_api_data = null)
48
-    {
46
+    public function __construct($_api_url, $_plugin_file, $_api_data = null) {
49 47
         global $edd_plugin_data;
50 48
 
51 49
         $this->api_url = trailingslashit($_api_url);
@@ -80,8 +78,7 @@  discard block
 block discarded – undo
80 78
      *
81 79
      * @return void
82 80
      */
83
-    public function init()
84
-    {
81
+    public function init() {
85 82
         add_filter('pre_set_site_transient_update_plugins', [$this, 'check_update']);
86 83
         add_filter('plugins_api', [$this, 'plugins_api_filter'], 10, 3);
87 84
         add_action('after_plugin_row', [$this, 'show_update_notification'], 10, 2);
@@ -102,8 +99,7 @@  discard block
 block discarded – undo
102 99
      *
103 100
      * @return array Modified update array with custom plugin data.
104 101
      */
105
-    public function check_update($_transient_data)
106
-    {
102
+    public function check_update($_transient_data) {
107 103
         global $pagenow;
108 104
 
109 105
         if (!is_object($_transient_data)) {
@@ -135,8 +131,7 @@  discard block
 block discarded – undo
135 131
      *
136 132
      * @return \stdClass
137 133
      */
138
-    public function get_repo_api_data()
139
-    {
134
+    public function get_repo_api_data() {
140 135
         $version_info = $this->get_cached_version_info();
141 136
 
142 137
         if (false === $version_info) {
@@ -167,8 +162,7 @@  discard block
 block discarded – undo
167 162
      * @param string $file
168 163
      * @param array  $plugin
169 164
      */
170
-    public function show_update_notification($file, $plugin)
171
-    {
165
+    public function show_update_notification($file, $plugin) {
172 166
 
173 167
         // Return early if in the network admin, or if this is not a multisite install.
174 168
         if (is_network_admin() || !is_multisite()) {
@@ -278,8 +272,7 @@  discard block
 block discarded – undo
278 272
      *
279 273
      * @return array
280 274
      */
281
-    private function get_active_plugins()
282
-    {
275
+    private function get_active_plugins() {
283 276
         $active_plugins = (array) get_option('active_plugins');
284 277
         $active_network_plugins = (array) get_site_option('active_sitewide_plugins');
285 278
 
@@ -297,8 +290,7 @@  discard block
 block discarded – undo
297 290
      *
298 291
      * @return object $_data
299 292
      */
300
-    public function plugins_api_filter($_data, $_action = '', $_args = null)
301
-    {
293
+    public function plugins_api_filter($_data, $_action = '', $_args = null) {
302 294
         if ('plugin_information' !== $_action) {
303 295
             return $_data;
304 296
         }
@@ -373,8 +365,7 @@  discard block
 block discarded – undo
373 365
      *
374 366
      * @return array
375 367
      */
376
-    private function convert_object_to_array($data)
377
-    {
368
+    private function convert_object_to_array($data) {
378 369
         if (!is_array($data) && !is_object($data)) {
379 370
             return [];
380 371
         }
@@ -394,8 +385,7 @@  discard block
 block discarded – undo
394 385
      *
395 386
      * @return object $array
396 387
      */
397
-    public function http_request_args($args, $url)
398
-    {
388
+    public function http_request_args($args, $url) {
399 389
         if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) {
400 390
             $args['sslverify'] = $this->verify_ssl();
401 391
         }
@@ -415,8 +405,7 @@  discard block
 block discarded – undo
415 405
      *
416 406
      * @return false|object|void
417 407
      */
418
-    private function api_request($_action, $_data)
419
-    {
408
+    private function api_request($_action, $_data) {
420 409
         $data = array_merge($this->api_data, $_data);
421 410
 
422 411
         if ($data['slug'] !== $this->slug) {
@@ -442,8 +431,7 @@  discard block
 block discarded – undo
442 431
      *
443 432
      * @return bool
444 433
      */
445
-    private function request_recently_failed()
446
-    {
434
+    private function request_recently_failed() {
447 435
         $failed_request_details = get_option($this->failed_request_cache_key);
448 436
 
449 437
         // Request has never failed.
@@ -474,16 +462,14 @@  discard block
 block discarded – undo
474 462
      * @see EDD_SL_Plugin_Updater::request_recently_failed
475 463
      * @since 1.9.1
476 464
      */
477
-    private function log_failed_request()
478
-    {
465
+    private function log_failed_request() {
479 466
         update_option($this->failed_request_cache_key, strtotime('+1 hour'));
480 467
     }
481 468
 
482 469
     /**
483 470
      * If available, show the changelog for sites in a multisite install.
484 471
      */
485
-    public function show_changelog()
486
-    {
472
+    public function show_changelog() {
487 473
         if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action']) {
488 474
             return;
489 475
         }
@@ -516,8 +502,7 @@  discard block
 block discarded – undo
516 502
      *
517 503
      * @return array|false
518 504
      */
519
-    private function get_version_from_remote()
520
-    {
505
+    private function get_version_from_remote() {
521 506
         $api_params = [
522 507
             'edd_action'  => 'get_version',
523 508
             'license'     => !empty($this->api_data['license']) ? $this->api_data['license'] : '',
@@ -588,8 +573,7 @@  discard block
 block discarded – undo
588 573
      *
589 574
      * @return object
590 575
      */
591
-    public function get_cached_version_info($cache_key = '')
592
-    {
576
+    public function get_cached_version_info($cache_key = '') {
593 577
         if (empty($cache_key)) {
594 578
             $cache_key = $this->get_cache_key();
595 579
         }
@@ -616,8 +600,7 @@  discard block
 block discarded – undo
616 600
      * @param string $value
617 601
      * @param string $cache_key
618 602
      */
619
-    public function set_version_info_cache($value = '', $cache_key = '')
620
-    {
603
+    public function set_version_info_cache($value = '', $cache_key = '') {
621 604
         if (empty($cache_key)) {
622 605
             $cache_key = $this->get_cache_key();
623 606
         }
@@ -640,8 +623,7 @@  discard block
 block discarded – undo
640 623
      *
641 624
      * @return bool
642 625
      */
643
-    private function verify_ssl()
644
-    {
626
+    private function verify_ssl() {
645 627
         return (bool) apply_filters('edd_sl_api_request_verify_ssl', true, $this);
646 628
     }
647 629
 
@@ -652,8 +634,7 @@  discard block
 block discarded – undo
652 634
      *
653 635
      * @return string
654 636
      */
655
-    private function get_cache_key()
656
-    {
637
+    private function get_cache_key() {
657 638
         $string = $this->slug.$this->api_data['license'].$this->beta;
658 639
 
659 640
         return 'edd_sl_'.md5(serialize($string));
Please login to merge, or discard this patch.
future/lib/class-gamajo-template-loader.php 3 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -16,320 +16,320 @@
 block discarded – undo
16 16
 
17 17
 if (!class_exists('\GV\Gamajo_Template_Loader')) {
18 18
 
19
-    /**
20
-     * Template loader.
21
-     *
22
-     * Originally based on functions in Easy Digital Downloads (thanks Pippin!).
23
-     *
24
-     * When using in a plugin, create a new class that extends this one and just overrides the properties.
25
-     *
26
-     * @author  Gary Jones
27
-     */
28
-    class Gamajo_Template_Loader
29
-    {
30
-        /**
31
-         * Prefix for filter names.
32
-         *
33
-         * @since 1.0.0
34
-         *
35
-         * @var string
36
-         */
37
-        protected $filter_prefix = 'your_plugin';
38
-
39
-        /**
40
-         * Directory name where custom templates for this plugin should be found in the theme.
41
-         *
42
-         * For example: 'your-plugin-templates'.
43
-         *
44
-         * @since 1.0.0
45
-         *
46
-         * @var string
47
-         */
48
-        protected $theme_template_directory = 'plugin-templates';
49
-
50
-        /**
51
-         * Reference to the root directory path of this plugin.
52
-         *
53
-         * Can either be a defined constant, or a relative reference from where the subclass lives.
54
-         *
55
-         * e.g. YOUR_PLUGIN_TEMPLATE or plugin_dir_path( dirname( __FILE__ ) ); etc.
56
-         *
57
-         * @since 1.0.0
58
-         *
59
-         * @var string
60
-         */
61
-        protected $plugin_directory = 'YOUR_PLUGIN_DIR';
62
-
63
-        /**
64
-         * Directory name where templates are found in this plugin.
65
-         *
66
-         * Can either be a defined constant, or a relative reference from where the subclass lives.
67
-         *
68
-         * e.g. 'templates' or 'includes/templates', etc.
69
-         *
70
-         * @since 1.1.0
71
-         *
72
-         * @var string
73
-         */
74
-        protected $plugin_template_directory = 'templates';
75
-
76
-        /**
77
-         * Internal use only: Store variable names used for template data.
78
-         *
79
-         * Means unset_template_data() can remove all custom references from $wp_query.
80
-         *
81
-         * Initialized to contain the default 'data'.
82
-         *
83
-         * @var array
84
-         */
85
-        private $template_data_var_names = ['data'];
86
-
87
-        /**
88
-         * Clean up template data.
89
-         *
90
-         * @since 1.2.0
91
-         */
92
-        public function __destruct()
93
-        {
94
-            $this->unset_template_data();
95
-        }
96
-
97
-        /**
98
-         * Retrieve a template part.
99
-         *
100
-         * @since 1.0.0
101
-         *
102
-         * @param string $slug Template slug.
103
-         * @param string $name Optional. Template variation name. Default null.
104
-         * @param bool   $load Optional. Whether to load template. Default true.
105
-         *
106
-         * @return string
107
-         */
108
-        public function get_template_part($slug, $name = null, $load = true)
109
-        {
110
-            // Execute code for this part.
111
-            do_action('get_template_part_'.$slug, $slug, $name);
112
-            do_action($this->filter_prefix.'_get_template_part_'.$slug, $slug, $name);
113
-
114
-            // Get files names of templates, for given slug and name.
115
-            $templates = $this->get_template_file_names($slug, $name);
116
-
117
-            // Return the part that is found.
118
-            return $this->locate_template($templates, $load, false);
119
-        }
120
-
121
-        /**
122
-         * Make custom data available to template.
123
-         *
124
-         * Data is available to the template as properties under the `$data` variable.
125
-         * i.e. A value provided here under `$data['foo']` is available as `$data->foo`.
126
-         *
127
-         * When an input key has a hyphen, you can use `$data->{foo-bar}` in the template.
128
-         *
129
-         * @since 1.2.0
130
-         *
131
-         * @param mixed  $data     Custom data for the template.
132
-         * @param string $var_name Optional. Variable under which the custom data is available in the template.
133
-         *                         Default is 'data'.
134
-         *
135
-         * @return Gamajo_Template_Loader
136
-         */
137
-        public function set_template_data($data, $var_name = 'data')
138
-        {
139
-            global $wp_query;
140
-
141
-            $wp_query->query_vars[$var_name] = (object) $data;
142
-
143
-            // Add $var_name to custom variable store if not default value.
144
-            if ('data' !== $var_name) {
145
-                $this->template_data_var_names[] = $var_name;
146
-            }
147
-
148
-            return $this;
149
-        }
150
-
151
-        /**
152
-         * Remove access to custom data in template.
153
-         *
154
-         * Good to use once the final template part has been requested.
155
-         *
156
-         * @since 1.2.0
157
-         *
158
-         * @return Gamajo_Template_Loader
159
-         */
160
-        public function unset_template_data()
161
-        {
162
-            global $wp_query;
163
-
164
-            // Remove any duplicates from the custom variable store.
165
-            $custom_var_names = array_unique($this->template_data_var_names);
166
-
167
-            // Remove each custom data reference from $wp_query.
168
-            foreach ($custom_var_names as $var) {
169
-                if (isset($wp_query->query_vars[$var])) {
170
-                    unset($wp_query->query_vars[$var]);
171
-                }
172
-            }
173
-
174
-            return $this;
175
-        }
176
-
177
-        /**
178
-         * Given a slug and optional name, create the file names of templates.
179
-         *
180
-         * @since 1.0.0
181
-         *
182
-         * @param string $slug Template slug.
183
-         * @param string $name Template variation name.
184
-         *
185
-         * @return array
186
-         */
187
-        protected function get_template_file_names($slug, $name)
188
-        {
189
-            $templates = [];
190
-            if (isset($name)) {
191
-                $templates[] = $slug.'-'.$name.'.php';
192
-            }
193
-            $templates[] = $slug.'.php';
194
-
195
-            /**
196
-             * Allow template choices to be filtered.
197
-             *
198
-             * The resulting array should be in the order of most specific first, to least specific last.
199
-             * e.g. 0 => recipe-instructions.php, 1 => recipe.php
200
-             *
201
-             * @since 1.0.0
202
-             *
203
-             * @param array  $templates Names of template files that should be looked for, for given slug and name.
204
-             * @param string $slug      Template slug.
205
-             * @param string $name      Template variation name.
206
-             */
207
-            return apply_filters($this->filter_prefix.'_get_template_part', $templates, $slug, $name);
208
-        }
209
-
210
-        /**
211
-         * Retrieve the name of the highest priority template file that exists.
212
-         *
213
-         * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
214
-         * inherit from a parent theme can just overload one file. If the template is
215
-         * not found in either of those, it looks in the theme-compat folder last.
216
-         *
217
-         * @since 1.0.0
218
-         *
219
-         * @param string|array $template_names Template file(s) to search for, in order.
220
-         * @param bool         $load           If true the template file will be loaded if it is found.
221
-         * @param bool         $require_once   Whether to require_once or require. Default true.
222
-         *                                     Has no effect if $load is false.
223
-         *
224
-         * @return string The template filename if one is located.
225
-         */
226
-        public function locate_template($template_names, $load = false, $require_once = true)
227
-        {
228
-            static $template_path_cache = [];
229
-
230
-            // Generate a fast hash of the template names for unique lookup
231
-            $cache_key = md5(json_encode($template_names));
232
-
233
-            // If the key is in the cache array, we've already located this file.
234
-            if (isset($template_path_cache[$this->filter_prefix][$cache_key])) {
235
-                $located = $template_path_cache[$this->filter_prefix][$cache_key];
236
-            } else {
237
-                // No file found yet.
238
-                $located = false;
239
-
240
-                // Remove empty entries.
241
-                $template_names = array_filter((array) $template_names);
242
-                $template_paths = $this->get_template_paths();
243
-
244
-                // Try to find a template file.
245
-                foreach ($template_names as $template_name) {
246
-                    // Trim off any slashes from the template name.
247
-                    $template_name = ltrim($template_name, '/');
248
-
249
-                    // Try locating this template file by looping through the template paths.
250
-                    foreach ($template_paths as $template_path) {
251
-                        if (file_exists($template_path.$template_name)) {
252
-                            $located = $template_path.$template_name;
253
-                            // Store the template path in the cache.
254
-                            $template_path_cache[$this->filter_prefix][$cache_key] = $located;
255
-                            break 2;
256
-                        }
257
-                    }
258
-                }
259
-
260
-                // The templates weren't found; don't look this up again.
261
-                if (!$located) {
262
-                    $template_path_cache[$this->filter_prefix][$cache_key] = false;
263
-                }
264
-            }
265
-
266
-            if ($load && $located) {
267
-                load_template($located, $require_once);
268
-            }
269
-
270
-            return $located;
271
-        }
272
-
273
-        /**
274
-         * Return a list of paths to check for template locations.
275
-         *
276
-         * Default is to check in a child theme (if relevant) before a parent theme, so that themes which inherit from a
277
-         * parent theme can just overload one file. If the template is not found in either of those, it looks in the
278
-         * theme-compat folder last.
279
-         *
280
-         * @since 1.0.0
281
-         *
282
-         * @return mixed|void
283
-         */
284
-        protected function get_template_paths()
285
-        {
286
-            static $file_paths;
287
-
288
-            if (!is_null($file_paths)) {
289
-                return $file_paths;
290
-            }
291
-
292
-            $theme_directory = trailingslashit($this->theme_template_directory);
293
-
294
-            $file_paths = [
295
-                10  => trailingslashit(get_template_directory()).$theme_directory,
296
-                100 => $this->get_templates_dir(),
297
-            ];
298
-
299
-            // Only add this conditionally, so non-child themes don't redundantly check active theme twice.
300
-            if (get_stylesheet_directory() !== get_template_directory()) {
301
-                $file_paths[1] = trailingslashit(get_stylesheet_directory()).$theme_directory;
302
-            }
303
-
304
-            /**
305
-             * Allow ordered list of template paths to be amended.
306
-             *
307
-             * @since 1.0.0
308
-             *
309
-             * @param array $var Default is directory in child theme at index 1, parent theme at 10, and plugin at 100.
310
-             */
311
-            $file_paths = apply_filters($this->filter_prefix.'_template_paths', $file_paths);
312
-
313
-            // Sort the file paths based on priority.
314
-            ksort($file_paths, SORT_NUMERIC);
315
-
316
-            $file_paths = array_map('trailingslashit', $file_paths);
317
-
318
-            return $file_paths;
319
-        }
320
-
321
-        /**
322
-         * Return the path to the templates directory in this plugin.
323
-         *
324
-         * May be overridden in subclass.
325
-         *
326
-         * @since 1.0.0
327
-         *
328
-         * @return string
329
-         */
330
-        protected function get_templates_dir()
331
-        {
332
-            return trailingslashit($this->plugin_directory).$this->plugin_template_directory;
333
-        }
334
-    }
19
+	/**
20
+	 * Template loader.
21
+	 *
22
+	 * Originally based on functions in Easy Digital Downloads (thanks Pippin!).
23
+	 *
24
+	 * When using in a plugin, create a new class that extends this one and just overrides the properties.
25
+	 *
26
+	 * @author  Gary Jones
27
+	 */
28
+	class Gamajo_Template_Loader
29
+	{
30
+		/**
31
+		 * Prefix for filter names.
32
+		 *
33
+		 * @since 1.0.0
34
+		 *
35
+		 * @var string
36
+		 */
37
+		protected $filter_prefix = 'your_plugin';
38
+
39
+		/**
40
+		 * Directory name where custom templates for this plugin should be found in the theme.
41
+		 *
42
+		 * For example: 'your-plugin-templates'.
43
+		 *
44
+		 * @since 1.0.0
45
+		 *
46
+		 * @var string
47
+		 */
48
+		protected $theme_template_directory = 'plugin-templates';
49
+
50
+		/**
51
+		 * Reference to the root directory path of this plugin.
52
+		 *
53
+		 * Can either be a defined constant, or a relative reference from where the subclass lives.
54
+		 *
55
+		 * e.g. YOUR_PLUGIN_TEMPLATE or plugin_dir_path( dirname( __FILE__ ) ); etc.
56
+		 *
57
+		 * @since 1.0.0
58
+		 *
59
+		 * @var string
60
+		 */
61
+		protected $plugin_directory = 'YOUR_PLUGIN_DIR';
62
+
63
+		/**
64
+		 * Directory name where templates are found in this plugin.
65
+		 *
66
+		 * Can either be a defined constant, or a relative reference from where the subclass lives.
67
+		 *
68
+		 * e.g. 'templates' or 'includes/templates', etc.
69
+		 *
70
+		 * @since 1.1.0
71
+		 *
72
+		 * @var string
73
+		 */
74
+		protected $plugin_template_directory = 'templates';
75
+
76
+		/**
77
+		 * Internal use only: Store variable names used for template data.
78
+		 *
79
+		 * Means unset_template_data() can remove all custom references from $wp_query.
80
+		 *
81
+		 * Initialized to contain the default 'data'.
82
+		 *
83
+		 * @var array
84
+		 */
85
+		private $template_data_var_names = ['data'];
86
+
87
+		/**
88
+		 * Clean up template data.
89
+		 *
90
+		 * @since 1.2.0
91
+		 */
92
+		public function __destruct()
93
+		{
94
+			$this->unset_template_data();
95
+		}
96
+
97
+		/**
98
+		 * Retrieve a template part.
99
+		 *
100
+		 * @since 1.0.0
101
+		 *
102
+		 * @param string $slug Template slug.
103
+		 * @param string $name Optional. Template variation name. Default null.
104
+		 * @param bool   $load Optional. Whether to load template. Default true.
105
+		 *
106
+		 * @return string
107
+		 */
108
+		public function get_template_part($slug, $name = null, $load = true)
109
+		{
110
+			// Execute code for this part.
111
+			do_action('get_template_part_'.$slug, $slug, $name);
112
+			do_action($this->filter_prefix.'_get_template_part_'.$slug, $slug, $name);
113
+
114
+			// Get files names of templates, for given slug and name.
115
+			$templates = $this->get_template_file_names($slug, $name);
116
+
117
+			// Return the part that is found.
118
+			return $this->locate_template($templates, $load, false);
119
+		}
120
+
121
+		/**
122
+		 * Make custom data available to template.
123
+		 *
124
+		 * Data is available to the template as properties under the `$data` variable.
125
+		 * i.e. A value provided here under `$data['foo']` is available as `$data->foo`.
126
+		 *
127
+		 * When an input key has a hyphen, you can use `$data->{foo-bar}` in the template.
128
+		 *
129
+		 * @since 1.2.0
130
+		 *
131
+		 * @param mixed  $data     Custom data for the template.
132
+		 * @param string $var_name Optional. Variable under which the custom data is available in the template.
133
+		 *                         Default is 'data'.
134
+		 *
135
+		 * @return Gamajo_Template_Loader
136
+		 */
137
+		public function set_template_data($data, $var_name = 'data')
138
+		{
139
+			global $wp_query;
140
+
141
+			$wp_query->query_vars[$var_name] = (object) $data;
142
+
143
+			// Add $var_name to custom variable store if not default value.
144
+			if ('data' !== $var_name) {
145
+				$this->template_data_var_names[] = $var_name;
146
+			}
147
+
148
+			return $this;
149
+		}
150
+
151
+		/**
152
+		 * Remove access to custom data in template.
153
+		 *
154
+		 * Good to use once the final template part has been requested.
155
+		 *
156
+		 * @since 1.2.0
157
+		 *
158
+		 * @return Gamajo_Template_Loader
159
+		 */
160
+		public function unset_template_data()
161
+		{
162
+			global $wp_query;
163
+
164
+			// Remove any duplicates from the custom variable store.
165
+			$custom_var_names = array_unique($this->template_data_var_names);
166
+
167
+			// Remove each custom data reference from $wp_query.
168
+			foreach ($custom_var_names as $var) {
169
+				if (isset($wp_query->query_vars[$var])) {
170
+					unset($wp_query->query_vars[$var]);
171
+				}
172
+			}
173
+
174
+			return $this;
175
+		}
176
+
177
+		/**
178
+		 * Given a slug and optional name, create the file names of templates.
179
+		 *
180
+		 * @since 1.0.0
181
+		 *
182
+		 * @param string $slug Template slug.
183
+		 * @param string $name Template variation name.
184
+		 *
185
+		 * @return array
186
+		 */
187
+		protected function get_template_file_names($slug, $name)
188
+		{
189
+			$templates = [];
190
+			if (isset($name)) {
191
+				$templates[] = $slug.'-'.$name.'.php';
192
+			}
193
+			$templates[] = $slug.'.php';
194
+
195
+			/**
196
+			 * Allow template choices to be filtered.
197
+			 *
198
+			 * The resulting array should be in the order of most specific first, to least specific last.
199
+			 * e.g. 0 => recipe-instructions.php, 1 => recipe.php
200
+			 *
201
+			 * @since 1.0.0
202
+			 *
203
+			 * @param array  $templates Names of template files that should be looked for, for given slug and name.
204
+			 * @param string $slug      Template slug.
205
+			 * @param string $name      Template variation name.
206
+			 */
207
+			return apply_filters($this->filter_prefix.'_get_template_part', $templates, $slug, $name);
208
+		}
209
+
210
+		/**
211
+		 * Retrieve the name of the highest priority template file that exists.
212
+		 *
213
+		 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
214
+		 * inherit from a parent theme can just overload one file. If the template is
215
+		 * not found in either of those, it looks in the theme-compat folder last.
216
+		 *
217
+		 * @since 1.0.0
218
+		 *
219
+		 * @param string|array $template_names Template file(s) to search for, in order.
220
+		 * @param bool         $load           If true the template file will be loaded if it is found.
221
+		 * @param bool         $require_once   Whether to require_once or require. Default true.
222
+		 *                                     Has no effect if $load is false.
223
+		 *
224
+		 * @return string The template filename if one is located.
225
+		 */
226
+		public function locate_template($template_names, $load = false, $require_once = true)
227
+		{
228
+			static $template_path_cache = [];
229
+
230
+			// Generate a fast hash of the template names for unique lookup
231
+			$cache_key = md5(json_encode($template_names));
232
+
233
+			// If the key is in the cache array, we've already located this file.
234
+			if (isset($template_path_cache[$this->filter_prefix][$cache_key])) {
235
+				$located = $template_path_cache[$this->filter_prefix][$cache_key];
236
+			} else {
237
+				// No file found yet.
238
+				$located = false;
239
+
240
+				// Remove empty entries.
241
+				$template_names = array_filter((array) $template_names);
242
+				$template_paths = $this->get_template_paths();
243
+
244
+				// Try to find a template file.
245
+				foreach ($template_names as $template_name) {
246
+					// Trim off any slashes from the template name.
247
+					$template_name = ltrim($template_name, '/');
248
+
249
+					// Try locating this template file by looping through the template paths.
250
+					foreach ($template_paths as $template_path) {
251
+						if (file_exists($template_path.$template_name)) {
252
+							$located = $template_path.$template_name;
253
+							// Store the template path in the cache.
254
+							$template_path_cache[$this->filter_prefix][$cache_key] = $located;
255
+							break 2;
256
+						}
257
+					}
258
+				}
259
+
260
+				// The templates weren't found; don't look this up again.
261
+				if (!$located) {
262
+					$template_path_cache[$this->filter_prefix][$cache_key] = false;
263
+				}
264
+			}
265
+
266
+			if ($load && $located) {
267
+				load_template($located, $require_once);
268
+			}
269
+
270
+			return $located;
271
+		}
272
+
273
+		/**
274
+		 * Return a list of paths to check for template locations.
275
+		 *
276
+		 * Default is to check in a child theme (if relevant) before a parent theme, so that themes which inherit from a
277
+		 * parent theme can just overload one file. If the template is not found in either of those, it looks in the
278
+		 * theme-compat folder last.
279
+		 *
280
+		 * @since 1.0.0
281
+		 *
282
+		 * @return mixed|void
283
+		 */
284
+		protected function get_template_paths()
285
+		{
286
+			static $file_paths;
287
+
288
+			if (!is_null($file_paths)) {
289
+				return $file_paths;
290
+			}
291
+
292
+			$theme_directory = trailingslashit($this->theme_template_directory);
293
+
294
+			$file_paths = [
295
+				10  => trailingslashit(get_template_directory()).$theme_directory,
296
+				100 => $this->get_templates_dir(),
297
+			];
298
+
299
+			// Only add this conditionally, so non-child themes don't redundantly check active theme twice.
300
+			if (get_stylesheet_directory() !== get_template_directory()) {
301
+				$file_paths[1] = trailingslashit(get_stylesheet_directory()).$theme_directory;
302
+			}
303
+
304
+			/**
305
+			 * Allow ordered list of template paths to be amended.
306
+			 *
307
+			 * @since 1.0.0
308
+			 *
309
+			 * @param array $var Default is directory in child theme at index 1, parent theme at 10, and plugin at 100.
310
+			 */
311
+			$file_paths = apply_filters($this->filter_prefix.'_template_paths', $file_paths);
312
+
313
+			// Sort the file paths based on priority.
314
+			ksort($file_paths, SORT_NUMERIC);
315
+
316
+			$file_paths = array_map('trailingslashit', $file_paths);
317
+
318
+			return $file_paths;
319
+		}
320
+
321
+		/**
322
+		 * Return the path to the templates directory in this plugin.
323
+		 *
324
+		 * May be overridden in subclass.
325
+		 *
326
+		 * @since 1.0.0
327
+		 *
328
+		 * @return string
329
+		 */
330
+		protected function get_templates_dir()
331
+		{
332
+			return trailingslashit($this->plugin_directory).$this->plugin_template_directory;
333
+		}
334
+	}
335 335
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 namespace GV;
16 16
 
17
-if (!class_exists('\GV\Gamajo_Template_Loader')) {
17
+if ( ! class_exists( '\GV\Gamajo_Template_Loader' ) ) {
18 18
 
19 19
     /**
20 20
      * Template loader.
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
          *
83 83
          * @var array
84 84
          */
85
-        private $template_data_var_names = ['data'];
85
+        private $template_data_var_names = [ 'data' ];
86 86
 
87 87
         /**
88 88
          * Clean up template data.
@@ -105,17 +105,17 @@  discard block
 block discarded – undo
105 105
          *
106 106
          * @return string
107 107
          */
108
-        public function get_template_part($slug, $name = null, $load = true)
108
+        public function get_template_part( $slug, $name = null, $load = true )
109 109
         {
110 110
             // Execute code for this part.
111
-            do_action('get_template_part_'.$slug, $slug, $name);
112
-            do_action($this->filter_prefix.'_get_template_part_'.$slug, $slug, $name);
111
+            do_action( 'get_template_part_' . $slug, $slug, $name );
112
+            do_action( $this->filter_prefix . '_get_template_part_' . $slug, $slug, $name );
113 113
 
114 114
             // Get files names of templates, for given slug and name.
115
-            $templates = $this->get_template_file_names($slug, $name);
115
+            $templates = $this->get_template_file_names( $slug, $name );
116 116
 
117 117
             // Return the part that is found.
118
-            return $this->locate_template($templates, $load, false);
118
+            return $this->locate_template( $templates, $load, false );
119 119
         }
120 120
 
121 121
         /**
@@ -134,15 +134,15 @@  discard block
 block discarded – undo
134 134
          *
135 135
          * @return Gamajo_Template_Loader
136 136
          */
137
-        public function set_template_data($data, $var_name = 'data')
137
+        public function set_template_data( $data, $var_name = 'data' )
138 138
         {
139 139
             global $wp_query;
140 140
 
141
-            $wp_query->query_vars[$var_name] = (object) $data;
141
+            $wp_query->query_vars[ $var_name ] = (object)$data;
142 142
 
143 143
             // Add $var_name to custom variable store if not default value.
144
-            if ('data' !== $var_name) {
145
-                $this->template_data_var_names[] = $var_name;
144
+            if ( 'data' !== $var_name ) {
145
+                $this->template_data_var_names[ ] = $var_name;
146 146
             }
147 147
 
148 148
             return $this;
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
             global $wp_query;
163 163
 
164 164
             // Remove any duplicates from the custom variable store.
165
-            $custom_var_names = array_unique($this->template_data_var_names);
165
+            $custom_var_names = array_unique( $this->template_data_var_names );
166 166
 
167 167
             // Remove each custom data reference from $wp_query.
168
-            foreach ($custom_var_names as $var) {
169
-                if (isset($wp_query->query_vars[$var])) {
170
-                    unset($wp_query->query_vars[$var]);
168
+            foreach ( $custom_var_names as $var ) {
169
+                if ( isset( $wp_query->query_vars[ $var ] ) ) {
170
+                    unset( $wp_query->query_vars[ $var ] );
171 171
                 }
172 172
             }
173 173
 
@@ -184,13 +184,13 @@  discard block
 block discarded – undo
184 184
          *
185 185
          * @return array
186 186
          */
187
-        protected function get_template_file_names($slug, $name)
187
+        protected function get_template_file_names( $slug, $name )
188 188
         {
189
-            $templates = [];
190
-            if (isset($name)) {
191
-                $templates[] = $slug.'-'.$name.'.php';
189
+            $templates = [ ];
190
+            if ( isset( $name ) ) {
191
+                $templates[ ] = $slug . '-' . $name . '.php';
192 192
             }
193
-            $templates[] = $slug.'.php';
193
+            $templates[ ] = $slug . '.php';
194 194
 
195 195
             /**
196 196
              * Allow template choices to be filtered.
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
              * @param string $slug      Template slug.
205 205
              * @param string $name      Template variation name.
206 206
              */
207
-            return apply_filters($this->filter_prefix.'_get_template_part', $templates, $slug, $name);
207
+            return apply_filters( $this->filter_prefix . '_get_template_part', $templates, $slug, $name );
208 208
         }
209 209
 
210 210
         /**
@@ -223,48 +223,48 @@  discard block
 block discarded – undo
223 223
          *
224 224
          * @return string The template filename if one is located.
225 225
          */
226
-        public function locate_template($template_names, $load = false, $require_once = true)
226
+        public function locate_template( $template_names, $load = false, $require_once = true )
227 227
         {
228
-            static $template_path_cache = [];
228
+            static $template_path_cache = [ ];
229 229
 
230 230
             // Generate a fast hash of the template names for unique lookup
231
-            $cache_key = md5(json_encode($template_names));
231
+            $cache_key = md5( json_encode( $template_names ) );
232 232
 
233 233
             // If the key is in the cache array, we've already located this file.
234
-            if (isset($template_path_cache[$this->filter_prefix][$cache_key])) {
235
-                $located = $template_path_cache[$this->filter_prefix][$cache_key];
234
+            if ( isset( $template_path_cache[ $this->filter_prefix ][ $cache_key ] ) ) {
235
+                $located = $template_path_cache[ $this->filter_prefix ][ $cache_key ];
236 236
             } else {
237 237
                 // No file found yet.
238 238
                 $located = false;
239 239
 
240 240
                 // Remove empty entries.
241
-                $template_names = array_filter((array) $template_names);
241
+                $template_names = array_filter( (array)$template_names );
242 242
                 $template_paths = $this->get_template_paths();
243 243
 
244 244
                 // Try to find a template file.
245
-                foreach ($template_names as $template_name) {
245
+                foreach ( $template_names as $template_name ) {
246 246
                     // Trim off any slashes from the template name.
247
-                    $template_name = ltrim($template_name, '/');
247
+                    $template_name = ltrim( $template_name, '/' );
248 248
 
249 249
                     // Try locating this template file by looping through the template paths.
250
-                    foreach ($template_paths as $template_path) {
251
-                        if (file_exists($template_path.$template_name)) {
252
-                            $located = $template_path.$template_name;
250
+                    foreach ( $template_paths as $template_path ) {
251
+                        if ( file_exists( $template_path . $template_name ) ) {
252
+                            $located = $template_path . $template_name;
253 253
                             // Store the template path in the cache.
254
-                            $template_path_cache[$this->filter_prefix][$cache_key] = $located;
254
+                            $template_path_cache[ $this->filter_prefix ][ $cache_key ] = $located;
255 255
                             break 2;
256 256
                         }
257 257
                     }
258 258
                 }
259 259
 
260 260
                 // The templates weren't found; don't look this up again.
261
-                if (!$located) {
262
-                    $template_path_cache[$this->filter_prefix][$cache_key] = false;
261
+                if ( ! $located ) {
262
+                    $template_path_cache[ $this->filter_prefix ][ $cache_key ] = false;
263 263
                 }
264 264
             }
265 265
 
266
-            if ($load && $located) {
267
-                load_template($located, $require_once);
266
+            if ( $load && $located ) {
267
+                load_template( $located, $require_once );
268 268
             }
269 269
 
270 270
             return $located;
@@ -285,20 +285,20 @@  discard block
 block discarded – undo
285 285
         {
286 286
             static $file_paths;
287 287
 
288
-            if (!is_null($file_paths)) {
288
+            if ( ! is_null( $file_paths ) ) {
289 289
                 return $file_paths;
290 290
             }
291 291
 
292
-            $theme_directory = trailingslashit($this->theme_template_directory);
292
+            $theme_directory = trailingslashit( $this->theme_template_directory );
293 293
 
294 294
             $file_paths = [
295
-                10  => trailingslashit(get_template_directory()).$theme_directory,
295
+                10  => trailingslashit( get_template_directory() ) . $theme_directory,
296 296
                 100 => $this->get_templates_dir(),
297 297
             ];
298 298
 
299 299
             // Only add this conditionally, so non-child themes don't redundantly check active theme twice.
300
-            if (get_stylesheet_directory() !== get_template_directory()) {
301
-                $file_paths[1] = trailingslashit(get_stylesheet_directory()).$theme_directory;
300
+            if ( get_stylesheet_directory() !== get_template_directory() ) {
301
+                $file_paths[ 1 ] = trailingslashit( get_stylesheet_directory() ) . $theme_directory;
302 302
             }
303 303
 
304 304
             /**
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
              *
309 309
              * @param array $var Default is directory in child theme at index 1, parent theme at 10, and plugin at 100.
310 310
              */
311
-            $file_paths = apply_filters($this->filter_prefix.'_template_paths', $file_paths);
311
+            $file_paths = apply_filters( $this->filter_prefix . '_template_paths', $file_paths );
312 312
 
313 313
             // Sort the file paths based on priority.
314
-            ksort($file_paths, SORT_NUMERIC);
314
+            ksort( $file_paths, SORT_NUMERIC );
315 315
 
316
-            $file_paths = array_map('trailingslashit', $file_paths);
316
+            $file_paths = array_map( 'trailingslashit', $file_paths );
317 317
 
318 318
             return $file_paths;
319 319
         }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
          */
330 330
         protected function get_templates_dir()
331 331
         {
332
-            return trailingslashit($this->plugin_directory).$this->plugin_template_directory;
332
+            return trailingslashit( $this->plugin_directory ) . $this->plugin_template_directory;
333 333
         }
334 334
     }
335 335
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -25,8 +25,7 @@  discard block
 block discarded – undo
25 25
      *
26 26
      * @author  Gary Jones
27 27
      */
28
-    class Gamajo_Template_Loader
29
-    {
28
+    class Gamajo_Template_Loader {
30 29
         /**
31 30
          * Prefix for filter names.
32 31
          *
@@ -89,8 +88,7 @@  discard block
 block discarded – undo
89 88
          *
90 89
          * @since 1.2.0
91 90
          */
92
-        public function __destruct()
93
-        {
91
+        public function __destruct() {
94 92
             $this->unset_template_data();
95 93
         }
96 94
 
@@ -105,8 +103,7 @@  discard block
 block discarded – undo
105 103
          *
106 104
          * @return string
107 105
          */
108
-        public function get_template_part($slug, $name = null, $load = true)
109
-        {
106
+        public function get_template_part($slug, $name = null, $load = true) {
110 107
             // Execute code for this part.
111 108
             do_action('get_template_part_'.$slug, $slug, $name);
112 109
             do_action($this->filter_prefix.'_get_template_part_'.$slug, $slug, $name);
@@ -134,8 +131,7 @@  discard block
 block discarded – undo
134 131
          *
135 132
          * @return Gamajo_Template_Loader
136 133
          */
137
-        public function set_template_data($data, $var_name = 'data')
138
-        {
134
+        public function set_template_data($data, $var_name = 'data') {
139 135
             global $wp_query;
140 136
 
141 137
             $wp_query->query_vars[$var_name] = (object) $data;
@@ -157,8 +153,7 @@  discard block
 block discarded – undo
157 153
          *
158 154
          * @return Gamajo_Template_Loader
159 155
          */
160
-        public function unset_template_data()
161
-        {
156
+        public function unset_template_data() {
162 157
             global $wp_query;
163 158
 
164 159
             // Remove any duplicates from the custom variable store.
@@ -184,8 +179,7 @@  discard block
 block discarded – undo
184 179
          *
185 180
          * @return array
186 181
          */
187
-        protected function get_template_file_names($slug, $name)
188
-        {
182
+        protected function get_template_file_names($slug, $name) {
189 183
             $templates = [];
190 184
             if (isset($name)) {
191 185
                 $templates[] = $slug.'-'.$name.'.php';
@@ -223,8 +217,7 @@  discard block
 block discarded – undo
223 217
          *
224 218
          * @return string The template filename if one is located.
225 219
          */
226
-        public function locate_template($template_names, $load = false, $require_once = true)
227
-        {
220
+        public function locate_template($template_names, $load = false, $require_once = true) {
228 221
             static $template_path_cache = [];
229 222
 
230 223
             // Generate a fast hash of the template names for unique lookup
@@ -281,8 +274,7 @@  discard block
 block discarded – undo
281 274
          *
282 275
          * @return mixed|void
283 276
          */
284
-        protected function get_template_paths()
285
-        {
277
+        protected function get_template_paths() {
286 278
             static $file_paths;
287 279
 
288 280
             if (!is_null($file_paths)) {
@@ -327,8 +319,7 @@  discard block
 block discarded – undo
327 319
          *
328 320
          * @return string
329 321
          */
330
-        protected function get_templates_dir()
331
-        {
322
+        protected function get_templates_dir() {
332 323
             return trailingslashit($this->plugin_directory).$this->plugin_template_directory;
333 324
         }
334 325
     }
Please login to merge, or discard this patch.
future/includes/class-gv-plugin.php 3 patches
Indentation   +677 added lines, -677 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -17,658 +17,658 @@  discard block
 block discarded – undo
17 17
  */
18 18
 final class Plugin
19 19
 {
20
-    /**
21
-     * @since 2.0
22
-     *
23
-     * @api
24
-     *
25
-     * @var string The plugin version.
26
-     */
27
-    public static $version = GV_PLUGIN_VERSION;
28
-
29
-    /**
30
-     * @var string Minimum WordPress version.
31
-     *
32
-     * GravityView requires at least this version of WordPress to function properly.
33
-     */
34
-    private static $min_wp_version = GV_MIN_WP_VERSION;
35
-
36
-    /**
37
-     * @var string Minimum WordPress version.
38
-     *
39
-     * @since 2.9.3
40
-     *
41
-     * GravityView will require this version of WordPress soon.
42
-     */
43
-    private static $future_min_wp_version = GV_FUTURE_MIN_WP_VERSION;
44
-
45
-    /**
46
-     * @var string Minimum Gravity Forms version.
47
-     *
48
-     * GravityView requires at least this version of Gravity Forms to function properly.
49
-     */
50
-    public static $min_gf_version = GV_MIN_GF_VERSION;
51
-
52
-    /**
53
-     * @var string Minimum PHP version.
54
-     *
55
-     * GravityView requires at least this version of PHP to function properly.
56
-     */
57
-    private static $min_php_version = GV_MIN_PHP_VERSION;
58
-
59
-    /**
60
-     * @var string|bool Minimum future PHP version.
61
-     *
62
-     * GravityView will require this version of PHP soon. False if no future PHP version changes are planned.
63
-     */
64
-    private static $future_min_php_version = GV_FUTURE_MIN_PHP_VERSION;
65
-
66
-    /**
67
-     * @var string|bool Minimum future Gravity Forms version.
68
-     *
69
-     * GravityView will require this version of Gravity Forms soon. False if no future Gravity Forms version changes are planned.
70
-     */
71
-    private static $future_min_gf_version = GV_FUTURE_MIN_GF_VERSION;
72
-
73
-    /**
74
-     * @var \GV\Plugin The \GV\Plugin static instance.
75
-     */
76
-    private static $__instance = null;
77
-
78
-    /**
79
-     * @since 2.0
80
-     *
81
-     * @api
82
-     *
83
-     * @var \GV\Addon_Settings The plugin "addon" settings.
84
-     */
85
-    public $settings;
86
-
87
-    /**
88
-     * @var string The GFQuery functionality identifier.
89
-     */
90
-    const FEATURE_GFQUERY = 'gfquery';
91
-
92
-    /**
93
-     * @var string The joins functionality identifier.
94
-     */
95
-    const FEATURE_JOINS = 'joins';
96
-
97
-    /**
98
-     * @var string The unions functionality identifier.
99
-     */
100
-    const FEATURE_UNIONS = 'unions';
101
-
102
-    /**
103
-     * @var string The REST API functionality identifier.
104
-     */
105
-    const FEATURE_REST = 'rest_api';
106
-
107
-    /**
108
-     * Get the global instance of \GV\Plugin.
109
-     *
110
-     * @return \GV\Plugin The global instance of GravityView Plugin.
111
-     */
112
-    public static function get()
113
-    {
114
-        if (!self::$__instance instanceof self) {
115
-            self::$__instance = new self();
116
-        }
117
-
118
-        return self::$__instance;
119
-    }
120
-
121
-    private function __construct()
122
-    {
123
-
124
-        /**
125
-         * Load translations. Must be priority 1.
126
-         */
127
-        add_action('plugins_loaded', [$this, 'load_textdomain'], 1);
128
-
129
-        /**
130
-         * Load some frontend-related legacy files.
131
-         */
132
-        add_action('gravityview/loaded', [$this, 'include_legacy_frontend']);
133
-
134
-        /**
135
-         * GFAddOn-backed settings, licensing.
136
-         */
137
-        add_action('plugins_loaded', [$this, 'load_license_settings']);
138
-    }
139
-
140
-    public function load_license_settings()
141
-    {
142
-        require_once $this->dir('future/includes/class-gv-license-handler.php');
143
-        require_once $this->dir('future/includes/class-gv-settings-addon.php');
144
-        if (class_exists('\GV\Addon_Settings')) {
145
-            $this->settings = new Addon_Settings();
146
-            include_once $this->dir('includes/class-gravityview-settings.php');
147
-        } else {
148
-            gravityview()->log->notice('\GV\Addon_Settings not loaded. Missing \GFAddOn.');
149
-        }
150
-    }
151
-
152
-    /**
153
-     * Check whether Gravity Forms is v2.5-beta or newer.
154
-     *
155
-     * @return bool
156
-     *
157
-     * @todo add @since
158
-     */
159
-    public function is_GF_25()
160
-    {
161
-        return version_compare('2.5-beta', \GFForms::$version, '<=');
162
-    }
163
-
164
-    /**
165
-     * Check whether GravityView `is network activated.
166
-     *
167
-     * @return bool Whether it's network activated or not.
168
-     */
169
-    public static function is_network_activated()
170
-    {
171
-        $plugin_basename = plugin_basename(GRAVITYVIEW_FILE);
172
-
173
-        return is_multisite() && (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network($plugin_basename));
174
-    }
175
-
176
-    /**
177
-     * Include more legacy stuff.
178
-     *
179
-     * @param bool $force Whether to force the includes.
180
-     *
181
-     * @return void
182
-     */
183
-    public function include_legacy_frontend($force = false)
184
-    {
185
-        if (gravityview()->request->is_admin() && !$force) {
186
-            return;
187
-        }
188
-
189
-        include_once $this->dir('includes/class-gravityview-image.php');
190
-        include_once $this->dir('includes/class-template.php');
191
-        include_once $this->dir('includes/class-api.php');
192
-        include_once $this->dir('includes/class-frontend-views.php');
193
-        include_once $this->dir('includes/class-gravityview-change-entry-creator.php');
194
-
195
-        /**
196
-         * @action     `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
197
-         *
198
-         * @deprecated Use `gravityview/loaded` along with \GV\Request::is_admin(), etc.
199
-         *
200
-         * Nice place to insert extensions' frontend stuff
201
-         */
202
-        do_action('gravityview_include_frontend_actions');
203
-    }
204
-
205
-    /**
206
-     * Load more legacy core files.
207
-     *
208
-     * @return void
209
-     */
210
-    public function include_legacy_core()
211
-    {
212
-        if (!class_exists('\GravityView_Extension')) {
213
-            include_once $this->dir('includes/class-gravityview-extension.php');
214
-        }
215
-
216
-        if (!gravityview()->plugin->is_compatible()) {
217
-            return;
218
-        }
219
-
220
-        // Load fields
221
-        include_once $this->dir('includes/fields/class-gravityview-fields.php');
222
-        include_once $this->dir('includes/fields/class-gravityview-field.php');
223
-
224
-        // Load all field files automatically
225
-        foreach (glob($this->dir('includes/fields/class-gravityview-field*.php')) as $gv_field_filename) {
226
-            include_once $gv_field_filename;
227
-        }
228
-
229
-        include_once $this->dir('includes/class-gravityview-entry-approval-status.php');
230
-        include_once $this->dir('includes/class-gravityview-entry-approval.php');
231
-
232
-        include_once $this->dir('includes/class-gravityview-entry-notes.php');
233
-        include_once $this->dir('includes/load-plugin-and-theme-hooks.php');
234
-
235
-        // Load Extensions
236
-        // @todo: Convert to a scan of the directory or a method where this all lives
237
-        include_once $this->dir('includes/extensions/edit-entry/class-edit-entry.php');
238
-        include_once $this->dir('includes/extensions/delete-entry/class-delete-entry.php');
239
-        include_once $this->dir('includes/extensions/duplicate-entry/class-duplicate-entry.php');
240
-        include_once $this->dir('includes/extensions/entry-notes/class-gravityview-field-notes.php');
241
-        include_once $this->dir('includes/extensions/lightbox/class-gravityview-lightbox.php');
242
-
243
-        // Load WordPress Widgets
244
-        include_once $this->dir('includes/wordpress-widgets/register-wordpress-widgets.php');
245
-
246
-        // Load GravityView Widgets
247
-        include_once $this->dir('includes/widgets/register-gravityview-widgets.php');
248
-
249
-        // Add oEmbed
250
-        include_once $this->dir('includes/class-api.php');
251
-        include_once $this->dir('includes/class-oembed.php');
252
-
253
-        // Add logging
254
-        include_once $this->dir('includes/class-gravityview-logging.php');
255
-
256
-        include_once $this->dir('includes/class-ajax.php');
257
-        include_once $this->dir('includes/class-gravityview-html-elements.php');
258
-        include_once $this->dir('includes/class-frontend-views.php');
259
-        include_once $this->dir('includes/class-gravityview-admin-bar.php');
260
-        include_once $this->dir('includes/class-gravityview-entry-list.php');
261
-        include_once $this->dir('includes/class-gravityview-merge-tags.php');
262
-        /** @since 1.8.4 */
263
-        include_once $this->dir('includes/class-data.php');
264
-        include_once $this->dir('includes/class-gravityview-shortcode.php');
265
-        include_once $this->dir('includes/class-gravityview-entry-link-shortcode.php');
266
-        include_once $this->dir('includes/class-gvlogic-shortcode.php');
267
-        include_once $this->dir('includes/presets/register-default-templates.php');
268
-
269
-        if (class_exists('\GFFormsModel')) {
270
-            include_once $this->dir('includes/class-gravityview-gfformsmodel.php');
271
-        }
272
-    }
273
-
274
-    /**
275
-     * Load the translations on `plugins_loaded`.
276
-     *
277
-     * Order of look-ups:
278
-     *
279
-     * 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core)
280
-     * 2. /wp-content/mu-plugins/gravityview-{locale}.mo
281
-     * 3. /wp-content/mu-plugins/languages/gravityview-{locale}.mo
282
-     * 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo
283
-     *
284
-     * @return void
285
-     */
286
-    public function load_textdomain()
287
-    {
288
-        $domain = 'gravityview';
289
-
290
-        // 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core)
291
-        if (is_textdomain_loaded($domain)) {
292
-            return;
293
-        }
294
-
295
-        // 2. /wp-content/languages/plugins/gravityview-{locale}.mo
296
-        // 3. /wp-content/mu-plugins/plugins/languages/gravityview-{locale}.mo
297
-        $loaded = load_muplugin_textdomain($domain, '/languages/');
298
-
299
-        if ($loaded) {
300
-            return;
301
-        }
302
-
303
-        // 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo
304
-        $loaded = load_plugin_textdomain($domain, false, $this->relpath('/languages/'));
305
-
306
-        if ($loaded) {
307
-            return;
308
-        }
309
-
310
-        $locale = apply_filters('plugin_locale', ((function_exists('get_user_locale') && is_admin()) ? get_user_locale() : get_locale()), 'gravityview');
311
-
312
-        gravityview()->log->error(sprintf('Unable to load textdomain for %s locale.', $locale));
313
-    }
314
-
315
-    /**
316
-     * Register hooks that are fired when the plugin is activated and deactivated.
317
-     *
318
-     * @return void
319
-     */
320
-    public function register_activation_hooks()
321
-    {
322
-        register_activation_hook($this->dir('gravityview.php'), [$this, 'activate']);
323
-        register_deactivation_hook($this->dir('gravityview.php'), [$this, 'deactivate']);
324
-    }
325
-
326
-    /**
327
-     * Plugin activation function.
328
-     *
329
-     * @return void
330
-     *
331
-     * @internal
332
-     */
333
-    public function activate()
334
-    {
335
-        gravityview();
336
-
337
-        if (!$this->is_compatible()) {
338
-            return;
339
-        }
340
-
341
-        /** Register the gravityview post type upon WordPress core init. */
342
-        require_once $this->dir('future/includes/class-gv-view.php');
343
-        View::register_post_type();
344
-
345
-        /** Add the entry rewrite endpoint. */
346
-        require_once $this->dir('future/includes/class-gv-entry.php');
347
-        Entry::add_rewrite_endpoint();
348
-
349
-        /** Flush all URL rewrites. */
350
-        flush_rewrite_rules();
351
-
352
-        update_option('gv_version', self::$version);
353
-
354
-        /** Add the transient to redirect to configuration page. */
355
-        set_transient('_gv_activation_redirect', true, 60);
356
-
357
-        /** Clear settings transient. */
358
-        delete_transient('gravityview_edd-activate_valid');
359
-
360
-        \GravityView_Roles_Capabilities::get_instance()->add_caps();
361
-    }
362
-
363
-    /**
364
-     * Plugin deactivation function.
365
-     *
366
-     * @return void
367
-     *
368
-     * @internal
369
-     */
370
-    public function deactivate()
371
-    {
372
-        flush_rewrite_rules();
373
-    }
374
-
375
-    /**
376
-     * Retrieve an absolute path within the GravityView plugin directory.
377
-     *
378
-     * @since 2.0
379
-     *
380
-     * @param string $path Optional. Append this extra path component.
381
-     *
382
-     * @return string The absolute path to the plugin directory.
383
-     *
384
-     * @api
385
-     */
386
-    public function dir($path = '')
387
-    {
388
-        return wp_normalize_path(GRAVITYVIEW_DIR.ltrim($path, '/'));
389
-    }
390
-
391
-    /**
392
-     * Retrieve a relative path to the GravityView plugin directory from the WordPress plugin directory.
393
-     *
394
-     * @since 2.2.3
395
-     *
396
-     * @param string $path Optional. Append this extra path component.
397
-     *
398
-     * @return string The relative path to the plugin directory from the plugin directory.
399
-     *
400
-     * @api
401
-     */
402
-    public function relpath($path = '')
403
-    {
404
-        $dirname = trailingslashit(dirname(plugin_basename(GRAVITYVIEW_FILE)));
405
-
406
-        return wp_normalize_path($dirname.ltrim($path, '/'));
407
-    }
408
-
409
-    /**
410
-     * Retrieve a URL within the GravityView plugin directory.
411
-     *
412
-     * @since 2.0
413
-     *
414
-     * @param string $path Optional. Extra path appended to the URL.
415
-     *
416
-     * @return string The URL to this plugin, with trailing slash.
417
-     *
418
-     * @api
419
-     */
420
-    public function url($path = '/')
421
-    {
422
-        return plugins_url($path, $this->dir('gravityview.php'));
423
-    }
424
-
425
-    /**
426
-     * Is everything compatible with this version of GravityView?
427
-     *
428
-     * @since 2.0
429
-     *
430
-     * @return bool
431
-     *
432
-     * @api
433
-     */
434
-    public function is_compatible()
435
-    {
436
-        return
437
-            $this->is_compatible_php()
438
-            && $this->is_compatible_wordpress()
439
-            && $this->is_compatible_gravityforms();
440
-    }
441
-
442
-    /**
443
-     * Is this version of GravityView compatible with the current version of PHP?
444
-     *
445
-     * @since 2.0
446
-     *
447
-     * @return bool true if compatible, false otherwise.
448
-     *
449
-     * @api
450
-     */
451
-    public function is_compatible_php()
452
-    {
453
-        return version_compare($this->get_php_version(), self::$min_php_version, '>=');
454
-    }
455
-
456
-    /**
457
-     * Is this version of GravityView compatible with the future required version of PHP?
458
-     *
459
-     * @since 2.0
460
-     *
461
-     * @return bool true if compatible, false otherwise.
462
-     *
463
-     * @api
464
-     */
465
-    public function is_compatible_future_php()
466
-    {
467
-        return version_compare($this->get_php_version(), self::$future_min_php_version, '>=');
468
-    }
469
-
470
-    /**
471
-     * Is this version of GravityView compatible with the current version of WordPress?
472
-     *
473
-     * @since 2.0
474
-     *
475
-     * @param string $version Version to check against; otherwise uses GV_MIN_WP_VERSION
476
-     *
477
-     * @return bool true if compatible, false otherwise.
478
-     *
479
-     * @api
480
-     */
481
-    public function is_compatible_wordpress($version = null)
482
-    {
483
-        if (!$version) {
484
-            $version = self::$min_wp_version;
485
-        }
486
-
487
-        return version_compare($this->get_wordpress_version(), $version, '>=');
488
-    }
489
-
490
-    /**
491
-     * Is this version of GravityView compatible with the future version of WordPress?
492
-     *
493
-     * @since 2.9.3
494
-     *
495
-     * @return bool true if compatible, false otherwise
496
-     *
497
-     * @api
498
-     */
499
-    public function is_compatible_future_wordpress()
500
-    {
501
-        $version = $this->get_wordpress_version();
502
-
503
-        return $version ? version_compare($version, self::$future_min_wp_version, '>=') : false;
504
-    }
505
-
506
-    /**
507
-     * Is this version of GravityView compatible with the current version of Gravity Forms?
508
-     *
509
-     * @since 2.0
510
-     *
511
-     * @return bool true if compatible, false otherwise (or not active/installed).
512
-     *
513
-     * @api
514
-     */
515
-    public function is_compatible_gravityforms()
516
-    {
517
-        $version = $this->get_gravityforms_version();
518
-
519
-        return $version ? version_compare($version, self::$min_gf_version, '>=') : false;
520
-    }
521
-
522
-    /**
523
-     * Is this version of GravityView compatible with the future version of Gravity Forms?
524
-     *
525
-     * @since 2.0
526
-     *
527
-     * @return bool true if compatible, false otherwise (or not active/installed).
528
-     *
529
-     * @api
530
-     */
531
-    public function is_compatible_future_gravityforms()
532
-    {
533
-        $version = $this->get_gravityforms_version();
534
-
535
-        return $version ? version_compare($version, self::$future_min_gf_version, '>=') : false;
536
-    }
537
-
538
-    /**
539
-     * Retrieve the current PHP version.
540
-     *
541
-     * Overridable with GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE during testing.
542
-     *
543
-     * @return string The version of PHP.
544
-     */
545
-    private function get_php_version()
546
-    {
547
-        return !empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE']) ?
548
-            $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
549
-    }
550
-
551
-    /**
552
-     * Retrieve the current WordPress version.
553
-     *
554
-     * Overridable with GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE during testing.
555
-     *
556
-     * @return string The version of WordPress.
557
-     */
558
-    private function get_wordpress_version()
559
-    {
560
-        return !empty($GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE']) ?
561
-            $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version'];
562
-    }
563
-
564
-    /**
565
-     * Retrieve the current Gravity Forms version.
566
-     *
567
-     * Overridable with GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE during testing.
568
-     *
569
-     * @return string|null The version of Gravity Forms or null if inactive.
570
-     */
571
-    private function get_gravityforms_version()
572
-    {
573
-        if (!class_exists('\GFCommon') || !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'])) {
574
-            gravityview()->log->error('Gravity Forms is inactive or not installed.');
575
-
576
-            return null;
577
-        }
578
-
579
-        return !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE']) ?
580
-            $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] : \GFCommon::$version;
581
-    }
582
-
583
-    /**
584
-     * Feature support detection.
585
-     *
586
-     * @param string $feature Feature name. Check FEATURE_* class constants.
587
-     *
588
-     * @return bool
589
-     */
590
-    public function supports($feature)
591
-    {
592
-        if (!is_null($supports = apply_filters("gravityview/plugin/feature/$feature", null))) {
593
-            return $supports;
594
-        }
595
-
596
-        switch ($feature) {
597
-            case self::FEATURE_GFQUERY:
598
-                return class_exists('\GF_Query');
599
-            case self::FEATURE_JOINS:
600
-            case self::FEATURE_UNIONS:
601
-                return apply_filters('gravityview/query/class', false) === '\GF_Patched_Query';
602
-            case self::FEATURE_REST:
603
-                return class_exists('\WP_REST_Controller');
604
-            default:
605
-                return false;
606
-        }
607
-    }
608
-
609
-    /**
610
-     * Delete GravityView Views, settings, roles, caps, etc.
611
-     *
612
-     * @return void
613
-     */
614
-    public function uninstall()
615
-    {
616
-        global $wpdb;
617
-
618
-        $suppress = $wpdb->suppress_errors();
619
-
620
-        /**
621
-         * Posts.
622
-         */
623
-        $items = get_posts([
624
-            'post_type'   => 'gravityview',
625
-            'post_status' => 'any',
626
-            'numberposts' => -1,
627
-            'fields'      => 'ids',
628
-        ]);
629
-
630
-        foreach ($items as $item) {
631
-            wp_delete_post($item, true);
632
-        }
633
-
634
-        /**
635
-         * Meta.
636
-         */
637
-        $tables = [];
638
-
639
-        if (version_compare(\GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=')) {
640
-            $tables[] = \GFFormsModel::get_entry_meta_table_name();
641
-        } elseif (!$this->is_GF_25()) {
642
-            $tables[] = \GFFormsModel::get_lead_meta_table_name();
643
-        }
644
-
645
-        foreach ($tables as $meta_table) {
646
-            $sql = "
20
+	/**
21
+	 * @since 2.0
22
+	 *
23
+	 * @api
24
+	 *
25
+	 * @var string The plugin version.
26
+	 */
27
+	public static $version = GV_PLUGIN_VERSION;
28
+
29
+	/**
30
+	 * @var string Minimum WordPress version.
31
+	 *
32
+	 * GravityView requires at least this version of WordPress to function properly.
33
+	 */
34
+	private static $min_wp_version = GV_MIN_WP_VERSION;
35
+
36
+	/**
37
+	 * @var string Minimum WordPress version.
38
+	 *
39
+	 * @since 2.9.3
40
+	 *
41
+	 * GravityView will require this version of WordPress soon.
42
+	 */
43
+	private static $future_min_wp_version = GV_FUTURE_MIN_WP_VERSION;
44
+
45
+	/**
46
+	 * @var string Minimum Gravity Forms version.
47
+	 *
48
+	 * GravityView requires at least this version of Gravity Forms to function properly.
49
+	 */
50
+	public static $min_gf_version = GV_MIN_GF_VERSION;
51
+
52
+	/**
53
+	 * @var string Minimum PHP version.
54
+	 *
55
+	 * GravityView requires at least this version of PHP to function properly.
56
+	 */
57
+	private static $min_php_version = GV_MIN_PHP_VERSION;
58
+
59
+	/**
60
+	 * @var string|bool Minimum future PHP version.
61
+	 *
62
+	 * GravityView will require this version of PHP soon. False if no future PHP version changes are planned.
63
+	 */
64
+	private static $future_min_php_version = GV_FUTURE_MIN_PHP_VERSION;
65
+
66
+	/**
67
+	 * @var string|bool Minimum future Gravity Forms version.
68
+	 *
69
+	 * GravityView will require this version of Gravity Forms soon. False if no future Gravity Forms version changes are planned.
70
+	 */
71
+	private static $future_min_gf_version = GV_FUTURE_MIN_GF_VERSION;
72
+
73
+	/**
74
+	 * @var \GV\Plugin The \GV\Plugin static instance.
75
+	 */
76
+	private static $__instance = null;
77
+
78
+	/**
79
+	 * @since 2.0
80
+	 *
81
+	 * @api
82
+	 *
83
+	 * @var \GV\Addon_Settings The plugin "addon" settings.
84
+	 */
85
+	public $settings;
86
+
87
+	/**
88
+	 * @var string The GFQuery functionality identifier.
89
+	 */
90
+	const FEATURE_GFQUERY = 'gfquery';
91
+
92
+	/**
93
+	 * @var string The joins functionality identifier.
94
+	 */
95
+	const FEATURE_JOINS = 'joins';
96
+
97
+	/**
98
+	 * @var string The unions functionality identifier.
99
+	 */
100
+	const FEATURE_UNIONS = 'unions';
101
+
102
+	/**
103
+	 * @var string The REST API functionality identifier.
104
+	 */
105
+	const FEATURE_REST = 'rest_api';
106
+
107
+	/**
108
+	 * Get the global instance of \GV\Plugin.
109
+	 *
110
+	 * @return \GV\Plugin The global instance of GravityView Plugin.
111
+	 */
112
+	public static function get()
113
+	{
114
+		if (!self::$__instance instanceof self) {
115
+			self::$__instance = new self();
116
+		}
117
+
118
+		return self::$__instance;
119
+	}
120
+
121
+	private function __construct()
122
+	{
123
+
124
+		/**
125
+		 * Load translations. Must be priority 1.
126
+		 */
127
+		add_action('plugins_loaded', [$this, 'load_textdomain'], 1);
128
+
129
+		/**
130
+		 * Load some frontend-related legacy files.
131
+		 */
132
+		add_action('gravityview/loaded', [$this, 'include_legacy_frontend']);
133
+
134
+		/**
135
+		 * GFAddOn-backed settings, licensing.
136
+		 */
137
+		add_action('plugins_loaded', [$this, 'load_license_settings']);
138
+	}
139
+
140
+	public function load_license_settings()
141
+	{
142
+		require_once $this->dir('future/includes/class-gv-license-handler.php');
143
+		require_once $this->dir('future/includes/class-gv-settings-addon.php');
144
+		if (class_exists('\GV\Addon_Settings')) {
145
+			$this->settings = new Addon_Settings();
146
+			include_once $this->dir('includes/class-gravityview-settings.php');
147
+		} else {
148
+			gravityview()->log->notice('\GV\Addon_Settings not loaded. Missing \GFAddOn.');
149
+		}
150
+	}
151
+
152
+	/**
153
+	 * Check whether Gravity Forms is v2.5-beta or newer.
154
+	 *
155
+	 * @return bool
156
+	 *
157
+	 * @todo add @since
158
+	 */
159
+	public function is_GF_25()
160
+	{
161
+		return version_compare('2.5-beta', \GFForms::$version, '<=');
162
+	}
163
+
164
+	/**
165
+	 * Check whether GravityView `is network activated.
166
+	 *
167
+	 * @return bool Whether it's network activated or not.
168
+	 */
169
+	public static function is_network_activated()
170
+	{
171
+		$plugin_basename = plugin_basename(GRAVITYVIEW_FILE);
172
+
173
+		return is_multisite() && (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network($plugin_basename));
174
+	}
175
+
176
+	/**
177
+	 * Include more legacy stuff.
178
+	 *
179
+	 * @param bool $force Whether to force the includes.
180
+	 *
181
+	 * @return void
182
+	 */
183
+	public function include_legacy_frontend($force = false)
184
+	{
185
+		if (gravityview()->request->is_admin() && !$force) {
186
+			return;
187
+		}
188
+
189
+		include_once $this->dir('includes/class-gravityview-image.php');
190
+		include_once $this->dir('includes/class-template.php');
191
+		include_once $this->dir('includes/class-api.php');
192
+		include_once $this->dir('includes/class-frontend-views.php');
193
+		include_once $this->dir('includes/class-gravityview-change-entry-creator.php');
194
+
195
+		/**
196
+		 * @action     `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
197
+		 *
198
+		 * @deprecated Use `gravityview/loaded` along with \GV\Request::is_admin(), etc.
199
+		 *
200
+		 * Nice place to insert extensions' frontend stuff
201
+		 */
202
+		do_action('gravityview_include_frontend_actions');
203
+	}
204
+
205
+	/**
206
+	 * Load more legacy core files.
207
+	 *
208
+	 * @return void
209
+	 */
210
+	public function include_legacy_core()
211
+	{
212
+		if (!class_exists('\GravityView_Extension')) {
213
+			include_once $this->dir('includes/class-gravityview-extension.php');
214
+		}
215
+
216
+		if (!gravityview()->plugin->is_compatible()) {
217
+			return;
218
+		}
219
+
220
+		// Load fields
221
+		include_once $this->dir('includes/fields/class-gravityview-fields.php');
222
+		include_once $this->dir('includes/fields/class-gravityview-field.php');
223
+
224
+		// Load all field files automatically
225
+		foreach (glob($this->dir('includes/fields/class-gravityview-field*.php')) as $gv_field_filename) {
226
+			include_once $gv_field_filename;
227
+		}
228
+
229
+		include_once $this->dir('includes/class-gravityview-entry-approval-status.php');
230
+		include_once $this->dir('includes/class-gravityview-entry-approval.php');
231
+
232
+		include_once $this->dir('includes/class-gravityview-entry-notes.php');
233
+		include_once $this->dir('includes/load-plugin-and-theme-hooks.php');
234
+
235
+		// Load Extensions
236
+		// @todo: Convert to a scan of the directory or a method where this all lives
237
+		include_once $this->dir('includes/extensions/edit-entry/class-edit-entry.php');
238
+		include_once $this->dir('includes/extensions/delete-entry/class-delete-entry.php');
239
+		include_once $this->dir('includes/extensions/duplicate-entry/class-duplicate-entry.php');
240
+		include_once $this->dir('includes/extensions/entry-notes/class-gravityview-field-notes.php');
241
+		include_once $this->dir('includes/extensions/lightbox/class-gravityview-lightbox.php');
242
+
243
+		// Load WordPress Widgets
244
+		include_once $this->dir('includes/wordpress-widgets/register-wordpress-widgets.php');
245
+
246
+		// Load GravityView Widgets
247
+		include_once $this->dir('includes/widgets/register-gravityview-widgets.php');
248
+
249
+		// Add oEmbed
250
+		include_once $this->dir('includes/class-api.php');
251
+		include_once $this->dir('includes/class-oembed.php');
252
+
253
+		// Add logging
254
+		include_once $this->dir('includes/class-gravityview-logging.php');
255
+
256
+		include_once $this->dir('includes/class-ajax.php');
257
+		include_once $this->dir('includes/class-gravityview-html-elements.php');
258
+		include_once $this->dir('includes/class-frontend-views.php');
259
+		include_once $this->dir('includes/class-gravityview-admin-bar.php');
260
+		include_once $this->dir('includes/class-gravityview-entry-list.php');
261
+		include_once $this->dir('includes/class-gravityview-merge-tags.php');
262
+		/** @since 1.8.4 */
263
+		include_once $this->dir('includes/class-data.php');
264
+		include_once $this->dir('includes/class-gravityview-shortcode.php');
265
+		include_once $this->dir('includes/class-gravityview-entry-link-shortcode.php');
266
+		include_once $this->dir('includes/class-gvlogic-shortcode.php');
267
+		include_once $this->dir('includes/presets/register-default-templates.php');
268
+
269
+		if (class_exists('\GFFormsModel')) {
270
+			include_once $this->dir('includes/class-gravityview-gfformsmodel.php');
271
+		}
272
+	}
273
+
274
+	/**
275
+	 * Load the translations on `plugins_loaded`.
276
+	 *
277
+	 * Order of look-ups:
278
+	 *
279
+	 * 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core)
280
+	 * 2. /wp-content/mu-plugins/gravityview-{locale}.mo
281
+	 * 3. /wp-content/mu-plugins/languages/gravityview-{locale}.mo
282
+	 * 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo
283
+	 *
284
+	 * @return void
285
+	 */
286
+	public function load_textdomain()
287
+	{
288
+		$domain = 'gravityview';
289
+
290
+		// 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core)
291
+		if (is_textdomain_loaded($domain)) {
292
+			return;
293
+		}
294
+
295
+		// 2. /wp-content/languages/plugins/gravityview-{locale}.mo
296
+		// 3. /wp-content/mu-plugins/plugins/languages/gravityview-{locale}.mo
297
+		$loaded = load_muplugin_textdomain($domain, '/languages/');
298
+
299
+		if ($loaded) {
300
+			return;
301
+		}
302
+
303
+		// 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo
304
+		$loaded = load_plugin_textdomain($domain, false, $this->relpath('/languages/'));
305
+
306
+		if ($loaded) {
307
+			return;
308
+		}
309
+
310
+		$locale = apply_filters('plugin_locale', ((function_exists('get_user_locale') && is_admin()) ? get_user_locale() : get_locale()), 'gravityview');
311
+
312
+		gravityview()->log->error(sprintf('Unable to load textdomain for %s locale.', $locale));
313
+	}
314
+
315
+	/**
316
+	 * Register hooks that are fired when the plugin is activated and deactivated.
317
+	 *
318
+	 * @return void
319
+	 */
320
+	public function register_activation_hooks()
321
+	{
322
+		register_activation_hook($this->dir('gravityview.php'), [$this, 'activate']);
323
+		register_deactivation_hook($this->dir('gravityview.php'), [$this, 'deactivate']);
324
+	}
325
+
326
+	/**
327
+	 * Plugin activation function.
328
+	 *
329
+	 * @return void
330
+	 *
331
+	 * @internal
332
+	 */
333
+	public function activate()
334
+	{
335
+		gravityview();
336
+
337
+		if (!$this->is_compatible()) {
338
+			return;
339
+		}
340
+
341
+		/** Register the gravityview post type upon WordPress core init. */
342
+		require_once $this->dir('future/includes/class-gv-view.php');
343
+		View::register_post_type();
344
+
345
+		/** Add the entry rewrite endpoint. */
346
+		require_once $this->dir('future/includes/class-gv-entry.php');
347
+		Entry::add_rewrite_endpoint();
348
+
349
+		/** Flush all URL rewrites. */
350
+		flush_rewrite_rules();
351
+
352
+		update_option('gv_version', self::$version);
353
+
354
+		/** Add the transient to redirect to configuration page. */
355
+		set_transient('_gv_activation_redirect', true, 60);
356
+
357
+		/** Clear settings transient. */
358
+		delete_transient('gravityview_edd-activate_valid');
359
+
360
+		\GravityView_Roles_Capabilities::get_instance()->add_caps();
361
+	}
362
+
363
+	/**
364
+	 * Plugin deactivation function.
365
+	 *
366
+	 * @return void
367
+	 *
368
+	 * @internal
369
+	 */
370
+	public function deactivate()
371
+	{
372
+		flush_rewrite_rules();
373
+	}
374
+
375
+	/**
376
+	 * Retrieve an absolute path within the GravityView plugin directory.
377
+	 *
378
+	 * @since 2.0
379
+	 *
380
+	 * @param string $path Optional. Append this extra path component.
381
+	 *
382
+	 * @return string The absolute path to the plugin directory.
383
+	 *
384
+	 * @api
385
+	 */
386
+	public function dir($path = '')
387
+	{
388
+		return wp_normalize_path(GRAVITYVIEW_DIR.ltrim($path, '/'));
389
+	}
390
+
391
+	/**
392
+	 * Retrieve a relative path to the GravityView plugin directory from the WordPress plugin directory.
393
+	 *
394
+	 * @since 2.2.3
395
+	 *
396
+	 * @param string $path Optional. Append this extra path component.
397
+	 *
398
+	 * @return string The relative path to the plugin directory from the plugin directory.
399
+	 *
400
+	 * @api
401
+	 */
402
+	public function relpath($path = '')
403
+	{
404
+		$dirname = trailingslashit(dirname(plugin_basename(GRAVITYVIEW_FILE)));
405
+
406
+		return wp_normalize_path($dirname.ltrim($path, '/'));
407
+	}
408
+
409
+	/**
410
+	 * Retrieve a URL within the GravityView plugin directory.
411
+	 *
412
+	 * @since 2.0
413
+	 *
414
+	 * @param string $path Optional. Extra path appended to the URL.
415
+	 *
416
+	 * @return string The URL to this plugin, with trailing slash.
417
+	 *
418
+	 * @api
419
+	 */
420
+	public function url($path = '/')
421
+	{
422
+		return plugins_url($path, $this->dir('gravityview.php'));
423
+	}
424
+
425
+	/**
426
+	 * Is everything compatible with this version of GravityView?
427
+	 *
428
+	 * @since 2.0
429
+	 *
430
+	 * @return bool
431
+	 *
432
+	 * @api
433
+	 */
434
+	public function is_compatible()
435
+	{
436
+		return
437
+			$this->is_compatible_php()
438
+			&& $this->is_compatible_wordpress()
439
+			&& $this->is_compatible_gravityforms();
440
+	}
441
+
442
+	/**
443
+	 * Is this version of GravityView compatible with the current version of PHP?
444
+	 *
445
+	 * @since 2.0
446
+	 *
447
+	 * @return bool true if compatible, false otherwise.
448
+	 *
449
+	 * @api
450
+	 */
451
+	public function is_compatible_php()
452
+	{
453
+		return version_compare($this->get_php_version(), self::$min_php_version, '>=');
454
+	}
455
+
456
+	/**
457
+	 * Is this version of GravityView compatible with the future required version of PHP?
458
+	 *
459
+	 * @since 2.0
460
+	 *
461
+	 * @return bool true if compatible, false otherwise.
462
+	 *
463
+	 * @api
464
+	 */
465
+	public function is_compatible_future_php()
466
+	{
467
+		return version_compare($this->get_php_version(), self::$future_min_php_version, '>=');
468
+	}
469
+
470
+	/**
471
+	 * Is this version of GravityView compatible with the current version of WordPress?
472
+	 *
473
+	 * @since 2.0
474
+	 *
475
+	 * @param string $version Version to check against; otherwise uses GV_MIN_WP_VERSION
476
+	 *
477
+	 * @return bool true if compatible, false otherwise.
478
+	 *
479
+	 * @api
480
+	 */
481
+	public function is_compatible_wordpress($version = null)
482
+	{
483
+		if (!$version) {
484
+			$version = self::$min_wp_version;
485
+		}
486
+
487
+		return version_compare($this->get_wordpress_version(), $version, '>=');
488
+	}
489
+
490
+	/**
491
+	 * Is this version of GravityView compatible with the future version of WordPress?
492
+	 *
493
+	 * @since 2.9.3
494
+	 *
495
+	 * @return bool true if compatible, false otherwise
496
+	 *
497
+	 * @api
498
+	 */
499
+	public function is_compatible_future_wordpress()
500
+	{
501
+		$version = $this->get_wordpress_version();
502
+
503
+		return $version ? version_compare($version, self::$future_min_wp_version, '>=') : false;
504
+	}
505
+
506
+	/**
507
+	 * Is this version of GravityView compatible with the current version of Gravity Forms?
508
+	 *
509
+	 * @since 2.0
510
+	 *
511
+	 * @return bool true if compatible, false otherwise (or not active/installed).
512
+	 *
513
+	 * @api
514
+	 */
515
+	public function is_compatible_gravityforms()
516
+	{
517
+		$version = $this->get_gravityforms_version();
518
+
519
+		return $version ? version_compare($version, self::$min_gf_version, '>=') : false;
520
+	}
521
+
522
+	/**
523
+	 * Is this version of GravityView compatible with the future version of Gravity Forms?
524
+	 *
525
+	 * @since 2.0
526
+	 *
527
+	 * @return bool true if compatible, false otherwise (or not active/installed).
528
+	 *
529
+	 * @api
530
+	 */
531
+	public function is_compatible_future_gravityforms()
532
+	{
533
+		$version = $this->get_gravityforms_version();
534
+
535
+		return $version ? version_compare($version, self::$future_min_gf_version, '>=') : false;
536
+	}
537
+
538
+	/**
539
+	 * Retrieve the current PHP version.
540
+	 *
541
+	 * Overridable with GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE during testing.
542
+	 *
543
+	 * @return string The version of PHP.
544
+	 */
545
+	private function get_php_version()
546
+	{
547
+		return !empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE']) ?
548
+			$GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
549
+	}
550
+
551
+	/**
552
+	 * Retrieve the current WordPress version.
553
+	 *
554
+	 * Overridable with GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE during testing.
555
+	 *
556
+	 * @return string The version of WordPress.
557
+	 */
558
+	private function get_wordpress_version()
559
+	{
560
+		return !empty($GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE']) ?
561
+			$GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version'];
562
+	}
563
+
564
+	/**
565
+	 * Retrieve the current Gravity Forms version.
566
+	 *
567
+	 * Overridable with GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE during testing.
568
+	 *
569
+	 * @return string|null The version of Gravity Forms or null if inactive.
570
+	 */
571
+	private function get_gravityforms_version()
572
+	{
573
+		if (!class_exists('\GFCommon') || !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'])) {
574
+			gravityview()->log->error('Gravity Forms is inactive or not installed.');
575
+
576
+			return null;
577
+		}
578
+
579
+		return !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE']) ?
580
+			$GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] : \GFCommon::$version;
581
+	}
582
+
583
+	/**
584
+	 * Feature support detection.
585
+	 *
586
+	 * @param string $feature Feature name. Check FEATURE_* class constants.
587
+	 *
588
+	 * @return bool
589
+	 */
590
+	public function supports($feature)
591
+	{
592
+		if (!is_null($supports = apply_filters("gravityview/plugin/feature/$feature", null))) {
593
+			return $supports;
594
+		}
595
+
596
+		switch ($feature) {
597
+			case self::FEATURE_GFQUERY:
598
+				return class_exists('\GF_Query');
599
+			case self::FEATURE_JOINS:
600
+			case self::FEATURE_UNIONS:
601
+				return apply_filters('gravityview/query/class', false) === '\GF_Patched_Query';
602
+			case self::FEATURE_REST:
603
+				return class_exists('\WP_REST_Controller');
604
+			default:
605
+				return false;
606
+		}
607
+	}
608
+
609
+	/**
610
+	 * Delete GravityView Views, settings, roles, caps, etc.
611
+	 *
612
+	 * @return void
613
+	 */
614
+	public function uninstall()
615
+	{
616
+		global $wpdb;
617
+
618
+		$suppress = $wpdb->suppress_errors();
619
+
620
+		/**
621
+		 * Posts.
622
+		 */
623
+		$items = get_posts([
624
+			'post_type'   => 'gravityview',
625
+			'post_status' => 'any',
626
+			'numberposts' => -1,
627
+			'fields'      => 'ids',
628
+		]);
629
+
630
+		foreach ($items as $item) {
631
+			wp_delete_post($item, true);
632
+		}
633
+
634
+		/**
635
+		 * Meta.
636
+		 */
637
+		$tables = [];
638
+
639
+		if (version_compare(\GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=')) {
640
+			$tables[] = \GFFormsModel::get_entry_meta_table_name();
641
+		} elseif (!$this->is_GF_25()) {
642
+			$tables[] = \GFFormsModel::get_lead_meta_table_name();
643
+		}
644
+
645
+		foreach ($tables as $meta_table) {
646
+			$sql = "
647 647
 				DELETE FROM $meta_table
648 648
 				WHERE (
649 649
 					`meta_key` = 'is_approved'
650 650
 				);
651 651
 			";
652
-            $wpdb->query($sql);
653
-        }
654
-
655
-        /**
656
-         * Notes.
657
-         */
658
-        $tables = [];
659
-
660
-        if (version_compare(\GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') && method_exists('GFFormsModel', 'get_entry_notes_table_name')) {
661
-            $tables[] = \GFFormsModel::get_entry_notes_table_name();
662
-        } elseif (!$this->is_GF_25()) {
663
-            $tables[] = \GFFormsModel::get_lead_notes_table_name();
664
-        }
665
-
666
-        $disapproved = __('Disapproved the Entry for GravityView', 'gravityview');
667
-        $approved = __('Approved the Entry for GravityView', 'gravityview');
668
-
669
-        $suppress = $wpdb->suppress_errors();
670
-        foreach ($tables as $notes_table) {
671
-            $sql = $wpdb->prepare("
652
+			$wpdb->query($sql);
653
+		}
654
+
655
+		/**
656
+		 * Notes.
657
+		 */
658
+		$tables = [];
659
+
660
+		if (version_compare(\GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') && method_exists('GFFormsModel', 'get_entry_notes_table_name')) {
661
+			$tables[] = \GFFormsModel::get_entry_notes_table_name();
662
+		} elseif (!$this->is_GF_25()) {
663
+			$tables[] = \GFFormsModel::get_lead_notes_table_name();
664
+		}
665
+
666
+		$disapproved = __('Disapproved the Entry for GravityView', 'gravityview');
667
+		$approved = __('Approved the Entry for GravityView', 'gravityview');
668
+
669
+		$suppress = $wpdb->suppress_errors();
670
+		foreach ($tables as $notes_table) {
671
+			$sql = $wpdb->prepare("
672 672
 				DELETE FROM $notes_table
673 673
 				WHERE (
674 674
 					`note_type` = 'gravityview' OR
@@ -676,33 +676,33 @@  discard block
 block discarded – undo
676 676
 					`value` = %s
677 677
 				);
678 678
 			", $approved, $disapproved);
679
-            $wpdb->query($sql);
680
-        }
681
-
682
-        $wpdb->suppress_errors($suppress);
683
-
684
-        /**
685
-         * Capabilities.
686
-         */
687
-        \GravityView_Roles_Capabilities::get_instance()->remove_caps();
688
-
689
-        /**
690
-         * Options.
691
-         */
692
-        delete_option('gravityview_cache_blacklist');
693
-        delete_option('gravityview_cache_blocklist');
694
-        delete_option('gv_version_upgraded_from');
695
-        delete_transient('gravityview_edd-activate_valid');
696
-        delete_transient('gravityview_edd-deactivate_valid');
697
-        delete_transient('gravityview_dismissed_notices');
698
-        delete_site_transient('gravityview_related_plugins');
699
-    }
700
-
701
-    public function __clone()
702
-    {
703
-    }
704
-
705
-    public function __wakeup()
706
-    {
707
-    }
679
+			$wpdb->query($sql);
680
+		}
681
+
682
+		$wpdb->suppress_errors($suppress);
683
+
684
+		/**
685
+		 * Capabilities.
686
+		 */
687
+		\GravityView_Roles_Capabilities::get_instance()->remove_caps();
688
+
689
+		/**
690
+		 * Options.
691
+		 */
692
+		delete_option('gravityview_cache_blacklist');
693
+		delete_option('gravityview_cache_blocklist');
694
+		delete_option('gv_version_upgraded_from');
695
+		delete_transient('gravityview_edd-activate_valid');
696
+		delete_transient('gravityview_edd-deactivate_valid');
697
+		delete_transient('gravityview_dismissed_notices');
698
+		delete_site_transient('gravityview_related_plugins');
699
+	}
700
+
701
+	public function __clone()
702
+	{
703
+	}
704
+
705
+	public function __wakeup()
706
+	{
707
+	}
708 708
 }
Please login to merge, or discard this patch.
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public static function get()
113 113
     {
114
-        if (!self::$__instance instanceof self) {
114
+        if ( ! self::$__instance instanceof self ) {
115 115
             self::$__instance = new self();
116 116
         }
117 117
 
@@ -124,28 +124,28 @@  discard block
 block discarded – undo
124 124
         /**
125 125
          * Load translations. Must be priority 1.
126 126
          */
127
-        add_action('plugins_loaded', [$this, 'load_textdomain'], 1);
127
+        add_action( 'plugins_loaded', [ $this, 'load_textdomain' ], 1 );
128 128
 
129 129
         /**
130 130
          * Load some frontend-related legacy files.
131 131
          */
132
-        add_action('gravityview/loaded', [$this, 'include_legacy_frontend']);
132
+        add_action( 'gravityview/loaded', [ $this, 'include_legacy_frontend' ] );
133 133
 
134 134
         /**
135 135
          * GFAddOn-backed settings, licensing.
136 136
          */
137
-        add_action('plugins_loaded', [$this, 'load_license_settings']);
137
+        add_action( 'plugins_loaded', [ $this, 'load_license_settings' ] );
138 138
     }
139 139
 
140 140
     public function load_license_settings()
141 141
     {
142
-        require_once $this->dir('future/includes/class-gv-license-handler.php');
143
-        require_once $this->dir('future/includes/class-gv-settings-addon.php');
144
-        if (class_exists('\GV\Addon_Settings')) {
142
+        require_once $this->dir( 'future/includes/class-gv-license-handler.php' );
143
+        require_once $this->dir( 'future/includes/class-gv-settings-addon.php' );
144
+        if ( class_exists( '\GV\Addon_Settings' ) ) {
145 145
             $this->settings = new Addon_Settings();
146
-            include_once $this->dir('includes/class-gravityview-settings.php');
146
+            include_once $this->dir( 'includes/class-gravityview-settings.php' );
147 147
         } else {
148
-            gravityview()->log->notice('\GV\Addon_Settings not loaded. Missing \GFAddOn.');
148
+            gravityview()->log->notice( '\GV\Addon_Settings not loaded. Missing \GFAddOn.' );
149 149
         }
150 150
     }
151 151
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public function is_GF_25()
160 160
     {
161
-        return version_compare('2.5-beta', \GFForms::$version, '<=');
161
+        return version_compare( '2.5-beta', \GFForms::$version, '<=' );
162 162
     }
163 163
 
164 164
     /**
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public static function is_network_activated()
170 170
     {
171
-        $plugin_basename = plugin_basename(GRAVITYVIEW_FILE);
171
+        $plugin_basename = plugin_basename( GRAVITYVIEW_FILE );
172 172
 
173
-        return is_multisite() && (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network($plugin_basename));
173
+        return is_multisite() && ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( $plugin_basename ) );
174 174
     }
175 175
 
176 176
     /**
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
      *
181 181
      * @return void
182 182
      */
183
-    public function include_legacy_frontend($force = false)
183
+    public function include_legacy_frontend( $force = false )
184 184
     {
185
-        if (gravityview()->request->is_admin() && !$force) {
185
+        if ( gravityview()->request->is_admin() && ! $force ) {
186 186
             return;
187 187
         }
188 188
 
189
-        include_once $this->dir('includes/class-gravityview-image.php');
190
-        include_once $this->dir('includes/class-template.php');
191
-        include_once $this->dir('includes/class-api.php');
192
-        include_once $this->dir('includes/class-frontend-views.php');
193
-        include_once $this->dir('includes/class-gravityview-change-entry-creator.php');
189
+        include_once $this->dir( 'includes/class-gravityview-image.php' );
190
+        include_once $this->dir( 'includes/class-template.php' );
191
+        include_once $this->dir( 'includes/class-api.php' );
192
+        include_once $this->dir( 'includes/class-frontend-views.php' );
193
+        include_once $this->dir( 'includes/class-gravityview-change-entry-creator.php' );
194 194
 
195 195
         /**
196 196
          * @action     `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
          *
200 200
          * Nice place to insert extensions' frontend stuff
201 201
          */
202
-        do_action('gravityview_include_frontend_actions');
202
+        do_action( 'gravityview_include_frontend_actions' );
203 203
     }
204 204
 
205 205
     /**
@@ -209,65 +209,65 @@  discard block
 block discarded – undo
209 209
      */
210 210
     public function include_legacy_core()
211 211
     {
212
-        if (!class_exists('\GravityView_Extension')) {
213
-            include_once $this->dir('includes/class-gravityview-extension.php');
212
+        if ( ! class_exists( '\GravityView_Extension' ) ) {
213
+            include_once $this->dir( 'includes/class-gravityview-extension.php' );
214 214
         }
215 215
 
216
-        if (!gravityview()->plugin->is_compatible()) {
216
+        if ( ! gravityview()->plugin->is_compatible() ) {
217 217
             return;
218 218
         }
219 219
 
220 220
         // Load fields
221
-        include_once $this->dir('includes/fields/class-gravityview-fields.php');
222
-        include_once $this->dir('includes/fields/class-gravityview-field.php');
221
+        include_once $this->dir( 'includes/fields/class-gravityview-fields.php' );
222
+        include_once $this->dir( 'includes/fields/class-gravityview-field.php' );
223 223
 
224 224
         // Load all field files automatically
225
-        foreach (glob($this->dir('includes/fields/class-gravityview-field*.php')) as $gv_field_filename) {
225
+        foreach ( glob( $this->dir( 'includes/fields/class-gravityview-field*.php' ) ) as $gv_field_filename ) {
226 226
             include_once $gv_field_filename;
227 227
         }
228 228
 
229
-        include_once $this->dir('includes/class-gravityview-entry-approval-status.php');
230
-        include_once $this->dir('includes/class-gravityview-entry-approval.php');
229
+        include_once $this->dir( 'includes/class-gravityview-entry-approval-status.php' );
230
+        include_once $this->dir( 'includes/class-gravityview-entry-approval.php' );
231 231
 
232
-        include_once $this->dir('includes/class-gravityview-entry-notes.php');
233
-        include_once $this->dir('includes/load-plugin-and-theme-hooks.php');
232
+        include_once $this->dir( 'includes/class-gravityview-entry-notes.php' );
233
+        include_once $this->dir( 'includes/load-plugin-and-theme-hooks.php' );
234 234
 
235 235
         // Load Extensions
236 236
         // @todo: Convert to a scan of the directory or a method where this all lives
237
-        include_once $this->dir('includes/extensions/edit-entry/class-edit-entry.php');
238
-        include_once $this->dir('includes/extensions/delete-entry/class-delete-entry.php');
239
-        include_once $this->dir('includes/extensions/duplicate-entry/class-duplicate-entry.php');
240
-        include_once $this->dir('includes/extensions/entry-notes/class-gravityview-field-notes.php');
241
-        include_once $this->dir('includes/extensions/lightbox/class-gravityview-lightbox.php');
237
+        include_once $this->dir( 'includes/extensions/edit-entry/class-edit-entry.php' );
238
+        include_once $this->dir( 'includes/extensions/delete-entry/class-delete-entry.php' );
239
+        include_once $this->dir( 'includes/extensions/duplicate-entry/class-duplicate-entry.php' );
240
+        include_once $this->dir( 'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
241
+        include_once $this->dir( 'includes/extensions/lightbox/class-gravityview-lightbox.php' );
242 242
 
243 243
         // Load WordPress Widgets
244
-        include_once $this->dir('includes/wordpress-widgets/register-wordpress-widgets.php');
244
+        include_once $this->dir( 'includes/wordpress-widgets/register-wordpress-widgets.php' );
245 245
 
246 246
         // Load GravityView Widgets
247
-        include_once $this->dir('includes/widgets/register-gravityview-widgets.php');
247
+        include_once $this->dir( 'includes/widgets/register-gravityview-widgets.php' );
248 248
 
249 249
         // Add oEmbed
250
-        include_once $this->dir('includes/class-api.php');
251
-        include_once $this->dir('includes/class-oembed.php');
250
+        include_once $this->dir( 'includes/class-api.php' );
251
+        include_once $this->dir( 'includes/class-oembed.php' );
252 252
 
253 253
         // Add logging
254
-        include_once $this->dir('includes/class-gravityview-logging.php');
255
-
256
-        include_once $this->dir('includes/class-ajax.php');
257
-        include_once $this->dir('includes/class-gravityview-html-elements.php');
258
-        include_once $this->dir('includes/class-frontend-views.php');
259
-        include_once $this->dir('includes/class-gravityview-admin-bar.php');
260
-        include_once $this->dir('includes/class-gravityview-entry-list.php');
261
-        include_once $this->dir('includes/class-gravityview-merge-tags.php');
254
+        include_once $this->dir( 'includes/class-gravityview-logging.php' );
255
+
256
+        include_once $this->dir( 'includes/class-ajax.php' );
257
+        include_once $this->dir( 'includes/class-gravityview-html-elements.php' );
258
+        include_once $this->dir( 'includes/class-frontend-views.php' );
259
+        include_once $this->dir( 'includes/class-gravityview-admin-bar.php' );
260
+        include_once $this->dir( 'includes/class-gravityview-entry-list.php' );
261
+        include_once $this->dir( 'includes/class-gravityview-merge-tags.php' );
262 262
         /** @since 1.8.4 */
263
-        include_once $this->dir('includes/class-data.php');
264
-        include_once $this->dir('includes/class-gravityview-shortcode.php');
265
-        include_once $this->dir('includes/class-gravityview-entry-link-shortcode.php');
266
-        include_once $this->dir('includes/class-gvlogic-shortcode.php');
267
-        include_once $this->dir('includes/presets/register-default-templates.php');
268
-
269
-        if (class_exists('\GFFormsModel')) {
270
-            include_once $this->dir('includes/class-gravityview-gfformsmodel.php');
263
+        include_once $this->dir( 'includes/class-data.php' );
264
+        include_once $this->dir( 'includes/class-gravityview-shortcode.php' );
265
+        include_once $this->dir( 'includes/class-gravityview-entry-link-shortcode.php' );
266
+        include_once $this->dir( 'includes/class-gvlogic-shortcode.php' );
267
+        include_once $this->dir( 'includes/presets/register-default-templates.php' );
268
+
269
+        if ( class_exists( '\GFFormsModel' ) ) {
270
+            include_once $this->dir( 'includes/class-gravityview-gfformsmodel.php' );
271 271
         }
272 272
     }
273 273
 
@@ -288,28 +288,28 @@  discard block
 block discarded – undo
288 288
         $domain = 'gravityview';
289 289
 
290 290
         // 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core)
291
-        if (is_textdomain_loaded($domain)) {
291
+        if ( is_textdomain_loaded( $domain ) ) {
292 292
             return;
293 293
         }
294 294
 
295 295
         // 2. /wp-content/languages/plugins/gravityview-{locale}.mo
296 296
         // 3. /wp-content/mu-plugins/plugins/languages/gravityview-{locale}.mo
297
-        $loaded = load_muplugin_textdomain($domain, '/languages/');
297
+        $loaded = load_muplugin_textdomain( $domain, '/languages/' );
298 298
 
299
-        if ($loaded) {
299
+        if ( $loaded ) {
300 300
             return;
301 301
         }
302 302
 
303 303
         // 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo
304
-        $loaded = load_plugin_textdomain($domain, false, $this->relpath('/languages/'));
304
+        $loaded = load_plugin_textdomain( $domain, false, $this->relpath( '/languages/' ) );
305 305
 
306
-        if ($loaded) {
306
+        if ( $loaded ) {
307 307
             return;
308 308
         }
309 309
 
310
-        $locale = apply_filters('plugin_locale', ((function_exists('get_user_locale') && is_admin()) ? get_user_locale() : get_locale()), 'gravityview');
310
+        $locale = apply_filters( 'plugin_locale', ( ( function_exists( 'get_user_locale' ) && is_admin() ) ? get_user_locale() : get_locale() ), 'gravityview' );
311 311
 
312
-        gravityview()->log->error(sprintf('Unable to load textdomain for %s locale.', $locale));
312
+        gravityview()->log->error( sprintf( 'Unable to load textdomain for %s locale.', $locale ) );
313 313
     }
314 314
 
315 315
     /**
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
      */
320 320
     public function register_activation_hooks()
321 321
     {
322
-        register_activation_hook($this->dir('gravityview.php'), [$this, 'activate']);
323
-        register_deactivation_hook($this->dir('gravityview.php'), [$this, 'deactivate']);
322
+        register_activation_hook( $this->dir( 'gravityview.php' ), [ $this, 'activate' ] );
323
+        register_deactivation_hook( $this->dir( 'gravityview.php' ), [ $this, 'deactivate' ] );
324 324
     }
325 325
 
326 326
     /**
@@ -334,28 +334,28 @@  discard block
 block discarded – undo
334 334
     {
335 335
         gravityview();
336 336
 
337
-        if (!$this->is_compatible()) {
337
+        if ( ! $this->is_compatible() ) {
338 338
             return;
339 339
         }
340 340
 
341 341
         /** Register the gravityview post type upon WordPress core init. */
342
-        require_once $this->dir('future/includes/class-gv-view.php');
342
+        require_once $this->dir( 'future/includes/class-gv-view.php' );
343 343
         View::register_post_type();
344 344
 
345 345
         /** Add the entry rewrite endpoint. */
346
-        require_once $this->dir('future/includes/class-gv-entry.php');
346
+        require_once $this->dir( 'future/includes/class-gv-entry.php' );
347 347
         Entry::add_rewrite_endpoint();
348 348
 
349 349
         /** Flush all URL rewrites. */
350 350
         flush_rewrite_rules();
351 351
 
352
-        update_option('gv_version', self::$version);
352
+        update_option( 'gv_version', self::$version );
353 353
 
354 354
         /** Add the transient to redirect to configuration page. */
355
-        set_transient('_gv_activation_redirect', true, 60);
355
+        set_transient( '_gv_activation_redirect', true, 60 );
356 356
 
357 357
         /** Clear settings transient. */
358
-        delete_transient('gravityview_edd-activate_valid');
358
+        delete_transient( 'gravityview_edd-activate_valid' );
359 359
 
360 360
         \GravityView_Roles_Capabilities::get_instance()->add_caps();
361 361
     }
@@ -383,9 +383,9 @@  discard block
 block discarded – undo
383 383
      *
384 384
      * @api
385 385
      */
386
-    public function dir($path = '')
386
+    public function dir( $path = '' )
387 387
     {
388
-        return wp_normalize_path(GRAVITYVIEW_DIR.ltrim($path, '/'));
388
+        return wp_normalize_path( GRAVITYVIEW_DIR . ltrim( $path, '/' ) );
389 389
     }
390 390
 
391 391
     /**
@@ -399,11 +399,11 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @api
401 401
      */
402
-    public function relpath($path = '')
402
+    public function relpath( $path = '' )
403 403
     {
404
-        $dirname = trailingslashit(dirname(plugin_basename(GRAVITYVIEW_FILE)));
404
+        $dirname = trailingslashit( dirname( plugin_basename( GRAVITYVIEW_FILE ) ) );
405 405
 
406
-        return wp_normalize_path($dirname.ltrim($path, '/'));
406
+        return wp_normalize_path( $dirname . ltrim( $path, '/' ) );
407 407
     }
408 408
 
409 409
     /**
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
      *
418 418
      * @api
419 419
      */
420
-    public function url($path = '/')
420
+    public function url( $path = '/' )
421 421
     {
422
-        return plugins_url($path, $this->dir('gravityview.php'));
422
+        return plugins_url( $path, $this->dir( 'gravityview.php' ) );
423 423
     }
424 424
 
425 425
     /**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      */
451 451
     public function is_compatible_php()
452 452
     {
453
-        return version_compare($this->get_php_version(), self::$min_php_version, '>=');
453
+        return version_compare( $this->get_php_version(), self::$min_php_version, '>=' );
454 454
     }
455 455
 
456 456
     /**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
      */
465 465
     public function is_compatible_future_php()
466 466
     {
467
-        return version_compare($this->get_php_version(), self::$future_min_php_version, '>=');
467
+        return version_compare( $this->get_php_version(), self::$future_min_php_version, '>=' );
468 468
     }
469 469
 
470 470
     /**
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
      *
479 479
      * @api
480 480
      */
481
-    public function is_compatible_wordpress($version = null)
481
+    public function is_compatible_wordpress( $version = null )
482 482
     {
483
-        if (!$version) {
483
+        if ( ! $version ) {
484 484
             $version = self::$min_wp_version;
485 485
         }
486 486
 
487
-        return version_compare($this->get_wordpress_version(), $version, '>=');
487
+        return version_compare( $this->get_wordpress_version(), $version, '>=' );
488 488
     }
489 489
 
490 490
     /**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
     {
501 501
         $version = $this->get_wordpress_version();
502 502
 
503
-        return $version ? version_compare($version, self::$future_min_wp_version, '>=') : false;
503
+        return $version ? version_compare( $version, self::$future_min_wp_version, '>=' ) : false;
504 504
     }
505 505
 
506 506
     /**
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
     {
517 517
         $version = $this->get_gravityforms_version();
518 518
 
519
-        return $version ? version_compare($version, self::$min_gf_version, '>=') : false;
519
+        return $version ? version_compare( $version, self::$min_gf_version, '>=' ) : false;
520 520
     }
521 521
 
522 522
     /**
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
     {
533 533
         $version = $this->get_gravityforms_version();
534 534
 
535
-        return $version ? version_compare($version, self::$future_min_gf_version, '>=') : false;
535
+        return $version ? version_compare( $version, self::$future_min_gf_version, '>=' ) : false;
536 536
     }
537 537
 
538 538
     /**
@@ -544,8 +544,8 @@  discard block
 block discarded – undo
544 544
      */
545 545
     private function get_php_version()
546 546
     {
547
-        return !empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE']) ?
548
-            $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
547
+        return ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE' ] ) ?
548
+            $GLOBALS[ 'GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE' ] : phpversion();
549 549
     }
550 550
 
551 551
     /**
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
      */
558 558
     private function get_wordpress_version()
559 559
     {
560
-        return !empty($GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE']) ?
561
-            $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version'];
560
+        return ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE' ] ) ?
561
+            $GLOBALS[ 'GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE' ] : $GLOBALS[ 'wp_version' ];
562 562
     }
563 563
 
564 564
     /**
@@ -570,14 +570,14 @@  discard block
 block discarded – undo
570 570
      */
571 571
     private function get_gravityforms_version()
572 572
     {
573
-        if (!class_exists('\GFCommon') || !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'])) {
574
-            gravityview()->log->error('Gravity Forms is inactive or not installed.');
573
+        if ( ! class_exists( '\GFCommon' ) || ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE' ] ) ) {
574
+            gravityview()->log->error( 'Gravity Forms is inactive or not installed.' );
575 575
 
576 576
             return null;
577 577
         }
578 578
 
579
-        return !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE']) ?
580
-            $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] : \GFCommon::$version;
579
+        return ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE' ] ) ?
580
+            $GLOBALS[ 'GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE' ] : \GFCommon::$version;
581 581
     }
582 582
 
583 583
     /**
@@ -587,20 +587,20 @@  discard block
 block discarded – undo
587 587
      *
588 588
      * @return bool
589 589
      */
590
-    public function supports($feature)
590
+    public function supports( $feature )
591 591
     {
592
-        if (!is_null($supports = apply_filters("gravityview/plugin/feature/$feature", null))) {
592
+        if ( ! is_null( $supports = apply_filters( "gravityview/plugin/feature/$feature", null ) ) ) {
593 593
             return $supports;
594 594
         }
595 595
 
596
-        switch ($feature) {
596
+        switch ( $feature ) {
597 597
             case self::FEATURE_GFQUERY:
598
-                return class_exists('\GF_Query');
598
+                return class_exists( '\GF_Query' );
599 599
             case self::FEATURE_JOINS:
600 600
             case self::FEATURE_UNIONS:
601
-                return apply_filters('gravityview/query/class', false) === '\GF_Patched_Query';
601
+                return apply_filters( 'gravityview/query/class', false ) === '\GF_Patched_Query';
602 602
             case self::FEATURE_REST:
603
-                return class_exists('\WP_REST_Controller');
603
+                return class_exists( '\WP_REST_Controller' );
604 604
             default:
605 605
                 return false;
606 606
         }
@@ -620,66 +620,66 @@  discard block
 block discarded – undo
620 620
         /**
621 621
          * Posts.
622 622
          */
623
-        $items = get_posts([
623
+        $items = get_posts( [
624 624
             'post_type'   => 'gravityview',
625 625
             'post_status' => 'any',
626 626
             'numberposts' => -1,
627 627
             'fields'      => 'ids',
628
-        ]);
628
+        ] );
629 629
 
630
-        foreach ($items as $item) {
631
-            wp_delete_post($item, true);
630
+        foreach ( $items as $item ) {
631
+            wp_delete_post( $item, true );
632 632
         }
633 633
 
634 634
         /**
635 635
          * Meta.
636 636
          */
637
-        $tables = [];
637
+        $tables = [ ];
638 638
 
639
-        if (version_compare(\GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=')) {
640
-            $tables[] = \GFFormsModel::get_entry_meta_table_name();
641
-        } elseif (!$this->is_GF_25()) {
642
-            $tables[] = \GFFormsModel::get_lead_meta_table_name();
639
+        if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) {
640
+            $tables[ ] = \GFFormsModel::get_entry_meta_table_name();
641
+        } elseif ( ! $this->is_GF_25() ) {
642
+            $tables[ ] = \GFFormsModel::get_lead_meta_table_name();
643 643
         }
644 644
 
645
-        foreach ($tables as $meta_table) {
645
+        foreach ( $tables as $meta_table ) {
646 646
             $sql = "
647 647
 				DELETE FROM $meta_table
648 648
 				WHERE (
649 649
 					`meta_key` = 'is_approved'
650 650
 				);
651 651
 			";
652
-            $wpdb->query($sql);
652
+            $wpdb->query( $sql );
653 653
         }
654 654
 
655 655
         /**
656 656
          * Notes.
657 657
          */
658
-        $tables = [];
658
+        $tables = [ ];
659 659
 
660
-        if (version_compare(\GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') && method_exists('GFFormsModel', 'get_entry_notes_table_name')) {
661
-            $tables[] = \GFFormsModel::get_entry_notes_table_name();
662
-        } elseif (!$this->is_GF_25()) {
663
-            $tables[] = \GFFormsModel::get_lead_notes_table_name();
660
+        if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) && method_exists( 'GFFormsModel', 'get_entry_notes_table_name' ) ) {
661
+            $tables[ ] = \GFFormsModel::get_entry_notes_table_name();
662
+        } elseif ( ! $this->is_GF_25() ) {
663
+            $tables[ ] = \GFFormsModel::get_lead_notes_table_name();
664 664
         }
665 665
 
666
-        $disapproved = __('Disapproved the Entry for GravityView', 'gravityview');
667
-        $approved = __('Approved the Entry for GravityView', 'gravityview');
666
+        $disapproved = __( 'Disapproved the Entry for GravityView', 'gravityview' );
667
+        $approved = __( 'Approved the Entry for GravityView', 'gravityview' );
668 668
 
669 669
         $suppress = $wpdb->suppress_errors();
670
-        foreach ($tables as $notes_table) {
671
-            $sql = $wpdb->prepare("
670
+        foreach ( $tables as $notes_table ) {
671
+            $sql = $wpdb->prepare( "
672 672
 				DELETE FROM $notes_table
673 673
 				WHERE (
674 674
 					`note_type` = 'gravityview' OR
675 675
 					`value` = %s OR
676 676
 					`value` = %s
677 677
 				);
678
-			", $approved, $disapproved);
679
-            $wpdb->query($sql);
678
+			", $approved, $disapproved );
679
+            $wpdb->query( $sql );
680 680
         }
681 681
 
682
-        $wpdb->suppress_errors($suppress);
682
+        $wpdb->suppress_errors( $suppress );
683 683
 
684 684
         /**
685 685
          * Capabilities.
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
         /**
690 690
          * Options.
691 691
          */
692
-        delete_option('gravityview_cache_blacklist');
693
-        delete_option('gravityview_cache_blocklist');
694
-        delete_option('gv_version_upgraded_from');
695
-        delete_transient('gravityview_edd-activate_valid');
696
-        delete_transient('gravityview_edd-deactivate_valid');
697
-        delete_transient('gravityview_dismissed_notices');
698
-        delete_site_transient('gravityview_related_plugins');
692
+        delete_option( 'gravityview_cache_blacklist' );
693
+        delete_option( 'gravityview_cache_blocklist' );
694
+        delete_option( 'gv_version_upgraded_from' );
695
+        delete_transient( 'gravityview_edd-activate_valid' );
696
+        delete_transient( 'gravityview_edd-deactivate_valid' );
697
+        delete_transient( 'gravityview_dismissed_notices' );
698
+        delete_site_transient( 'gravityview_related_plugins' );
699 699
     }
700 700
 
701 701
     public function __clone()
Please login to merge, or discard this patch.
Braces   +29 added lines, -58 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * Accessible via gravityview()->plugin
17 17
  */
18
-final class Plugin
19
-{
18
+final class Plugin {
20 19
     /**
21 20
      * @since 2.0
22 21
      *
@@ -109,8 +108,7 @@  discard block
 block discarded – undo
109 108
      *
110 109
      * @return \GV\Plugin The global instance of GravityView Plugin.
111 110
      */
112
-    public static function get()
113
-    {
111
+    public static function get() {
114 112
         if (!self::$__instance instanceof self) {
115 113
             self::$__instance = new self();
116 114
         }
@@ -118,8 +116,7 @@  discard block
 block discarded – undo
118 116
         return self::$__instance;
119 117
     }
120 118
 
121
-    private function __construct()
122
-    {
119
+    private function __construct() {
123 120
 
124 121
         /**
125 122
          * Load translations. Must be priority 1.
@@ -137,8 +134,7 @@  discard block
 block discarded – undo
137 134
         add_action('plugins_loaded', [$this, 'load_license_settings']);
138 135
     }
139 136
 
140
-    public function load_license_settings()
141
-    {
137
+    public function load_license_settings() {
142 138
         require_once $this->dir('future/includes/class-gv-license-handler.php');
143 139
         require_once $this->dir('future/includes/class-gv-settings-addon.php');
144 140
         if (class_exists('\GV\Addon_Settings')) {
@@ -156,8 +152,7 @@  discard block
 block discarded – undo
156 152
      *
157 153
      * @todo add @since
158 154
      */
159
-    public function is_GF_25()
160
-    {
155
+    public function is_GF_25() {
161 156
         return version_compare('2.5-beta', \GFForms::$version, '<=');
162 157
     }
163 158
 
@@ -166,8 +161,7 @@  discard block
 block discarded – undo
166 161
      *
167 162
      * @return bool Whether it's network activated or not.
168 163
      */
169
-    public static function is_network_activated()
170
-    {
164
+    public static function is_network_activated() {
171 165
         $plugin_basename = plugin_basename(GRAVITYVIEW_FILE);
172 166
 
173 167
         return is_multisite() && (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network($plugin_basename));
@@ -180,8 +174,7 @@  discard block
 block discarded – undo
180 174
      *
181 175
      * @return void
182 176
      */
183
-    public function include_legacy_frontend($force = false)
184
-    {
177
+    public function include_legacy_frontend($force = false) {
185 178
         if (gravityview()->request->is_admin() && !$force) {
186 179
             return;
187 180
         }
@@ -207,8 +200,7 @@  discard block
 block discarded – undo
207 200
      *
208 201
      * @return void
209 202
      */
210
-    public function include_legacy_core()
211
-    {
203
+    public function include_legacy_core() {
212 204
         if (!class_exists('\GravityView_Extension')) {
213 205
             include_once $this->dir('includes/class-gravityview-extension.php');
214 206
         }
@@ -283,8 +275,7 @@  discard block
 block discarded – undo
283 275
      *
284 276
      * @return void
285 277
      */
286
-    public function load_textdomain()
287
-    {
278
+    public function load_textdomain() {
288 279
         $domain = 'gravityview';
289 280
 
290 281
         // 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core)
@@ -317,8 +308,7 @@  discard block
 block discarded – undo
317 308
      *
318 309
      * @return void
319 310
      */
320
-    public function register_activation_hooks()
321
-    {
311
+    public function register_activation_hooks() {
322 312
         register_activation_hook($this->dir('gravityview.php'), [$this, 'activate']);
323 313
         register_deactivation_hook($this->dir('gravityview.php'), [$this, 'deactivate']);
324 314
     }
@@ -330,8 +320,7 @@  discard block
 block discarded – undo
330 320
      *
331 321
      * @internal
332 322
      */
333
-    public function activate()
334
-    {
323
+    public function activate() {
335 324
         gravityview();
336 325
 
337 326
         if (!$this->is_compatible()) {
@@ -367,8 +356,7 @@  discard block
 block discarded – undo
367 356
      *
368 357
      * @internal
369 358
      */
370
-    public function deactivate()
371
-    {
359
+    public function deactivate() {
372 360
         flush_rewrite_rules();
373 361
     }
374 362
 
@@ -383,8 +371,7 @@  discard block
 block discarded – undo
383 371
      *
384 372
      * @api
385 373
      */
386
-    public function dir($path = '')
387
-    {
374
+    public function dir($path = '') {
388 375
         return wp_normalize_path(GRAVITYVIEW_DIR.ltrim($path, '/'));
389 376
     }
390 377
 
@@ -399,8 +386,7 @@  discard block
 block discarded – undo
399 386
      *
400 387
      * @api
401 388
      */
402
-    public function relpath($path = '')
403
-    {
389
+    public function relpath($path = '') {
404 390
         $dirname = trailingslashit(dirname(plugin_basename(GRAVITYVIEW_FILE)));
405 391
 
406 392
         return wp_normalize_path($dirname.ltrim($path, '/'));
@@ -417,8 +403,7 @@  discard block
 block discarded – undo
417 403
      *
418 404
      * @api
419 405
      */
420
-    public function url($path = '/')
421
-    {
406
+    public function url($path = '/') {
422 407
         return plugins_url($path, $this->dir('gravityview.php'));
423 408
     }
424 409
 
@@ -431,8 +416,7 @@  discard block
 block discarded – undo
431 416
      *
432 417
      * @api
433 418
      */
434
-    public function is_compatible()
435
-    {
419
+    public function is_compatible() {
436 420
         return
437 421
             $this->is_compatible_php()
438 422
             && $this->is_compatible_wordpress()
@@ -448,8 +432,7 @@  discard block
 block discarded – undo
448 432
      *
449 433
      * @api
450 434
      */
451
-    public function is_compatible_php()
452
-    {
435
+    public function is_compatible_php() {
453 436
         return version_compare($this->get_php_version(), self::$min_php_version, '>=');
454 437
     }
455 438
 
@@ -462,8 +445,7 @@  discard block
 block discarded – undo
462 445
      *
463 446
      * @api
464 447
      */
465
-    public function is_compatible_future_php()
466
-    {
448
+    public function is_compatible_future_php() {
467 449
         return version_compare($this->get_php_version(), self::$future_min_php_version, '>=');
468 450
     }
469 451
 
@@ -478,8 +460,7 @@  discard block
 block discarded – undo
478 460
      *
479 461
      * @api
480 462
      */
481
-    public function is_compatible_wordpress($version = null)
482
-    {
463
+    public function is_compatible_wordpress($version = null) {
483 464
         if (!$version) {
484 465
             $version = self::$min_wp_version;
485 466
         }
@@ -496,8 +477,7 @@  discard block
 block discarded – undo
496 477
      *
497 478
      * @api
498 479
      */
499
-    public function is_compatible_future_wordpress()
500
-    {
480
+    public function is_compatible_future_wordpress() {
501 481
         $version = $this->get_wordpress_version();
502 482
 
503 483
         return $version ? version_compare($version, self::$future_min_wp_version, '>=') : false;
@@ -512,8 +492,7 @@  discard block
 block discarded – undo
512 492
      *
513 493
      * @api
514 494
      */
515
-    public function is_compatible_gravityforms()
516
-    {
495
+    public function is_compatible_gravityforms() {
517 496
         $version = $this->get_gravityforms_version();
518 497
 
519 498
         return $version ? version_compare($version, self::$min_gf_version, '>=') : false;
@@ -528,8 +507,7 @@  discard block
 block discarded – undo
528 507
      *
529 508
      * @api
530 509
      */
531
-    public function is_compatible_future_gravityforms()
532
-    {
510
+    public function is_compatible_future_gravityforms() {
533 511
         $version = $this->get_gravityforms_version();
534 512
 
535 513
         return $version ? version_compare($version, self::$future_min_gf_version, '>=') : false;
@@ -542,8 +520,7 @@  discard block
 block discarded – undo
542 520
      *
543 521
      * @return string The version of PHP.
544 522
      */
545
-    private function get_php_version()
546
-    {
523
+    private function get_php_version() {
547 524
         return !empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE']) ?
548 525
             $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
549 526
     }
@@ -555,8 +532,7 @@  discard block
 block discarded – undo
555 532
      *
556 533
      * @return string The version of WordPress.
557 534
      */
558
-    private function get_wordpress_version()
559
-    {
535
+    private function get_wordpress_version() {
560 536
         return !empty($GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE']) ?
561 537
             $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version'];
562 538
     }
@@ -568,8 +544,7 @@  discard block
 block discarded – undo
568 544
      *
569 545
      * @return string|null The version of Gravity Forms or null if inactive.
570 546
      */
571
-    private function get_gravityforms_version()
572
-    {
547
+    private function get_gravityforms_version() {
573 548
         if (!class_exists('\GFCommon') || !empty($GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'])) {
574 549
             gravityview()->log->error('Gravity Forms is inactive or not installed.');
575 550
 
@@ -587,8 +562,7 @@  discard block
 block discarded – undo
587 562
      *
588 563
      * @return bool
589 564
      */
590
-    public function supports($feature)
591
-    {
565
+    public function supports($feature) {
592 566
         if (!is_null($supports = apply_filters("gravityview/plugin/feature/$feature", null))) {
593 567
             return $supports;
594 568
         }
@@ -611,8 +585,7 @@  discard block
 block discarded – undo
611 585
      *
612 586
      * @return void
613 587
      */
614
-    public function uninstall()
615
-    {
588
+    public function uninstall() {
616 589
         global $wpdb;
617 590
 
618 591
         $suppress = $wpdb->suppress_errors();
@@ -698,11 +671,9 @@  discard block
 block discarded – undo
698 671
         delete_site_transient('gravityview_related_plugins');
699 672
     }
700 673
 
701
-    public function __clone()
702
-    {
674
+    public function __clone() {
703 675
     }
704 676
 
705
-    public function __wakeup()
706
-    {
677
+    public function __wakeup() {
707 678
     }
708 679
 }
Please login to merge, or discard this patch.
future/includes/class-gv-template-view-legacy.php 3 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -14,42 +14,42 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class View_Legacy_Template extends View_Template
16 16
 {
17
-    /**
18
-     * Render an old template.
19
-     */
20
-    public function render()
21
-    {
22
-        if (!class_exists('GravityView_Template')) {
23
-            return;
24
-        }
17
+	/**
18
+	 * Render an old template.
19
+	 */
20
+	public function render()
21
+	{
22
+		if (!class_exists('GravityView_Template')) {
23
+			return;
24
+		}
25 25
 
26
-        $context = [
27
-            'view'    => $this->view,
28
-            'fields'  => $this->view->fields->by_visible($this->view),
29
-            'entries' => $this->entries,
30
-            'request' => $this->request,
31
-        ];
26
+		$context = [
27
+			'view'    => $this->view,
28
+			'fields'  => $this->view->fields->by_visible($this->view),
29
+			'entries' => $this->entries,
30
+			'request' => $this->request,
31
+		];
32 32
 
33
-        global $post;
33
+		global $post;
34 34
 
35
-        if ($post) {
36
-            $context['post'] = $post;
37
-        }
35
+		if ($post) {
36
+			$context['post'] = $post;
37
+		}
38 38
 
39
-        \GV\Mocks\Legacy_Context::push($context);
39
+		\GV\Mocks\Legacy_Context::push($context);
40 40
 
41
-        $sections = ['header', 'body', 'footer'];
41
+		$sections = ['header', 'body', 'footer'];
42 42
 
43
-        $sections = apply_filters('gravityview_render_view_sections', $sections, $this->view->settings->get('template'));
43
+		$sections = apply_filters('gravityview_render_view_sections', $sections, $this->view->settings->get('template'));
44 44
 
45
-        $template = \GravityView_View::getInstance();
45
+		$template = \GravityView_View::getInstance();
46 46
 
47
-        $slug = apply_filters('gravityview_template_slug_'.$this->view->settings->get('template'), 'table', 'directory');
47
+		$slug = apply_filters('gravityview_template_slug_'.$this->view->settings->get('template'), 'table', 'directory');
48 48
 
49
-        foreach ($sections as $section) {
50
-            $template->render($slug, $section, false);
51
-        }
49
+		foreach ($sections as $section) {
50
+			$template->render($slug, $section, false);
51
+		}
52 52
 
53
-        \GV\Mocks\Legacy_Context::pop();
54
-    }
53
+		\GV\Mocks\Legacy_Context::pop();
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -19,35 +19,35 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public function render()
21 21
     {
22
-        if (!class_exists('GravityView_Template')) {
22
+        if ( ! class_exists( 'GravityView_Template' ) ) {
23 23
             return;
24 24
         }
25 25
 
26 26
         $context = [
27 27
             'view'    => $this->view,
28
-            'fields'  => $this->view->fields->by_visible($this->view),
28
+            'fields'  => $this->view->fields->by_visible( $this->view ),
29 29
             'entries' => $this->entries,
30 30
             'request' => $this->request,
31 31
         ];
32 32
 
33 33
         global $post;
34 34
 
35
-        if ($post) {
36
-            $context['post'] = $post;
35
+        if ( $post ) {
36
+            $context[ 'post' ] = $post;
37 37
         }
38 38
 
39
-        \GV\Mocks\Legacy_Context::push($context);
39
+        \GV\Mocks\Legacy_Context::push( $context );
40 40
 
41
-        $sections = ['header', 'body', 'footer'];
41
+        $sections = [ 'header', 'body', 'footer' ];
42 42
 
43
-        $sections = apply_filters('gravityview_render_view_sections', $sections, $this->view->settings->get('template'));
43
+        $sections = apply_filters( 'gravityview_render_view_sections', $sections, $this->view->settings->get( 'template' ) );
44 44
 
45 45
         $template = \GravityView_View::getInstance();
46 46
 
47
-        $slug = apply_filters('gravityview_template_slug_'.$this->view->settings->get('template'), 'table', 'directory');
47
+        $slug = apply_filters( 'gravityview_template_slug_' . $this->view->settings->get( 'template' ), 'table', 'directory' );
48 48
 
49
-        foreach ($sections as $section) {
50
-            $template->render($slug, $section, false);
49
+        foreach ( $sections as $section ) {
50
+            $template->render( $slug, $section, false );
51 51
         }
52 52
 
53 53
         \GV\Mocks\Legacy_Context::pop();
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,13 +12,11 @@
 block discarded – undo
12 12
  *
13 13
  * Can be used to render old templates as needed.
14 14
  */
15
-class View_Legacy_Template extends View_Template
16
-{
15
+class View_Legacy_Template extends View_Template {
17 16
     /**
18 17
      * Render an old template.
19 18
      */
20
-    public function render()
21
-    {
19
+    public function render() {
22 20
         if (!class_exists('GravityView_Template')) {
23 21
             return;
24 22
         }
Please login to merge, or discard this patch.
future/includes/class-gv-collection-entry-filter-gravityforms.php 3 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -14,82 +14,82 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GF_Entry_Filter extends Entry_Filter
16 16
 {
17
-    /**
18
-     * @var array The array used by Gravity Forms
19
-     */
20
-    private $search_criteria = [];
17
+	/**
18
+	 * @var array The array used by Gravity Forms
19
+	 */
20
+	private $search_criteria = [];
21 21
 
22
-    /**
23
-     * Create a filter from this criteria.
24
-     *
25
-     * @param array $search_criteria The Gravity Forms search criteria.
26
-     *
27
-     * @see GFAPI::search_entries
28
-     *
29
-     * @return \GV\GF_Entry_Filter The filter.
30
-     */
31
-    public static function from_search_criteria($search_criteria)
32
-    {
33
-        $filter = new self();
34
-        $filter->search_criteria = $search_criteria;
22
+	/**
23
+	 * Create a filter from this criteria.
24
+	 *
25
+	 * @param array $search_criteria The Gravity Forms search criteria.
26
+	 *
27
+	 * @see GFAPI::search_entries
28
+	 *
29
+	 * @return \GV\GF_Entry_Filter The filter.
30
+	 */
31
+	public static function from_search_criteria($search_criteria)
32
+	{
33
+		$filter = new self();
34
+		$filter->search_criteria = $search_criteria;
35 35
 
36
-        return $filter;
37
-    }
36
+		return $filter;
37
+	}
38 38
 
39
-    /**
40
-     * Merge two search criteria arrays.
41
-     *
42
-     * If two values collide, $b always wins.
43
-     *
44
-     * @param array $a One Gravity Forms search criteria.
45
-     * @param array $a Another Gravity Forms search criteria.
46
-     *
47
-     * @see GFAPI::search_entries
48
-     *
49
-     * @return array Merged search criteria.
50
-     */
51
-    public static function merge_search_criteria($a, $b)
52
-    {
53
-        $search_criteria = [];
39
+	/**
40
+	 * Merge two search criteria arrays.
41
+	 *
42
+	 * If two values collide, $b always wins.
43
+	 *
44
+	 * @param array $a One Gravity Forms search criteria.
45
+	 * @param array $a Another Gravity Forms search criteria.
46
+	 *
47
+	 * @see GFAPI::search_entries
48
+	 *
49
+	 * @return array Merged search criteria.
50
+	 */
51
+	public static function merge_search_criteria($a, $b)
52
+	{
53
+		$search_criteria = [];
54 54
 
55
-        foreach (['field_filters', 'start_date', 'end_date', 'status'] as $key) {
56
-            switch ($key) {
57
-                case 'field_filters':
58
-                    $field_filters = array_merge(empty($a[$key]) ? [] : $a[$key], empty($b[$key]) ? [] : $b[$key]);
59
-                    if (!empty($field_filters)) {
60
-                        $search_criteria[$key] = $field_filters;
61
-                    }
55
+		foreach (['field_filters', 'start_date', 'end_date', 'status'] as $key) {
56
+			switch ($key) {
57
+				case 'field_filters':
58
+					$field_filters = array_merge(empty($a[$key]) ? [] : $a[$key], empty($b[$key]) ? [] : $b[$key]);
59
+					if (!empty($field_filters)) {
60
+						$search_criteria[$key] = $field_filters;
61
+					}
62 62
 
63
-                    if (!empty($b[$key]['mode'])) {
64
-                        $search_criteria[$key]['mode'] = $b[$key]['mode'];
65
-                    } elseif (!empty($a[$key]['mode'])) {
66
-                        $search_criteria[$key]['mode'] = $a[$key]['mode'];
67
-                    }
68
-                    break;
69
-                case 'start_date':
70
-                case 'end_date':
71
-                case 'status':
72
-                    if (isset($b[$key])) {
73
-                        $search_criteria[$key] = $b[$key];
74
-                    } elseif (isset($a[$key])) {
75
-                        $search_criteria[$key] = $a[$key];
76
-                    }
77
-                    break;
78
-            }
79
-        }
63
+					if (!empty($b[$key]['mode'])) {
64
+						$search_criteria[$key]['mode'] = $b[$key]['mode'];
65
+					} elseif (!empty($a[$key]['mode'])) {
66
+						$search_criteria[$key]['mode'] = $a[$key]['mode'];
67
+					}
68
+					break;
69
+				case 'start_date':
70
+				case 'end_date':
71
+				case 'status':
72
+					if (isset($b[$key])) {
73
+						$search_criteria[$key] = $b[$key];
74
+					} elseif (isset($a[$key])) {
75
+						$search_criteria[$key] = $a[$key];
76
+					}
77
+					break;
78
+			}
79
+		}
80 80
 
81
-        return $search_criteria;
82
-    }
81
+		return $search_criteria;
82
+	}
83 83
 
84
-    /**
85
-     * Get the $search_criteria.
86
-     *
87
-     * @see GFAPI::search_entries
88
-     *
89
-     * @return array $search_criteria The Gravity Forms search criteria.
90
-     */
91
-    public function as_search_criteria()
92
-    {
93
-        return $this->search_criteria;
94
-    }
84
+	/**
85
+	 * Get the $search_criteria.
86
+	 *
87
+	 * @see GFAPI::search_entries
88
+	 *
89
+	 * @return array $search_criteria The Gravity Forms search criteria.
90
+	 */
91
+	public function as_search_criteria()
92
+	{
93
+		return $this->search_criteria;
94
+	}
95 95
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @var array The array used by Gravity Forms
19 19
      */
20
-    private $search_criteria = [];
20
+    private $search_criteria = [ ];
21 21
 
22 22
     /**
23 23
      * Create a filter from this criteria.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @return \GV\GF_Entry_Filter The filter.
30 30
      */
31
-    public static function from_search_criteria($search_criteria)
31
+    public static function from_search_criteria( $search_criteria )
32 32
     {
33 33
         $filter = new self();
34 34
         $filter->search_criteria = $search_criteria;
@@ -48,31 +48,31 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @return array Merged search criteria.
50 50
      */
51
-    public static function merge_search_criteria($a, $b)
51
+    public static function merge_search_criteria( $a, $b )
52 52
     {
53
-        $search_criteria = [];
53
+        $search_criteria = [ ];
54 54
 
55
-        foreach (['field_filters', 'start_date', 'end_date', 'status'] as $key) {
56
-            switch ($key) {
55
+        foreach ( [ 'field_filters', 'start_date', 'end_date', 'status' ] as $key ) {
56
+            switch ( $key ) {
57 57
                 case 'field_filters':
58
-                    $field_filters = array_merge(empty($a[$key]) ? [] : $a[$key], empty($b[$key]) ? [] : $b[$key]);
59
-                    if (!empty($field_filters)) {
60
-                        $search_criteria[$key] = $field_filters;
58
+                    $field_filters = array_merge( empty( $a[ $key ] ) ? [ ] : $a[ $key ], empty( $b[ $key ] ) ? [ ] : $b[ $key ] );
59
+                    if ( ! empty( $field_filters ) ) {
60
+                        $search_criteria[ $key ] = $field_filters;
61 61
                     }
62 62
 
63
-                    if (!empty($b[$key]['mode'])) {
64
-                        $search_criteria[$key]['mode'] = $b[$key]['mode'];
65
-                    } elseif (!empty($a[$key]['mode'])) {
66
-                        $search_criteria[$key]['mode'] = $a[$key]['mode'];
63
+                    if ( ! empty( $b[ $key ][ 'mode' ] ) ) {
64
+                        $search_criteria[ $key ][ 'mode' ] = $b[ $key ][ 'mode' ];
65
+                    } elseif ( ! empty( $a[ $key ][ 'mode' ] ) ) {
66
+                        $search_criteria[ $key ][ 'mode' ] = $a[ $key ][ 'mode' ];
67 67
                     }
68 68
                     break;
69 69
                 case 'start_date':
70 70
                 case 'end_date':
71 71
                 case 'status':
72
-                    if (isset($b[$key])) {
73
-                        $search_criteria[$key] = $b[$key];
74
-                    } elseif (isset($a[$key])) {
75
-                        $search_criteria[$key] = $a[$key];
72
+                    if ( isset( $b[ $key ] ) ) {
73
+                        $search_criteria[ $key ] = $b[ $key ];
74
+                    } elseif ( isset( $a[ $key ] ) ) {
75
+                        $search_criteria[ $key ] = $a[ $key ];
76 76
                     }
77 77
                     break;
78 78
             }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * The good old $search_criteria in object form.
14 14
  */
15
-class GF_Entry_Filter extends Entry_Filter
16
-{
15
+class GF_Entry_Filter extends Entry_Filter {
17 16
     /**
18 17
      * @var array The array used by Gravity Forms
19 18
      */
@@ -28,8 +27,7 @@  discard block
 block discarded – undo
28 27
      *
29 28
      * @return \GV\GF_Entry_Filter The filter.
30 29
      */
31
-    public static function from_search_criteria($search_criteria)
32
-    {
30
+    public static function from_search_criteria($search_criteria) {
33 31
         $filter = new self();
34 32
         $filter->search_criteria = $search_criteria;
35 33
 
@@ -48,8 +46,7 @@  discard block
 block discarded – undo
48 46
      *
49 47
      * @return array Merged search criteria.
50 48
      */
51
-    public static function merge_search_criteria($a, $b)
52
-    {
49
+    public static function merge_search_criteria($a, $b) {
53 50
         $search_criteria = [];
54 51
 
55 52
         foreach (['field_filters', 'start_date', 'end_date', 'status'] as $key) {
@@ -88,8 +85,7 @@  discard block
 block discarded – undo
88 85
      *
89 86
      * @return array $search_criteria The Gravity Forms search criteria.
90 87
      */
91
-    public function as_search_criteria()
92
-    {
88
+    public function as_search_criteria() {
93 89
         return $this->search_criteria;
94 90
     }
95 91
 }
Please login to merge, or discard this patch.