post_type, 'title' ) ) { $fields[] = array( 'locator' => 'post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post->post_title, 'writable' => true, 'whole_column' => true, 'note' => 'The page heading WordPress shows and lists. The SEO title (browser tab, search results) is managed in ' . \AdiBridge\Seo::owner() . '.', ); } if ( post_type_supports( $post->post_type, 'excerpt' ) ) { $fields[] = array( 'locator' => 'post_excerpt', 'label' => 'Excerpt', 'type' => 'textarea', 'value' => $post->post_excerpt, 'writable' => true, 'whole_column' => true, 'note' => 'Short summary some themes show in listings.', ); } $fields[] = array( 'locator' => 'post_name', 'label' => 'Slug (address)', 'type' => 'readonly', 'value' => $post->post_name, 'writable' => false, 'note' => 'Changing a page address breaks existing links and search rankings, so ADI does not change it.', ); if ( post_type_supports( $post->post_type, 'thumbnail' ) ) { // A WooCommerce product's image is changed through WooCommerce's product API (woocommerce:featured_image, #21). $product = 'product' === $post->post_type && isset( \AdiBridge\Content::adapters()['woocommerce'] ) && WooCommerce::catalog_product( $post->ID ); $field = array( 'locator' => 'featured_image', 'label' => 'Featured image', 'type' => 'image', 'value' => (int) get_post_thumbnail_id( $post ), 'writable' => ! $product, ); if ( $product ) { $field['note'] = 'Read-only here: on products, change it with woocommerce:featured_image (the product image).'; } $fields[] = $field; } return $fields; } public function post_column( $locator ) { return in_array( $locator, array( 'post_title', 'post_excerpt' ), true ) ? $locator : null; } public function read( \WP_Post $post, $locator ) { foreach ( $this->list_fields( $post ) as $field ) { if ( $field['locator'] === $locator ) { return $field; } } return null; } public function write( \WP_Post $post, $locator, $value ) { switch ( $locator ) { case 'post_title': case 'post_excerpt': $result = wp_update_post( wp_slash( array( 'ID' => $post->ID, $locator => $value, ) ), true ); if ( is_wp_error( $result ) ) { throw new Tool_Error( esc_html( 'WordPress refused the change: ' . $result->get_error_message() ) ); } return; case 'featured_image': if ( 0 === $value ) { delete_post_thumbnail( $post ); } elseif ( ! set_post_thumbnail( $post, $value ) && (int) get_post_thumbnail_id( $post ) !== $value ) { throw new Tool_Error( 'WordPress refused to set the featured image.' ); } return; } throw new Tool_Error( esc_html( "core:$locator can't be changed through ADI." ) ); } }