Making WordPress.org


Ignore:
Timestamp:
01/12/2016 04:36:29 PM (9 years ago)
Author:
iandunn
Message:

WordCamp Budgets: Move payment-request script enqueing into module.

Since it's not shared across modules, it should live in the Payment Requests module.

File:
1 edited

Legend:

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

    r2274 r2277  
    1212        add_action( 'init',                   array( __CLASS__, 'register_post_statuses' ) );
    1313        add_action( 'add_meta_boxes',         array( $this, 'init_meta_boxes' ) );
     14        add_action( 'admin_enqueue_scripts',  array( $this, 'enqueue_assets' ), 11 );
    1415
    1516        // Miscellaneous
     
    169170        add_meta_box( 'wcp_log', __( 'Log', 'wordcamporg' ), array( $this, 'render_log_metabox' ),
    170171            self::POST_TYPE, 'normal', 'high' );
     172    }
     173
     174    /**
     175     * Enqueue scripts and stylesheets
     176     */
     177    public function enqueue_assets() {
     178        global $post;
     179
     180        // Register our assets
     181        wp_register_script(
     182            'payment-requests',
     183            plugins_url( 'javascript/payment-requests.js', __DIR__ ),
     184            array( 'jquery', 'jquery-ui-datepicker', 'media-upload', 'media-views' ),
     185            WordCamp_Budgets::VERSION,
     186            true
     187        );
     188
     189        wp_register_script(
     190            'wcp-attached-files',
     191            plugins_url( 'javascript/attached-files.js', __DIR__ ),
     192            array( 'payment-requests', 'backbone', 'wp-util' ),
     193            WordCamp_Budgets::VERSION,
     194            true
     195        );
     196
     197        // Enqueue our assets if they're needed on the current screen
     198        $current_screen = get_current_screen();
     199
     200        if ( 'wcp_payment_request' !== $current_screen->id ) {
     201            return;
     202        }
     203
     204        wp_enqueue_script( 'payment-requests' );
     205        wp_enqueue_style(  'wordcamp-budgets' );
     206
     207        if ( isset( $post->ID ) ) {
     208            wp_enqueue_media( array( 'post' => $post->ID ) );
     209            wp_enqueue_script( 'wcp-attached-files' );
     210        }
     211
     212        wp_localize_script(
     213            'payment-requests',
     214            'wcpLocalizedStrings',      // todo merge into paymentRequests var
     215            array(
     216                'uploadModalTitle'  => __( 'Attach Supporting Documentation', 'wordcamporg' ),
     217                'uploadModalButton' => __( 'Attach Files', 'wordcamporg' ),
     218            )
     219        );
    171220    }
    172221
Note: See TracChangeset for help on using the changeset viewer.