PluginProbe ʕ •ᴥ•ʔ
Admin Help Docs / 2.0.3
Admin Help Docs v2.0.3
2.0.3 2.0.2 2.0.1.1 trunk 1.4.3.2 2.0.0 2.0.0.1 2.0.0.2 2.0.1
admin-help-docs / inc / docs / page-locations / top.php
admin-help-docs / inc / docs / page-locations Last commit date
js 23 hours ago bottom.php 23 hours ago contextual.php 23 hours ago element.php 23 hours ago side.php 23 hours ago top.php 23 hours ago
top.php
97 lines
1 <?php
2 /**
3 * Top of Pages
4 */
5
6 namespace PluginRx\AdminHelpDocs;
7
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 class Top {
11
12 /**
13 * The placement of the top docs
14 *
15 * @var string
16 */
17 private $placement = 'admin_notices'; // Default placement
18
19
20 /**
21 * The docs to be rendered
22 *
23 * @var array
24 */
25 private array $docs = [];
26
27
28 /**
29 * Constructor
30 */
31 public function __construct( $docs = [] ) {
32 if ( empty( $docs ) ) {
33 return;
34 }
35
36 $this->docs = $docs;
37
38 $available_placements = Settings::top_placements();
39 $this->placement = sanitize_key( get_option( 'helpdocs_top_location_type', 'admin_notices' ) );
40 if ( array_key_exists( $this->placement, $available_placements ) ) {
41 add_action( $this->placement, [ $this, 'render' ] );
42 }
43
44 add_action( 'admin_enqueue_scripts', [ $this, 'scripts' ] );
45 } // End __construct()
46
47
48 /**
49 * Render the docs
50 */
51 public function render() : void {
52 if ( Helpers::is_gutenberg() || empty( $this->docs ) ) {
53 return;
54 }
55
56 $allowed_tags = Helpers::allow_addt_tags( wp_kses_allowed_html( 'post' ) );
57
58 echo '<div class="helpdocs-top-wrapper helpdocs-' . esc_attr( str_replace( '_', '-', $this->placement ) ) . '">';
59 foreach ( $this->docs as $doc ) {
60 $content = apply_filters( 'the_content', $doc->post_content );
61 $html = Helpers::output_doc( $doc->ID, $doc->post_title, $content, 'top' );
62
63 echo wp_kses( $html, $allowed_tags );
64 }
65 echo '</div>';
66 } // End render()
67
68
69 /**
70 * Enqueue scripts
71 */
72 public function scripts() : void {
73 $screen = get_current_screen();
74 if ( ! $screen || ! Helpers::is_gutenberg() || empty( $this->docs ) ) {
75 return;
76 }
77
78 $docs = Helpers::clean_docs_for_gutenberg( $this->docs );
79
80 $text_domain = Bootstrap::textdomain();
81 $script_version = Bootstrap::script_version();
82
83 wp_enqueue_script( $text_domain . "-top", Bootstrap::url( "inc/docs/page-locations/js/top.js" ), [ 'jquery' ], $script_version, true );
84 wp_localize_script( $text_domain . "-top", "helpdocs_top", [
85 'docs' => $docs,
86 'template' => Helpers::output_doc( '{doc_id}', '{doc_title}', '{doc_content}', 'top' ),
87 ] );
88 } // End scripts()
89
90
91 /**
92 * Prevent cloning and unserializing
93 */
94 public function __clone() {}
95 public function __wakeup() {}
96
97 }