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
Implement wrapping infrastructure for dealing with WordPress post metadata #3154
Comments
IB ✅ |
@felixarntz just a thought which we could change later – why not make |
@aaemnnosttv I was thinking about that too, but I think for now the |
QA Eng ✅ |
As part of the Idea Hub module functionality, it will be necessary for the first time in Site Kit to deal with post metadata. Therefore, we should add basic infrastructure wrapping the relevant WordPress API (similar to e.g.
Options
andUser_Options
classes). See more information on the overall approach.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Google\Site_Kit\Core\Storage\Post_Meta_Interface
, with the following methods:get( int $post_id, string $key, bool $single = false ) : mixed
: Gets the value of the given post meta key.update( int $post_id, string $key, mixed $value, mixed $prev_value = '' ): bool
: Updates the value for a post meta key.add( int $post_id, string $key, mixed $value, bool $unique = false ) : bool
: Adds a new value for a post meta key.delete( int $post_id, string $key, mixed $value = '' ): bool
: Deletes the given post meta key.Google\Site_Kit\Core\Storage\Post_Meta
which implements the above interface:get
should rely onget_post_meta
.update
should rely onupdate_post_meta
.add
should rely onadd_post_meta
.delete
should rely ondelete_post_meta
.Google\Site_Kit\Core\Storage\Post_Meta_Setting
:META_KEY
class constant, to be defined in each sub-class.Post_Meta_Interface
being passed into the constructor.register()
method, which callsregister_meta( 'post', ... )
. It should rely on protected methodsget_type()
andget_sanitize_callback()
which can be overridden by each sub-class (similar to e.g. in the existingUser_Setting
class. Thesingle
argument should be enforced totrue
for now.get( $post_id )
,set( $post_id )
anddelete( $post_id )
which wrap the respectivePost_Meta
methods.get
should always use$single
astrue
, and it should return the value of a protectedget_default()
method if no actual meta value is set.default
meta value in version 5.5, but we support back to 4.7, so we can't rely on this.set
should useupdate
for now, since for$single
meta keys that is always appropriate.Post_Meta::update
andPost_Meta::delete
, as well asPost_Meta::add
overall won't be needed as long as we only deal with$single
meta keys. They should still be available in the lower-level infrastructure to allow flexibility.googlesitekit_
should be wiped.Implementation Brief
Create a new interface
/includes/Core/Storage/Post_Meta_Interface.php
with the following methods, params, return types and documentation as specified in AC.Create a new class implementing the interface
/includes/Core/Storage/Post_Meta.php
final class Post_Meta implements Post_Meta_Interface
implementing the four methods using the relevant*_post_meta
functions as specified in the AC.Create a new abstract class
/includes/Core/Storage/Post_Meta_Setting.php
following the ACs, here is a skeleton to start you offUpdate
Google\Site_Kit\Core\Util\Reset::all()
to handle post_metasite-kit-wp/includes/Core/Util/Reset.php
Line 110 in 17a5a8c
$this->delete_post_meta( $scope = 'site' or 'network' )
take a look at eitherdelete_options()
ordelete_user_options()
to help build the query to delete the post_meta.There is also Reset_Persistent, but it won't require any changes
https://github.com/google/site-kit-wp/blob/17a5a8c3800c8ae68d7c8982b36b9ae83118ea72/includes/Core/Util/Reset_Persistent.php
Test Coverage
tests/phpunit/integration/Core/Storage/Post_MetaTest.php
tests/phpunit/integration/Core/Util/ResetTest.php
tests/phpunit/integration/Core/Util/ResetPersistentTest.php
Make sure
wp google-site-kit reset
works for postmetagooglesitekit_foo
Make sure
wp google-site-kit reset --persistent
works for postmetaVisual Regression Changes
QA Brief
QA:Eng
googlesitekit_foo
and another with a post meta with a keygooglesitekitpersistent_foo
.wp google-site-kit reset
deletes onlygooglesitekit_foo
wp google-site-kit reset --persistent
deletes bothgooglesitekit_foo
andgooglesitekitpersistent_foo
Changelog entry
The text was updated successfully, but these errors were encountered: