LPH
Well-known member
The following code works but maybe there is a better way to get the first_post_id for the Post\Editor. Currently, the thread_id is known and the first post is to be edited.
Is there a more efficient way to edit the first post outside of XenForo 2?
PHP:
/**
* @param $post
*
* @return bool
*/
public function edit( $post ) {
$message = get_post_field( 'post_content', $post->ID );
$content_except = get_post_field( 'post_excerpt', $post->ID );
$excerpt_length = $this->options['xf_excerpt_length'];
// Get thread in order to get first post id
$thread_ID = get_post_meta($post->ID, 'thread_id', true);
if ( ! empty( $thread_ID ) ) {
return false;
}
$thread = \XF::app()->finder('XF:Thread')->where('thread_id', $thread_ID)->fetchOne();
$firstPost = \XF::app()->finder('XF:Post')->where('post_id', $thread['first_post_id'])->fetchOne();
/** @var \XF\Service\Post\Editor $editor */
$editor = \XF::app()->service('XF:Post\Editor', $firstPost);
$editor->setMessage( $message );
$editor->save();
}
Is there a more efficient way to edit the first post outside of XenForo 2?