Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only read post object keys #14

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading