Completed
Push — add/admin-page-package ( b95118 )
by
unknown
26:28 queued 19:26
created

Page::get_render_content()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * An admin page wrapper
4
 *
5
 * @package jetpack-admin-page
6
 */
7
8
namespace Automattic\Jetpack\AdminPage;
9
10
/**
11
 * Create and render a Jetpack logo.
12
 */
13
class Page {
14
	/**
15
	 * Absolute URL of the Jetpack logo.
16
	 *
17
	 * @var string
18
	 */
19
	private $header;
20
21
	private $footer;
22
23
	/**
24
	 * Constructor.
25
	 * You can optionally pass a URL to override the default one.
26
	 */
27
	public function __construct( $page_hook = null ) {
28
		if ( $page_hook ) {
29
			if ( is_array( $page_hook ) ) {
30
				foreach ( $page_hook as $hook ) {
31
					add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) );
32
				}
33
			} else {
34
				add_action( "admin_print_styles-$page_hook", array( $this, 'admin_styles' ) );
35
			}
36
		}
37
	}
38
39
	public function admin_styles() {
40
		// TODO: implement min and rtl styles in some sort of build process?
41
		$version = time(); // where does this come from?
42
		wp_enqueue_style( 'jetpack-admin-page', plugins_url( 'assets/style.css', __DIR__ ), array(), $version );
43
		// wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
44
		// wp_style_add_data( 'jetpack-admin', 'suffix', $min );
45
	}
46
47
	public function init() {
48
		$header       = new Header();
49
		$this->header = apply_filters( 'jetpack-admin-page-set-header', $header );
50
51
		$footer       = new Footer();
52
		$this->footer = apply_filters( 'jetpack-admin-page-set-footer', $footer );
53
	}
54
55
	/**
56
	 * Build and render an <img /> tag with the Jetpack logo.
57
	 *
58
	 * @return string
59
	 */
60
	public function render( $callback = null ) {
61
		$this->init();
62
		$html  = '';
63
		$html .= $this->header->render();
0 ignored issues
show
Bug introduced by
The method render cannot be called on $this->header (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
64
		$html .= $this->get_render_content( $callback );
65
		$html .= $this->footer->render();
66
		return $html;
67
	}
68
69
	private function get_render_content( $callback ) {
70
		if ( is_callable( $callback ) ) {
71
			ob_start();
72
			?>
73
			<div class="jetpack-admin-page__container">
74
				<?php call_user_func( $callback ); ?>
75
			</div>
76
			<?php
77
			$html .= ob_get_contents();
0 ignored issues
show
Bug introduced by
The variable $html does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
78
			ob_end_clean();
79
			return $html;
80
		}
81
	}
82
}
83