Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ALwrity ALwrity WordPressPublisher resolve content manager

From Leeroopedia
Knowledge Sources
Domains Blog_Writer, Publishing, Integration
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for resolving a WordPress content manager (OAuth or legacy app-password) for a user and site, provided by the ALwrity publishing subsystem.

Description

The WordPressPublisher._resolve_content_manager method is the entry point for WordPress publishing in the ALwrity blog writer pipeline (stage 6). It attempts to resolve a WordPressOAuthContentManager first: it looks up the wordpress_oauth_tokens table in the per-user SQLite DB, finds a matching active token row for the given site ID, decrypts the access token via WordPressOAuthService (Fernet), and returns a content manager bound to the blog URL and decrypted token. If no OAuth token matches (legacy-only user), it falls back to WordPressService.get_site_credentials and returns a WordPressContentManager bound to the legacy site URL, username, and app password.

The returned tuple (manager, kind) lets the caller know whether the publish path is oauth or legacy, which affects capabilities (OAuth supports media uploads and scheduled posts; legacy is app-password based).

Usage

Import this publisher when:

  • The blog writer pipeline has final content and needs to publish to WordPress.
  • A user may have either OAuth or legacy app-password credentials; the code must handle both.
  • Published post metadata must be persisted to the per-user DB.

Code Reference

Source Location

  • Repository: ALwrity
  • File: backend/services/integrations/wordpress_publisher.py (L31-142)

Signature

class WordPressPublisher:
    """Handles publishing content to WordPress."""

    def __init__(self, db_path: str = None):
        self.wp_service = WordPressService()

    def _resolve_content_manager(
        self,
        user_id: str,
        site_id: int,
    ) -> tuple:
        """
        Resolve a content manager for site_id, preferring OAuth over legacy.

        Args:
            user_id: Clerk user ID.
            site_id: WordPress site identifier (matches token row PK).

        Returns:
            Tuple of (manager, kind) where kind is 'oauth' or 'legacy',
            or (None, None) if no credential path matches.
        """

Import

from services.integrations.wordpress_publisher import WordPressPublisher

I/O Contract

Inputs

Name Type Required Description
user_id str Yes Clerk user ID
site_id int Yes WordPress site identifier (token row PK)

Outputs

Name Type Description
return tuple WordPressContentManager, 'oauth' | 'legacy') or (None, None)

Usage Examples

Resolving and publishing

from services.integrations.wordpress_publisher import WordPressPublisher

publisher = WordPressPublisher()
manager, kind = publisher._resolve_content_manager(
    user_id="clerk_user_123",
    site_id=5,
)

if manager is None:
    raise ValueError("No WordPress credentials configured for this site")

# manager exposes a publish() method
post = manager.publish(
    title="My Blog Post",
    content_html="<p>Generated content...</p>",
    status="draft",
)
print(f"Published via {kind}: post_id={post['id']}, url={post['url']}")

Persisting published post metadata

publisher.save_post_info(
    user_id="clerk_user_123",
    wp_post_id=post["id"],
    wp_url=post["url"],
    title="My Blog Post",
    status="draft",
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment