self::ID, 'name' => __( 'Pre-publish check', 'forensix-digital' ), 'description' => __( 'Before you publish in the block editor, shows what is worth a second look: an empty title, placeholder text, images without a description, skipped heading levels, links without an address, dates that have passed. It only advises, never blocks publishing, and never changes your text.', 'forensix-digital' ), 'category' => 'content', 'edition' => Edition::FREE, 'dependencies' => array(), 'features' => array( 'C-02' => Edition::FREE, ), 'deactivation_effects' => array( __( 'The panel disappears from the editor. Your pages and posts are not changed.', 'forensix-digital' ), ), 'factory' => static fn(): self => new self(), ) ); } /** * Hooks the app while it is active. */ public function register(): void { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue' ) ); } /** * Nothing to set up. */ public function activate(): void {} /** * Removes the panel. */ public function deactivate(): void { remove_action( 'rest_api_init', array( $this, 'register_routes' ) ); remove_action( 'enqueue_block_editor_assets', array( $this, 'enqueue' ) ); } /** * Nothing stored. */ public function delete_data(): void {} /** * POST forensix/v1/precheck. */ public function register_routes(): void { register_rest_route( Api::NAMESPACE, '/precheck', array( 'methods' => 'POST', 'callback' => array( $this, 'check' ), 'permission_callback' => static fn(): bool => current_user_can( 'edit_posts' ), 'args' => array( 'title' => array( 'type' => 'string', 'default' => '', ), 'content' => array( 'type' => 'string', 'default' => '', ), 'type' => array( 'type' => 'string', 'default' => 'post', ), 'featured' => array( 'type' => 'boolean', 'default' => false, ), ), ) ); } /** * Checks a draft. * * @param \WP_REST_Request $request Request. */ public function check( \WP_REST_Request $request ): \WP_REST_Response { // The Business details app provides its details through this filter while it is active. $profile = apply_filters( 'forensix_business_details', null ); $profile = is_array( $profile ) && BusinessConfig::has_contacts( $profile ) ? $profile : null; $notes = PreCheckRules::notes( array( 'title' => substr( (string) $request['title'], 0, 1000 ), 'content' => substr( (string) $request['content'], 0, 500000 ), 'type' => sanitize_key( (string) $request['type'] ), 'featured' => (bool) $request['featured'], ), $profile, (string) wp_parse_url( home_url(), PHP_URL_HOST ), time() ); return new \WP_REST_Response( array( 'notes' => $notes ), 200 ); } /** * Loads the editor panel. */ public function enqueue(): void { wp_enqueue_script( 'fxd-precheck', FORENSIX_URL . 'admin/editor/precheck.js', array( 'wp-plugins', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data', 'wp-api-fetch', 'wp-i18n', 'wp-hooks' ), FORENSIX_VERSION, true ); wp_set_script_translations( 'fxd-precheck', 'forensix-digital', FORENSIX_PATH . 'languages' ); } }