add_meta_boxes(); add_action( 'edit_form_top', array( $this, 'add_header' ) ); add_action( 'dbx_post_sidebar', array( $this, 'add_footer' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'register_styles_scripts' ) ); add_filter( 'script_loader_tag', array( $this, 'add_alpine_defer_attribute' ), 10, 2 ); add_action( 'save_post', array( $this, 'save_post' ), 10, 3 ); add_action( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 10, 2 ); add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_post_updated_messages' ), 10, 2 ); add_filter( 'redirect_post_location', array( $this, 'redirect_post_location' ), 10, 2 ); add_action( 'admin_notices', array( $this, 'admin_notices' ), 10 ); } /** * Output wrapper opening for alpinejs x-data */ public function add_header() { if ( 'airwpsync-connection' === get_post_type() ) { echo '
'; echo ''; } } /** * Output wrapper closing for alpinejs x-data */ public function add_footer() { if ( 'airwpsync-connection' === get_post_type() ) { echo '
'; } } /** * Register admin styles and scripts */ public function register_styles_scripts() { $screen = get_current_screen(); if ( is_object( $screen ) && 'airwpsync-connection' === $screen->id ) { wp_enqueue_script( 'air-wp-sync-alpine', plugins_url( 'assets/js/alpinejs@3.10.2.min.js', AIR_WP_SYNC_PLUGIN_FILE ), false, AIR_WP_SYNC_VERSION, false ); wp_enqueue_script( 'air-wp-sync-admin-filters', plugins_url( 'assets/js/filters/main.js', AIR_WP_SYNC_PLUGIN_FILE ), array( 'wp-i18n' ), AIR_WP_SYNC_VERSION, false ); wp_set_script_translations( 'air-wp-sync-admin-filters', 'air-wp-sync', AIR_WP_SYNC_PLUGIN_DIR . 'languages/' ); wp_enqueue_script( 'air-wp-sync-admin', plugins_url( 'assets/js/admin-page.js', AIR_WP_SYNC_PLUGIN_FILE ), array( 'air-wp-sync-alpine', 'jquery-ui-tooltip', 'wp-hooks', 'air-wp-sync-admin-filters', 'wp-i18n' ), AIR_WP_SYNC_VERSION, false ); wp_add_inline_script( 'air-wp-sync-admin', 'var airwpsyncImporterData = ' . $this->get_config(), 'before' ); wp_add_inline_script( 'air-wp-sync-admin', 'var airWpSync = ' . $this->get_modules_config(), 'before' ); wp_localize_script( 'air-wp-sync-admin', 'airWpSyncL10n', $this->get_l10n_strings() ); wp_enqueue_script( 'air-wp-sync-admin-metabox-mapping', plugins_url( 'assets/js/metabox-mapping/main.js', AIR_WP_SYNC_PLUGIN_FILE ), array( 'air-wp-sync-admin', 'wp-i18n' ), AIR_WP_SYNC_VERSION, false ); wp_set_script_translations( 'air-wp-sync-admin-metabox-mapping', 'air-wp-sync', AIR_WP_SYNC_PLUGIN_DIR . 'languages/' ); wp_enqueue_style( 'air-wp-sync-ui', plugins_url( 'assets/js/air-wp-sync-ui/library/index.css', AIR_WP_SYNC_PLUGIN_FILE ), false, AIR_WP_SYNC_VERSION ); // .airwpsync-ui class is required by 'air-wp-sync-ui' style. add_filter( 'admin_body_class', function ( $body_class ) { $body_class .= ' airwpsync-ui'; return $body_class; } ); } } /** * Add defer attribute to AlpineJS script * * @param string $tag The `