Created
March 30, 2026 10:58
-
-
Save GaryJones/4fb02deafdcf2edf2ceed41b86941864 to your computer and use it in GitHub Desktop.
Distributor Post Modifier plugin for WordPress VIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Distributor Post Modifier | |
| * Description: Modifies pulled posts to show excerpts and link to original sources. | |
| * Version: 1.0.0 | |
| * Author: Automattic | |
| * License: GPL v2 or later | |
| * License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
| */ | |
| namespace Automattic\DistributorPostModifier; | |
| // Exit if accessed directly | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| // Hook into Distributor's pull action | |
| add_action( 'dt_pull_post', __NAMESPACE__ . '\\modify_pulled_post', 10, 3 ); | |
| // Filter post permalink to point to original source | |
| add_filter( 'post_link', __NAMESPACE__ . '\\modify_post_link', 10, 3 ); | |
| /** | |
| * Modify pulled post after it's created | |
| * | |
| * @param int $new_post_id The new post ID | |
| * @param object $connection The connection object | |
| * @param array $post_array The original post data | |
| */ | |
| function modify_pulled_post( $new_post_id, $connection, $post_array ) { | |
| // Set post format to "Link" | |
| set_post_format( $new_post_id, 'link' ); | |
| } | |
| /** | |
| * Modify post permalink to point to original source | |
| * | |
| * @param string $permalink The post permalink | |
| * @param WP_Post $post The post object | |
| * @param bool $leavename Whether to leave the post name | |
| * @return string Modified permalink | |
| */ | |
| function modify_post_link( $permalink, $post, $leavename ) { | |
| // Check if this is a distributed post | |
| $original_url = get_post_meta( $post->ID, 'dt_original_post_url', true ); | |
| if ( ! empty( $original_url ) ) { | |
| return $original_url; | |
| } | |
| return $permalink; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment