Issues (4138)

classes/class-scpo-engine.php (287 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
3
namespace lsx_health_plan\classes;
4
5
class SCPO_Engine {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class SCPO_Engine
Loading history...
6
7
	/**
8
	 * Holds class instance
9
	 *
10
	 * @since 1.0.0
11
	 *
12
	 * @var      object \lsx_health_plan\classes\SCPO_Engine()
13
	 */
14
	protected static $instance = null;
15
16
	/**
17
	 * Return an instance of this class.
18
	 *
19
	 * @since 1.0.0
20
	 *
21
	 * @return    object \lsx_health_plan\classes\SCPO_Engine()    A single instance of this class.
22
	 */
23
	public static function get_instance() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
24
		// If the single instance hasn't been set, set it now.
25
		if ( null == self::$instance ) {
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...
26
			self::$instance = new self;
0 ignored issues
show
Parenthesis should always be used when instantiating a new object.
Loading history...
27
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
28
		return self::$instance;
29
	}
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...
30
31
	public function __construct() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
32
		if ( ! get_option( 'lsx_to_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...
33
			$this->lsx_to_scporder_install();
34
		}
35
36
		add_action( 'admin_init', array( $this, 'refresh' ) );
37
		add_action( 'admin_init', array( $this, 'load_script_css' ) );
38
39
		add_action( 'wp_ajax_update-menu-order', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
40
			$this,
41
			'update_menu_order',
42
		) );
0 ignored issues
show
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...
43
		add_action( 'wp_ajax_update-menu-order-tags', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
44
			$this,
45
			'update_menu_order_tags',
46
		) );
0 ignored issues
show
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...
47
48
		add_action( 'pre_get_posts', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
49
			$this,
50
			'lsx_to_scporder_pre_get_posts',
51
		) );
0 ignored issues
show
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...
52
53
		add_filter( 'get_previous_post_where', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
54
			$this,
55
			'lsx_to_scporder_previous_post_where',
56
		) );
0 ignored issues
show
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...
57
		add_filter( 'get_previous_post_sort', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
58
			$this,
59
			'lsx_to_scporder_previous_post_sort',
60
		) );
0 ignored issues
show
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...
61
		add_filter( 'get_next_post_where', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
62
			$this,
63
			'lsx_to_scporder_next_post_where',
64
		) );
0 ignored issues
show
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...
65
		add_filter( 'get_next_post_sort', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
66
			$this,
67
			'lsx_to_scporder_next_post_sort',
68
		) );
0 ignored issues
show
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...
69
70
		add_filter( 'get_terms_orderby', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
71
			$this,
72
			'lsx_to_scporder_get_terms_orderby',
73
		), 10, 3 );
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...
74
		add_filter( 'wp_get_object_terms', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
75
			$this,
76
			'lsx_to_scporder_get_object_terms',
77
		), 10, 4 );
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...
78
		add_filter( 'get_terms', array(
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
79
			$this,
80
			'lsx_to_scporder_get_object_terms',
81
		), 10, 4 );
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...
82
	}
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...
83
84
	public function lsx_to_scporder_install() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_install()
Loading history...
85
		global $wpdb;
