Passed
Push — master ( 93685b...ba539e )
by Warwick
02:09
created

helpers.php ➔ get_options()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 5
nop 0
dl 0
loc 14
rs 8.4444
c 0
b 0
f 0
1
<?php
2
/**
3
 * Helper functions
4
 *
5
 * @package   lsx_wetu_importer
6
 * @author    LightSpeed
7
 * @license   GPL-2.0+
8
 * @link
9
 * @copyright 2019 LightSpeed
10
 **/
11
12
/**
13
 * Gets the settings
14
 *
15
 * @return array
16
 */
17
function lsx_wetu_get_options() {
18
	$options = get_option( 'lsx_wetu_importer_settings', array() );
19
	if ( empty( $options ) ) {
20
		// Check for any previous options.
21
		$temp_options = get_option( '_lsx-to_settings', false );
22
		if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) {
23
			$options = $temp_options['lsx-wetu-importer'];
24
		}
25
		if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) {
26
			$options['api_key'] = $temp_options['api']['wetu_api_key'];
27
		}
28
	}
29
	return $options;
30
}
31
32
/**
33
 * Get the post count.
34
 *
35
 * @param string $post_type
36
 * @param string $post_status
37
 * @return void
38
 */
39
function lsx_wetu_get_post_count( $post_type = '', $post_status = '' ) {
40
	global $wpdb;
41
	$count = '0';
42
	if ( '' !== $post_type && '' !== $post_status ) {
43
		$result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
44
		if ( false !== $result && '' !== $result ) {
45
			$count = $result;
46
		}
47
	}
48
	return $count;
49
}
50
51
/**
52
 * Returns the wetu queue count.
53
 *
54
 * @param string $post_type
55
 * @return void
56
 */
57
function lsx_wetu_get_queue_count( $post_type = '' ) {
58
	$count = '0';
59
	$queued_imports = get_option( 'lsx_wetu_importer_que', array() );
60
	if ( isset( $queued_imports[ $post_type ] ) ) {
61
		$count = count( $queued_imports[ $post_type ] );
62
	}
63
	return $count;
64
}
65
66
/**
67
 * Returns the wetu tour count.
68
 *
69
 * @param string $post_type
70
 * @return void
71
 */
72
function lsx_wetu_get_tour_count( $post_type = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
	$count = '0';
74
	$wetu_tours = get_transient( 'lsx_ti_tours', array() );
75
	if ( ! empty( $wetu_tours ) ) {
76
		$count = count( $wetu_tours );
77
	}
78
	return $count;
79
}
80