Passed
Push — dev/6.0.1 ( 1b5ca4...416dbb )
by Sudar
44:22
created

Upseller::get_user_upsell_addons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Addon;
4
5 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
6
7
/**
8
 * Upsell pro add-ons.
9
 *
10
 * @since 6.0.0
11
 */
12
class Upseller {
13
	/**
14
	 * Setup hooks.
15
	 */
16
	public function load() {
17
		add_action( 'bd_after_modules', array( $this, 'load_upsell_modules' ) );
18
	}
19
20
	/**
21
	 * Load upsell modules after free modules.
22
	 *
23
	 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page The page to which the modules are added.
24
	 */
25
	public function load_upsell_modules( $page ) {
26
		$upsell_addon_details = $this->get_upsell_addon_details_for_page( $page->get_page_slug() );
27
28
		foreach ( $upsell_addon_details as $upsell_addon_detail ) {
29
			$page->add_module( new UpsellModule( new AddonUpsellInfo( $upsell_addon_detail ) ) );
30
		}
31
	}
32
33
	/**
34
	 * Get Upsell add-on to be shown on a particular page.
35
	 *
36
	 * @since 6.0.1 Using page_slug instead of page.
37
	 *
38
	 * @param string $page_slug The page slug of the page in which upsell add-ons to be shown.
39
	 *
40
	 * @return array List of Upsell modules.
41
	 */
42
	protected function get_upsell_addon_details_for_page( $page_slug ) {
43
		$addon_upsell_details = array();
44
45
		switch ( $page_slug ) {
46
			case 'bulk-delete-posts':
47
				$addon_upsell_details = $this->get_default_post_upsell_addons();
48
				break;
49
50
			case 'bulk-delete-pages':
51
				$addon_upsell_details = $this->get_default_page_upsell_addons();
52
				break;
53
		}
54
55
		/**
56
		 * List of Upsell add-ons based on page slug.
57
		 *
58
		 * @since 6.0.0
59
		 * @since 6.0.1 Replaced Item type with page slug.
60
		 *
61
		 * @param array  $addon_details Add-on details.
62
		 * @param string $page_slug     Page slug.
63
		 */
64
		return apply_filters( 'bd_upsell_addons', $addon_upsell_details, $page_slug );
65
	}
66
67
	/**
68
	 * Get default list of upsell add-ons for delete posts page.
69
	 *
70
	 * Eventually this will come from a feed.
71
	 *
72
	 * @return array List of upsell add-on details.
73
	 */
74
	protected function get_default_post_upsell_addons() {
75
		return array(
76
			array(
77
				'name'           => 'Bulk Delete Posts by Custom Field',
78
				'description'    => 'This addon adds the ability to delete posts based on custom field. This will be really useful, if your plugin or theme uses custom fields to store additional information about a post.',
79
				'slug'           => 'bulk-delete-posts-by-custom-field',
80
				'url'            => 'https://bulkwp.com/addons/bulk-delete-posts-by-custom-field/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-cf',
81
				'buy_url'        => '',
82
				'upsell_title'   => 'Want to delete Posts based on Custom Field (Post Meta)?',
83
				'upsell_message' => '<strong>Bulk Delete Posts by Custom Field</strong> add-on allows you to delete posts based on custom field (also known as post meta).',
84
			),
85
			array(
86
				'name'           => 'Bulk Delete Posts by Title',
87
				'description'    => 'This addon adds the ability to delete posts based on title.',
88
				'slug'           => 'bulk-delete-posts-by-title',
89
				'url'            => 'https://bulkwp.com/addons/bulk-delete-posts-by-title/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-ti',
90
				'buy_url'        => '',
91
				'upsell_title'   => 'Want to delete Posts based on title?',
92
				'upsell_message' => '<strong>Bulk Delete Posts by Title</strong> add-on allows you to delete posts based on title.',
93
			),
94
			array(
95
				'name'           => 'Bulk Delete Posts by Duplicate Title',
96
				'description'    => 'This addon adds the ability to delete posts based on duplicate title.',
97
				'slug'           => 'bulk-delete-posts-by-duplicate-title',
98
				'url'            => 'https://bulkwp.com/addons/bulk-delete-posts-by-duplicate-title/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-dti',
99
				'buy_url'        => '',
100
				'upsell_title'   => 'Want to delete Posts that have duplicate titles?',
101
				'upsell_message' => '<strong>Bulk Delete Posts by Duplicate Title</strong> add-on allows you to delete posts that have duplicate title.',
102
			),
103
			array(
104
				'name'           => 'Bulk Delete Posts by Content',
105
				'description'    => 'This addon adds the ability to delete posts based on content.',
106
				'slug'           => 'bulk-delete-posts-by-content',
107
				'url'            => 'https://bulkwp.com/addons/bulk-delete-posts-by-content/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-p-co',
108
				'buy_url'        => '',
109
				'upsell_title'   => 'Want to delete Posts based on the post content?',
110
				'upsell_message' => '<strong>Bulk Delete Posts by Content</strong> add-on allows you to delete posts based on its post content.',
111
			),
112
			array(
113
				'name'           => 'Bulk Delete Posts by User',
114
				'description'    => 'This addon adds the ability to delete posts based on the author who created the post.',
115
				'slug'           => 'bulk-delete-posts-by-user',
116
				'url'            => 'https://bulkwp.com/addons/bulk-delete-posts-by-user/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-p-u',
117
				'buy_url'        => '',
118
				'upsell_title'   => 'Want to delete Posts based on the user who created it?',
119
				'upsell_message' => '<strong>Bulk Delete Posts by User</strong> add-on allows you to delete posts based on user who created the post.',
120
			),
121
			array(
122
				'name'           => 'Bulk Delete Posts by Attachment',
123
				'description'    => 'This addon adds the ability to delete posts based on attachment.',
124
				'slug'           => 'bulk-delete-posts-by-attachment',
125
				'url'            => 'https://bulkwp.com/addons/bulk-delete-posts-by-attachment/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-p-at',
126
				'buy_url'        => '',
127
				'upsell_title'   => 'Want to delete Posts based on whether it has an attachment?',
128
				'upsell_message' => "<strong>Bulk Delete Posts by Attachment</strong> add-on allows you to delete posts based on whether a post contains (or doesn't contain) an attachment.",
129
			),
130
			array(
131
				'name'           => 'Bulk Delete From Trash',
132
				'description'    => 'This addon adds the ability to delete posts or pages from trash.',
133
				'slug'           => 'bulk-delete-from-trash',
134
				'url'            => 'https://bulkwp.com/addons/bulk-delete-from-trash/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-th',
135
				'buy_url'        => '',
136
				'upsell_title'   => 'Want to delete Posts that are in trash?',
137
				'upsell_message' => '<strong>Bulk Delete From Trash</strong> add-on allows you to delete posts that are in trash.',
138
			),
139
		);
140
	}
141
142
	/**
143
	 * Get default list of upsell add-ons for delete pages page.
144
	 *
145
	 * Eventually this will come from a feed.
146
	 *
147
	 * @return array List of upsell add-on details.
148
	 */
149
	protected function get_default_page_upsell_addons() {
150
		return array(
151
			array(
152
				'name'           => 'Bulk Delete From Trash',
153
				'description'    => 'This addon adds the ability to delete posts or pages from trash.',
154
				'slug'           => 'bulk-delete-from-trash',
155
				'url'            => 'https://bulkwp.com/addons/bulk-delete-from-trash/?utm_campaign=Upsell&utm_medium=wp-admin&utm_source=upsell-module&utm_content=bd-th',
156
				'buy_url'        => '',
157
				'upsell_title'   => 'Want to delete pages that are in trash?',
158
				'upsell_message' => '<strong>Bulk Delete From Trash</strong> add-on allows you to delete pages that are in trash.',
159
			),
160
		);
161
	}
162
}
163