DeprecatedModule   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 90
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0
wmc 13

7 Methods

Rating   Name   Duplication   Size   Complexity  
A load_if_needed() 0 8 2
A process() 0 1 1
A convert_user_input_to_options() 0 2 1
A get_success_message() 0 1 1
A hide_upsell_module() 0 24 6
A parse_common_filters() 0 2 1
A do_delete() 0 1 1
1
<?php
2
3
namespace BulkWP\BulkDelete\Deprecated\Addons;
4
5
use BulkWP\BulkDelete\Core\Base\BaseModule;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Base class for all Deprecated Modules.
11
 *
12
 * This class just extends all the abstract methods with an empty implementation.
13
 *
14
 * @since 6.0.0
15
 */
16
abstract class DeprecatedModule extends BaseModule {
17
	/**
18
	 * Addon class name of the old add-on that is used to find out whether the old add-on is active or not.
19
	 *
20
	 * @var string
21
	 */
22
	protected $addon_class_name = '';
23
24
	/**
25
	 * Slug of the old add-on.
26
	 *
27
	 * @var string
28
	 */
29
	protected $addon_slug = '';
30
31
	/**
32
	 * Load the deprecated module if the old add-on is active.
33
	 *
34
	 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page Page object.
35
	 */
36
	public function load_if_needed( $page ) {
37
		if ( ! class_exists( $this->addon_class_name ) ) {
38
			return;
39
		}
40
41
		add_filter( 'bd_upsell_addons', array( $this, 'hide_upsell_module' ), 10, 2 );
42
43
		$page->add_module( $this );
44
	}
45
46
	/**
47
	 * Hide the upsell message if the add-on is active.
48
	 *
49
	 * @since 6.0.1 Use $page_slug instead of $item_type.
50
	 *
51
	 * @param array  $addon_details Addon Details.
52
	 * @param string $page_slug     Page slug.
53
	 *
54
	 * @return array Modified list of Addon Details.
55
	 */
56
	public function hide_upsell_module( $addon_details, $page_slug ) {
57
		if ( ! class_exists( $this->addon_class_name ) ) {
58
			return $addon_details;
59
		}
60
61
		if ( $this->page_slug !== $page_slug ) {
62
			return $addon_details;
63
		}
64
65
		$modified_addon_details = array();
66
67
		foreach ( $addon_details as $addon_detail ) {
68
			if ( ! array_key_exists( 'slug', $addon_detail ) ) {
69
				continue;
70
			}
71
72
			if ( $this->addon_slug === $addon_detail['slug'] ) {
73
				continue;
74
			}
75
76
			$modified_addon_details[] = $addon_detail;
77
		}
78
79
		return $modified_addon_details;
80
	}
81
82
	/**
83
	 * Don't do any processing here.
84
	 *
85
	 * It is currently handled in the add-on.
86
	 *
87
	 * @param array $request Request object.
88
	 */
89
	public function process( $request ) {
90
		// Empty by design. Processing of data happens in the add-on.
91
	}
92
93
	protected function parse_common_filters( $request ) {
94
		return array();
95
	}
96
97
	protected function convert_user_input_to_options( $request, $options ) {
98
		return $options;
99
	}
100
101
	protected function do_delete( $options ) {
102
		// Empty by design.
103
	}
104
105
	protected function get_success_message( $items_deleted ) {
106
		// Empty by design.
107
	}
108
}
109