-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencpadnote.php
More file actions
90 lines (75 loc) · 2.44 KB
/
encpadnote.php
File metadata and controls
90 lines (75 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Plugin Name: EncPadNote
* Description: A serverless markdown editor with encryption that stores content in the URL hash.
* Version: 2.1.0
* Author: LukaWe
* Author URI: https://github.com/LukaWe
* Requires PHP: 8.3
*/
declare(strict_types=1);
namespace EncPadNote;
if (!defined('ABSPATH')) {
exit;
}
final class Plugin
{
private const VERSION = '2.1.0';
private const SLUG = 'encpadnote';
public function __construct()
{
add_shortcode('encpadnote', [$this, 'renderShortcode']);
add_action('wp_enqueue_scripts', [$this, 'registerAssets']);
}
public function registerAssets(): void
{
// Vendor scripts
wp_register_script(
self::SLUG . '-marked',
plugins_url('vendor/marked.min.js', __FILE__),
[],
'12.0.0',
['strategy' => 'defer', 'in_footer' => true]
);
wp_register_script(
self::SLUG . '-dompurify',
plugins_url('vendor/dompurify.min.js', __FILE__),
[],
'3.0.9',
['strategy' => 'defer', 'in_footer' => true]
);
// Main plugin assets
$jsFile = plugin_dir_path(__FILE__) . 'js/encpadnote.js';
$cssFile = plugin_dir_path(__FILE__) . 'css/encpadnote.css';
$jsVersion = file_exists($jsFile) ? (string)filemtime($jsFile) : self::VERSION;
$cssVersion = file_exists($cssFile) ? (string)filemtime($cssFile) : self::VERSION;
wp_register_script(
self::SLUG,
plugins_url('js/encpadnote.js', __FILE__),
[self::SLUG . '-marked', self::SLUG . '-dompurify'],
$jsVersion,
['strategy' => 'defer', 'in_footer' => true]
);
wp_register_style(
self::SLUG,
plugins_url('css/encpadnote.css', __FILE__),
[],
$cssVersion
);
}
public function renderShortcode(array|string $atts = [], ?string $content = null): string
{
wp_enqueue_script(self::SLUG);
wp_enqueue_style(self::SLUG);
$atts = shortcode_atts(['height' => '80vh'], $atts, self::SLUG);
$height = $atts['height'];
if (!preg_match('/^[0-9]+(px|vh|vw|%|em|rem)?$/', $height)) {
$height = '80vh';
}
return sprintf(
'<div id="encpadnote-app" class="encpadnote-wrapper" style="height: %s;"></div>',
esc_attr($height)
);
}
}
new Plugin();