Making WordPress.org


Ignore:
Timestamp:
11/16/2015 01:16:20 PM (11 years ago)
Author:
kovshenin
Message:

WordCamp.org: Add some basic logging to our payment requests plugin.

File:
1 edited

Legend:

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

    r1939 r2083  
    1111         */
    1212        public function __construct() {
    13                 add_action( 'admin_enqueue_scripts',  array( $this, 'enqueue_assets' ) );
     13                add_action( 'admin_enqueue_scripts',  array( $this, 'enqueue_assets' ), 11 );
    1414        }
    1515
     
    3939                );
    4040
     41                // Let's still include our .css file even if these are unavailable.
     42                $soft_deps = array( 'jquery-ui', 'wp-datepicker-skins' );
     43                foreach ( $soft_deps as $key => $handle )
     44                        if ( ! wp_style_is( $handle, 'registered' ) )
     45                                unset( $soft_deps[ $key ] );
     46
    4147                wp_register_style(
    4248                        'wordcamp-payments',
    4349                        plugins_url( 'css/wordcamp-payments.css', __DIR__ ),
    44                         array( 'jquery-ui', 'wp-datepicker-skins' ),
     50                        $soft_deps,
    4551                        self::VERSION
    4652                );
     
    6874                }
    6975        }
     76
     77        /**
     78         * Log something with a payment request.
     79         *
     80         * @param int $post_id The payment requset ID.
     81         * @param string $message A log message.
     82         * @param array $data Optional data.
     83         */
     84        public static function log( $post_id, $message, $data = array() ) {
     85                global $wpdb;
     86
     87                $entry = array(
     88                        'timestamp' => time(),
     89                        'message' => $message,
     90                        'data' => $data,
     91                );
     92
     93                $log = get_post_meta( $post_id, '_wcp_log', true );
     94                if ( empty( $log ) )
     95                        $log = '[]';
     96
     97                $log = json_decode( $log, true );
     98                $log[] = $entry;
     99                $log = json_encode( $log );
     100
     101                update_post_meta( $post_id, '_wcp_log', wp_slash( $log ) );
     102        }
    70103}
Note: See TracChangeset for help on using the changeset viewer.