Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Review.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -12,173 +12,173 @@
 block discarded – undo
12 12
 
13 13
 class Review implements \ArrayAccess
14 14
 {
15
-    public $assigned_to;
16
-    public $author;
17
-    public $avatar;
18
-    public $content;
19
-    public $custom;
20
-    public $date;
21
-    public $email;
22
-    public $ID;
23
-    public $ip_address;
24
-    public $modified;
25
-    public $pinned;
26
-    public $rating;
27
-    public $response;
28
-    public $review_id;
29
-    public $review_type;
30
-    public $status;
31
-    public $term_ids;
32
-    public $title;
33
-    public $url;
34
-    public $user_id;
15
+	public $assigned_to;
16
+	public $author;
17
+	public $avatar;
18
+	public $content;
19
+	public $custom;
20
+	public $date;
21
+	public $email;
22
+	public $ID;
23
+	public $ip_address;
24
+	public $modified;
25
+	public $pinned;
26
+	public $rating;
27
+	public $response;
28
+	public $review_id;
29
+	public $review_type;
30
+	public $status;
31
+	public $term_ids;
32
+	public $title;
33
+	public $url;
34
+	public $user_id;
35 35
 
36
-    public function __construct(WP_Post $post)
37
-    {
38
-        if (Application::POST_TYPE != $post->post_type) {
39
-            return;
40
-        }
41
-        $this->content = $post->post_content;
42
-        $this->date = $post->post_date;
43
-        $this->ID = intval($post->ID);
44
-        $this->status = $post->post_status;
45
-        $this->title = $post->post_title;
46
-        $this->user_id = intval($post->post_author);
47
-        $this->setProperties($post);
48
-        $this->setTermIds($post);
49
-    }
36
+	public function __construct(WP_Post $post)
37
+	{
38
+		if (Application::POST_TYPE != $post->post_type) {
39
+			return;
40
+		}
41
+		$this->content = $post->post_content;
42
+		$this->date = $post->post_date;
43
+		$this->ID = intval($post->ID);
44
+		$this->status = $post->post_status;
45
+		$this->title = $post->post_title;
46
+		$this->user_id = intval($post->post_author);
47
+		$this->setProperties($post);
48
+		$this->setTermIds($post);
49
+	}
50 50
 
51
-    /**
52
-     * @return mixed
53
-     */
54
-    public function __get($key)
55
-    {
56
-        return $this->offsetGet($key);
57
-    }
51
+	/**
52
+	 * @return mixed
53
+	 */
54
+	public function __get($key)
55
+	{
56
+		return $this->offsetGet($key);
57
+	}
58 58
 
59
-    /**
60
-     * @return string
61
-     */
62
-    public function __toString()
63
-    {
64
-        return (string) $this->build();
65
-    }
59
+	/**
60
+	 * @return string
61
+	 */
62
+	public function __toString()
63
+	{
64
+		return (string) $this->build();
65
+	}
66 66
 
67
-    /**
68
-     * @return ReviewHtml
69
-     */
70
-    public function build(array $args = [])
71
-    {
72
-        if (empty($this->ID)) {
73
-            return new ReviewHtml($this);
74
-        }
75
-        $partial = glsr(SiteReviewsPartial::class);
76
-        $partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
-        $partial->options = Arr::flatten(glsr(OptionManager::class)->all());
78
-        return $partial->buildReview($this);
79
-    }
67
+	/**
68
+	 * @return ReviewHtml
69
+	 */
70
+	public function build(array $args = [])
71
+	{
72
+		if (empty($this->ID)) {
73
+			return new ReviewHtml($this);
74
+		}
75
+		$partial = glsr(SiteReviewsPartial::class);
76
+		$partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
+		$partial->options = Arr::flatten(glsr(OptionManager::class)->all());
78
+		return $partial->buildReview($this);
79
+	}
80 80
 
81
-    /**
82
-     * @param mixed $key
83
-     * @return bool
84
-     */
85
-    public function offsetExists($key)
86
-    {
87
-        return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
88
-    }
81
+	/**
82
+	 * @param mixed $key
83
+	 * @return bool
84
+	 */
85
+	public function offsetExists($key)
86
+	{
87
+		return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
88
+	}
89 89
 
90
-    /**
91
-     * @param mixed $key
92
-     * @return mixed
93
-     */
94
-    public function offsetGet($key)
95
-    {
96
-        return property_exists($this, $key)
97
-            ? $this->$key
98
-            : Arr::get($this->custom, $key, null);
99
-    }
90
+	/**
91
+	 * @param mixed $key
92
+	 * @return mixed
93
+	 */
94
+	public function offsetGet($key)
95
+	{
96
+		return property_exists($this, $key)
97
+			? $this->$key
98
+			: Arr::get($this->custom, $key, null);
99
+	}
100 100
 
101
-    /**
102
-     * @param mixed $key
103
-     * @param mixed $value
104
-     * @return void
105
-     */
106
-    public function offsetSet($key, $value)
107
-    {
108
-        if (property_exists($this, $key)) {
109
-            $this->$key = $value;
110
-            return;
111
-        }
112
-        if (!is_array($this->custom)) {
113
-            $this->custom = array_filter((array) $this->custom);
114
-        }
115
-        $this->custom[$key] = $value;
116
-    }
101
+	/**
102
+	 * @param mixed $key
103
+	 * @param mixed $value
104
+	 * @return void
105
+	 */
106
+	public function offsetSet($key, $value)
107
+	{
108
+		if (property_exists($this, $key)) {
109
+			$this->$key = $value;
110
+			return;
111
+		}
112
+		if (!is_array($this->custom)) {
113
+			$this->custom = array_filter((array) $this->custom);
114
+		}
115
+		$this->custom[$key] = $value;
116
+	}
117 117
 
118
-    /**
119
-     * @param mixed $key
120
-     * @return void
121
-     */
122
-    public function offsetUnset($key)
123
-    {
124
-        $this->offsetSet($key, null);
125
-    }
118
+	/**
119
+	 * @param mixed $key
120
+	 * @return void
121
+	 */
122
+	public function offsetUnset($key)
123
+	{
124
+		$this->offsetSet($key, null);
125
+	}
126 126
 
127
-    /**
128
-     * @return void
129
-     */
130
-    public function render()
131
-    {
132
-        echo $this->build();
133
-    }
127
+	/**
128
+	 * @return void
129
+	 */
130
+	public function render()
131
+	{
132
+		echo $this->build();
133
+	}
134 134
 
135
-    /**
136
-     * @return bool
137
-     */
138
-    protected function isModified(array $properties)
139
-    {
140
-        return $this->date != $properties['date']
141
-            || $this->content != $properties['content']
142
-            || $this->title != $properties['title'];
143
-    }
135
+	/**
136
+	 * @return bool
137
+	 */
138
+	protected function isModified(array $properties)
139
+	{
140
+		return $this->date != $properties['date']
141
+			|| $this->content != $properties['content']
142
+			|| $this->title != $properties['title'];
143
+	}
144 144
 
145
-    /**
146
-     * @return void
147
-     */
148
-    protected function setProperties(WP_Post $post)
149
-    {
150
-        $defaults = [
151
-            'author' => __('Anonymous', 'site-reviews'),
152
-            'date' => '',
153
-            'review_id' => '',
154
-            'review_type' => 'local',
155
-        ];
156
-        $meta = array_filter(
157
-            array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
158
-            'strlen'
159
-        );
160
-        $meta = array_merge($defaults, Arr::unprefixKeys($meta));
161
-        $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
-        $this->modified = $this->isModified($properties);
163
-        array_walk($properties, function ($value, $key) {
164
-            if (!property_exists($this, $key) || isset($this->$key)) {
165
-                return;
166
-            }
167
-            $this->$key = maybe_unserialize($value);
168
-        });
169
-    }
145
+	/**
146
+	 * @return void
147
+	 */
148
+	protected function setProperties(WP_Post $post)
149
+	{
150
+		$defaults = [
151
+			'author' => __('Anonymous', 'site-reviews'),
152
+			'date' => '',
153
+			'review_id' => '',
154
+			'review_type' => 'local',
155
+		];
156
+		$meta = array_filter(
157
+			array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
158
+			'strlen'
159
+		);
160
+		$meta = array_merge($defaults, Arr::unprefixKeys($meta));
161
+		$properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
+		$this->modified = $this->isModified($properties);
163
+		array_walk($properties, function ($value, $key) {
164
+			if (!property_exists($this, $key) || isset($this->$key)) {
165
+				return;
166
+			}
167
+			$this->$key = maybe_unserialize($value);
168
+		});
169
+	}
170 170
 
171
-    /**
172
-     * @return void
173
-     */
174
-    protected function setTermIds(WP_Post $post)
175
-    {
176
-        $this->term_ids = [];
177
-        if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
178
-            return;
179
-        }
180
-        foreach ($terms as $term) {
181
-            $this->term_ids[] = $term->term_id;
182
-        }
183
-    }
171
+	/**
172
+	 * @return void
173
+	 */
174
+	protected function setTermIds(WP_Post $post)
175
+	{
176
+		$this->term_ids = [];
177
+		if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
178
+			return;
179
+		}
180
+		foreach ($terms as $term) {
181
+			$this->term_ids[] = $term->term_id;
182
+		}
183
+	}
184 184
 }
Please login to merge, or discard this patch.
plugin/Database/QueryBuilder.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,190 +12,190 @@
 block discarded – undo
12 12
 
13 13
 class QueryBuilder
14 14
 {
15
-    /**
16
-     * Build a WP_Query meta_query/tax_query.
17
-     * @return array
18
-     */
19
-    public function buildQuery(array $keys = [], array $values = [])
20
-    {
21
-        $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
24
-                continue;
25
-            }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
28
-                continue;
29
-            }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
32
-                $queries[] = $query;
33
-            }
34
-        }
35
-        return $queries;
36
-    }
15
+	/**
16
+	 * Build a WP_Query meta_query/tax_query.
17
+	 * @return array
18
+	 */
19
+	public function buildQuery(array $keys = [], array $values = [])
20
+	{
21
+		$queries = [];
22
+		foreach ($keys as $key) {
23
+			if (!array_key_exists($key, $values)) {
24
+				continue;
25
+			}
26
+			$methodName = Helper::buildMethodName($key, __FUNCTION__);
27
+			if (!method_exists($this, $methodName)) {
28
+				continue;
29
+			}
30
+			$query = call_user_func([$this, $methodName], $values[$key]);
31
+			if (is_array($query)) {
32
+				$queries[] = $query;
33
+			}
34
+		}
35
+		return $queries;
36
+	}
37 37
 
38
-    /**
39
-     * @return string
40
-     */
41
-    public function buildSqlLines(array $values, array $conditions)
42
-    {
43
-        $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
47
-                continue;
48
-            }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
52
-                : $value;
53
-        }
54
-        return $string;
55
-    }
38
+	/**
39
+	 * @return string
40
+	 */
41
+	public function buildSqlLines(array $values, array $conditions)
42
+	{
43
+		$string = '';
44
+		$values = array_filter($values);
45
+		foreach ($conditions as $key => $value) {
46
+			if (!isset($values[$key])) {
47
+				continue;
48
+			}
49
+			$values[$key] = implode(',', (array) $values[$key]);
50
+			$string.= Str::contains($value, '%s')
51
+				? sprintf($value, strval($values[$key]))
52
+				: $value;
53
+		}
54
+		return $string;
55
+	}
56 56
 
