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