Making WordPress.org


Ignore:
Timestamp:
02/22/2018 07:43:32 PM (7 years ago)
Author:
coreymckrill
Message:

WordCamp Payments: Add default title for all payment posts

Having a default title on the new post screen prevents the post from being
saved as auto-draft, which causes problems if attachments have been added
to the post.

Fixes #2851
Props hlashbrooke, miss_jwo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/wordcamp-budgets.php

    r6110 r6717  
    1212     */
    1313    public function __construct() {
    14         add_action( 'init', array( __CLASS__, 'register_post_statuses' ) );
    15         add_action( 'admin_menu',             array( $this, 'register_budgets_menu' )     );
    16         add_action( 'admin_enqueue_scripts',  array( $this, 'enqueue_common_assets' ), 11 );
     14        add_action( 'init',                   array( __CLASS__, 'register_post_statuses' )              );
     15        add_action( 'admin_menu',             array( $this, 'register_budgets_menu' )                    );
     16        add_action( 'admin_enqueue_scripts',  array( $this, 'enqueue_common_assets' ),             11    );
    1717        add_filter( 'user_has_cap',           array( __CLASS__, 'user_can_view_payment_details' ), 10, 4 );
     18        add_filter( 'default_title',          array( $this, 'set_default_payments_title'),         10, 2 );
    1819    }
    1920
     
    119120            30
    120121        );
     122    }
     123
     124    /**
     125     * Set default post title for reimbursements, vendor payments and sponsor invoices.
     126     *
     127     * @param  string  $post_title Default post title.
     128     * @param  WP_Post $post       Current post object.
     129     *
     130     * @return string $post_title Post title.
     131     */
     132    public function set_default_payments_title ( $post_title, $post ) {
     133        if ( $post instanceof WP_Post && ! empty( $post->post_type ) ) {
     134            $new_title = '';
     135
     136            // Generate default title for payment CPTs.
     137            switch ( $post->post_type ) {
     138                case 'wcb_reimbursement':   $new_title = __( 'Reimbursement Request', 'wordcamporg' ); break;
     139                case 'wcp_payment_request': $new_title = __( 'Vendor Payment', 'wordcamporg' );        break;
     140                case 'wcb_sponsor_invoice': $new_title = __( 'Sponsor Invoice', 'wordcamporg' );       break;
     141            }
     142
     143            // Prepend title with post ID to make it unique.
     144            if ( $new_title ) {
     145               $post_title = sprintf( __( '[%s] Untitled %s', 'wordcamporg' ), $post->ID, $new_title );
     146            }
     147        }
     148
     149        return $post_title;
    121150    }
    122151
Note: See TracChangeset for help on using the changeset viewer.