hook = is_string( $hook ) ? $hook : ''; } /** * Page container; the React app mounts into it. */ public function render(): void { echo '

' . esc_html( UNBREAK_NAME ) . '

' . esc_html__( 'Loading…', 'unbreak' ) . '

'; } /** * Enqueue the app on our page only. * * @param string $hook Current admin page hook. */ public function assets( $hook ): void { if ( '' === $this->hook || $hook !== $this->hook ) { return; } $asset_file = UNBREAK_DIR . 'assets/build/index.asset.php'; $asset = file_exists( $asset_file ) ? require $asset_file : array( 'dependencies' => array(), 'version' => UNBREAK_VERSION, ); wp_enqueue_script( self::HANDLE, UNBREAK_URL . 'assets/build/index.js', $asset['dependencies'], $asset['version'], true ); wp_set_script_translations( self::HANDLE, 'unbreak', UNBREAK_DIR . 'languages' ); wp_enqueue_style( 'wp-components' ); if ( file_exists( UNBREAK_DIR . 'assets/build/style-index.css' ) ) { wp_enqueue_style( self::HANDLE, UNBREAK_URL . 'assets/build/style-index.css', array( 'wp-components' ), $asset['version'] ); wp_style_add_data( self::HANDLE, 'rtl', 'replace' ); } wp_add_inline_script( self::HANDLE, 'window.unbreakAdmin = ' . wp_json_encode( array( 'restPath' => 'unbreak/v1', 'canManage' => current_user_can( 'manage_options' ), 'adminEmail' => (string) get_option( 'admin_email' ), 'homeUrl' => home_url( '/' ), 'version' => UNBREAK_VERSION, 'name' => UNBREAK_NAME, 'postTypes' => $this->post_type_options(), ) ) . ';', 'before' ); } /** * Post types for the filter dropdown. * * @return array */ private function post_type_options(): array { $out = array(); foreach ( \Unbreak\Extract\Indexer::post_types() as $type ) { $object = get_post_type_object( $type ); $out[] = array( 'value' => $type, 'label' => $object ? (string) $object->labels->singular_name : $type, ); } return $out; } /** * One dismissible notice after activation, shown once and only on our own screen. */ public function activation_notice(): void { $screen = get_current_screen(); if ( '' === $this->hook || ! $screen || $screen->id !== $this->hook ) { return; } if ( ! get_option( Lifecycle::NOTICE_FLAG ) || ! current_user_can( Settings::capability() ) ) { return; } delete_option( Lifecycle::NOTICE_FLAG ); printf( '

%s

', esc_html__( 'Unbreak is scanning your site for broken links in the background. No account needed.', 'unbreak' ) ); } /** * "Open" link on the Plugins screen. * * @param array $links Links. * @return array */ public function action_links( $links ): array { $open = sprintf( '%s', esc_url( admin_url( 'tools.php?page=' . self::SLUG ) ), esc_html__( 'Open', 'unbreak' ) ); array_unshift( $links, $open ); return $links; } }