requires_premium && ! AIIL_Core::is_licence_active() ) { return false; } if ( ! $this->is_editor_active() ) { return false; } // Check if current post type is supported. return $this->is_supported_post_type(); } /** * Check if current post type is supported. * Uses $_GET parameters to determine post type early in the request lifecycle. * * @return bool */ protected function is_supported_post_type() { $post_type = $this->get_current_post_type(); if ( ! $post_type ) { return false; } $supported_post_types = AIIL_Core::get_supported_post_types(); $is_supported = in_array( $post_type, $supported_post_types, true ); return $is_supported; } /** * Get current post type from request. * * Note: Nonce verification is not required here as this method only reads * GET parameters to determine the current context (post type) for the editor. * It's used during asset enqueuing and doesn't process, save, or modify data. * All values are properly sanitized before use. * * @return string|false Post type or false if not found. */ protected function get_current_post_type() { global $pagenow; // For new posts: post-new.php?post_type=custom_type // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reading context, not processing data. if ( isset( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reading context, not processing data. $post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); return $post_type; } // For existing posts: post.php?post=123 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reading context, not processing data. if ( isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reading context, not processing data. $post_id = absint( $_GET['post'] ); $post = get_post( $post_id ); if ( $post ) { return $post->post_type; } } // Default to 'post' if we're on post-new.php without post_type param. if ( 'post-new.php' === $pagenow ) { return 'post'; } return false; } /** * Check if editor is active. * * @return bool */ abstract protected function is_editor_active(); /** * Enqueue editor assets. */ abstract public function enqueue_assets(); /** * Get editor name. * * @return string */ public function get_name() { return $this->name; } }