57
-    /**
58
-     * Build a SQL 'OR' string from an array.
59
-     * @param string|array $values
60
-     * @param string $sprintfFormat
61
-     * @return string
62
-     */
63
-    public function buildSqlOr($values, $sprintfFormat)
64
-    {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
67
-        }
68
-        $values = array_filter(array_map('trim', (array) $values));
69
-        $values = array_map(function ($value) use ($sprintfFormat) {
70
-            return sprintf($sprintfFormat, $value);
71
-        }, $values);
72
-        return implode(' OR ', $values);
73
-    }
57
+	/**
58
+	 * Build a SQL 'OR' string from an array.
59
+	 * @param string|array $values
60
+	 * @param string $sprintfFormat
61
+	 * @return string
62
+	 */
63
+	public function buildSqlOr($values, $sprintfFormat)
64
+	{
65
+		if (!is_array($values)) {
66
+			$values = explode(',', $values);
67
+		}
68
+		$values = array_filter(array_map('trim', (array) $values));
69
+		$values = array_map(function ($value) use ($sprintfFormat) {
70
+			return sprintf($sprintfFormat, $value);
71
+		}, $values);
72
+		return implode(' OR ', $values);
73
+	}
74 74
 
75
-    /**
76
-     * Search SQL filter for matching against post title only.
77
-     * @see http://wordpress.stackexchange.com/a/11826/1685
78
-     * @param string $search
79
-     * @return string
80
-     * @filter posts_search
81
-     */
82
-    public function filterSearchByTitle($search, WP_Query $query)
83
-    {
84
-        if (empty($search) || empty($query->get('search_terms'))) {
85
-            return $search;
86
-        }
87
-        global $wpdb;
88
-        $n = empty($query->get('exact'))
89
-            ? '%'
90
-            : '';
91
-        $search = [];
92
-        foreach ((array) $query->get('search_terms') as $term) {
93
-            $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
94
-        }
95
-        if (!is_user_logged_in()) {
96
-            $search[] = "{$wpdb->posts}.post_password = ''";
97
-        }
98
-        return ' AND '.implode(' AND ', $search);
99
-    }
75
+	/**
76
+	 * Search SQL filter for matching against post title only.
77
+	 * @see http://wordpress.stackexchange.com/a/11826/1685
78
+	 * @param string $search
79
+	 * @return string
80
+	 * @filter posts_search
81
+	 */
82
+	public function filterSearchByTitle($search, WP_Query $query)
83
+	{
84
+		if (empty($search) || empty($query->get('search_terms'))) {
85
+			return $search;
86
+		}
87
+		global $wpdb;
88
+		$n = empty($query->get('exact'))
89
+			? '%'
90
+			: '';
91
+		$search = [];
92
+		foreach ((array) $query->get('search_terms') as $term) {
93
+			$search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
94
+		}
95
+		if (!is_user_logged_in()) {
96
+			$search[] = "{$wpdb->posts}.post_password = ''";
97
+		}
98
+		return ' AND '.implode(' AND ', $search);
99
+	}
100 100
 
101
-    /**
102
-     * Get the current page number from the global query.
103
-     * @param bool $isEnabled
104
-     * @return int
105
-     */
106
-    public function getPaged($isEnabled = true)
107
-    {
108
-        return $isEnabled
109
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
-            : 1;
111
-    }
101
+	/**
102
+	 * Get the current page number from the global query.
103
+	 * @param bool $isEnabled
104
+	 * @return int
105
+	 */
106
+	public function getPaged($isEnabled = true)
107
+	{
108
+		return $isEnabled
109
+			? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
+			: 1;
111
+	}
112 112
 
113
-    /**
114
-     * @param string $value
115
-     * @return void|array
116
-     */
117
-    protected function buildQueryAssignedTo($value)
118
-    {
119
-        if (!empty($value)) {
120
-            $postIds = Arr::convertFromString($value, 'is_numeric');
121
-            return [
122
-                'compare' => 'IN',
123
-                'key' => '_assigned_to',
124
-                'value' => glsr(Multilingual::class)->getPostIds($postIds),
125
-            ];
126
-        }
127
-    }
113
+	/**
114
+	 * @param string $value
115
+	 * @return void|array
116
+	 */
117
+	protected function buildQueryAssignedTo($value)
118
+	{
119
+		if (!empty($value)) {
120
+			$postIds = Arr::convertFromString($value, 'is_numeric');
121
+			return [
122
+				'compare' => 'IN',
123
+				'key' => '_assigned_to',
124
+				'value' => glsr(Multilingual::class)->getPostIds($postIds),
125
+			];
126
+		}
127
+	}
128 128
 
129
-    /**
130
-     * @param array $value
131
-     * @return void|array
132
-     */
133
-    protected function buildQueryCategory($value)
134
-    {
135
-        if (!empty($value)) {
136
-            return [
137
-                'field' => 'term_id',
138
-                'taxonomy' => Application::TAXONOMY,
139
-                'terms' => $value,
140
-            ];
141
-        }
142
-    }
129
+	/**
130
+	 * @param array $value
131
+	 * @return void|array
132
+	 */
133
+	protected function buildQueryCategory($value)
134
+	{
135
+		if (!empty($value)) {
136
+			return [
137
+				'field' => 'term_id',
138
+				'taxonomy' => Application::TAXONOMY,
139
+				'terms' => $value,
140
+			];
141
+		}
142
+	}
143 143
 
144
-    /**
145
-     * @param string $value
146
-     * @return void|array
147
-     */
148
-    protected function buildQueryEmail($value)
149
-    {
150
-        if (!empty($value)) {
151
-            return [
152
-                'key' => '_email',
153
-                'value' => $value,
154
-            ];
155
-        }
156
-    }
144
+	/**
145
+	 * @param string $value
146
+	 * @return void|array
147
+	 */
148
+	protected function buildQueryEmail($value)
149
+	{
150
+		if (!empty($value)) {
151
+			return [
152
+				'key' => '_email',
153
+				'value' => $value,
154
+			];
155
+		}
156
+	}
157 157
 
158
-    /**
159
-     * @param string $value
160
-     * @return void|array
161
-     */
162
-    protected function buildQueryIpAddress($value)
163
-    {
164
-        if (!empty($value)) {
165
-            return [
166
-                'key' => '_ip_address',
167
-                'value' => $value,
168
-            ];
169
-        }
170
-    }
158
+	/**
159
+	 * @param string $value
160
+	 * @return void|array
161
+	 */
162
+	protected function buildQueryIpAddress($value)
163
+	{
164
+		if (!empty($value)) {
165
+			return [
166
+				'key' => '_ip_address',
167
+				'value' => $value,
168
+			];
169
+		}
170
+	}
171 171
 
172
-    /**
173
-     * @param string $value
174
-     * @return void|array
175
-     */
176
-    protected function buildQueryRating($value)
177
-    {
178
-        if (is_numeric($value)
179
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
-            return [
181
-                'compare' => '>=',
182
-                'key' => '_rating',
183
-                'value' => $value,
184
-            ];
185
-        }
186
-    }
172
+	/**
173
+	 * @param string $value
174
+	 * @return void|array
175
+	 */
176
+	protected function buildQueryRating($value)
177
+	{
178
+		if (is_numeric($value)
179
+			&& in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
+			return [
181
+				'compare' => '>=',
182
+				'key' => '_rating',
183
+				'value' => $value,
184
+			];
185
+		}
186
+	}
187 187
 
188
-    /**
189
-     * @param string $value
190
-     * @return void|array
191
-     */
192
-    protected function buildQueryType($value)
193
-    {
194
-        if (!in_array($value, ['', 'all'])) {
195
-            return [
196
-                'key' => '_review_type',
197
-                'value' => $value,
198
-            ];
199
-        }
200
-    }
188
+	/**
189
+	 * @param string $value
190
+	 * @return void|array
191
+	 */
192
+	protected function buildQueryType($value)
193
+	{
194
+		if (!in_array($value, ['', 'all'])) {
195
+			return [
196
+				'key' => '_review_type',
197
+				'value' => $value,
198
+			];
199
+		}
200
+	}
201 201
 }
Please login to merge, or discard this patch.
plugin/Database/ReviewManager.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -16,204 +16,204 @@
 block discarded – undo
16 16
 
17 17
 class ReviewManager
18 18
 {
19
-    /**
20
-     * @return false|Review
21
-     */
22
-    public function create(CreateReview $command)
23
-    {
24
-        $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
25
-        $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
26
-        $reviewValues = Arr::prefixKeys($reviewValues);
27
-        unset($reviewValues['json']); // @todo remove the need for this
28
-        $postValues = [
29
-            'comment_status' => 'closed',
30
-            'meta_input' => $reviewValues,
31
-            'ping_status' => 'closed',
32
-            'post_content' => $reviewValues['_content'],
33
-            'post_date' => $reviewValues['_date'],
34
-            'post_date_gmt' => get_gmt_from_date($reviewValues['_date']),
35
-            'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'],
36
-            'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
37
-            'post_title' => $reviewValues['_title'],
38
-            'post_type' => Application::POST_TYPE,
39
-        ];
40
-        $postId = wp_insert_post($postValues, true);
41
-        if (is_wp_error($postId)) {
42
-            glsr_log()->error($postId->get_error_message())->debug($postValues);
43
-            return false;
44
-        }
45
-        $this->setTerms($postId, $command->category);
46
-        $review = $this->single(get_post($postId));
47
-        do_action('site-reviews/review/created', $review, $command);
48
-        return $review;
49
-    }
19
+	/**
20
+	 * @return false|Review
21
+	 */
22
+	public function create(CreateReview $command)
23
+	{
24
+		$reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
25
+		$reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
26
+		$reviewValues = Arr::prefixKeys($reviewValues);
27
+		unset($reviewValues['json']); // @todo remove the need for this
28
+		$postValues = [
29
+			'comment_status' => 'closed',
30
+			'meta_input' => $reviewValues,
31
+			'ping_status' => 'closed',
32
+			'post_content' => $reviewValues['_content'],
33
+			'post_date' => $reviewValues['_date'],
34
+			'post_date_gmt' => get_gmt_from_date($reviewValues['_date']),
35
+			'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'],
36
+			'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
37
+			'post_title' => $reviewValues['_title'],
38
+			'post_type' => Application::POST_TYPE,
39
+		];
40
+		$postId = wp_insert_post($postValues, true);
41
+		if (is_wp_error($postId)) {
42
+			glsr_log()->error($postId->get_error_message())->debug($postValues);
43
+			return false;
44
+		}
45
+		$this->setTerms($postId, $command->category);
46
+		$review = $this->single(get_post($postId));
47
+		do_action('site-reviews/review/created', $review, $command);
48
+		return $review;
49
+	}
50 50
 
