HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vcz/wp-content/plugins/volonteka-site-plugin/rest-api.php
<?php

// Adds featured_image_url and clean_excerpt to the rest api posts feed
add_action('rest_api_init', function(){
  register_rest_field( array('post'),
      'featured_image_url',
      array(
          'get_callback'    => 'get_rest_featured_image_url',
          'update_callback' => null,
          'schema'          => null,
      )
  );
  register_rest_field( array('post'),
      'clean_excerpt',
      array(
          'get_callback'    => 'get_rest_clean_excerpt',
          'update_callback' => null,
          'schema'          => null,
      )
  );
  register_rest_field( array('post'),
      'clean_title',
      array(
          'get_callback'    => 'get_rest_clean_title',
          'update_callback' => null,
          'schema'          => null,
      )
  );
});

// Returns the featured_media src. To be used in rest api posts feed
function get_rest_featured_image_url( $object, $field_name, $request ) {
  if( $object['featured_media'] ){
      $img = wp_get_attachment_image_src( $object['featured_media'], 'app-thumb' );
      return $img[0];
  }
  return false;
}
// Returns the cleaned up excerpt without html tags. To be used in rest api posts feed
function get_rest_clean_excerpt( $object, $field_name, $request ) {
  if( $object['excerpt'] ){
    $stripped_text = wp_strip_all_tags(get_the_excerpt());
    $decoded_text = html_entity_decode($stripped_text);
    
    return $decoded_text;
  }
  return false;
}

// Returns the cleaned up title without html entities. To be used in rest api posts feed
function get_rest_clean_title( $object, $field_name, $request ) {
  if( $object['title'] ){
      return html_entity_decode(get_the_title());
  }
  return false;
}