|
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(); |
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
78
|
|
|
ob_end_clean(); |
|
79
|
|
|
return $html; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.