51
-    /**
52
-     * @param string $metaReviewId
53
-     * @return void
54
-     */
55
-    public function delete($metaReviewId)
56
-    {
57
-        if ($postId = $this->getPostId($metaReviewId)) {
58
-            wp_delete_post($postId, true);
59
-        }
60
-    }
51
+	/**
52
+	 * @param string $metaReviewId
53
+	 * @return void
54
+	 */
55
+	public function delete($metaReviewId)
56
+	{
57
+		if ($postId = $this->getPostId($metaReviewId)) {
58
+			wp_delete_post($postId, true);
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * @return object
64
-     */
65
-    public function get(array $args = [])
66
-    {
67
-        $args = glsr(ReviewsDefaults::class)->merge($args);
68
-        $metaQuery = glsr(QueryBuilder::class)->buildQuery(
69
-            ['assigned_to', 'email', 'ip_address', 'type', 'rating'],
70
-            $args
71
-        );
72
-        $taxQuery = glsr(QueryBuilder::class)->buildQuery(
73
-            ['category'],
74
-            ['category' => $this->normalizeTermIds($args['category'])]
75
-        );
76
-        $paged = glsr(QueryBuilder::class)->getPaged(
77
-            wp_validate_boolean($args['pagination'])
78
-        );
79
-        $parameters = [
80
-            'meta_key' => '_pinned',
81
-            'meta_query' => $metaQuery,
82
-            'offset' => $args['offset'],
83
-            'order' => $args['order'],
84
-            'orderby' => 'meta_value '.$args['orderby'],
85
-            'paged' => Arr::get($args, 'paged', $paged),
86
-            'post__in' => $args['post__in'],
87
-            'post__not_in' => $args['post__not_in'],
88
-            'post_status' => 'publish',
89
-            'post_type' => Application::POST_TYPE,
90
-            'posts_per_page' => $args['per_page'],
91
-            'tax_query' => $taxQuery,
92
-        ];
93
-        $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
94
-        $query = new WP_Query($parameters);
95
-        $results = array_map([$this, 'single'], $query->posts);
96
-        $reviews = new Reviews($results, $query->max_num_pages, $args);
97
-        return apply_filters('site-reviews/get/reviews', $reviews, $query);
98
-    }
62
+	/**
63
+	 * @return object
64
+	 */
65
+	public function get(array $args = [])
66
+	{
67
+		$args = glsr(ReviewsDefaults::class)->merge($args);
68
+		$metaQuery = glsr(QueryBuilder::class)->buildQuery(
69
+			['assigned_to', 'email', 'ip_address', 'type', 'rating'],
70
+			$args
71
+		);
72
+		$taxQuery = glsr(QueryBuilder::class)->buildQuery(
73
+			['category'],
74
+			['category' => $this->normalizeTermIds($args['category'])]
75
+		);
76
+		$paged = glsr(QueryBuilder::class)->getPaged(
77
+			wp_validate_boolean($args['pagination'])
78
+		);
79
+		$parameters = [
80
+			'meta_key' => '_pinned',
81
+			'meta_query' => $metaQuery,
82
+			'offset' => $args['offset'],
83
+			'order' => $args['order'],
84
+			'orderby' => 'meta_value '.$args['orderby'],
85
+			'paged' => Arr::get($args, 'paged', $paged),
86
+			'post__in' => $args['post__in'],
87
+			'post__not_in' => $args['post__not_in'],
88
+			'post_status' => 'publish',
89
+			'post_type' => Application::POST_TYPE,
90
+			'posts_per_page' => $args['per_page'],
91
+			'tax_query' => $taxQuery,
92
+		];
93
+		$parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
94
+		$query = new WP_Query($parameters);
95
+		$results = array_map([$this, 'single'], $query->posts);
96
+		$reviews = new Reviews($results, $query->max_num_pages, $args);
97
+		return apply_filters('site-reviews/get/reviews', $reviews, $query);
98
+	}
99 99
 
100
-    /**
101
-     * @param string $metaReviewId
102
-     * @return int
103
-     */
104
-    public function getPostId($metaReviewId)
105
-    {
106
-        return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
107
-    }
100
+	/**
101
+	 * @param string $metaReviewId
102
+	 * @return int
103
+	 */
104
+	public function getPostId($metaReviewId)
105
+	{
106
+		return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
107
+	}
108 108
 
109
-    /**
110
-     * @return array
111
-     */
112
-    public function getRatingCounts(array $args = [])
113
-    {
114
-        $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
115
-        $counts = glsr(CountsManager::class)->getCounts([
116
-            'post_ids' => Arr::convertFromString($args['assigned_to']),
117
-            'term_ids' => $this->normalizeTermIds($args['category']),
118
-            'type' => $args['type'],
119
-        ]);
120
-        return glsr(CountsManager::class)->flatten($counts, [
121
-            'min' => $args['rating'],
122
-        ]);
123
-    }
109
+	/**
110
+	 * @return array
111
+	 */
112
+	public function getRatingCounts(array $args = [])
113
+	{
114
+		$args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
115
+		$counts = glsr(CountsManager::class)->getCounts([
116
+			'post_ids' => Arr::convertFromString($args['assigned_to']),
117
+			'term_ids' => $this->normalizeTermIds($args['category']),
118
+			'type' => $args['type'],
119
+		]);
120
+		return glsr(CountsManager::class)->flatten($counts, [
121
+			'min' => $args['rating'],
122
+		]);
123
+	}
124 124
 
125
-    /**
126
-     * @param string $commaSeparatedTermIds
127
-     * @return array
128
-     */
129
-    public function normalizeTermIds($commaSeparatedTermIds)
130
-    {
131
-        $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
132
-        return array_unique(array_map('intval', $termIds));
133
-    }
125
+	/**
126
+	 * @param string $commaSeparatedTermIds
127
+	 * @return array
128
+	 */
129
+	public function normalizeTermIds($commaSeparatedTermIds)
130
+	{
131
+		$termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
132
+		return array_unique(array_map('intval', $termIds));
133
+	}
134 134
 
135
-    /**
136
-     * @param string $commaSeparatedTermIds
137
-     * @return array
138
-     */
139
-    public function normalizeTerms($commaSeparatedTermIds)
140
-    {
141
-        $terms = [];
142
-        $termIds = Arr::convertFromString($commaSeparatedTermIds);
143
-        foreach ($termIds as $termId) {
144
-            if (is_numeric($termId)) {
145
-                $termId = intval($termId);
146
-            }
147
-            $term = term_exists($termId, Application::TAXONOMY);
148
-            if (!isset($term['term_id'])) {
149
-                continue;
150
-            }
151
-            $terms[] = $term;
152
-        }
153
-        return $terms;
154
-    }
135
+	/**
136
+	 * @param string $commaSeparatedTermIds
137
+	 * @return array
138
+	 */
139
+	public function normalizeTerms($commaSeparatedTermIds)
140
+	{
141
+		$terms = [];
142
+		$termIds = Arr::convertFromString($commaSeparatedTermIds);
143
+		foreach ($termIds as $termId) {
144
+			if (is_numeric($termId)) {
145
+				$termId = intval($termId);
146
+			}
147
+			$term = term_exists($termId, Application::TAXONOMY);
148
+			if (!isset($term['term_id'])) {
149
+				continue;
150
+			}
151
+			$terms[] = $term;
152
+		}
153
+		return $terms;
154
+	}
155 155
 
156
-    /**
157
-     * @param int $postId
158
-     * @return void
159
-     */
160
-    public function revert($postId)
161
-    {
162
-        if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
163
-            return;
164
-        }
165
-        delete_post_meta($postId, '_edit_last');
166
-        $result = wp_update_post([
167
-            'ID' => $postId,
168
-            'post_content' => glsr(Database::class)->get($postId, 'content'),
169
-            'post_date' => glsr(Database::class)->get($postId, 'date'),
170
-            'post_title' => glsr(Database::class)->get($postId, 'title'),
171
-        ]);
172
-        if (is_wp_error($result)) {
173
-            glsr_log()->error($result->get_error_message());
174
-            return;
175
-        }
176
-        do_action('site-reviews/review/reverted', glsr_get_review($postId));
177
-    }
156
+	/**
157
+	 * @param int $postId
158
+	 * @return void
159
+	 */
160
+	public function revert($postId)
161
+	{
162
+		if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
163
+			return;
164
+		}
165
+		delete_post_meta($postId, '_edit_last');
166
+		$result = wp_update_post([
167
+			'ID' => $postId,
168
+			'post_content' => glsr(Database::class)->get($postId, 'content'),
169
+			'post_date' => glsr(Database::class)->get($postId, 'date'),
170
+			'post_title' => glsr(Database::class)->get($postId, 'title'),
171
+		]);
172
+		if (is_wp_error($result)) {
173
+			glsr_log()->error($result->get_error_message());
174
+			return;
175
+		}
176
+		do_action('site-reviews/review/reverted', glsr_get_review($postId));
177
+	}
178 178
 
179
-    /**
180
-     * @return Review
181
-     */
182
-    public function single(WP_Post $post)
183
-    {
184
-        if (Application::POST_TYPE != $post->post_type) {
185
-            $post = new WP_Post((object) []);
186
-        }
187
-        $review = new Review($post);
188
-        return apply_filters('site-reviews/get/review', $review, $post);
189
-    }
179
+	/**
180
+	 * @return Review
181
+	 */
182
+	public function single(WP_Post $post)
183
+	{
184
+		if (Application::POST_TYPE != $post->post_type) {
185
+			$post = new WP_Post((object) []);
186
+		}
187
+		$review = new Review($post);
188
+		return apply_filters('site-reviews/get/review', $review, $post);
189
+	}
190 190
 
191
-    /**
192
-     * @param bool $isBlacklisted
193
-     * @return string
194
-     */
195
-    protected function getNewPostStatus(array $reviewValues, $isBlacklisted)
196
-    {
197
-        $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
198
-        return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted)
199
-            ? 'pending'
200
-            : 'publish';
201
-    }
191
+	/**
192
+	 * @param bool $isBlacklisted
193
+	 * @return string
194
+	 */
195
+	protected function getNewPostStatus(array $reviewValues, $isBlacklisted)
196
+	{
197
+		$requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
198
+		return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted)
199
+			? 'pending'
200
+			: 'publish';
201
+	}
202 202
 
203
-    /**
204
-     * @param int $postId
205
-     * @param string $termIds
206
-     * @return void
207
-     */
208
-    protected function setTerms($postId, $termIds)
209
-    {
210
-        $termIds = $this->normalizeTermIds($termIds);
211
-        if (empty($termIds)) {
212
-            return;
213
-        }
214
-        $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
215
-        if (is_wp_error($termTaxonomyIds)) {
216
-            glsr_log()->error($termTaxonomyIds->get_error_message());
217
-        }
218
-    }
203
+	/**
204
+	 * @param int $postId
205
+	 * @param string $termIds
206
+	 * @return void
207
+	 */
208
+	protected function setTerms($postId, $termIds)
209
+	{
210
+		$termIds = $this->normalizeTermIds($termIds);
211
+		if (empty($termIds)) {
212
+			return;
213
+		}
214
+		$termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
215
+		if (is_wp_error($termTaxonomyIds)) {
216
+			glsr_log()->error($termTaxonomyIds->get_error_message());
217
+		}
218
+	}
219 219
 }
Please login to merge, or discard this patch.
plugin/Database/DefaultsManager.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -6,60 +6,60 @@
 block discarded – undo
