Issues (1066)

includes/class-lsx-projects-scpo-engine.php (192 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
3
$lsx_projects_scporder = new LSX_Projects_SCPO_Engine();
4
5
/**
6
 * SCPO Engine
7
 *
8
 * @package   LSX Projects
9
 * @author    LightSpeed
10
 * @license   GPL3
11
 * @link
12
 * @copyright 2016 LightSpeed
13
 */
14
class LSX_Projects_SCPO_Engine {
15
16
	function __construct() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
Expected 2 blank lines before function; 1 found
Loading history...
17
		if ( ! get_option( 'lsx_projects_scporder_install' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
18
			$this->lsx_projects_scporder_install();
19
		}
20
21
		add_action( 'admin_init', array( $this, 'refresh' ) );
22
		add_action( 'admin_init', array( $this, 'load_script_css' ) );
23
24
		add_action( 'wp_ajax_update-menu-order', array( $this, 'update_menu_order' ) );
25
26
		add_action( 'pre_get_posts', array( $this, 'lsx_projects_scporder_pre_get_posts' ) );
27
28
		add_filter( 'get_previous_post_where', array( $this, 'lsx_projects_scporder_previous_post_where' ) );
29
		add_filter( 'get_previous_post_sort', array( $this, 'lsx_projects_scporder_previous_post_sort' ) );
30
		add_filter( 'get_next_post_where', array( $this, 'lsx_projects_scporder_next_post_where' ) );
31
		add_filter( 'get_next_post_sort', array( $this, 'lsx_projects_scporder_next_post_sort' ) );
32
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
33
34
	function lsx_projects_scporder_install() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_install()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for lsx_projects_scporder_install.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
35
		update_option( 'lsx_projects_scporder_install', 1 );
36
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
37
38
	function _check_load_script_css() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function _check_load_script_css()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for _check_load_script_css.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
39
		$active = false;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40
		$objects = $this->get_lsx_projects_scporder_options_objects();
41
42
		if ( empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
43
			return false;
44
		}
45
46
		if ( isset( $_GET['orderby'] ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'action=edit' ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/post-new.php' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
Detected usage of a possibly undefined superglobal array index: $_SERVER['REQUEST_URI']. Use isset() or empty() to check the index exists before using it
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
It seems like wp_unslash($_SERVER['REQUEST_URI']) can also be of type array; however, parameter $str of sanitize_text_field() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
		if ( isset( $_GET['orderby'] ) || strstr( sanitize_text_field( /** @scrutinizer ignore-type */ wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'action=edit' ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/post-new.php' ) ) {
Loading history...
47
			return false;
48
		}
49
50
		if ( ! empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
51
			if ( isset( $_GET['post_type'] ) && ! isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['post_type'] ) ), $objects ) ) { // if page or custom post types
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
52
				$active = true;
53
			}
54
55
			if ( ! isset( $_GET['post_type'] ) && strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/edit.php' ) && array_key_exists( 'post', $objects ) ) { // if post
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
Detected usage of a possibly undefined superglobal array index: $_SERVER['REQUEST_URI']. Use isset() or empty() to check the index exists before using it
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
56
				$active = true;
57
			}
58
		}
59
60
		return $active;
61
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
62
63
	function load_script_css() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function load_script_css()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for load_script_css.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
64
		if ( $this->_check_load_script_css() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
65
			wp_enqueue_script( 'scporderjs', LSX_PROJECTS_URL . 'assets/js/scporder.min.js', array( 'jquery', 'jquery-ui-sortable' ), null, true );
0 ignored issues
show
Resource version not set in call to wp_enqueue_script(). This means new versions of the script will not always be loaded due to browser caching.
Loading history...
66
67
			$scporderjs_params = array(
68
				'ajax_url' => admin_url( 'admin-ajax.php' ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 3 space(s) between "'ajax_url'" and double arrow, but found 1.
Loading history...
69
				'ajax_nonce' => wp_create_nonce( 'scporder' ),
70
			);
71
72
			wp_localize_script( 'scporderjs', 'scporderjs_params', $scporderjs_params );
73
74
			wp_enqueue_style( 'scporder', LSX_PROJECTS_URL . 'assets/css/scporder.css', array(), null );
0 ignored issues
show
Resource version not set in call to wp_enqueue_style(). This means new versions of the style will not always be loaded due to browser caching.
Loading history...
75
		}
76
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
77
78
	function refresh() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function refresh()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for refresh.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
79
		global $wpdb;
80
81
		$objects = $this->get_lsx_projects_scporder_options_objects();
82
83
		if ( ! empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
84
			foreach ( $objects as $object => $object_data ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
85
				$result = $wpdb->get_results($wpdb->prepare("
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
86
					SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
87
					FROM $wpdb->posts
88
					WHERE post_type = '%s' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
0 ignored issues
show
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
89
				", $object));
0 ignored issues
show
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
90
91
				if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
92
					continue;
93
				}
94
95
				$results = $wpdb->get_results( $wpdb->prepare("
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
96
					SELECT ID
97
					FROM $wpdb->posts
98
					WHERE post_type = '%s' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
0 ignored issues
show
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
99
					ORDER BY menu_order ASC
100
				", $object ) );
0 ignored issues
show
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
101
102
				foreach ( $results as $key => $result ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
103
					$wpdb->update(
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
104
						$wpdb->posts,
105
						array(
106
							'menu_order' => $key + 1,
107
						),
108
						array(
109
							'ID' => $result->ID,
110
						)
111
					);
112
				}
113
			}
114
		}
115
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
116
117
	function update_menu_order() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function update_menu_order()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for update_menu_order.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
118
		check_ajax_referer( 'scporder', 'security' );
119
120
		global $wpdb;
121
122
		parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data );
0 ignored issues
show
Detected usage of a possibly undefined superglobal array index: $_POST['order']. Use isset() or empty() to check the index exists before using it
Loading history...
123
124
		if ( ! is_array( $data ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
125
			return false;
126
		}
127
128
		$id_arr = array();
129
130
		foreach ( $data as $key => $values ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
131
			foreach ( $values as $position => $id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
132
				$id_arr[] = $id;
133
			}
134
		}
135
136
		$menu_order_arr = array();
137
138
		foreach ( $id_arr as $key => $id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
139
			$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval( $id ) );
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
140
141
			foreach ( $results as $result ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
142
				$menu_order_arr[] = $result->menu_order;
143
			}
144
		}
145
146
		sort( $menu_order_arr );
147
148
		foreach ( $data as $key => $values ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
149
			foreach ( $values as $position => $id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
150
				$wpdb->update(
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
151
					$wpdb->posts,
152
					array(
153
						'menu_order' => $menu_order_arr[ $position ],
154
					),
155
					array(
156
						'ID' => intval( $id ),
157
					)
158
				);
159
			}
160
		}
161
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
162
163
	function lsx_projects_scporder_previous_post_where( $where ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_previous_post_where()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for lsx_projects_scporder_previous_post_where.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
164
		global $post;
165
166
		$objects = $this->get_lsx_projects_scporder_options_objects();
167
168
		if ( empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
169
			return $where;
170
		}
171
172
		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
173
			$current_menu_order = $post->menu_order;
174
			$where = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
175
		}
176
177
		return $where;
178
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
179
180
	function lsx_projects_scporder_previous_post_sort( $orderby ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_previous_post_sort()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for lsx_projects_scporder_previous_post_sort.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
181
		global $post;
182
183
		$objects = $this->get_lsx_projects_scporder_options_objects();
184
185
		if ( empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
186
			return $orderby;
187
		}
188
189
		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
190
			$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
191
		}
192
193
		return $orderby;
194
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
195
196
	function lsx_projects_scporder_next_post_where( $where ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_next_post_where()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for lsx_projects_scporder_next_post_where.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
197
		global $post;
198
199
		$objects = $this->get_lsx_projects_scporder_options_objects();
200
201
		if ( empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
202
			return $where;
203
		}
204
205
		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
206
			$current_menu_order = $post->menu_order;
207
			$where = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
208
		}
209
210
		return $where;
211
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
212
213
	function lsx_projects_scporder_next_post_sort( $orderby ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_next_post_sort()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for lsx_projects_scporder_next_post_sort.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
214
		global $post;
215
216
		$objects = $this->get_lsx_projects_scporder_options_objects();
217
218
		if ( empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
219
			return $orderby;
220
		}
221
222
		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
223
			$orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
224
		}
225
226
		return $orderby;
227
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
228
229
	function lsx_projects_scporder_pre_get_posts( $wp_query ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_pre_get_posts()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for lsx_projects_scporder_pre_get_posts.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
230
		$objects = $this->get_lsx_projects_scporder_options_objects();
231
232
		if ( empty( $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
233
			return false;
234
		}
235
236
		if ( is_admin() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
237
			if ( isset( $wp_query->query['post_type'] ) && ! isset( $_GET['orderby'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
238
				if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
239
					$wp_query->set( 'orderby', 'menu_order' );
240
					$wp_query->set( 'order', 'ASC' );
241
				}
242
			}
243
		} else {
244
			$active = false;
245
246
			if ( isset( $wp_query->query['post_type'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
247
				if ( ! is_array( $wp_query->query['post_type'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
248
					if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
249
						$active = true;
250
					}
251
				}
252
			} else {
253
				if ( array_key_exists( 'post', $objects ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
254
					$active = true;
255
				}
256
			}
257
258
			if ( ! $active ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
259
				return false;
260
			}
261
262
			if ( isset( $wp_query->query['suppress_filters'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
263
				if ( $wp_query->get( 'orderby' ) == 'date' ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
264
					$wp_query->set( 'orderby', 'menu_order' );
265
				}
266
267
				if ( $wp_query->get( 'order' ) == 'DESC' ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
268
					$wp_query->set( 'order', 'ASC' );
269
				}
270
			} else {
271
				if ( ! $wp_query->get( 'orderby' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
272
					$wp_query->set( 'orderby', 'menu_order' );
273
				}
274
275
				if ( ! $wp_query->get( 'order' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
276
					$wp_query->set( 'order', 'ASC' );
277
				}
278
			}
279
		}
280
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
281
282
	function get_lsx_projects_scporder_options_objects() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function get_lsx_projects_scporder_options_objects()
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for get_lsx_projects_scporder_options_objects.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
283
		return array(
284
			'project' => esc_html_x( 'Project', 'post type singular name', 'lsx-project' ),
285
		);
286
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
287
288
}
289
290
/**
291
 * SCP Order Uninstall hook
292
 */
293
register_uninstall_hook( __FILE__, 'lsx_projects_scporder_uninstall' );
294
295
function lsx_projects_scporder_uninstall() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_uninstall()
Loading history...
Expected 2 blank lines before function; 1 found
Loading history...
296
	global $wpdb;
297
298
	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
299
		$curr_blog = $wpdb->blogid;
300
		$blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
301
302
		foreach ( $blogids as $blog_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
303
			switch_to_blog( $blog_id );
304
			lsx_projects_scporder_uninstall_db();
305
		}
306
307
		switch_to_blog( $curr_blog );
308
	} else {
309
		lsx_projects_scporder_uninstall_db();
310
	}
311
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
312
313
function lsx_projects_scporder_uninstall_db() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_scporder_uninstall_db()
Loading history...
314
	delete_option( 'lsx_projects_scporder_install' );
315
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
316