|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Helper functions |
|
4
|
|
|
* |
|
5
|
|
|
* @package wetu_importer |
|
6
|
|
|
* @author LightSpeed |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link |
|
9
|
|
|
* @copyright 2019 LightSpeed |
|
10
|
|
|
**/ |
|
11
|
|
|
|
|
12
|
|
|
namespace wetu_importer\includes\helpers; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Gets the settings |
|
16
|
|
|
* |
|
17
|
|
|
* @return array |
|
18
|
|
|
*/ |
|
19
|
|
|
function get_options() { |
|
20
|
|
|
$options = get_option( 'wetu_importer_settings', array() ); |
|
21
|
|
|
if ( empty( $options ) ) { |
|
22
|
|
|
// Check for any previous options. |
|
23
|
|
|
$temp_options = get_option( '_lsx-to_settings', false ); |
|
24
|
|
|
if ( false !== $temp_options && isset( $temp_options['wetu-importer'] ) && ! empty( $temp_options['wetu-importer'] ) ) { |
|
25
|
|
|
$options = $temp_options['wetu-importer']; |
|
26
|
|
|
} |
|
27
|
|
|
if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) { |
|
28
|
|
|
$options['api_key'] = $temp_options['api']['wetu_api_key']; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
return $options; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get the post count. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $post_type |
|
39
|
|
|
* @param string $post_status |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
function get_post_count( $post_type = '', $post_status = '' ) { |
|
43
|
|
|
global $wpdb; |
|
44
|
|
|
$count = '0'; |
|
45
|
|
|
if ( '' !== $post_type && '' !== $post_status ) { |
|
46
|
|
|
$result = $wpdb->get_var(" |
|
47
|
|
|
SELECT COUNT(`ID`) |
|
48
|
|
|
FROM `{$wpdb->posts}` |
|
49
|
|
|
WHERE `post_status` = '{$post_status}' AND `post_type` = '{$post_type}' |
|
50
|
|
|
"); |
|
51
|
|
|
if ( false !== $result && '' !== $result ) { |
|
52
|
|
|
$count = $result; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
return $count; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the wetu queue count. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $post_type |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
function get_wetu_queue_count( $post_type = '' ) { |
|
65
|
|
|
$count = '0'; |
|
66
|
|
|
$queued_imports = get_option( 'wetu_importer_que', array() ); |
|
67
|
|
|
if ( isset( $queued_imports[ $post_type ] ) ) { |
|
68
|
|
|
$count = count( $queued_imports[ $post_type ] ); |
|
69
|
|
|
} |
|
70
|
|
|
return $count; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the wetu tour count. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $post_type |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
function get_wetu_tour_count( $post_type = '' ) { |
|
|
|
|
|
|
80
|
|
|
$count = '0'; |
|
81
|
|
|
$wetu_tours = get_transient( 'lsx_ti_tours', array() ); |
|
82
|
|
|
if ( ! empty( $wetu_tours ) ) { |
|
83
|
|
|
$count = count( $wetu_tours ); |
|
84
|
|
|
} |
|
85
|
|
|
return $count; |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.