• Resolved swinggraphics

    (@swinggraphics)


    I want to broadcast a page that contains internal links and automatically rewrite those links replacing the parent site_url with the child site_url. What hook should I use, and what part of the API is relevant?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author edward_plainview

    (@edward_plainview)

    My favorite actions are:

    • threewp_broadcast_broadcasting_started
    • threewp_broadcast_broadcasting_modify_post
    • threewp_broadcast_broadcasting_before_restore_current_blog

    The first action I use to note down whatever links I find in the post_content that are relevant to the parent blog.

    The second action is to modify the post content with new data.

    The third is to modify other things, like the custom fields.

    The post in question you’ll find in the first parameter: $action.
    $action->broadcast_data->post
    or
    $action->broadcast_data->new_post

    You should look at broadcast / src / traits / broadcasting.php, which contains a lot of nice code, I hope. ??

    Thread Starter swinggraphics

    (@swinggraphics)

    Thanks for the super fast reply! :O

    I’ll have a look and post my solution when I work it out.

    Thread Starter swinggraphics

    (@swinggraphics)

    Example for others interested:

    add_action( 'threewp_broadcast_broadcasting_modify_post', 'my_broadcasting_modify_post', 20 );
    function my_broadcasting_modify_post( $action ) {
    	$bcd = $action->broadcasting_data;
    	$parent_site_url = get_site_url( $bcd->parent_blog_id );
    	$child_site_url = get_site_url( $bcd->current_child_blog_id );
    	$modified_content = $bcd->modified_post->post_content;
    	$modified_content = str_replace( $parent_site_url, $child_site_url, $modified_content );
    	$bcd->modified_post->post_content = $modified_content;
    }

    I’m trying to make this into an option with a checkbox in the Broadcast metabox, but I haven’t figured out yet how to get the options to stick.

    Thread Starter swinggraphics

    (@swinggraphics)

    Full code, including checkbox added to Broadcast options:
    https://gist.github.com/swinggraphics/78057a3af32eec21c8bf47c734638528

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hook for modifying post content’ is closed to new replies.