6 6
 
7 7
 class DefaultsManager
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function defaults()
13
-    {
14
-        $settings = $this->settings();
15
-        $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
-        return wp_parse_args($defaults, [
17
-            'version' => '',
18
-            'version_upgraded_from' => '',
19
-        ]);
20
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function defaults()
13
+	{
14
+		$settings = $this->settings();
15
+		$defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
+		return wp_parse_args($defaults, [
17
+			'version' => '',
18
+			'version_upgraded_from' => '',
19
+		]);
20
+	}
21 21
 
22
-    /**
23
-     * @return array
24
-     */
25
-    public function get()
26
-    {
27
-        return Arr::convertFromDotNotation($this->defaults());
28
-    }
22
+	/**
23
+	 * @return array
24
+	 */
25
+	public function get()
26
+	{
27
+		return Arr::convertFromDotNotation($this->defaults());
28
+	}
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function set()
34
-    {
35
-        $settings = glsr(OptionManager::class)->all();
36
-        $currentSettings = Arr::removeEmptyValues($settings);
37
-        $defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
-        $updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
-        update_option(OptionManager::databaseKey(), $updatedSettings);
40
-        return $defaultSettings;
41
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function set()
34
+	{
35
+		$settings = glsr(OptionManager::class)->all();
36
+		$currentSettings = Arr::removeEmptyValues($settings);
37
+		$defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
+		$updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
+		update_option(OptionManager::databaseKey(), $updatedSettings);
40
+		return $defaultSettings;
41
+	}
42 42
 
43
-    /**
44
-     * @return array
45
-     */
46
-    public function settings()
47
-    {
48
-        $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
-        return $this->normalize($settings);
50
-    }
43
+	/**
44
+	 * @return array
45
+	 */
46
+	public function settings()
47
+	{
48
+		$settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
+		return $this->normalize($settings);
50
+	}
51 51
 
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function normalize(array $settings)
56
-    {
57
-        array_walk($settings, function (&$setting) {
58
-            if (isset($setting['default'])) {
59
-                return;
60
-            }
61
-            $setting['default'] = '';
62
-        });
63
-        return $settings;
64
-    }
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function normalize(array $settings)
56
+	{
57
+		array_walk($settings, function (&$setting) {
58
+			if (isset($setting['default'])) {
59
+				return;
60
+			}
61
+			$setting['default'] = '';
62
+		});
63
+		return $settings;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
plugin/Database/OptionManager.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -9,157 +9,157 @@
 block discarded – undo
9 9
 
10 10
 class OptionManager
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    protected $options;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	protected $options;
16 16
 
17
-    /**
18
-     * @return string
19
-     */
20
-    public static function databaseKey($version = null)
21
-    {
22
-        if (1 == $version) {
23
-            return 'geminilabs_site_reviews_settings';
24
-        }
25
-        if (2 == $version) {
26
-            return 'geminilabs_site_reviews-v2';
27
-        }
28
-        if (null === $version) {
29
-            $version = explode('.', glsr()->version);
30
-            $version = array_shift($version);
31
-        }
32
-        return Str::snakeCase(Application::ID.'-v'.intval($version));
33
-    }
17
+	/**
18
+	 * @return string
19
+	 */
20
+	public static function databaseKey($version = null)
21
+	{
22
+		if (1 == $version) {
23
+			return 'geminilabs_site_reviews_settings';
24
+		}
25
+		if (2 == $version) {
26
+			return 'geminilabs_site_reviews-v2';
27
+		}
28
+		if (null === $version) {
29
+			$version = explode('.', glsr()->version);
30
+			$version = array_shift($version);
31
+		}
32
+		return Str::snakeCase(Application::ID.'-v'.intval($version));
33
+	}
34 34
 
35
-    /**
36
-     * @return array
37
-     */
38
-    public function all()
39
-    {
40
-        if (empty($this->options)) {
41
-            $this->reset();
42
-        }
43
-        return $this->options;
44
-    }
35
+	/**
36
+	 * @return array
37
+	 */
38
+	public function all()
39
+	{
40
+		if (empty($this->options)) {
41
+			$this->reset();
42
+		}
43
+		return $this->options;
44
+	}
45 45
 
46
-    /**
47
-     * @param string $path
48
-     * @return bool
49
-     */
50
-    public function delete($path)
51
-    {
52
-        $keys = explode('.', $path);
53
-        $last = array_pop($keys);
54
-        $options = $this->all();
55
-        $pointer = &$options;
56
-        foreach ($keys as $key) {
57
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
58
-                continue;
59
-            }
60
-            $pointer = &$pointer[$key];
61
-        }
62
-        unset($pointer[$last]);
63
-        return $this->set($options);
64
-    }
46
+	/**
47
+	 * @param string $path
48
+	 * @return bool
49
+	 */
50
+	public function delete($path)
51
+	{
52
+		$keys = explode('.', $path);
53
+		$last = array_pop($keys);
54
+		$options = $this->all();
55
+		$pointer = &$options;
56
+		foreach ($keys as $key) {
57
+			if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
58
+				continue;
59
+			}
60
+			$pointer = &$pointer[$key];
61
+		}
62
+		unset($pointer[$last]);
63
+		return $this->set($options);
64
+	}
65 65
 
66
-    /**
67
-     * @param string $path
68
-     * @param mixed $fallback
69
-     * @param string $cast
70
-     * @return mixed
71
-     */
72
-    public function get($path = '', $fallback = '', $cast = '')
73
-    {
74
-        $result = Arr::get($this->all(), $path, $fallback);
75
-        return Helper::castTo($cast, $result);
76
-    }
66
+	/**
67
+	 * @param string $path
68
+	 * @param mixed $fallback
69
+	 * @param string $cast
70
+	 * @return mixed
71
+	 */
72
+	public function get($path = '', $fallback = '', $cast = '')
73
+	{
74
+		$result = Arr::get($this->all(), $path, $fallback);
75
+		return Helper::castTo($cast, $result);
76
+	}
77 77
 
78
-    /**
79
-     * @param string $path
80
-     * @return bool
81
-     */
82
-    public function getBool($path)
83
-    {
84
-        return Helper::castToBool($this->get($path));
85
-    }
78
+	/**
79
+	 * @param string $path
80
+	 * @return bool
81
+	 */
82
+	public function getBool($path)
83
+	{
84
+		return Helper::castToBool($this->get($path));
85
+	}
86 86
 
87
-    /**
88
-     * @param string $path
89
-     * @param mixed $fallback
90
-     * @param string $cast
91
-     * @return mixed
92
-     */
93
-    public function getWP($path, $fallback = '', $cast = '')
94
-    {
95
-        $option = get_option($path, $fallback);
96
-        if (empty($option)) {
97
-            $option = $fallback;
98
-        }
99
-        return Helper::castTo($cast, $option);
100
-    }
87
+	/**
88
+	 * @param string $path
89
+	 * @param mixed $fallback
90
+	 * @param string $cast
91
+	 * @return mixed
92
+	 */
93
+	public function getWP($path, $fallback = '', $cast = '')
94
+	{
95
+		$option = get_option($path, $fallback);
96
+		if (empty($option)) {
97
+			$option = $fallback;
98
+		}
99
+		return Helper::castTo($cast, $option);
100
+	}
101 101
 
102
-    /**
103
-     * @return string
104
-     */
105
-    public function json()
106
-    {
107
-        return json_encode($this->all());
108
-    }
102
+	/**
103
+	 * @return string
104
+	 */
105
+	public function json()
106
+	{
107
+		return json_encode($this->all());
108
+	}
109 109
 
110
-    /**
111
-     * @return array
112
-     */
113
-    public function normalize(array $options = [])
114
-    {
115
-        $options = wp_parse_args(
116
-            Arr::flatten($options),
117
-            glsr(DefaultsManager::class)->defaults()
118
-        );
119
-        array_walk($options, function (&$value) {
120
-            if (!is_string($value)) {
121
-                return;
122
-            }
123
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
124
-        });
125
-        return Arr::convertFromDotNotation($options);
126
-    }
110
+	/**
111
+	 * @return array
112
+	 */
113
+	public function normalize(array $options = [])
114
+	{
115
+		$options = wp_parse_args(
116
+			Arr::flatten($options),
117
+			glsr(DefaultsManager::class)->defaults()
118
+		);
119
+		array_walk($options, function (&$value) {
120
+			if (!is_string($value)) {
121
+				return;
122
+			}
123
+			$value = wp_kses($value, wp_kses_allowed_html('post'));
124
+		});
125
+		return Arr::convertFromDotNotation($options);
126
+	}
127 127
 
128
-    /**
129
-     * @return bool
130
-     */
131
-    public function isRecaptchaEnabled()
132
-    {
133
-        $integration = $this->get('settings.submissions.recaptcha.integration');
134
-        return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
135
-    }
128
+	/**
129
+	 * @return bool
130
+	 */
131
+	public function isRecaptchaEnabled()
132
+	{
133
+		$integration = $this->get('settings.submissions.recaptcha.integration');
134
+		return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
135
+	}
136 136
 
137
-    /**
138
-     * @return array
139
-     */
140
-    public function reset()
141
-    {
142
-        $options = $this->getWP(static::databaseKey(), []);
143
-        if (!is_array($options) || empty($options)) {
144
-            delete_option(static::databaseKey());
145
-            $options = glsr()->defaults ?: [];
146
-        }
147
-        $this->options = $options;
148
-    }
137
+	/**
138
+	 * @return array
139
+	 */
140
+	public function reset()
141
+	{
142
+		$options = $this->getWP(static::databaseKey(), []);
143
+		if (!is_array($options) || empty($options)) {
144
+			delete_option(static::databaseKey());
145
+			$options = glsr()->defaults ?: [];
146
+		}
147
+		$this->options = $options;
148
+	}
149 149
 
150
-    /**
151
-     * @param string|array $pathOrOptions
152
-     * @param mixed $value
153
-     * @return bool
154
-     */
155
-    public function set($pathOrOptions, $value = '')
156
-    {
157
-        if (is_string($pathOrOptions)) {
158
-            $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
159
-        }
160
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
161
-            $this->reset();
162
-        }
163
-        return $result;
164
-    }
150
+	/**
151
+	 * @param string|array $pathOrOptions
152
+	 * @param mixed $value
153
+	 * @return bool
154
+	 */
155
+	public function set($pathOrOptions, $value = '')
156
+	{
157
+		if (is_string($pathOrOptions)) {
158
+			$pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
159
+		}
160
+		if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
161
+			$this->reset();
162
+		}
163
+		return $result;
164
+	}
165 165
 }
Please login to merge, or discard this patch.
plugin/Addons/Addon.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -11,83 +11,83 @@
 block discarded – undo
11 11
  */
12 12
 abstract class Addon
