-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlivecodes-embed.php
More file actions
70 lines (63 loc) · 2.11 KB
/
Copy pathlivecodes-embed.php
File metadata and controls
70 lines (63 loc) · 2.11 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
<?php
/**
* Plugin Name: LiveCodes Embed
* Plugin URI: https://livecodes.io/docs/features/embeds
* Description: Embed LiveCodes playgrounds in posts and pages by pasting a URL.
* Version: 1.0.0
* Requires at least: 5.6
* Requires PHP: 7.2
* Author: LiveCodes
* Author URI: https://livecodes.io
* License: MIT
* License URI: https://github.com/live-codes/wordpress-livecodes-embed/blob/main/LICENSE
* Donate link: https://ko-fi.com/hatemhosny
* Text Domain: livecodes-embed
*/
defined( 'ABSPATH' ) || exit;
define( 'LIVECODES_EMBED_VERSION', '1.0.0' );
/**
* Register livecodes.io as a trusted oEmbed provider.
*/
function livecodes_embed_register_provider() {
/**
* Filter the URL pattern matched for LiveCodes embeds.
*
* Useful for self-hosted LiveCodes instances.
*
* @param string $pattern Regex (with delimiters) matched against pasted URLs.
*/
$pattern = apply_filters(
'livecodes_embed_url_pattern',
'!^https?://(?:[a-z0-9\-]+\.)?livecodes\.io/?(?:index\.html)?(?:\?[^#]*)?(?:#.*)?$!i'
);
/**
* Filter the oEmbed endpoint used to resolve LiveCodes URLs.
*
* Useful for self-hosted LiveCodes instances (the docker setup ships
* its own oEmbed server).
*
* @param string $endpoint The oEmbed API endpoint URL.
*/
$endpoint = apply_filters(
'livecodes_embed_provider_endpoint',
'https://livecodes.io/oembed'
);
wp_oembed_add_provider( $pattern, $endpoint, true );
}
add_action( 'init', 'livecodes_embed_register_provider' );
/**
* Register the editor script that adds a "LiveCodes" variation of the
* core Embed block to the inserter. Purely cosmetic: paste-to-embed
* works from the provider registration alone.
*/
function livecodes_embed_enqueue_editor_assets() {
wp_enqueue_script(
'livecodes-embed-editor',
plugins_url( 'editor.js', __FILE__ ),
array( 'wp-blocks', 'wp-element', 'wp-i18n' ),
LIVECODES_EMBED_VERSION,
true
);
wp_set_script_translations( 'livecodes-embed-editor', 'livecodes-embed' );
}
add_action( 'enqueue_block_editor_assets', 'livecodes_embed_enqueue_editor_assets' );