Posts::actions_section()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
nc 3
nop 0
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace DummyPress\Views;
3
use DummyPress\Abstracts as Abs;
4
5
/**
6
 * Generate view for creating and deleting posts.
7
 *
8
 * @abstract
9
 * @package    WordPress
10
 * @subpackage Test Content
11
 * @author     Mike Selander
12
 */
13
class Posts extends Abs\View {
14
15
	public function __construct() {
16
17
		$this->title	= __( 'Posts', 'dummybot' );
18
		$this->type		= 'post';
19
		$this->priority	= 1;
20
21
	}
22
23
	/**
24
	 * Our sections action block - button to create and delete.
25
	 *
26
	 * @access protected
27
	 *
28
	 * @return string HTML content.
29
	 */
30
	protected function actions_section() {
31
		$html = '';
32
33
		// Loop through every post type available on the site
34
		$post_types = get_post_types( array( 'public' => true ), 'objects' );
35
36
		foreach ( $post_types as $post_type ) :
37
38
			$skipped_cpts = array(
39
				'attachment'
40
			);
41
42
			// Skip banned cpts
43
			if ( in_array( $post_type->name, $skipped_cpts ) ) {
44
				continue;
45
			}
46
47
			$html .= "<div class='test-data-cpt'>";
48
49
				$html .= "<h3>";
50
51
					$html .= "<span class='label'>" . esc_html( $post_type->labels->name ) . "</span>";
52
					$html .= $this->build_button( 'create', $post_type->name, __( 'Create Test Data', 'dummybot' ) );
53
					$html .= $this->build_button( 'delete', $post_type->name, __( 'Delete Test Data', 'dummybot' ) );
54
55
				$html .= "</h3>";
56
57
			$html .= "</div>";
58
59
		endforeach;
60
61
		return $html;
62
	}
63
64
}
65