Completed
Push — dev/5.7.0 ( 2a5bdf )
by Sudar
12:47 queued 10:45
created

deprecated.php ➔ array_get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Deprecated and backward compatibility code.
4
 * Don't depend on the code in this file. It would be removed in future versions of the plugin.
5
 *
6
 * @author     Sudar
7
 *
8
 * @package    BulkDelete\Util\Deprecated
9
 *
10
 * @since 5.5
11
 */
12
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
13
14
/**
15
 * Backward compatibility for delete options.
16
 *
17
 * @since 5.5
18
 *
19
 * @param array $options Old options.
20
 *
21
 * @return array New options.
22
 */
23
function bd_delete_options_compatibility( $options ) {
24
	// Convert bool keys to boolean
25
	$bool_keys = array( 'restrict', 'force_delete', 'private' );
26
	foreach ( $bool_keys as $key ) {
27
		if ( array_key_exists( $key, $options ) ) {
28
			$options[ $key ] = bd_to_bool( $options[ $key ] );
29
		}
30
	}
31
32
	// convert old date comparison operators
33
	if ( array_key_exists( 'date_op', $options ) && array_key_exists( 'days', $options ) ) {
34
		if ( '<' == $options['date_op'] ) {
35
			$options['date_op'] = 'before';
36
		} elseif ( '>' == $options['date_op'] ) {
37
			$options['date_op'] = 'after';
38
		}
39
	}
40
41
	return $options;
42
}
43
add_filter( 'bd_delete_options', 'bd_delete_options_compatibility' );
44
45
/**
46
 * Handle backward compatibility for Delete Posts by status delete options.
47
 *
48
 * Backward compatibility code. Will be removed in Bulk Delete v6.0.
49
 *
50
 * @since 5.6.0
51
 *
52
 * @param array $delete_options Delete Options.
53
 *
54
 * @return array Processed delete options.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,false|null|array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
55
 */
56
function bd_convert_old_options_for_delete_post_by_status( $delete_options ) {
57
	// Format changed in 5.5.0.
58
	if ( array_key_exists( 'post_status_op', $delete_options ) ) {
59
		$delete_options['date_op'] = $delete_options['post_status_op'];
60
		$delete_options['days']    = $delete_options['post_status_days'];
61
	}
62
63
	// Format changed in 5.6.0.
64
	if ( isset( $delete_options['sticky'] ) ) {
65
		if ( 'sticky' === $delete_options['sticky'] ) {
66
			$delete_options['delete-sticky-posts'] = true;
67
		} else {
68
			$delete_options['delete-sticky-posts'] = false;
69
		}
70
	}
71
72
	if ( ! isset( $delete_options['post_status'] ) ) {
73
		$delete_options['post_status'] = array();
74
	}
75
76
	$old_statuses = array( 'publish', 'draft', 'pending', 'future', 'private' );
77
78
	foreach ( $old_statuses as $old_status ) {
79
		if ( isset( $delete_options[ $old_status ] ) ) {
80
			$delete_options['post_status'][] = $old_status;
81
		}
82
	}
83
84
	if ( isset( $delete_options['drafts'] ) && 'drafts' === $delete_options['drafts'] ) {
85
		$delete_options['post_status'][] = 'draft';
86
	}
87
88
	return $delete_options;
89
}
90
91
/**
92
 * Enable cron for old pro addons that required separate JavaScript.
93
 * This will be removed in v6.0.
94
 *
95
 * @since 5.5
96
 *
97
 * @param array $js_array JavaScript Array
98
 *
99
 * @return array Modified JavaScript Array
100
 */
101
function bd_enable_cron_for_old_addons( $js_array ) {
102
	if ( ! function_exists( 'is_plugin_active' ) ) {
103
		require_once ABSPATH . 'wp-admin/includes/plugin.php';
104
	}
105
106
	if ( is_plugin_active( 'bulk-delete-scheduler-for-deleting-users-by-role/bulk-delete-scheduler-for-deleting-users-by-role.php' ) ) {
107
		$js_array['pro_iterators'][] = 'u_role';
108
	}
109
110
	return $js_array;
111
}
112
add_filter( 'bd_javascript_array', 'bd_enable_cron_for_old_addons' );
113
114
// Deprecated functions.
115
116
if ( ! function_exists( 'array_get' ) ) {
117
	/**
118
	 * Deprecated. Use `bd_array_get`.
119
	 *
120
	 * @param mixed      $array
121
	 * @param mixed      $key
122
	 * @param mixed|null $default
123
	 */
124
	function array_get( $array, $key, $default = null ) {
125
		return bd_array_get( $array, $key, $default );
126
	}
127
}
128
129
if ( ! function_exists( 'array_get_bool' ) ) {
130
	/**
131
	 * Deprecated. Use `bd_array_get_bool`.
132
	 *
133
	 * @param mixed $array
134
	 * @param mixed $key
135
	 * @param mixed $default
136
	 */
137
	function array_get_bool( $array, $key, $default = false ) {
138
		return bd_array_get_bool( $array, $key, $default );
139
	}
140
}
141