-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoembed-infogram.php
More file actions
74 lines (63 loc) · 2.31 KB
/
oembed-infogram.php
File metadata and controls
74 lines (63 loc) · 2.31 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
<?php
/**
* @wordpress-plugin
* Plugin Name: oEmbed Infogram
* Description: A simple plugin that adds support for embedding Infogram.
* Version: 1.3.1
* Requires at least: 6.6
* Requires PHP: 7.4
* Plugin URI: https://github.com/android-com-pl/oembed-infogram
* Author: android.com.pl
* Author URI: https://android.com.pl/
* License: GPL v3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* @package oembed-infogram
*/
namespace ACP\oEmbed;
if ( ! defined( 'ABSPATH' ) ) {
http_response_code( 403 );
exit();
}
class Infogram {
public static function init() {
add_action( 'init', [ self::class, 'add_provider' ] );
add_action( 'enqueue_block_editor_assets', [ self::class, 'enqueue_block_editor_assets' ] );
add_filter( 'amp_content_embed_handlers', [ self::class, 'add_amp_handler' ], 10, 2 );
add_filter( 'plugin_row_meta', [ self::class, 'add_plugin_row_meta_links' ], 10, 4 );
}
public static function add_provider(): void {
wp_oembed_add_provider( 'https://infogram.com/*', 'https://infogram.com/oembed/?format=json' );
}
public static function enqueue_block_editor_assets(): void {
$asset_file_path = plugin_dir_path( __FILE__ ) . 'build/index.asset.php';
if ( ! file_exists( $asset_file_path ) ) {
return;
}
$asset = require $asset_file_path;
wp_enqueue_script(
'oembed-infogram-block-editor',
plugins_url( 'build/index.js', __FILE__ ),
$asset['dependencies'],
$asset['version'],
true
);
wp_set_script_translations( 'oembed-infogram-block-editor', 'oembed-infogram' );
}
/** @see https://amp-wp.org/documentation/playbooks/custom-embed-handler/ */
public static function add_amp_handler( array $handler_classes ): array {
require_once plugin_dir_path( __FILE__ ) . 'class-amp-infogram-oembed-handler.php';
$handler_classes[ __NAMESPACE__ . '\\Infogram_Embed_Handler' ] = [];
return $handler_classes;
}
public static function add_plugin_row_meta_links( array $plugin_meta, string $plugin_file ): array {
if ( str_contains( $plugin_file, basename( __FILE__ ) ) ) {
$plugin_meta[] = '<a href="https://github.com/android-com-pl/oembed-infogram">GitHub</a>';
$plugin_meta[] = sprintf(
'<a href="https://github.com/android-com-pl/oembed-infogram?sponsor=1">%s</a>',
__( 'Donate', 'oembed-infogram' )
);
}
return $plugin_meta;
}
}
Infogram::init();