GC_Post is the abstraction the Global Content plugin uses while processing posts. It wraps a WordPress post and normalizes both native WP_Post fields and Global Content–specific attributes used during synchronization and distribution. You construct it with a WP_Post, an object, or a post ID. The constructor validates input, prevents operating on trashed or missing posts, and initializes default values so downstream code can rely on a consistent shape.
This class is designed for read/write operations during processing. It exposes a minimal public API: public properties that mirror the key post fields plus Global Content metadata, and a small set of public methods for safe instantiation, metadata hydration, and utility conversion. Code outside this class should treat private or protected mechanisms as internal; only the public surface documented here is supported.
Architecture and flow
During a processing run, the plugin builds a GC_Post instance for each relevant post. Construction accepts either an ID or an object; non-object input is resolved via get_post. The constructor guards against missing or trashed content by throwing an exception early. It then maps core post fields into public properties, applies sane defaults for missing data, and defers Global Content metadata loading to get_meta.
When metadata is requested, get_meta starts from the plugin’s default meta schema and merges persisted values from post meta or, for remote posts, from the attributes provided by the distribution layer. It also normalizes edge cases, such as values stored as zero-indexed arrays during export, and ensures required identifiers are present. The method returns a complete associative array that downstream components can safely use.
Public API reference
Public properties
ID
Integer ID of the wrapped post. Always set if construction succeeds.post_name
String slug for the post. Defaults to an empty string if missing.post_title
String title. Defaults to an empty string.post_content
String content. Defaults to an empty string.post_excerpt
String excerpt. Defaults to an empty string.post_date
String date inY-m-d H:i:sformat. Defaults to0000-00-00 00:00:00.post_status
String status. Defaults topublish. The constructor rejectstrash.post_author
Integer author ID. Defaults to0.post_type
String post type. Defaults toany.meta
Array holding Global Content metadata. Empty by default; populated and normalized byget_meta.blog_id
Integer blog ID for the post. Defaults to0.site_url
String ornull. The site URL associated with the post context.nullby default.network_url
String ornull. Populated for remote posts to indicate their originating network.nullby default.post_links
Array of links related to the post (e.g., previews, edit URLs). Empty by default.language
String ornull. Language code of the post. If not provided and nonetwork_urlis set, the constructor attempts to resolve the language via the plugin’s helper.
Public Methods
__construct( $post )
Creates a new GC_Post from a WP_Post, generic object, or post ID. Resolves IDs to WP_Post objects, throws an exception if the post does not exist or is trashed, initializes defaults, and sets the language if it is still unset and the post is local.
Parameters: $post (WP_Post|object|int).
Throws: Exception if the post is not found or is trashed.
Returns: void.
get_meta()
Builds and returns the Global Content metadata array for the current post. Starts with default meta values, merges persisted post meta when available, normalizes export-induced array shapes, and, for remote posts, computes required identifiers based on attributes such as gc_post_status, blog_id, or network_url. The method updates $this->meta and returns the finalized array.
Parameters: none.
Returns: array of normalized metadata.
obj2arr( $object )
Utility to convert an object or array to a plain PHP array. Uses JSON encode/decode to recursively normalize nested structures; returns scalars unchanged.
Parameters: $object (mixed).
Returns: array|mixed (array for objects/arrays; original value otherwise).
static get_instance( $post_id )
Defensive factory method that returns a GC_Post for a given post ID or false if the post cannot be resolved. Validates the ID, fetches the WP_Post, and returns a constructed instance.
Parameters: $post_id (int).
Returns: GC_Post|false.