Passed
Push — 189-fix/delete-posts-by-post-s... ( 468a0e...78e3f0 )
by Sudar
53:13 queued 41:17
created

DeprecatedModule::hide_upsell_module()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 2
dl 0
loc 24
rs 8.9137
c 0
b 0
f 0
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
	 * @param array  $addon_details Addon Details.
50
	 * @param string $item_type     Item type.
51
	 *
52
	 * @return array Modified list of Addon Details.
53
	 */
54
	public function hide_upsell_module( $addon_details, $item_type ) {
55
		if ( ! class_exists( $this->addon_class_name ) ) {
56
			return $addon_details;
57
		}
58
59
		if ( $this->item_type !== $item_type ) {
60
			return $addon_details;
61
		}
62
63
		$modified_addon_details = array();
64
65
		foreach ( $addon_details as $addon_detail ) {
66
			if ( ! array_key_exists( 'slug', $addon_detail ) ) {
67
				continue;
68
			}
69
70
			if ( $this->addon_slug === $addon_detail['slug'] ) {
71
				continue;
72
			}
73
74
			$modified_addon_details[] = $addon_detail;
75
		}
76
77
		return $modified_addon_details;
78
	}
79
80
	/**
81
	 * Don't do any processing here.
82
	 *
83
	 * It is currently handled in the add-on.
84
	 *
85
	 * @param array $request Request object.
86
	 */
87
	public function process( $request ) {
88
		// Empty by design. Processing of data happens in the add-on.
89
	}
90
91
	protected function parse_common_filters( $request ) {
92
		return array();
93
	}
94
95
	protected function convert_user_input_to_options( $request, $options ) {
96
		return $options;
97
	}
98
99
	protected function do_delete( $options ) {
100
		// Empty by design.
101
	}
102
103
	protected function get_success_message( $items_deleted ) {
104
		// Empty by design.
105
	}
106
}
107