86
		$result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_to_term_order`" );
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...
87
88
		if ( ! $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...
89
			$result = $wpdb->query( "ALTER TABLE $wpdb->terms ADD `lsx_to_term_order` INT(4) NULL DEFAULT '0'" );
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...
Attempting a database schema change is discouraged.
Loading history...
90
		}
91
92
		update_option( 'lsx_to_scporder_install', 1 );
93
	}
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...
94
95
	public function _check_load_script_css() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function _check_load_script_css()
Loading history...
96
		$active = false;
97
98
		$objects = $this->get_to_scporder_options_objects();
99
		$tags    = $this->get_to_scporder_options_tags();
100
101
		if ( empty( $objects ) && empty( $tags ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
102
			return false;
103
		}
104
105
		if ( isset( $_GET['orderby'] ) || strstr( sanitize_text_field( $_SERVER['REQUEST_URI'] ), 'action=edit' ) || strstr( sanitize_text_field( $_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...
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
106
			return false;
107
		}
108
109
		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...
110
			if ( isset( $_GET['post_type'] ) && ! isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( $_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...
$_GET data not unslashed before sanitization. Use wp_unslash() or similar
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...
111
				$active = true;
112
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
113
			if ( ! isset( $_GET['post_type'] ) && strstr( sanitize_text_field( $_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...
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar
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...
114
				$active = true;
115
			}
116
		}
117
118
		if ( ! empty( $tags ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
119
			if ( isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( $_GET['taxonomy'] ), $tags ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
$_GET data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
120
				$active = true;
121
			}
122
		}
123
124
		return $active;
125
	}
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...
126
127
	public function load_script_css() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function load_script_css()
Loading history...
128
		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...
129
			wp_enqueue_script( 'scporderjs', LSX_HEALTH_PLAN_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...
130
131
			$scporderjs_params = array(
132
				'ajax_url'   => admin_url( 'admin-ajax.php' ),
133
				'ajax_nonce' => wp_create_nonce( 'scporder' ),
134
			);
135
136
			wp_localize_script( 'scporderjs', 'scporderjs_params', $scporderjs_params );
137
138
			wp_enqueue_style( 'scporder', LSX_HEALTH_PLAN_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...
139
			wp_style_add_data( 'scporder', 'rtl', 'replace' );
140
		}
141
	}
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...
142
143
	public function refresh() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function refresh()
Loading history...
144
		global $wpdb;
145
		$objects = $this->get_to_scporder_options_objects();
146
		$tags    = $this->get_to_scporder_options_tags();
147
148
		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...
149
			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...
150
				$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...
151
					SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
152
					FROM $wpdb->posts
153
					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...
154
				", $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...
155
156
				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...
157
					continue;
158
				}
159
160
				$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...
161
					SELECT ID
162
					FROM $wpdb->posts
163
					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...
164
					ORDER BY menu_order ASC
165
				", $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...
166
167
				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...
168
					$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...
169
						$wpdb->posts,
170
						array(
171
							'menu_order' => $key + 1,
172
						),
173
						array(
174
							'ID' => $result->ID,
175
						)
176
					);
177
				}
178
			}
179
		}
180
181
		if ( ! empty( $tags ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
182
			foreach ( $tags as $taxonomy => $taxonomy_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...
183
				$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...
184
					SELECT count(*) as cnt, max(lsx_to_term_order) as max, min(lsx_to_term_order) as min
185
					FROM $wpdb->terms AS terms
186
					INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
187
					WHERE term_taxonomy.taxonomy = '%s'
0 ignored issues
show
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
188
				", $taxonomy ) );
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...
189
190
				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...
191
					continue;
192
				}
193
194
				$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...
195
					SELECT terms.term_id
196
					FROM $wpdb->terms AS terms
197
					INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
198
					WHERE term_taxonomy.taxonomy = '%s'
0 ignored issues
show
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
199
					ORDER BY lsx_to_term_order ASC
200
				", $taxonomy ) );
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...
201
202
				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...
203
					$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...
204
						$wpdb->terms,
205
						array(
206
							'lsx_to_term_order' => $key + 1,
207
						),
208
						array(
209
							'term_id' => $result->term_id,
210
						)
211
					);
212
				}
213
			}
214
		}
215
	}
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...
216
217
	public function update_menu_order() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function update_menu_order()
Loading history...
218
		check_ajax_referer( 'scporder', 'security' );
219
220
		global $wpdb;
221
222
		parse_str( sanitize_text_field( $_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...
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
223
224
		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...
225
			return false;
226
		}
227
228
		/*$id_arr = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Block comment text must start on a new line
Loading history...
229
230
		foreach ( $data as $key => $values ) {
231
			foreach ( $values as $position => $id ) {
232
				$id_arr[] = $id;
233
			}
234
		}
235
236
		$menu_order_arr = array();
237
238
		foreach ( $id_arr as $key => $id ) {
239
			$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval( $id ) );
240
			foreach ( $results as $result ) {
241
				$menu_order_arr[] = $result->menu_order;
242
			}
243
		}
244
245
		sort( $menu_order_arr );*/
246
247
		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...
248
			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...
249
				$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...
250
					$wpdb->posts,
251
					array(
252
						'menu_order' => $position,
253
					),
254
					array(
255
						'ID' => intval( $id ),
256
					)
257
				);
258
			}
259
		}
260
	}
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...
261
262
	public function update_menu_order_tags() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function update_menu_order_tags()
Loading history...
263
		check_ajax_referer( 'scporder', 'security' );
264
265
		global $wpdb;
266
267
		parse_str( sanitize_text_field( $_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...
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
268
269
		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...
270
			return false;
271
		}
272
273
		/*$current_user = wp_get_current_user();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Block comment text must start on a new line
Loading history...
274
		if ( false === $current_user || 'lightspeed' !== $current_user->data->user_login ) {
275
			return false;
276
		}*/
277
278
		/*$id_arr = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Block comment text must start on a new line
Loading history...
279
280
		foreach ( $data as $key => $values ) {
281
			foreach ( $values as $position => $id ) {
282
				$id_arr[] = $id;
283
			}
284
		}
285
286
		$menu_order_arr = array();
287
288
		foreach ( $id_arr as $key => $id ) {
289
			$results = $wpdb->get_results( "SELECT lsx_to_term_order FROM $wpdb->terms WHERE term_id = " . intval( $id ) );
290
			foreach ( $results as $result ) {
291
				$menu_order_arr[] = $result->lsx_to_term_order;
292
			}
293
		}
294
295
		sort( $menu_order_arr );*/
296
297
		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...
298
			$term_ids = array();
299
			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...
300
				$wpdb->update(
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
301
					$wpdb->terms,
302
					array(
303
						'lsx_to_term_order' => $position + 1,
304
					),
305
					array(
306
						'term_id' => intval( $id ),
307
					)
308
				);
309
				$term_ids[] = intval( $id );
310
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
311
			clean_term_cache( $term_ids );
312
		}
313
	}
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...
314
315
	public function lsx_to_scporder_previous_post_where( $where ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_previous_post_where()
Loading history...
316
		global $post;
317
		$objects = $this->get_to_scporder_options_objects();
318
319
		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...
320
			return $where;
321
		}
322
323
		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...
324
			$current_menu_order = $post->menu_order;
325
			$where              = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
326
		}
327
328
		return $where;
329
	}
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...
330
331
	public function lsx_to_scporder_previous_post_sort( $orderby ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_previous_post_sort()
Loading history...
332
		global $post;
333
		$objects = $this->get_to_scporder_options_objects();
334
335
		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...
336
			return $orderby;
337
		}
338
339
		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...
340
			$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
341
		}
342
343
		return $orderby;
344
	}
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...
345
346
	public function lsx_to_scporder_next_post_where( $where ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_next_post_where()
Loading history...
347
		global $post;
348
		$objects = $this->get_to_scporder_options_objects();
349
350
		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...
351
			return $where;
352
		}
353
354
		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...
355
			$current_menu_order = $post->menu_order;
356
			$where              = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
357
		}
358
359
		return $where;
360
	}
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...
361
362
	public function lsx_to_scporder_next_post_sort( $orderby ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_next_post_sort()
Loading history...
363
		global $post;
364
		$objects = $this->get_to_scporder_options_objects();
365
366
		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...
367
			return $orderby;
368
		}
369
370
		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...
371
			$orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
372
		}
373
374
		return $orderby;
375
	}
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...
376
377
	public function lsx_to_scporder_pre_get_posts( $wp_query ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_pre_get_posts()
Loading history...
378
		$objects = $this->get_to_scporder_options_objects();
379
380
		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...
381
			return false;
382
		}
383
384
		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...
385
			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...
386
				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...
387
					$wp_query->set( 'orderby', 'menu_order' );
388
					$wp_query->set( 'order', 'ASC' );
389
				}
390
			}
391
		} else {
392
			$active = false;
393
394
			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...
395
				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...
396
					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...
397
						$active = true;
398
					}
399
				}
400
			} else {
401
				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...
402
					$active = true;
403
				}
404
			}
405
406
			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...
407
				return false;
408
			}
409
410
			if ( isset( $wp_query->query['disabled_custom_post_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...
411
				return false;
412
			}
413
414
			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...
415
				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...
416
					$wp_query->set( 'orderby', 'menu_order' );
417
				}
0 ignored issues
show
No blank line found after control structure
Loading history...
418
				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...
419
					$wp_query->set( 'order', 'ASC' );
420
				}
421
			} else {
422
				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...
423
					$wp_query->set( 'orderby', 'menu_order' );
424
				}
0 ignored issues
show
No blank line found after control structure
Loading history...
425
				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...
426
					$wp_query->set( 'order', 'ASC' );
427
				}
428
			}
429
		}
430
	}
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...
431
432
	public function lsx_to_scporder_get_terms_orderby( $orderby, $args ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_get_terms_orderby()
Loading history...
Expected 0 blank lines after opening function brace; 1 found
Loading history...
433
434
		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...
435
			return $orderby;
436
		}
437
438
		if ( isset( $args['disabled_custom_post_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...
439
			return $orderby;
440
		}
441
442
		$tags = $this->get_to_scporder_options_tags();
443
444
		if ( ! isset( $args['taxonomy'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
445
			return $orderby;
446
		}
447
448
		$taxonomy = $args['taxonomy'];
449
		if ( is_array( $taxonomy ) && count( $taxonomy ) == 1 ) {
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...
450
			$taxonomy = $taxonomy[0];
451
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
452
		if ( ! is_array( $taxonomy ) && ! array_key_exists( $taxonomy, $tags ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
453
			return $orderby;
454
		}
455
456
		$orderby = 't.lsx_to_term_order';
457
458
		return $orderby;
459
	}
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...
460
461
	public function lsx_to_scporder_get_object_terms( $terms, $not_used, $args_1, $args_2 = null ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_to_scporder_get_object_terms()
Loading history...
462
		$tags = $this->get_to_scporder_options_tags();
463
464
		if ( is_admin() && 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...
465
			return $terms;
466
		}
467
468
		$args = is_null( $args_2 ) || ! is_array( $args_2 ) ? $args_1 : $args_2;
469
470
		if ( isset( $args['disabled_custom_post_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...
471
			return $terms;
472
		}
473
474
		foreach ( $terms as $key => $term ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
475
			if ( is_object( $term ) && isset( $term->taxonomy ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
476
				$taxonomy = $term->taxonomy;
477
				if ( ! array_key_exists( $taxonomy, $tags ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
478
					return $terms;
479
				}
480
			} else {
481
				return $terms;
482
			}
483
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
484
		usort( $terms, array( $this, 'taxcmp' ) );
485
		return $terms;
486
	}
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...
487
488
	public function taxcmp( $a, $b ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function taxcmp()
Loading history...
489
		if ( $a->lsx_to_term_order == $b->lsx_to_term_order ) {
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...
490
			return 0;
491
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
492
		return ( $a->lsx_to_term_order < $b->lsx_to_term_order ) ? - 1 : 1;
493
	}
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...
494
495
	public function get_to_scporder_options_objects() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function get_to_scporder_options_objects()
Loading history...
496
		$ordering = array(
497
			'plan' => 'plan',
498
		);
499
		return $ordering;
500
	}
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...
501
502
	public function get_to_scporder_options_tags() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function get_to_scporder_options_tags()
Loading history...
503
		$ordering = array(
504
			'week' => 'week',
0 ignored issues
show
Array double arrow not aligned correctly; expected 8 space(s) between "'week'" and double arrow, but found 1.
Loading history...
505
			'recipe-type' => 'recipe-type',
506
		);
507
		return $ordering;
508
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
509
}
510
511