Completed
Push — dev/6.0.0 ( a4b39f...3ea23f )
by Sudar
10:26 queued 03:53
created

DeletePostsPage::add_plugin_action_links()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 6
rs 9.6666
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Posts;
4
5
use BulkWP\BulkDelete\Core\Base\MetaboxPage;
6
7 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Bulk Delete Posts Page.
11
 *
12
 * Shows the list of modules that allows you to delete posts.
13
 *
14
 * @since 6.0.0
15
 */
16
class DeletePostsPage extends MetaboxPage {
17
18
	/**
19
	 * Position in which the Bulk WP menu should appear.
20
	 */
21
	const MENU_POSITION = '26';
22
23
	/**
24
	 * Initialize and setup variables.
25
	 */
26
	protected function initialize() {
27
		$this->page_slug  = 'bulk-delete-posts';
28
		$this->item_type  = 'posts';
29
		$this->capability = 'delete_posts';
30
31
		$this->label = array(
32
			'page_title' => __( 'Bulk Delete Posts', 'bulk-delete' ),
33
			'menu_title' => __( 'Bulk Delete Posts', 'bulk-delete' ),
34
		);
35
36
		$this->messages = array(
37
			'warning_message' => __( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ),
38
		);
39
40
		add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 );
41
	}
42
43
	public function register() {
44
		parent::register();
45
46
		add_menu_page(
47
			__( 'Bulk WP', 'bulk-delete' ),
48
			__( 'Bulk WP', 'bulk-delete' ),
49
			$this->capability,
50
			$this->page_slug,
51
			array( $this, 'render_page' ),
52
			'dashicons-trash',
53
			$this->get_bulkwp_menu_position()
54
		);
55
	}
56
57
	/**
58
	 * Get the Menu position of BulkWP menu.
59
	 *
60
	 * @return int Menu position.
61
	 */
62
	protected function get_bulkwp_menu_position() {
63
		/**
64
		 * Bulk WP Menu position.
65
		 *
66
		 * @since 6.0.0
67
		 *
68
		 * @param int Menu Position.
69
		 */
70
		return apply_filters( 'bd_bulkwp_menu_position', self::MENU_POSITION );
71
	}
72
73
	/**
74
	 * Adds setting links in plugin listing page.
75
	 * Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/.
76
	 *
77
	 * @param array  $links List of current links
78
	 * @param string $file  Plugin filename
79
	 *
80
	 * @return array $links Modified list of links
81
	 */
82
	public function add_plugin_action_links( $links, $file ) {
83
		$this_plugin = plugin_basename( Bulk_Delete::$PLUGIN_FILE );
0 ignored issues
show
Bug introduced by
The type BulkWP\BulkDelete\Core\Posts\Bulk_Delete was not found. Did you mean Bulk_Delete? If so, make sure to prefix the type with \.
Loading history...
84
85
		if ( $file == $this_plugin ) {
86
			$delete_users_link = '<a href="admin.php?page=' . $this->page_slug . '">' . __( 'Bulk Delete Users', 'bulk-delete' ) . '</a>';
87
			array_unshift( $links, $delete_users_link ); // before other links
88
		}
89
90
		return $links;
91
	}
92
93
	/**
94
	 * Add Help tabs.
95
	 *
96
	 * @since 5.5
97
	 *
98
	 * @param mixed $help_tabs
99
	 */
100
	protected function add_help_tab( $help_tabs ) {
101
		$overview_tab = array(
102
			'title'    => __( 'Overview', 'bulk-delete' ),
103
			'id'       => 'overview_tab',
104
			'content'  => '<p>' . __( 'This screen contains different modules that allows you to delete users or schedule them for deletion.', 'bulk-delete' ) . '</p>',
105
			'callback' => false,
106
		);
107
		$help_tabs['overview_tab'] = $overview_tab;
108
109
		return $help_tabs;
110
	}
111
}
112