13 13
 {
14
-    const ID = '';
15
-    const SLUG = '';
16
-    const UPDATE_URL = '';
14
+	const ID = '';
15
+	const SLUG = '';
16
+	const UPDATE_URL = '';
17 17
 
18
-    public $file;
19
-    public $languages;
20
-    public $name;
21
-    public $testedTo;
22
-    public $updater;
23
-    public $version;
18
+	public $file;
19
+	public $languages;
20
+	public $name;
21
+	public $testedTo;
22
+	public $updater;
23
+	public $version;
24 24
 
25
-    public function __construct()
26
-    {
27
-        $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName());
28
-        $plugin = get_file_data($this->file, [
29
-            'languages' => 'Domain Path',
30
-            'name' => 'Plugin Name',
31
-            'testedTo' => 'Tested up to',
32
-            'version' => 'Version',
33
-        ], 'plugin');
34
-        array_walk($plugin, function ($value, $key) {
35
-            if (property_exists($this, $key)) {
36
-                $this->$key = $value;
37
-            }
38
-        });
39
-    }
25
+	public function __construct()
26
+	{
27
+		$this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName());
28
+		$plugin = get_file_data($this->file, [
29
+			'languages' => 'Domain Path',
30
+			'name' => 'Plugin Name',
31
+			'testedTo' => 'Tested up to',
32
+			'version' => 'Version',
33
+		], 'plugin');
34
+		array_walk($plugin, function ($value, $key) {
35
+			if (property_exists($this, $key)) {
36
+				$this->$key = $value;
37
+			}
38
+		});
39
+	}
40 40
 
41
-    /**
42
-     * @param string $property
43
-     * @return void|string
44
-     */
45
-    public function __get($property)
46
-    {
47
-        if (property_exists($this, $property)) {
48
-            return $this->$property;
49
-        }
50
-        $constant = 'static::'.strtoupper($property);
51
-        if (defined($constant)) {
52
-            return constant($constant);
53
-        }
54
-    }
41
+	/**
42
+	 * @param string $property
43
+	 * @return void|string
44
+	 */
45
+	public function __get($property)
46
+	{
47
+		if (property_exists($this, $property)) {
48
+			return $this->$property;
49
+		}
50
+		$constant = 'static::'.strtoupper($property);
51
+		if (defined($constant)) {
52
+			return constant($constant);
53
+		}
54
+	}
55 55
 
56
-    public function make($class)
57
-    {}
56
+	public function make($class)
57
+	{}
58 58
 
59
-    /**
60
-     * @return void
61
-     */
62
-    abstract public function init();
59
+	/**
60
+	 * @return void
61
+	 */
62
+	abstract public function init();
63 63
 
64
-    /**
65
-     * @param string $file
66
-     * @return string
67
-     */
68
-    public function path($file = '')
69
-    {
70
-        return plugin_dir_path($this->file).ltrim(trim($file), '/');
71
-    }
64
+	/**
65
+	 * @param string $file
66
+	 * @return string
67
+	 */
68
+	public function path($file = '')
69
+	{
70
+		return plugin_dir_path($this->file).ltrim(trim($file), '/');
71
+	}
72 72
 
73
-    /**
74
-     * @return void
75
-     */
76
-    public function update()
77
-    {
78
-        $this->updater = new Updater(static::UPDATE_URL, $this->file, [
79
-            'license' => glsr_get_option('settings.licenses.'.static::ID),
80
-            'testedTo' => $this->testedTo,
81
-        ]);
82
-        $this->updater->init();
83
-    }
73
+	/**
74
+	 * @return void
75
+	 */
76
+	public function update()
77
+	{
78
+		$this->updater = new Updater(static::UPDATE_URL, $this->file, [
79
+			'license' => glsr_get_option('settings.licenses.'.static::ID),
80
+			'testedTo' => $this->testedTo,
81
+		]);
82
+		$this->updater->init();
83
+	}
84 84
 
85
-    /**
86
-     * @param string $path
87
-     * @return string
88
-     */
89
-    public function url($path = '')
90
-    {
91
-        return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
92
-    }
85
+	/**
86
+	 * @param string $path
87
+	 * @return string
88
+	 */
89
+	public function url($path = '')
90
+	{
91
+		return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
92
+	}
93 93
 }
Please login to merge, or discard this patch.
plugin/Addons/Controller.php 1 patch
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -12,325 +12,325 @@
 block discarded – undo
12 12
 
13 13
 abstract class Controller extends BaseController
14 14
 {
15
-    /**
16
-     * @var Addon
17
-     */
18
-    protected $addon;
15
+	/**
16
+	 * @var Addon
17
+	 */
18
+	protected $addon;
19 19
 
20
-    public function __construct()
21
-    {
22
-        $this->setAddon();
23
-    }
20
+	public function __construct()
21
+	{
22
+		$this->setAddon();
23
+	}
24 24
 
25
-    /**
26
-     * @return void
27
-     * @action admin_enqueue_scripts
28
-     */
29
-    public function enqueueAdminAssets()
30
-    {
31
-        if (!$this->isReviewAdminPage()) {
32
-            return;
33
-        }
34
-        $this->enqueueAsset('css', ['suffix' => 'admin']);
35
-        $this->enqueueAsset('js', ['suffix' => 'admin']);
36
-    }
25
+	/**
26
+	 * @return void
27
+	 * @action admin_enqueue_scripts
28
+	 */
29
+	public function enqueueAdminAssets()
30
+	{
31
+		if (!$this->isReviewAdminPage()) {
32
+			return;
33
+		}
34
+		$this->enqueueAsset('css', ['suffix' => 'admin']);
35
+		$this->enqueueAsset('js', ['suffix' => 'admin']);
36
+	}
37 37
 
38
-    /**
39
-     * @return void
40
-     * @action enqueue_block_editor_assets
41
-     */
42
-    public function enqueueBlockAssets()
43
-    {
44
-        $this->registerAsset('css', ['suffix' => 'blocks']);
45
-        $this->registerAsset('js', ['suffix' => 'blocks']);
46
-    }
38
+	/**
39
+	 * @return void
40
+	 * @action enqueue_block_editor_assets
41
+	 */
42
+	public function enqueueBlockAssets()
43
+	{
44
+		$this->registerAsset('css', ['suffix' => 'blocks']);
45
+		$this->registerAsset('js', ['suffix' => 'blocks']);
46
+	}
47 47
 
48
-    /**
49
-     * @return void
50
-     * @action wp_enqueue_scripts
51
-     */
52
-    public function enqueuePublicAssets()
53
-    {
54
-        $this->enqueueAsset('css');
55
-        $this->enqueueAsset('js');
56
-    }
48
+	/**
49
+	 * @return void
50
+	 * @action wp_enqueue_scripts
51
+	 */
52
+	public function enqueuePublicAssets()
53
+	{
54
+		$this->enqueueAsset('css');
55
+		$this->enqueueAsset('js');
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     * @filter plugin_action_links_{addon_id}/{addon_id}.php
61
-     */
62
-    public function filterActionLinks(array $links)
63
-    {
64
-        $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
65
-            'href' => admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#tab-addons'),
66
-        ]);
67
-        return $links;
68
-    }
58
+	/**
59
+	 * @return array
60
+	 * @filter plugin_action_links_{addon_id}/{addon_id}.php
61
+	 */
62
+	public function filterActionLinks(array $links)
63
+	{
64
+		$links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
65
+			'href' => admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#tab-addons'),
66
+		]);
67
+		return $links;
68
+	}
69 69
 
70
-    /**
71
-     * @param string $path
72
-     * @return string
73
-     * @filter site-reviews/config
74
-     */
75
-    public function filterConfigPath($path)
76
-    {
77
-        $addonPrefix = $this->addon->id.'/';
78
-        return Str::contains($path, $addonPrefix)
79
-            ? $addonPrefix.str_replace($addonPrefix, '', $path)
80
-            : $path;
81
-    }
70
+	/**
71
+	 * @param string $path
72
+	 * @return string
73
+	 * @filter site-reviews/config
74
+	 */
75
+	public function filterConfigPath($path)
76
+	{
77
+		$addonPrefix = $this->addon->id.'/';
78
+		return Str::contains($path, $addonPrefix)
79
+			? $addonPrefix.str_replace($addonPrefix, '', $path)
80
+			: $path;
81
+	}
82 82
 
83
-    /**
84
-     * @return array
85
-     * @filter site-reviews/addon/documentation
86
-     */
87
-    public function filterDocumentation(array $documentation)
88
-    {
89
-        $documentation[$this->addon->name] = glsr(Template::class)->build($this->addon->id.'/documentation');
90
-        return $documentation;
91
-    }
83
+	/**
84
+	 * @return array
85
+	 * @filter site-reviews/addon/documentation
86
+	 */
87
+	public function filterDocumentation(array $documentation)
88
+	{
89
+		$documentation[$this->addon->name] = glsr(Template::class)->build($this->addon->id.'/documentation');
90
+		return $documentation;
91
+	}
92 92
 
93
-    /**
94
-     * @param string $path
95
-     * @param string $file
96
-     * @return string
97
-     * @filter site-reviews/path
98
-     */
99
-    public function filterFilePaths($path, $file)
100
-    {
101
-        $addonPrefix = $this->addon->id.'/';
102
-        return Str::startsWith($addonPrefix, $file)
103
-            ? $this->addon->path(Str::replaceFirst($addonPrefix, '', $file))
104
-            : $path;
105
-    }
93
+	/**
94
+	 * @param string $path
95
+	 * @param string $file
96
+	 * @return string
97
+	 * @filter site-reviews/path
98
+	 */
99
+	public function filterFilePaths($path, $file)
100
+	{
101
+		$addonPrefix = $this->addon->id.'/';
102
+		return Str::startsWith($addonPrefix, $file)
103
+			? $this->addon->path(Str::replaceFirst($addonPrefix, '', $file))
104
+			: $path;
105
+	}
106 106
 
107
-    /**
108
-     * @param string $translation
109
-     * @param string $text
110
-     * @return string
111
-     * @filter site-reviews/gettext/{addon_id}
112
-     */
113
-    public function filterGettext($translation, $text)
114
-    {
115
-        return glsr(Translator::class)->translate($translation, $this->addon->id, [
116
-            'single' => $text,
117
-        ]);
118
-    }
107
+	/**
108
+	 * @param string $translation
109
+	 * @param string $text
110
+	 * @return string
111
+	 * @filter site-reviews/gettext/{addon_id}
112
+	 */
113
+	public function filterGettext($translation, $text)
114
+	{
115
+		return glsr(Translator::class)->translate($translation, $this->addon->id, [
116
+			'single' => $text,
117
+		]);
118
+	}
119 119
 
120
-    /**
121
-     * @param string $translation
122
-     * @param string $text
123
-     * @param string $context
124
-     * @return string
125
-     * @filter site-reviews/gettext_with_context/{addon_id}
126
-     */
127
-    public function filterGettextWithContext($translation, $text, $context)
128
-    {
129
-        return glsr(Translator::class)->translate($translation, $this->addon->id, [
130
-            'context' => $context,
131
-            'single' => $text,
132
-        ]);
133
-    }
120
+	/**
121
+	 * @param string $translation
122
+	 * @param string $text
123
+	 * @param string $context
124
+	 * @return string
125
+	 * @filter site-reviews/gettext_with_context/{addon_id}
126
+	 */
127
+	public function filterGettextWithContext($translation, $text, $context)
128
+	{
129
+		return glsr(Translator::class)->translate($translation, $this->addon->id, [
130
+			'context' => $context,
131
+			'single' => $text,
132
+		]);
133
+	}
134 134
 
