%s
.',
+ esc_html( get_post_status( $post_ID ) )
+ ),
+ PledgeForm\get_form_submission()
+ );
+ }
+}
+
+/**
+ * Record logs for events when postmeta values change.
+ *
+ * @param int $meta_id Unused. ID of updated metadata entry.
+ * @param int $object_id Post ID.
+ * @param string $meta_key Meta key.
+ * @param mixed $meta_value Meta value.
+ *
+ * @return void
+ */
+function capture_updated_postmeta( $meta_id, $object_id, $meta_key, $meta_value ) {
+ $post_type = get_post_type( $object_id );
+
+ if ( Pledge\CPT_ID !== $post_type ) {
+ return;
+ }
+
+ $valid_keys = array_keys( PledgeMeta\get_pledge_meta_config( 'user_input' ) );
+ $trimmed_meta_key = str_replace( PledgeMeta\META_PREFIX, '', $meta_key );
+
+ if ( in_array( $trimmed_meta_key, $valid_keys, true ) ) {
+ add_log_entry(
+ $object_id,
+ 'pledge_data_changed',
+ sprintf(
+ 'Changed %1$s
to %2$s
.',
+ esc_html( $trimmed_meta_key ),
+ esc_html( $meta_value )
+ ),
+ array(
+ $meta_key => $meta_value,
+ )
+ );
+ }
+}
+
+/**
+ * Record logs for events when new postmeta values are added (not changed).
+ *
+ * @param int $meta_id Unused. ID of updated metadata entry.
+ * @param int $object_id Post ID.
+ * @param string $meta_key Meta key.
+ * @param mixed $meta_value Meta value.
+ *
+ * @return void
+ */
+function capture_added_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
+ $post_type = get_post_type( $object_id );
+
+ if ( Pledge\CPT_ID !== $post_type ) {
+ return;
+ }
+
+ switch ( $meta_key ) {
+ case PledgeMeta\META_PREFIX . 'pledge-email-confirmed':
+ if ( true === $meta_value ) {
+ add_log_entry(
+ $object_id,
+ 'pledge_email_confirmed',
+ 'Pledge email address confirmed.',
+ array(
+ 'email' => get_post_meta( $object_id, PledgeMeta\META_PREFIX . 'org-pledge-email', true ),
+ )
+ );
+ }
+ break;
+ }
+}
+
+/**
+ * Record logs for events when a pledge post's status changes.
+ *
+ * @param string $new_status
+ * @param string $old_status
+ * @param WP_Post $post
+ *
+ * @return void
+ */
+function capture_transition_post_status( $new_status, $old_status, WP_Post $post ) {
+ $cpts = array( Pledge\CPT_ID, Contributor\CPT_ID );
+ $post_type = get_post_type( $post );
+
+ if ( ! in_array( $post_type, $cpts, true ) ) {
+ return;
+ }
+
+ if ( $new_status === $old_status ) {
+ return;
+ }
+
+ switch ( $post_type ) {
+ case Pledge\CPT_ID:
+ add_log_entry(
+ $post->ID,
+ 'pledge_status_changed',
+ sprintf(
+ 'Pledge status changed from %1$s
to %2$s
.',
+ esc_html( $old_status ),
+ esc_html( $new_status )
+ ),
+ array()
+ );
+ break;
+
+ case Contributor\CPT_ID:
+ $pledge = get_post( $post->post_parent );
+
+ add_log_entry(
+ $pledge->ID,
+ 'contributor_status_changed',
+ sprintf(
+ 'Contributor %1$s
status changed from %2$s
to %3$s
.',
+ esc_html( $post->post_title ),
+ esc_html( $old_status ),
+ esc_html( $new_status )
+ ),
+ array()
+ );
+ break;
+ }
+}
+
+/**
+ * Record a log for the event of contributors being added to a pledge.
+ *
+ * @param int $pledge_id The post ID of the pledge.
+ * @param array $contributors Array of contributor wporg usernames.
+ * @param array $results Associative array, key is wporg username, value is post ID on success,
+ * or an error code on failure.
+ *
+ * @return void
+ */
+function capture_add_pledge_contributors( $pledge_id, $contributors, $results ) {
+ add_log_entry(
+ $pledge_id,
+ 'contributors_added',
+ sprintf(
+ 'Contributors added: %s
',
+ implode( ', ', $contributors )
+ ),
+ $results
+ );
+}
+
+/**
+ * Record a log for the event when a contributor is removed from a pledge.
+ *
+ * @param int $pledge_id The post ID of the pledge.
+ * @param int $contributor_post_id The post ID of the pledge.
+ * @param WP_Post|false|null $result The result of the attempt to trash the post.
+ *
+ * @return void
+ */
+function capture_remove_contributor( $pledge_id, $contributor_post_id, $result ) {
+ // If the result isn't a post object, then it was already trashed, or didn't exist.
+ if ( $result instanceof WP_Post ) {
+ $contributor_post = get_post( $contributor_post_id );
+
+ add_log_entry(
+ $pledge_id,
+ 'contributor_removed',
+ sprintf(
+ 'Contributor removed: %s
',
+ esc_html( $contributor_post->post_title )
+ ),
+ array(
+ 'previous_status' => $contributor_post->_wp_trash_meta_status,
+ )
+ );
+ }
+}
diff --git a/plugins/wporg-5ftf/includes/pledge-meta.php b/plugins/wporg-5ftf/includes/pledge-meta.php
index a9c38cf..a9d2e90 100755
--- a/plugins/wporg-5ftf/includes/pledge-meta.php
+++ b/plugins/wporg-5ftf/includes/pledge-meta.php
@@ -28,9 +28,11 @@ add_action( 'added_post_meta', __NAMESPACE__ . '\update_generated_meta', 10, 4
/**
* Define pledge meta fields and their properties.
*
+ * @param string $context Optional. The part of the config to return. 'user_input', 'generated', or 'all'.
+ *
* @return array
*/
-function get_pledge_meta_config( $context = '' ) {
+function get_pledge_meta_config( $context = 'all' ) {
$user_input = array(
'org-description' => array(
'single' => true,
@@ -283,6 +285,7 @@ function update_generated_meta( $meta_id, $object_id, $meta_key, $_meta_value )
case META_PREFIX . 'org-name':
if ( 'updated_postmeta' === current_action() ) {
wp_update_post( array(
+ 'ID' => $object_id,
'post_title' => $_meta_value,
) );
}
diff --git a/plugins/wporg-5ftf/index.php b/plugins/wporg-5ftf/index.php
index 54e1d28..be8c836 100755
--- a/plugins/wporg-5ftf/index.php
+++ b/plugins/wporg-5ftf/index.php
@@ -30,6 +30,7 @@ function load() {
require_once get_includes_path() . 'pledge-form.php';
require_once get_includes_path() . 'directory.php';
require_once get_includes_path() . 'xprofile.php';
+ require_once get_includes_path() . 'pledge-log.php';
}
/**
diff --git a/plugins/wporg-5ftf/views/log.php b/plugins/wporg-5ftf/views/log.php
new file mode 100644
index 0000000..7742418
--- /dev/null
+++ b/plugins/wporg-5ftf/views/log.php
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+ Date
+ Entry
+ User
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ user_login ); ?>
+
+
+
+
+
+
+
+
+
+
+ There are no log entries.
+
+
+
+