Skip to content

Instantly share code, notes, and snippets.

@vanpariyar
Created September 26, 2023 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanpariyar/95880b458a6110bb9f4d8c588cb4f119 to your computer and use it in GitHub Desktop.
Save vanpariyar/95880b458a6110bb9f4d8c588cb4f119 to your computer and use it in GitHub Desktop.
Day to day customisation needed for code so making one plugin to reuse in every plugin
class Customise_WordPress {

  function __construct($name) {
  // Remove the REST API HTML entities.
    $post_type = "post";
    add_filter( 'rest_prepare_ . $post_type', array( $this, 'decode_rest_api_title' ), 20, 3 );
  }
  
  /**
   * Decode HTML entities from the website title.
   *
   * @param string $response Actual response.
   * @param Object    $request Actual request.
   * @param Object    $post actual Post object.
   *
   * @return $response return text with decoded entirties.
   */
  public function decode_rest_api_title( $response, $post, $request ) {
    if ( isset( $post ) ) {
      $decoded_title = html_entity_decode( $response->data['title']['rendered'] );
      $response->data['title']['rendered'] = $decoded_title;
    }
    return $response;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment