forked from reviewjs/annotate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordpress.php
More file actions
56 lines (53 loc) · 1.61 KB
/
Copy pathwordpress.php
File metadata and controls
56 lines (53 loc) · 1.61 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
<?php
/**
* WordPress integration for annotate.js
*
* Two ways to add it:
*
* A) No code — install a "header & footer scripts" plugin (WPCode, Insert
* Headers and Footers, etc.) and paste this into the FOOTER box:
*
* <script src="https://cdn.jsdelivr.net/npm/@reviewjs/annotate/annotate.js"
* data-project="my-wp-site" defer></script>
*
* B) Theme code — copy the function below into your (child) theme's
* functions.php, or wrap it in a small mu-plugin.
*
* The example below also restricts the review tools to logged-in editors so
* your public visitors never see the toolbar. Remove the current_user_can()
* guard to show it to everyone.
*/
function annotatejs_enqueue() {
// Only load for users who can edit content. Delete this block to show it
// to every visitor.
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
wp_enqueue_script(
'annotatejs',
'https://cdn.jsdelivr.net/npm/@reviewjs/annotate/annotate.js',
array(), // no dependencies
'1.0.1', // version (also busts caches)
true // load in the footer
);
}
add_action( 'wp_enqueue_scripts', 'annotatejs_enqueue' );
/**
* Optional: pass configuration (project, accent color, theme) by defining
* window.AnnotateConfig just before the script runs.
*/
function annotatejs_config() {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
?>
<script>
window.AnnotateConfig = {
project: "<?php echo esc_js( get_bloginfo( 'name' ) ); ?>",
accent: "#6d28d9",
theme: "auto"
};
</script>
<?php
}
add_action( 'wp_print_footer_scripts', 'annotatejs_config', 9 ); // before the script