Making WordPress.org


Ignore:
Timestamp:
03/23/2016 10:04:20 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Log status changes and notes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r2517 r2784  
    4343        // Post status transitions
    4444        add_action( 'transition_post_status',                         array( $this, 'trigger_schedule_actions' ), 10, 3 );
     45        add_action( 'transition_post_status',                         array( $this, 'log_status_changes'       ), 10, 3 );
    4546        add_action( 'wcpt_added_to_planning_schedule',                array( $this, 'add_organizer_to_central' ), 10 );
    4647        add_action( 'wcpt_added_to_planning_schedule',                array( $this, 'mark_date_added_to_planning_schedule' ), 10 );
     
    5152        add_action( 'admin_notices',                                  array( $this, 'print_admin_notices' ) );
    5253        add_filter( 'redirect_post_location',                         array( $this, 'add_admin_notices_to_redirect_url' ), 10, 2 );
     54    }
     55
     56    // todo phpdoc
     57    public static function get_status_name( $status_slug ) {
     58        // todo call get_custom_statuses and map ?
     59
     60        return '{status name}';
     61    }
     62
     63    //todo phpdoc
     64    public static function get_milestone_from_status( $status_slug ) {
     65        // todo just have an array that maps them together?
     66
     67        return '{milestone name}';
    5368    }
    5469
     
    87102            'high'
    88103        );
     104       
     105        add_meta_box(
     106            'wcpt_notes',
     107            __( 'Add a Note', 'wordcamporg' ),
     108            'wcpt_add_note_metabox',
     109            WCPT_POST_TYPE_ID,
     110            'side',
     111            'low'
     112        );
     113
     114        add_meta_box(
     115            'wcpt_log',
     116            'Log',
     117            'wcpt_log_metabox',
     118            WCPT_POST_TYPE_ID,
     119            'advanced',
     120            'low'
     121        );
    89122    }
    90123
     
    159192            }
    160193        }
    161     }
     194
     195        $this->validate_and_add_note( $post_id );
     196    }
     197
     198    /**
     199     * Validate and add a new note
     200     *
     201     * @param int $post_id
     202     */
     203    protected function validate_and_add_note( $post_id ) {
     204        // todo make sure edit is actionable - done in caller, but test
     205
     206        check_admin_referer( 'wcpt_notes', 'wcpt_notes_nonce' );    // todo test working
     207
     208        $new_note_message = sanitize_text_field( wp_unslash( $_POST['wcpt_new_note'] ) );
     209
     210        if ( empty( $new_note_message ) ) {
     211            return;
     212        }
     213
     214        add_post_meta( $post_id, '_note', array(
     215            'timestamp' => current_time( 'timestamp' ),
     216            'user_id'   => get_current_user_id(),
     217            'message'   => $new_note_message,
     218        ) );
     219    }
     220
    162221
    163222    /**
     
    553612
    554613    /**
     614     * Log when the post status changes
     615     *
     616     * @param string  $new_status
     617     * @param string  $old_status
     618     * @param WP_Post $post
     619     */
     620    public function log_status_changes( $new_status, $old_status, $post ) {
     621        if ( $new_status === $old_status ) {
     622            return;
     623        }
     624
     625        add_post_meta( $post->ID, '_status_change', array(
     626            'timestamp' => current_time( 'timestamp' ),
     627            'user_id'   => get_current_user_id(),
     628            'message'   => sprintf( '%s -> %s', $old_status, $new_status ), /// todo use get_status_name() when it's ready
     629        ) );
     630    }
     631
     632    /**
    555633     * Add the lead organizer to Central when a WordCamp application is accepted.
    556634     *
Note: See TracChangeset for help on using the changeset viewer.