class-activation.php
7 months ago
class-admin-menu-organizer.php
7 months ago
class-admin-menu-svg-icon-mask.php
7 months ago
class-auto-publish-posts-with-missed-schedule.php
7 months ago
class-avif-upload.php
7 months ago
class-captcha-protection.php
7 months ago
class-change-login-url.php
7 months ago
class-cleanup-admin-bar.php
7 months ago
class-common-methods.php
7 months ago
class-content-duplication.php
7 months ago
class-content-order.php
7 months ago
class-custom-admin-footer-text.php
7 months ago
class-custom-body-class.php
7 months ago
class-custom-css.php
7 months ago
class-custom-nav-menu-items-in-new-tab.php
7 months ago
class-deactivation.php
7 months ago
class-disable-author-archives.php
7 months ago
class-disable-comments.php
7 months ago
class-disable-dashboard-widgets.php
7 months ago
class-disable-embeds.php
7 months ago
class-disable-feeds.php
7 months ago
class-disable-gutenberg.php
7 months ago
class-disable-rest-api.php
7 months ago
class-disable-smaller-components.php
7 months ago
class-disable-updates.php
7 months ago
class-disable-xml-rpc.php
7 months ago
class-display-system-summary.php
7 months ago
class-email-address-obfuscator.php
7 months ago
class-email-delivery.php
7 months ago
class-enhance-list-tables.php
7 months ago
class-external-permalinks.php
7 months ago
class-heartbeat-control.php
7 months ago
class-hide-admin-bar.php
7 months ago
class-hide-admin-notices.php
7 months ago
class-image-sizes-panel.php
7 months ago
class-image-upload-control.php
7 months ago
class-insert-head-body-footer-code.php
7 months ago
class-last-login-column.php
7 months ago
class-limit-login-attempts.php
7 months ago
class-login-id-type.php
7 months ago
class-login-logout-menu.php
7 months ago
class-maintenance-mode.php
7 months ago
class-manage-ads-appads-txt.php
7 months ago
class-manage-robots-txt.php
7 months ago
class-media-replacement.php
7 months ago
class-multiple-user-roles.php
7 months ago
class-obfuscate-author-slugs.php
7 months ago
class-open-external-links-in-new-tab.php
7 months ago
class-password-protection.php
7 months ago
class-redirect-after-login.php
7 months ago
class-redirect-after-logout.php
7 months ago
class-redirect-fourofour.php
7 months ago
class-registration-date-column.php
7 months ago
class-revisions-control.php
7 months ago
class-search-engines-visibility.php
7 months ago
class-settings-fields-render.php
7 months ago
class-settings-sanitization.php
7 months ago
class-settings-sections-fields.php
7 months ago
class-show-custom-taxonomy-filters.php
7 months ago
class-site-identity-on-login-page.php
7 months ago
class-svg-upload.php
7 months ago
class-various-admin-ui-enhancements.php
7 months ago
class-view-admin-as-role.php
7 months ago
class-wider-admin-menu.php
7 months ago
class-wp-config-transformer.php
7 months ago
class-disable-embeds.php
171 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class for Disable Embeds module. |
| 7 | * Ported from the Disable Embeds plugin v1.5.0 by Pascal Birchler |
| 8 | * @link https://wordpress.org/plugins/disable-embeds/ |
| 9 | * |
| 10 | * @since 8.0.0 |
| 11 | */ |
| 12 | class Disable_Embeds { |
| 13 | |
| 14 | /** |
| 15 | * Disable embeds on init. |
| 16 | * |
| 17 | * - Removes the needed query vars. |
| 18 | * - Disables oEmbed discovery. |
| 19 | * - Completely removes the related JavaScript. |
| 20 | * - Disables the core-embed/wordpress block type (WordPress 5.0+) |
| 21 | * |
| 22 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L23 |
| 23 | * @since 8.0.0 |
| 24 | */ |
| 25 | public function disable_embeds_init() { |
| 26 | /* @var WP $wp */ |
| 27 | global $wp; |
| 28 | |
| 29 | // Remove the embed query var. |
| 30 | $wp->public_query_vars = array_diff( $wp->public_query_vars, array( |
| 31 | 'embed', |
| 32 | ) ); |
| 33 | |
| 34 | // Remove the oembed/1.0/embed REST route. |
| 35 | add_filter( 'rest_endpoints', [ $this, 'disable_embeds_remove_embed_endpoint'] ); |
| 36 | |
| 37 | // Disable handling of internal embeds in oembed/1.0/proxy REST route. |
| 38 | add_filter( 'oembed_response_data', [ $this, 'disable_embeds_filter_oembed_response_data' ] ); |
| 39 | |
| 40 | // Turn off oEmbed auto discovery. |
| 41 | add_filter( 'embed_oembed_discover', '__return_false' ); |
| 42 | |
| 43 | // Don't filter oEmbed results. |
| 44 | remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 ); |
| 45 | |
| 46 | // Remove oEmbed discovery links. |
| 47 | remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); |
| 48 | |
| 49 | // Remove oEmbed-specific JavaScript from the front-end and back-end. |
| 50 | remove_action( 'wp_head', 'wp_oembed_add_host_js' ); |
| 51 | add_filter( 'tiny_mce_plugins', [ $this, 'disable_embeds_tiny_mce_plugin' ] ); |
| 52 | |
| 53 | // Remove all embeds rewrite rules. |
| 54 | add_filter( 'rewrite_rules_array', [ $this, 'disable_embeds_rewrites' ] ); |
| 55 | |
| 56 | // Remove filter of the oEmbed result before any HTTP requests are made. |
| 57 | remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 ); |
| 58 | |
| 59 | // Load block editor JavaScript. |
| 60 | add_action( 'enqueue_block_editor_assets', [ $this, 'disable_embeds_enqueue_block_editor_assets' ] ); |
| 61 | |
| 62 | // Remove wp-embed dependency of wp-edit-post script handle. |
| 63 | add_action( 'wp_default_scripts', [ $this, 'disable_embeds_remove_script_dependencies' ] ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Removes the oembed/1.0/embed REST route. |
| 68 | * |
| 69 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L128 |
| 70 | * @since 8.0.0 |
| 71 | * |
| 72 | * @param array $endpoints Registered REST API endpoints. |
| 73 | * @return array Filtered REST API endpoints. |
| 74 | */ |
| 75 | public function disable_embeds_remove_embed_endpoint( $endpoints ) { |
| 76 | unset( $endpoints['/oembed/1.0/embed'] ); |
| 77 | |
| 78 | return $endpoints; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Disables sending internal oEmbed response data in proxy endpoint. |
| 83 | * |
| 84 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L142 |
| 85 | * @since 8.0.0 |
| 86 | * |
| 87 | * @param array $data The response data. |
| 88 | * @return array|false Response data or false if in a REST API context. |
| 89 | */ |
| 90 | public function disable_embeds_filter_oembed_response_data( $data ) { |
| 91 | if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | return $data; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Removes the 'wpembed' TinyMCE plugin. |
| 100 | * |
| 101 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L74 |
| 102 | * @since 8.0.0 |
| 103 | * |
| 104 | * @param array $plugins List of TinyMCE plugins. |
| 105 | * @return array The modified list. |
| 106 | */ |
| 107 | public function disable_embeds_tiny_mce_plugin( $plugins ) { |
| 108 | return array_diff( $plugins, array( 'wpembed' ) ); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Remove all rewrite rules related to embeds. |
| 113 | * |
| 114 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L86 |
| 115 | * @since 8.0.0 |
| 116 | * |
| 117 | * @param array $rules WordPress rewrite rules. |
| 118 | * @return array Rewrite rules without embeds rules. |
| 119 | */ |
| 120 | public function disable_embeds_rewrites( $rules ) { |
| 121 | foreach ( $rules as $rule => $rewrite ) { |
| 122 | if ( false !== strpos( $rewrite, 'embed=true' ) ) { |
| 123 | unset( $rules[ $rule ] ); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return $rules; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Enqueues JavaScript for the block editor. |
| 132 | * |
| 133 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L157 |
| 134 | * @since 8.0.0 |
| 135 | * |
| 136 | * This is used to unregister the `core-embed/wordpress` block type. |
| 137 | */ |
| 138 | public function disable_embeds_enqueue_block_editor_assets() { |
| 139 | $asset_file = ASENHA_PATH . 'includes/disable-embeds/build/index.asset.php'; |
| 140 | |
| 141 | $asset = is_readable( $asset_file ) ? require $asset_file : []; |
| 142 | |
| 143 | $asset['dependencies'] = isset( $asset['dependencies'] ) ? $asset['dependencies'] : []; |
| 144 | $asset['version'] = isset( $asset['version'] ) ? $asset['version'] : ''; |
| 145 | |
| 146 | wp_enqueue_script( |
| 147 | 'disable-embeds', |
| 148 | plugins_url( 'includes/disable-embeds/build/index.js', __DIR__ ), |
| 149 | $asset['dependencies'], |
| 150 | $asset['version'], |
| 151 | true |
| 152 | ); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Removes wp-embed dependency of core packages. |
| 157 | * |
| 158 | * @link https://plugins.trac.wordpress.org/browser/disable-embeds/tags/1.5.0/disable-embeds.php#L180 |
| 159 | * @since 8.0.0 |
| 160 | * |
| 161 | * @param WP_Scripts $scripts WP_Scripts instance, passed by reference. |
| 162 | */ |
| 163 | public function disable_embeds_remove_script_dependencies( $scripts ) { |
| 164 | if ( ! empty( $scripts->registered['wp-edit-post'] ) ) { |
| 165 | $scripts->registered['wp-edit-post']->deps = array_diff( |
| 166 | $scripts->registered['wp-edit-post']->deps, |
| 167 | array( 'wp-embed' ) |
| 168 | ); |
| 169 | } |
| 170 | } |
| 171 | } |