Skip to content

Commit

Permalink
Docs: fix comment punctuation (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl authored and Adam Silverstein committed May 1, 2019
1 parent 5063639 commit 82b2d6e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
82 changes: 41 additions & 41 deletions tests/test-meta-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class MetaRevisionTests extends WP_UnitTestCase {

/**
* Callback function to add the revisioned keys
* Callback function to add the revisioned keys.
*/
public function add_revisioned_keys( $keys ) {
$keys[] = 'meta_revision_test';
Expand All @@ -28,11 +28,11 @@ public function add_revisioned_keys( $keys ) {
* @dataProvider slashed_data_provider
*/
public function test_revisions_stores_meta_values_with_slashes( $passed, $expected ) {
// Set up a new post
// Set up a new post.
$post_id = $this->factory->post->create();
$original_post_id = $post_id;

// And update to store an initial revision
// And update to store an initial revision.
wp_update_post(
array(
'post_content' => 'some initial content',
Expand All @@ -41,32 +41,32 @@ public function test_revisions_stores_meta_values_with_slashes( $passed, $expect
);
add_filter( 'wp_post_revision_meta_keys', array( $this, 'add_revisioned_keys' ) );

// Store a custom meta value, which is not revisioned by default
// Store a custom meta value, which is not revisioned by default.
update_post_meta( $post_id, 'meta_revision_test', wp_slash( $passed ) );
$this->assertEquals( $expected, get_post_meta( $post_id, 'meta_revision_test', true ) );

// Update the post, storing a revision
// Update the post, storing a revision.
wp_update_post(
array(
'post_content' => 'some more content',
'ID' => $post_id,
)
);

// Overwrite
// Overwrite.
update_post_meta( $post_id, 'meta_revision_test', 'original' );
// Update the post, storing a revision
// Update the post, storing a revision.
wp_update_post(
array(
'post_content' => 'some more content again',
'ID' => $post_id,
)
);

// Restore the previous revision
// Restore the previous revision.
$revisions = (array) wp_get_post_revisions( $post_id );

// Go back two to load the previous revision
// Go back two to load the previous revision.
array_shift( $revisions );
$last_revision = array_shift( $revisions );

Expand Down Expand Up @@ -99,7 +99,7 @@ public function slashed_data_provider() {
}

/**
* Test the revisions system for storage of meta values
* Test the revisions system for storage of meta values.
*
* @group revision
*/
Expand All @@ -108,11 +108,11 @@ public function test_revisions_stores_meta_values() {
* Set Up.
*/

// Set up a new post
// Set up a new post.
$post_id = $this->factory->post->create();
$original_post_id = $post_id;

// And update to store an initial revision
// And update to store an initial revision.
wp_update_post(
array(
'post_content' => 'some initial content',
Expand All @@ -125,13 +125,13 @@ public function test_revisions_stores_meta_values() {
$this->assertCount( 1, $revisions );

/*
* First set up a meta value
* First set up a meta value.
*/

// Store a custom meta value, which is not revisioned by default
// Store a custom meta value, which is not revisioned by default.
update_post_meta( $post_id, 'meta_revision_test', 'original' );

// Update the post, storing a revision
// Update the post, storing a revision.
wp_update_post(
array(
'post_content' => 'some more content',
Expand All @@ -142,7 +142,7 @@ public function test_revisions_stores_meta_values() {
$revisions = wp_get_post_revisions( $post_id );
$this->assertCount( 2, $revisions );

// Next, store some updated meta values for the same key.
// Next, store some updated meta values for the same key.
update_post_meta( $post_id, 'meta_revision_test', 'update1' );

// Save the post, changing content to force a revision.
Expand All @@ -157,13 +157,13 @@ public function test_revisions_stores_meta_values() {
$this->assertCount( 3, $revisions );

/*
* Now restore the original revision
* Now restore the original revision.
*/

// Restore the previous revision
// Restore the previous revision.
$revisions = (array) wp_get_post_revisions( $post_id );

// Go back two to load the previous revision
// Go back two to load the previous revision.
array_shift( $revisions );
$last_revision = array_shift( $revisions );

Expand All @@ -178,19 +178,19 @@ public function test_revisions_stores_meta_values() {
* Check the meta values to verify they are NOT revisioned - they are not revisioned by default.
*/

// Custom post meta should NOT be restored, orignal value should not be restored, value still 'update1'
// Custom post meta should NOT be restored, orignal value should not be restored, value still 'update1'.
$this->assertEquals( 'update1', get_post_meta( $post_id, 'meta_revision_test', true ) );

update_post_meta( $post_id, 'meta_revision_test', 'update2' );

/*
* Test the revisioning of custom meta when enabled by the wp_post_revision_meta_keys filter
* Test the revisioning of custom meta when enabled by the wp_post_revision_meta_keys filter.
*/

// Add the custom field to be revised via the wp_post_revision_meta_keys filter
// Add the custom field to be revised via the wp_post_revision_meta_keys filter.
add_filter( 'wp_post_revision_meta_keys', array( $this, 'add_revisioned_keys' ) );

// Save the post, changing content to force a revision
// Save the post, changing content to force a revision.
wp_update_post(
array(
'post_content' => 'more updated content',
Expand All @@ -201,32 +201,32 @@ public function test_revisions_stores_meta_values() {
$revisions = wp_get_post_revisions( $post_id );
$this->assertCount( 5, $revisions );

// Store custom meta values, which should now be revisioned
// Store custom meta values, which should now be revisioned.
update_post_meta( $post_id, 'meta_revision_test', 'update3' );

/*
* Save the post again, custom meta should now be revisioned
* Save the post again, custom meta should now be revisioned.
*
* Note that a revision is saved even though there is no change
* in post content, because the revisioned post_meta has changed
* in post content, because the revisioned post_meta has changed.
*/
wp_update_post(
array(
'ID' => $post_id,
)
);

// This revision contains the existing post meta ('update3')
// This revision contains the existing post meta ('update3').
$revisions = wp_get_post_revisions( $post_id );
$this->assertCount( 6, $revisions );

// Verify that previous post meta is set
// Verify that previous post meta is set.
$this->assertEquals( 'update3', get_post_meta( $post_id, 'meta_revision_test', true ) );

// Restore the previous revision
// Restore the previous revision.
$revisions = wp_get_post_revisions( $post_id );

// Go back two to load the previous revision
// Go back two to load the previous revision.
array_shift( $revisions );
$last_revision = array_shift( $revisions );
wp_restore_post_revision( $last_revision->ID );
Expand All @@ -236,7 +236,7 @@ public function test_revisions_stores_meta_values() {
*/
$this->assertEquals( 'update2', get_post_meta( $post_id, 'meta_revision_test', true ) );

// Try storing a blank meta
// Try storing a blank meta.
update_post_meta( $post_id, 'meta_revision_test', '' );
wp_update_post(
array(
Expand All @@ -251,14 +251,14 @@ public function test_revisions_stores_meta_values() {
)
);

// Restore the previous revision
// Restore the previous revision.
$revisions = wp_get_post_revisions( $post_id );
array_shift( $revisions );
$last_revision = array_shift( $revisions );
wp_restore_post_revision( $last_revision->ID );

/*
* Verify that previous blank post meta is restored
* Verify that previous blank post meta is restored.
*/
$this->assertEquals( '', get_post_meta( $post_id, 'meta_revision_test', true ) );

Expand All @@ -267,7 +267,7 @@ public function test_revisions_stores_meta_values() {
*/
remove_all_filters( 'wp_post_revision_meta_keys' );

// Meta should no longer be revisioned
// Meta should no longer be revisioned.
update_post_meta( $post_id, 'meta_revision_test', 'update 5' );
wp_update_post(
array(
Expand All @@ -283,7 +283,7 @@ public function test_revisions_stores_meta_values() {
)
);

// Restore the previous revision
// Restore the previous revision.
$revisions = wp_get_post_revisions( $post_id );
array_shift( $revisions );
$last_revision = array_shift( $revisions );
Expand All @@ -294,26 +294,26 @@ public function test_revisions_stores_meta_values() {
*/
$this->assertEquals( 'update 6', get_post_meta( $post_id, 'meta_revision_test', true ) );

// Add the custom field to be revised via the wp_post_revision_meta_keys filter
// Add the custom field to be revised via the wp_post_revision_meta_keys filter.
add_filter( 'wp_post_revision_meta_keys', array( $this, 'add_revisioned_keys' ) );

/*
* Test the revisioning of multiple meta keys
* Test the revisioning of multiple meta keys.
*/

// Add three values for meta
// Add three values for meta.
update_post_meta( $post_id, 'meta_revision_test', 'update 7' );
add_post_meta( $post_id, 'meta_revision_test', 'update 7 number 2' );
add_post_meta( $post_id, 'meta_revision_test', 'update 7 number 3' );
wp_update_post( array( 'ID' => $post_id ) );

// Update all three values
// Update all three values.
update_post_meta( $post_id, 'meta_revision_test', 'update 8', 'update 7' );
update_post_meta( $post_id, 'meta_revision_test', 'update 8 number 2', 'update 7 number 2' );
update_post_meta( $post_id, 'meta_revision_test', 'update 8 number 3', 'update 7 number 3' );
wp_update_post( array( 'ID' => $post_id ) );

// Restore the previous revision
// Restore the previous revision.
$revisions = wp_get_post_revisions( $post_id );
array_shift( $revisions );
$last_revision = array_shift( $revisions );
Expand Down Expand Up @@ -359,7 +359,7 @@ public function test_revisions_stores_meta_values() {
// Update to save.
wp_update_post( array( 'ID' => $post_id ) );

// Restore the previous revision
// Restore the previous revision.
$revisions = wp_get_post_revisions( $post_id );
array_shift( $revisions );
$last_revision = array_shift( $revisions );
Expand Down
10 changes: 5 additions & 5 deletions wp-post-meta-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class WP_Post_Meta_Revisioning {

/**
* Set up the plugin actions
* Set up the plugin actions.
*/
public function __construct() {

// Actions
// Actions.
//
// When restoring a revision, also restore that revisions's revisioned meta.
add_action( 'wp_restore_post_revision', array( $this, '_wp_restore_post_revision_meta' ), 10, 2 );
Expand All @@ -38,7 +38,7 @@ public function __construct() {
// When creating a revision, also save any revisioned meta.
add_action( '_wp_put_post_revision', array( $this, '_wp_save_revisioned_meta_fields' ) );

//Filters
// Filters.
// When revisioned post meta has changed, trigger a revision save.
add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_wp_check_revisioned_meta_fields_have_changed' ), 10, 3 );

Expand Down Expand Up @@ -166,9 +166,9 @@ public function _wp_restore_post_revision_meta( $post_id, $revision_id ) {
$metas_revisioned = $this->_wp_post_revision_meta_keys();
if ( isset( $metas_revisioned ) && 0 !== count( $metas_revisioned ) ) {
foreach ( $metas_revisioned as $meta_key ) {
// Clear any existing metas
// Clear any existing metas.
delete_post_meta( $post_id, $meta_key );
// Get the stored meta, not stored === blank
// Get the stored meta, not stored === blank.
$meta_values = get_post_meta( $revision_id, $meta_key, true );
if ( 0 !== count( $meta_values ) && is_array( $meta_values ) ) {
foreach ( $meta_values as $meta_value ) {
Expand Down

0 comments on commit 82b2d6e

Please sign in to comment.