135
-    /**
136
-     * @param string $translation
137
-     * @param string $single
138
-     * @param string $plural
139
-     * @param int $number
140
-     * @return string
141
-     * @filter site-reviews/ngettext/{addon_id}
142
-     */
143
-    public function filterNgettext($translation, $single, $plural, $number)
144
-    {
145
-        return glsr(Translator::class)->translate($translation, $this->addon->id, [
146
-            'number' => $number,
147
-            'plural' => $plural,
148
-            'single' => $single,
149
-        ]);
150
-    }
135
+	/**
136
+	 * @param string $translation
137
+	 * @param string $single
138
+	 * @param string $plural
139
+	 * @param int $number
140
+	 * @return string
141
+	 * @filter site-reviews/ngettext/{addon_id}
142
+	 */
143
+	public function filterNgettext($translation, $single, $plural, $number)
144
+	{
145
+		return glsr(Translator::class)->translate($translation, $this->addon->id, [
146
+			'number' => $number,
147
+			'plural' => $plural,
148
+			'single' => $single,
149
+		]);
150
+	}
151 151
 
152
-    /**
153
-     * @param string $translation
154
-     * @param string $single
155
-     * @param string $plural
156
-     * @param int $number
157
-     * @param string $context
158
-     * @return string
159
-     * @filter site-reviews/ngettext_with_context/{addon_id}
160
-     */
161
-    public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context)
162
-    {
163
-        return glsr(Translator::class)->translate($translation, $this->addon->id, [
164
-            'context' => $context,
165
-            'number' => $number,
166
-            'plural' => $plural,
167
-            'single' => $single,
168
-        ]);
169
-    }
152
+	/**
153
+	 * @param string $translation
154
+	 * @param string $single
155
+	 * @param string $plural
156
+	 * @param int $number
157
+	 * @param string $context
158
+	 * @return string
159
+	 * @filter site-reviews/ngettext_with_context/{addon_id}
160
+	 */
161
+	public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context)
162
+	{
163
+		return glsr(Translator::class)->translate($translation, $this->addon->id, [
164
+			'context' => $context,
165
+			'number' => $number,
166
+			'plural' => $plural,
167
+			'single' => $single,
168
+		]);
169
+	}
170 170
 
171
-    /**
172
-     * @return array
173
-     * @filter site-reviews/addon/settings
174
-     */
175
-    public function filterSettings(array $settings)
176
-    {
177
-        $settingsFile = $this->addon->path('config/settings.php');
178
-        if (file_exists($settingsFile)) {
179
-            $settings = array_merge((include $settingsFile), $settings);
180
-        }
181
-        return $settings;
182
-    }
171
+	/**
172
+	 * @return array
173
+	 * @filter site-reviews/addon/settings
174
+	 */
175
+	public function filterSettings(array $settings)
176
+	{
177
+		$settingsFile = $this->addon->path('config/settings.php');
178
+		if (file_exists($settingsFile)) {
179
+			$settings = array_merge((include $settingsFile), $settings);
180
+		}
181
+		return $settings;
182
+	}
183 183
 
184
-    /**
185
-     * @return array
186
-     * @filter site-reviews/addon/system-info
187
-     */
188
-    public function filterSystemInfo(array $details)
189
-    {
190
-        $version = $this->addon->version;
191
-        $previousVersion = glsr(OptionManager::class)->get('addons.'.$this->addon->id.'.version_upgraded_from');
192
-        if (empty($previousVersion)) {
193
-            $previousVersion = $version;
194
-        }
195
-        $details[$this->addon->name] = sprintf('%s (%s)', $this->addon->version, $previousVersion);
196
-        return $details;
197
-    }
184
+	/**
185
+	 * @return array
186
+	 * @filter site-reviews/addon/system-info
187
+	 */
188
+	public function filterSystemInfo(array $details)
189
+	{
190
+		$version = $this->addon->version;
191
+		$previousVersion = glsr(OptionManager::class)->get('addons.'.$this->addon->id.'.version_upgraded_from');
192
+		if (empty($previousVersion)) {
193
+			$previousVersion = $version;
194
+		}
195
+		$details[$this->addon->name] = sprintf('%s (%s)', $this->addon->version, $previousVersion);
196
+		return $details;
197
+	}
198 198
 
199
-    /**
200
-     * @return array
201
-     * @filter site-reviews/translation/entries
202
-     */
203
-    public function filterTranslationEntries(array $entries)
204
-    {
205
-        $potFile = $this->addon->path($this->addon->languages.'/'.$this->addon->id.'.pot');
206
-        return glsr(Translation::class)->extractEntriesFromPotFile($potFile, $entries);
207
-    }
199
+	/**
200
+	 * @return array
201
+	 * @filter site-reviews/translation/entries
202
+	 */
203
+	public function filterTranslationEntries(array $entries)
204
+	{
205
+		$potFile = $this->addon->path($this->addon->languages.'/'.$this->addon->id.'.pot');
206
+		return glsr(Translation::class)->extractEntriesFromPotFile($potFile, $entries);
207
+	}
208 208
 
209
-    /**
210
-     * @return array
211
-     * @filter site-reviews/translator/domains
212
-     */
213
-    public function filterTranslatorDomains(array $domains)
214
-    {
215
-        $domains[] = $this->addon->id;
216
-        return $domains;
217
-    }
209
+	/**
210
+	 * @return array
211
+	 * @filter site-reviews/translator/domains
212
+	 */
213
+	public function filterTranslatorDomains(array $domains)
214
+	{
215
+		$domains[] = $this->addon->id;
216
+		return $domains;
217
+	}
218 218
 
219
-    /**
220
-     * @return void
221
-     * @action init
222
-     */
223
-    public function registerBlocks()
224
-    {
225
-    }
219
+	/**
220
+	 * @return void
221
+	 * @action init
222
+	 */
223
+	public function registerBlocks()
224
+	{
225
+	}
226 226
 
227
-    /**
228
-     * @return void
229
-     * @action plugins_loaded
230
-     */
231
-    public function registerLanguages()
232
-    {
233
-        load_plugin_textdomain($this->addon->id, false,
234
-            trailingslashit(plugin_basename($this->addon->path()).'/'.$this->addon->languages)
235
-        );
236
-    }
227
+	/**
228
+	 * @return void
229
+	 * @action plugins_loaded
230
+	 */
231
+	public function registerLanguages()
232
+	{
233
+		load_plugin_textdomain($this->addon->id, false,
234
+			trailingslashit(plugin_basename($this->addon->path()).'/'.$this->addon->languages)
235
+		);
236
+	}
237 237
 
238
-    /**
239
-     * @return void
240
-     * @action init
241
-     */
242
-    public function registerShortcodes()
243
-    {
244
-    }
238
+	/**
239
+	 * @return void
240
+	 * @action init
241
+	 */
242
+	public function registerShortcodes()
243
+	{
244
+	}
245 245
 
246
-    /**
247
-     * @return void
248
-     * @action admin_init
249
-     */
250
-    public function registerTinymcePopups()
251
-    {
252
-    }
246
+	/**
247
+	 * @return void
248
+	 * @action admin_init
249
+	 */
250
+	public function registerTinymcePopups()
251
+	{
252
+	}
253 253
 
254
-    /**
255
-     * @return void
256
-     * @action widgets_init
257
-     */
258
-    public function registerWidgets()
259
-    {
260
-    }
254
+	/**
255
+	 * @return void
256
+	 * @action widgets_init
257
+	 */
258
+	public function registerWidgets()
259
+	{
260
+	}
261 261
 
262
-    /**
263
-     * @param string $rows
264
-     * @return void
265
-     * @action site-reviews/addon/settings/{addon_slug}
266
-     */
267
-    public function renderSettings($rows)
268
-    {
269
-        glsr(Template::class)->render($this->addon->id.'/views/settings', [
270
-            'context' => [
271
-                'rows' => $rows,
272
-                'title' => $this->addon->name,
273
-            ],
274
-        ]);
275
-    }
262
+	/**
263
+	 * @param string $rows
264
+	 * @return void
265
+	 * @action site-reviews/addon/settings/{addon_slug}
266
+	 */
267
+	public function renderSettings($rows)
268
+	{
269
+		glsr(Template::class)->render($this->addon->id.'/views/settings', [
270
+			'context' => [
271
+				'rows' => $rows,
272
+				'title' => $this->addon->name,
273
+			],
274
+		]);
275
+	}
276 276
 
277
-    /**
278
-     * @param string $extension
279
-     * @return array
280
-     */
281
-    protected function buildAssetArgs($extension, array $args = [])
282
-    {
283
-        $args = wp_parse_args($args, [
284
-            'dependencies' => [],
285
-            'in_footer' => true,
286
-            'suffix' => '',
287
-        ]);
288
-        $path = 'assets/'.$this->addon->id.Str::prefix('-', $args['suffix']).'.'.$extension;
289
-        if (!file_exists($this->addon->path($path)) || !in_array($extension, ['css', 'js'])) {
290
-            return [];
291
-        }
292
-        $funcArgs = [
293
-            $this->addon->id.Str::prefix('/', $args['suffix']),
294
-            $this->addon->url($path),
295
-            array_merge([glsr()->id.Str::prefix('/', $args['suffix'])], $args['dependencies']),
296
-            $this->addon->version,
297
-        ];
298
-        if ('js' === $extension && $args['in_footer']) {
299
-            $funcArgs[] = true; // load script in the footer
300
-        }
301
-        return $funcArgs;
302
-    }
277
+	/**
278
+	 * @param string $extension
279
+	 * @return array
280
+	 */
281
+	protected function buildAssetArgs($extension, array $args = [])
282
+	{
283
+		$args = wp_parse_args($args, [
284
+			'dependencies' => [],
285
+			'in_footer' => true,
286
+			'suffix' => '',
287
+		]);
288
+		$path = 'assets/'.$this->addon->id.Str::prefix('-', $args['suffix']).'.'.$extension;
289
+		if (!file_exists($this->addon->path($path)) || !in_array($extension, ['css', 'js'])) {
290
+			return [];
291
+		}
292
+		$funcArgs = [
293
+			$this->addon->id.Str::prefix('/', $args['suffix']),
294
+			$this->addon->url($path),
295
+			array_merge([glsr()->id.Str::prefix('/', $args['suffix'])], $args['dependencies']),
296
+			$this->addon->version,
297
+		];
298
+		if ('js' === $extension && $args['in_footer']) {
299
+			$funcArgs[] = true; // load script in the footer
300
+		}
301
+		return $funcArgs;
302
+	}
303 303
 
304
-    /**
305
-     * @param string $extension
306
-     * @return void
307
-     */
308
-    protected function enqueueAsset($extension, array $args = [])
309
-    {
310
-        if ($args = $this->buildAssetArgs($extension, $args)) {
311
-            $function = 'js' === $extension
312
-                ? 'wp_enqueue_script'
313
-                : 'wp_enqueue_style';
314
-            call_user_func_array($function, $args);
315
-        }
316
-    }
304
+	/**
305
+	 * @param string $extension
306
+	 * @return void
307
+	 */
308
+	protected function enqueueAsset($extension, array $args = [])
309
+	{
310
+		if ($args = $this->buildAssetArgs($extension, $args)) {
311
+			$function = 'js' === $extension
312
+				? 'wp_enqueue_script'
313
+				: 'wp_enqueue_style';
314
+			call_user_func_array($function, $args);
315
+		}
316
+	}
317 317
 
318
-    /**
319
-     * @param string $extension
320
-     * @return void
321
-     */
322
-    protected function registerAsset($extension, array $args = [])
323
-    {
324
-        if ($args = $this->buildAssetArgs($extension, $args)) {
325
-            $function = 'js' === $extension
326
-                ? 'wp_register_script'
327
-                : 'wp_register_style';
328
-            call_user_func_array($function, $args);
329
-        }
330
-    }
318
+	/**
319
+	 * @param string $extension
320
+	 * @return void
321
+	 */
322
+	protected function registerAsset($extension, array $args = [])
323
+	{
324
+		if ($args = $this->buildAssetArgs($extension, $args)) {
325
+			$function = 'js' === $extension
326
+				? 'wp_register_script'
327
+				: 'wp_register_style';
328
+			call_user_func_array($function, $args);
329
+		}
330
+	}
331 331
 
332
-    /**
333
-     * @return void
334
-     */
335
-    abstract protected function setAddon();
332
+	/**
333
+	 * @return void
334
+	 */
335
+	abstract protected function setAddon();
336 336
 }
Please login to merge, or discard this patch.
plugin/Addons/Hooks.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,36 +4,36 @@
 block discarded – undo
4 4
 
5 5
 abstract class Hooks
6 6
 {
7
-    protected $addon;
8
-    protected $basename;
9
-    protected $controller;
7
+	protected $addon;
8
+	protected $basename;
9
+	protected $controller;
10 10
 
11
-    /**
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        add_action('init',                                                   [$this->addon, 'update']);
17
-        add_action('admin_enqueue_scripts',                                  [$this->controller, 'enqueueAdminAssets']);
18
-        add_action('enqueue_block_editor_assets',                            [$this->controller, 'enqueueBlockAssets']);
19
-        add_action('wp_enqueue_scripts',                                     [$this->controller, 'enqueuePublicAssets']);
20
-        add_filter('plugin_action_links_'.$this->basename,                   [$this->controller, 'filterActionLinks']);
21
-        add_filter('site-reviews/config',                                    [$this->controller, 'filterConfigPath']);
22
-        add_filter('site-reviews/addon/documentation',                       [$this->controller, 'filterDocumentation']);
23
-        add_filter('site-reviews/gettext/site-reviews-images',               [$this->controller, 'filterGettext'], 10, 2);
24
-        add_filter('site-reviews/gettext_with_context/site-reviews-images',  [$this->controller, 'filterGettextWithContext'], 10, 3);
25
-        add_filter('site-reviews/ngettext/site-reviews-images',              [$this->controller, 'filterNgettext'], 10, 4);
26
-        add_filter('site-reviews/ngettext_with_context/site-reviews-images', [$this->controller, 'filterNgettextWithContext'], 10, 5);
27
-        add_filter('site-reviews/path',                                      [$this->controller, 'filterFilePaths'], 10, 2);
28
-        add_filter('site-reviews/addon/settings',                            [$this->controller, 'filterSettings']);
29
-        add_filter('site-reviews/addon/system-info',                         [$this->controller, 'filterSystemInfo']);
30
-        add_filter('site-reviews/translation/entries',                       [$this->controller, 'filterTranslationEntries']);
31
-        add_filter('site-reviews/translator/domains',                        [$this->controller, 'filterTranslatorDomains']);
32
-        add_action('init',                                                   [$this->controller, 'registerBlocks']);
33
-        add_action('plugins_loaded',                                         [$this->controller, 'registerLanguages']);
34
-        add_action('init',                                                   [$this->controller, 'registerShortcodes']);
35
-        add_action('init',                                                   [$this->controller, 'registerTinymcePopups']);
36
-        add_action('widgets_init',                                           [$this->controller, 'registerWidgets']);
37
-        add_action('site-reviews/addon/settings/'.$this->addon->slug,        [$this->controller, 'renderSettings']);
38
-    }
11
+	/**
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		add_action('init',                                                   [$this->addon, 'update']);
17
+		add_action('admin_enqueue_scripts',                                  [$this->controller, 'enqueueAdminAssets']);
18
+		add_action('enqueue_block_editor_assets',                            [$this->controller, 'enqueueBlockAssets']);
19
+		add_action('wp_enqueue_scripts',                                     [$this->controller, 'enqueuePublicAssets']);
20
+		add_filter('plugin_action_links_'.$this->basename,                   [$this->controller, 'filterActionLinks']);
21
+		add_filter('site-reviews/config',                                    [$this->controller, 'filterConfigPath']);
22
+		add_filter('site-reviews/addon/documentation',                       [$this->controller, 'filterDocumentation']);
23
+		add_filter('site-reviews/gettext/site-reviews-images',               [$this->controller, 'filterGettext'], 10, 2);
24
+		add_filter('site-reviews/gettext_with_context/site-reviews-images',  [$this->controller, 'filterGettextWithContext'], 10, 3);
25
+		add_filter('site-reviews/ngettext/site-reviews-images',              [$this->controller, 'filterNgettext'], 10, 4);
26
+		add_filter('site-reviews/ngettext_with_context/site-reviews-images', [$this->controller, 'filterNgettextWithContext'], 10, 5);
27
+		add_filter('site-reviews/path',                                      [$this->controller, 'filterFilePaths'], 10, 2);
28
+		add_filter('site-reviews/addon/settings',                            [$this->controller, 'filterSettings']);
29
+		add_filter('site-reviews/addon/system-info',                         [$this->controller, 'filterSystemInfo']);
30
+		add_filter('site-reviews/translation/entries',                       [$this->controller, 'filterTranslationEntries']);
31
+		add_filter('site-reviews/translator/domains',                        [$this->controller, 'filterTranslatorDomains']);
32
+		add_action('init',                                                   [$this->controller, 'registerBlocks']);
33
+		add_action('plugins_loaded',                                         [$this->controller, 'registerLanguages']);
34
+		add_action('init',                                                   [$this->controller, 'registerShortcodes']);
35
+		add_action('init',                                                   [$this->controller, 'registerTinymcePopups']);
36
+		add_action('widgets_init',                                           [$this->controller, 'registerWidgets']);
37
+		add_action('site-reviews/addon/settings/'.$this->addon->slug,        [$this->controller, 'renderSettings']);
38
+	}
39 39
 }
Please login to merge, or discard this patch.
plugin/Addons/Updater.php 1 patch
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -8,266 +8,266 @@
 block discarded – undo
8 8
 
9 9
 class Updater
10 10
 {
11
-    /**
12
-     * @var string
13
-     */
14
-    protected $apiUrl;
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $data;
19
-    /**
20
-     * @var string
21
-     */
22
-    protected $plugin;
23
-    /**
24
-     * @var string
25
-     */
26
-    protected $transientName;
11
+	/**
12
+	 * @var string
13
+	 */
14
+	protected $apiUrl;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $data;
19
+	/**
20
+	 * @var string
21
+	 */
22
+	protected $plugin;
23
+	/**
24
+	 * @var string
25
+	 */
26
+	protected $transientName;
27 27
 
28
-    /**
29
-     * @param string $apiUrl
30
-     * @param string $file
31
-     */
32
-    public function __construct($apiUrl, $file, array $data = [])
33
-    {
34
-        if (!function_exists('get_plugin_data')) {
35
-            require_once ABSPATH.WPINC.'/plugin.php';
36
-        }
37
-        $this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl));
38
-        $this->data = wp_parse_args($data, get_plugin_data($file));
39
-        $this->plugin = plugin_basename($file);
40
-        $this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain'));
41
-    }
28
+	/**
29
+	 * @param string $apiUrl
30
+	 * @param string $file
31
+	 */
32
+	public function __construct($apiUrl, $file, array $data = [])
33
+	{
34
+		if (!function_exists('get_plugin_data')) {
35
+			require_once ABSPATH.WPINC.'/plugin.php';
36
+		}
37
+		$this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl));
38
+		$this->data = wp_parse_args($data, get_plugin_data($file));
39
+		$this->plugin = plugin_basename($file);
40
+		$this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain'));
41
+	}
42 42
 
43
-    /**
44
-     * @return object
45
-     */
46
-    public function activateLicense(array $data = [])
47
-    {
48
-        return $this->request('activate_license', $data);
49
-    }
43
+	/**
44
+	 * @return object
45
+	 */
46
+	public function activateLicense(array $data = [])
47
+	{
48
+		return $this->request('activate_license', $data);
49
+	}
50 50
 
51
-    /**
52
-     * @return object
53
-     */
54
-    public function checkLicense(array $data = [])
55
-    {
56
-        $response = $this->request('check_license', $data);
57
-        if ('valid' === Arr::get($response, 'license')) {
58
-            $this->getPluginUpdate(true);
59
-        }
60
-        return $response;
61
-    }
51
+	/**
52
+	 * @return object
53
+	 */
54
+	public function checkLicense(array $data = [])
55
+	{
56
+		$response = $this->request('check_license', $data);
57
+		if ('valid' === Arr::get($response, 'license')) {
58
+			$this->getPluginUpdate(true);
59
+		}
60
+		return $response;
61
+	}
62 62
 
63
-    /**
64
-     * @return object
65
-     */
66
-    public function deactivateLicense(array $data = [])
67
-    {
68
-        return $this->request('deactivate_license', $data);
69
-    }
63
+	/**
64
+	 * @return object
65
+	 */
66
+	public function deactivateLicense(array $data = [])
67
+	{
68
+		return $this->request('deactivate_license', $data);
69
+	}
70 70
 
71
-    /**
72
-     * @param false|object|array $result
73
-     * @param string $action
74
-     * @param object $args
75
-     * @return mixed
76
-     */
77
-    public function filterPluginUpdateDetails($result, $action, $args)
78
-    {
79
-        if ('plugin_information' != $action
80
-            || Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) {
81
-            return $result;
82
-        }
83
-        if ($updateInfo = $this->getPluginUpdate()) {
84
-            return $this->modifyUpdateDetails($updateInfo);
85
-        }
86
-        return $result;
87
-    }
71
+	/**
72
+	 * @param false|object|array $result
73
+	 * @param string $action
74
+	 * @param object $args
75
+	 * @return mixed
76
+	 */
77
+	public function filterPluginUpdateDetails($result, $action, $args)
78
+	{
79
+		if ('plugin_information' != $action
80
+			|| Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) {
81
+			return $result;
82
+		}
83
+		if ($updateInfo = $this->getPluginUpdate()) {
84
+			return $this->modifyUpdateDetails($updateInfo);
85
+		}
86
+		return $result;
87
+	}
88 88
 
89
-    /**
90
-     * @param object $transient
91
-     * @return object
92
-     */
93
-    public function filterPluginUpdates($transient)
94
-    {
95
-        if ($updateInfo = $this->getPluginUpdate()) {
96
-            return $this->modifyPluginUpdates($transient, $updateInfo);
97
-        }
98
-        return $transient;
99
-    }
89
+	/**
90
+	 * @param object $transient
91
+	 * @return object
92
+	 */
93
+	public function filterPluginUpdates($transient)
94
+	{
95
+		if ($updateInfo = $this->getPluginUpdate()) {
96
+			return $this->modifyPluginUpdates($transient, $updateInfo);
97
+		}
98
+		return $transient;
99
+	}
100 100
 
101
-    /**
102
-     * @return object
103
-     */
104
-    public function getVersion(array $data = [])
105
-    {
106
-        return $this->request('get_version', $data);
107
-    }
101
+	/**
102
+	 * @return object
103
+	 */
104
+	public function getVersion(array $data = [])
105
+	{
106
+		return $this->request('get_version', $data);
107
+	}
108 108
 
109
-    /**
110
-     * @return void
111
-     */
112
-    public function init()
113
-    {
114
-        if ($this->apiUrl === trailingslashit(home_url())) {
115
-            return;
116
-        }
117
-        add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3);
118
-        add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999);
119
-        add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9);
120
-        add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']);
121
-    }
109
+	/**
110
+	 * @return void
111
+	 */
112
+	public function init()
113
+	{
114
+		if ($this->apiUrl === trailingslashit(home_url())) {
115
+			return;
116
+		}
117
+		add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3);
118
+		add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999);
119
+		add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9);
120
+		add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']);
121
+	}
122 122
 
123
-    /**
124
-     * @return bool
125
-     */
126
-    public function isLicenseValid()
127
-    {
128
-        $result = $this->checkLicense();
129
-        return 'valid' === Arr::get($result, 'license');
130
-    }
123
+	/**
124
+	 * @return bool
125
+	 */
126
+	public function isLicenseValid()
127
+	{
128
+		$result = $this->checkLicense();
129
+		return 'valid' === Arr::get($result, 'license');
130
+	}
131 131
 
132
-    /**
133
-     * @return void
134
-     */
135
-    public function onForceUpdateCheck()
136
-    {
137
-        if (!filter_input(INPUT_GET, 'force-check')) {
138
-            return;
139
-        }
140
-        foreach (glsr()->addons as $addon) {
141
-            try {
142
-                glsr($addon)->updater->getPluginUpdate(true);
143
-            } catch (\Exception $e) {
144
-                glsr_log()->error($e->getMessage());
145
-            }
146
-        }
147
-    }
132
+	/**
133
+	 * @return void
134
+	 */
135
+	public function onForceUpdateCheck()
136
+	{
137
+		if (!filter_input(INPUT_GET, 'force-check')) {
138
+			return;
139
+		}
140
+		foreach (glsr()->addons as $addon) {
141
+			try {
142
+				glsr($addon)->updater->getPluginUpdate(true);
143
+			} catch (\Exception $e) {
144
+				glsr_log()->error($e->getMessage());
145
+			}
146
+		}
147
+	}
148 148
 
149
-    /**
150
-     * @return void
151
-     */
152
-    public function renderLicenseMissingLink()
153
-    {
154
-        if (!$this->isLicenseValid()) {
155
-            glsr()->render('partials/addons/license-missing');
156
-        }
157
-    }
149
+	/**
150
+	 * @return void
151
+	 */
152
+	public function renderLicenseMissingLink()
153
+	{
154
+		if (!$this->isLicenseValid()) {
155
+			glsr()->render('partials/addons/license-missing');
156
+		}
157
+	}
158 158
 
159
-    /**
160
-     * @return false|object
161
-     */
162
-    protected function getCachedVersion()
163
-    {
164
-        return get_transient($this->transientName);
165
-    }
159
+	/**
160
+	 * @return false|object
161
+	 */
162
+	protected function getCachedVersion()
163
+	{
164
+		return get_transient($this->transientName);
165
+	}
166 166
 
167
-    /**
168
-     * @param bool $force
169
-     * @return false|object
170
-     */
171
-    protected function getPluginUpdate($force = false)
172
-    {
173
-        $version = $this->getCachedVersion();
174
-        if (false === $version || $force) {
175
-            $version = $this->getVersion();
176
-            $this->setCachedVersion($version);
177
-        }
178
-        if (isset($version->error)) {
179
-            glsr_log()->error($version->error);
180
-            return false;
181
-        }
182
-        return $version;
183
-    }
167
+	/**
168
+	 * @param bool $force
169
+	 * @return false|object
170
+	 */
171
+	protected function getPluginUpdate($force = false)
172
+	{
173
+		$version = $this->getCachedVersion();
174
+		if (false === $version || $force) {
175
+			$version = $this->getVersion();
176
+			$this->setCachedVersion($version);
177
+		}
178
+		if (isset($version->error)) {
179
+			glsr_log()->error($version->error);
180
+			return false;
181
+		}
182
+		return $version;
183
+	}
184 184
 
185
-    /**
186
-     * @param object $transient
187
-     * @param object $updateInfo
188
-     * @return object
189
-     */
190
-    protected function modifyPluginUpdates($transient, $updateInfo)
191
-    {
192
-        $updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain');
193
-        $updateInfo->plugin = $this->plugin;
194
-        $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP');
195
-        $updateInfo->tested = Arr::get($this->data, 'testedTo');
196
-        $transient->checked[$this->plugin] = Arr::get($this->data, 'Version');
197
-        $transient->last_checked = time();
198
-        if (Helper::isGreaterThan($updateInfo->new_version, Arr::get($this->data, 'Version'))) {
199
-            unset($transient->no_update[$this->plugin]);
200
-            $updateInfo->update = true;
201
-            $transient->response[$this->plugin] = $updateInfo;
202
-        } else {
203
-            unset($transient->response[$this->plugin]);
204
-            $transient->no_update[$this->plugin] = $updateInfo;
205
-        }
206
-        return $transient;
207
-    }
185
+	/**
186
+	 * @param object $transient
187
+	 * @param object $updateInfo
188
+	 * @return object
189
+	 */
190
+	protected function modifyPluginUpdates($transient, $updateInfo)
191
+	{
192
+		$updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain');
193
+		$updateInfo->plugin = $this->plugin;
194
+		$updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP');
195
+		$updateInfo->tested = Arr::get($this->data, 'testedTo');
196
+		$transient->checked[$this->plugin] = Arr::get($this->data, 'Version');
197
+		$transient->last_checked = time();
198
+		if (Helper::isGreaterThan($updateInfo->new_version, Arr::get($this->data, 'Version'))) {
199
+			unset($transient->no_update[$this->plugin]);
200
+			$updateInfo->update = true;
201
+			$transient->response[$this->plugin] = $updateInfo;
202
+		} else {
203
+			unset($transient->response[$this->plugin]);
204
+			$transient->no_update[$this->plugin] = $updateInfo;
205
+		}
206
+		return $transient;
207
+	}
208 208
 
209
-    /**
210
-     * @param object $updateInfo
211
-     * @return object
212
-     */
213
-    protected function modifyUpdateDetails($updateInfo)
214
-    {
215
-        $updateInfo->author = Arr::get($this->data, 'Author');
216
-        $updateInfo->author_profile = Arr::get($this->data, 'AuthorURI');
217
-        $updateInfo->requires = Arr::get($this->data, 'RequiresWP');
218
-        $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP');
219
-        $updateInfo->tested = Arr::get($this->data, 'testedTo');
220
-        $updateInfo->version = $updateInfo->new_version;
221
-        return $updateInfo;
222
-    }
209
+	/**
210
+	 * @param object $updateInfo
211
+	 * @return object
212
+	 */
213
+	protected function modifyUpdateDetails($updateInfo)
214
+	{
215
+		$updateInfo->author = Arr::get($this->data, 'Author');
216
+		$updateInfo->author_profile = Arr::get($this->data, 'AuthorURI');
217
+		$updateInfo->requires = Arr::get($this->data, 'RequiresWP');
218
+		$updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP');
219
+		$updateInfo->tested = Arr::get($this->data, 'testedTo');
220
+		$updateInfo->version = $updateInfo->new_version;
221
+		return $updateInfo;
222
+	}
223 223
 
224
-    /**
225
-     * @param \WP_Error|array $response
226
-     * @return object
227
-     */
228
-    protected function normalizeResponse($response)
229
-    {
230
-        $body = wp_remote_retrieve_body($response);
231
-        if ($data = json_decode($body)) {
232
-            $data = array_map('maybe_unserialize', (array) $data);
233
-            return (object) $data;
234
-        }
235
-        $error = is_wp_error($response)
236
-            ? $response->get_error_message()
237
-            : 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')';
238
-        return (object) ['error' => $error];
239
-    }
224
+	/**
225
+	 * @param \WP_Error|array $response
226
+	 * @return object
227
+	 */
228
+	protected function normalizeResponse($response)
229
+	{
230
+		$body = wp_remote_retrieve_body($response);
231
+		if ($data = json_decode($body)) {
232
+			$data = array_map('maybe_unserialize', (array) $data);
233
+			return (object) $data;
234
+		}
235
+		$error = is_wp_error($response)
236
+			? $response->get_error_message()
237
+			: 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')';
238
+		return (object) ['error' => $error];
239
+	}
240 240
 
241
-    /**
242
-     * @param string $action activate_license|check_license|deactivate_license|get_version
243
-     * @return object
244
-     */
245
-    protected function request($action, array $data = [])
246
-    {
247
-        $data = wp_parse_args($data, $this->data);
248
-        $response = wp_remote_post($this->apiUrl, [
249
-            'body' => [
250
-                'edd_action' => $action,
251
-                'item_id' => Arr::get($data, 'item_id'),
252
-                'item_name' => Arr::get($data, 'Name'),
253
-                'license' => Arr::get($data, 'license'),
254
-                'slug' => Arr::get($data, 'TextDomain'),
255
-                'url' => home_url(),
256
-            ],
257
-            'sslverify' => apply_filters('site-reviews/sslverify/post', false),
258
-            'timeout' => 15,
259
-        ]);
260
-        return $this->normalizeResponse($response);
261
-    }
241
+	/**
242
+	 * @param string $action activate_license|check_license|deactivate_license|get_version
243
+	 * @return object
244
+	 */
245
+	protected function request($action, array $data = [])
246
+	{
247
+		$data = wp_parse_args($data, $this->data);
248
+		$response = wp_remote_post($this->apiUrl, [
249
+			'body' => [
250
+				'edd_action' => $action,
251
+				'item_id' => Arr::get($data, 'item_id'),
252
+				'item_name' => Arr::get($data, 'Name'),
253
+				'license' => Arr::get($data, 'license'),
254
+				'slug' => Arr::get($data, 'TextDomain'),
255
+				'url' => home_url(),
256
+			],
257
+			'sslverify' => apply_filters('site-reviews/sslverify/post', false),
258
+			'timeout' => 15,
259
+		]);
260
+		return $this->normalizeResponse($response);
261
+	}
262 262
 
263
-    /**
264
-     * @param object $version
265
-     * @return void
266
-     */
267
-    protected function setCachedVersion($version)
268
-    {
269
-        if (!isset($version->error)) {
270
-            set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS);
271
-        }
272
-    }
263
+	/**
264
+	 * @param object $version
265
+	 * @return void
266
+	 */
267
+	protected function setCachedVersion($version)
268
+	{
269
+		if (!isset($version->error)) {
270
+			set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS);
271
+		}
272
+	}
273 273
 }
Please login to merge, or discard this patch.