3rd-party
3 days ago
abstracts
3 months ago
admin
2 weeks ago
emails
2 weeks ago
forms
3 days ago
helper
3 months ago
promoted-jobs
3 days ago
ui
2 weeks ago
widgets
2 weeks ago
class-access-token.php
2 years ago
class-dev-tools.php
2 years ago
class-guest-session.php
2 years ago
class-guest-user.php
2 years ago
class-job-dashboard-shortcode.php
6 months ago
class-job-listing-stats.php
2 years ago
class-job-overlay.php
2 years ago
class-stats-dashboard.php
2 years ago
class-stats-script.php
3 months ago
class-stats.php
3 months ago
class-wp-job-manager-ajax.php
2 months ago
class-wp-job-manager-api.php
6 years ago
class-wp-job-manager-blocks.php
2 weeks ago
class-wp-job-manager-cache-helper.php
3 months ago
class-wp-job-manager-category-walker.php
6 years ago
class-wp-job-manager-com-api.php
2 years ago
class-wp-job-manager-data-cleaner.php
2 years ago
class-wp-job-manager-data-exporter.php
3 months ago
class-wp-job-manager-dependency-checker.php
2 years ago
class-wp-job-manager-email-notifications.php
2 years ago
class-wp-job-manager-forms.php
5 years ago
class-wp-job-manager-geocode.php
2 weeks ago
class-wp-job-manager-install.php
2 years ago
class-wp-job-manager-post-types.php
3 days ago
class-wp-job-manager-recaptcha.php
6 months ago
class-wp-job-manager-rest-api.php
2 months ago
class-wp-job-manager-shortcodes.php
2 weeks ago
class-wp-job-manager-usage-tracking-data.php
2 years ago
class-wp-job-manager-usage-tracking.php
2 years ago
class-wp-job-manager-widget.php
2 weeks ago
class-wp-job-manager.php
3 months ago
trait-singleton.php
2 years ago
class-wp-job-manager-blocks.php
111 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles Job Manager's Gutenberg Blocks. |
| 4 | * |
| 5 | * @package wp-job-manager |
| 6 | * @since 1.32.0 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; // Exit if accessed directly. |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Class WP_Job_Manager_Blocks. |
| 15 | */ |
| 16 | class WP_Job_Manager_Blocks { |
| 17 | /** |
| 18 | * The static instance of the WP_Job_Manager_Blocks |
| 19 | * |
| 20 | * @var self |
| 21 | */ |
| 22 | private static $instance = null; |
| 23 | |
| 24 | /** |
| 25 | * Singleton instance getter |
| 26 | * |
| 27 | * @return self |
| 28 | */ |
| 29 | public static function get_instance() { |
| 30 | if ( ! self::$instance ) { |
| 31 | self::$instance = new WP_Job_Manager_Blocks(); |
| 32 | } |
| 33 | |
| 34 | return self::$instance; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Instance constructor |
| 39 | */ |
| 40 | private function __construct() { |
| 41 | if ( ! function_exists( 'register_block_type' ) ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | add_action( 'init', [ $this, 'register_blocks' ] ); |
| 46 | add_action( 'enqueue_block_editor_assets', [ $this, 'enable_legacy_widget_block' ] ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Register all Gutenblocks |
| 51 | */ |
| 52 | public function register_blocks() { |
| 53 | // Add script includes for gutenblocks. |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Enable the core Legacy Widget block in the Site Editor. |
| 58 | * |
| 59 | * On a block theme there is no classic Widgets screen, and the Site Editor |
| 60 | * does not expose the Legacy Widget block by default, so there is no UI to |
| 61 | * insert the plugin's classic widgets (Recent Jobs, Featured Jobs). Opting |
| 62 | * the block in here restores that path. Scoped to the Site Editor screen so |
| 63 | * the post/page editor is left untouched. |
| 64 | * |
| 65 | * The Site Editor registers `core/legacy-widget` itself with |
| 66 | * `supports.inserter: false`, so calling `registerLegacyWidgetBlock()` here |
| 67 | * would be a duplicate registration and log "Block core/legacy-widget is |
| 68 | * already registered". Instead, flip the inserter support flag on core's own |
| 69 | * registration via the `blocks.registerBlockType` filter. |
| 70 | * |
| 71 | * @see https://developer.wordpress.org/block-editor/how-to-guides/widgets/legacy-widget-block/ |
| 72 | * @see https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/ |
| 73 | */ |
| 74 | public function enable_legacy_widget_block() { |
| 75 | if ( ! function_exists( 'get_current_screen' ) ) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | $screen = get_current_screen(); |
| 80 | |
| 81 | if ( ! $screen || 'site-editor' !== $screen->id ) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | if ( ! wp_script_is( 'wp-widgets', 'registered' ) ) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | // `wp-widgets` loads before `wp-edit-site`, so the filter is in place |
| 90 | // before the Site Editor registers the block. |
| 91 | wp_enqueue_script( 'wp-widgets' ); |
| 92 | wp_add_inline_script( |
| 93 | 'wp-widgets', |
| 94 | 'wp.hooks.addFilter( |
| 95 | "blocks.registerBlockType", |
| 96 | "wp-job-manager/enable-legacy-widget-inserter", |
| 97 | function ( settings, name ) { |
| 98 | if ( "core/legacy-widget" !== name ) { |
| 99 | return settings; |
| 100 | } |
| 101 | return Object.assign( {}, settings, { |
| 102 | supports: Object.assign( {}, settings.supports, { inserter: true } ), |
| 103 | } ); |
| 104 | } |
| 105 | );' |
| 106 | ); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | WP_Job_Manager_Blocks::get_instance(); |
| 111 |