Skip to content

Commit

Permalink
fix: only read post object keys when indexing (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin authored Mar 26, 2024
1 parent 530c706 commit 692a7e8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions source/php/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Index
//Maximum size of record
private static $_nearMaxLimitSize = 9999;

// Post Object keys
private $wpPostObjectKeys = [];

/**
* Constructor, runs code on wordpress hooks.
*/
Expand All @@ -29,6 +32,8 @@ public function __construct($hookActions = true)
return;
}

$this->wpPostObjectKeys = array_keys(get_object_vars(new \WP_Post((object) [])));

//Add & update
add_action('save_post', array($this, 'index'), self::$_priority);

Expand Down Expand Up @@ -114,8 +119,17 @@ public function index($post)
$post = _wp_json_sanity_check($post, 10);

//Esape html entities
array_walk_recursive($post, function (&$value) {
$value = htmlentities($value);

array_walk_recursive($post, function (&$value, $key) {
if (in_array($key, $this->wpPostObjectKeys)) {

// Converts Int to string (ID)
if (!is_string($value)) {
$value = strval($value);
}

$value = htmlentities($value);
}
});

//Index post
Expand Down

0 comments on commit 692a7e8

Please sign in to comment.