|
| 1 | +<?php |
| 2 | + |
| 3 | +// If this file is called directly, abort. |
| 4 | +if ( ! defined( 'WPINC' ) ) { |
| 5 | + die; |
| 6 | +} |
| 7 | + |
| 8 | +/** |
| 9 | + * Enqueue BenchPress plugin assets. |
| 10 | + * |
| 11 | + * @since 1.0.0 |
| 12 | + * @return void |
| 13 | + */ |
| 14 | +function benchpress_enqueue_assets( $hook ) { |
| 15 | + // Bail early if we're not on BenchPress pages. |
| 16 | + if ( ! in_array( $hook, [ |
| 17 | + 'toplevel_page_benchpress', |
| 18 | + 'benchpress_page_benchpress-snapshots', |
| 19 | + 'benchpress_page_benchpress-settings' |
| 20 | + ], true ) ) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + wp_enqueue_style( 'benchpress-styles', plugin_dir_url( __FILE__ ) . '../assets/css/style.css', [], BENCHPRESS_VERSION ); |
| 25 | + wp_enqueue_style( 'select2-css', plugin_dir_url( __FILE__ ) . '../assets/css/select2.min.css', [], BENCHPRESS_VERSION ); |
| 26 | + wp_enqueue_script( 'select2-js', plugin_dir_url( __FILE__ ) . '../assets/js/select2.min.js', [ 'jquery' ], BENCHPRESS_VERSION, true ); |
| 27 | + wp_enqueue_script( 'benchpress-admin-js', plugin_dir_url( __FILE__ ) . '../assets/js/benchpress-admin.js', [ 'jquery', 'select2' ], BENCHPRESS_VERSION, true ); |
| 28 | + wp_enqueue_script( 'benchpress-ajax', plugin_dir_url( __FILE__ ) . '../assets/js/benchpress-ajax.js', ['jquery'], BENCHPRESS_VERSION, true ); |
| 29 | + |
| 30 | + wp_localize_script( 'benchpress-ajax', 'benchpress_ajax', [ |
| 31 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 32 | + 'nonce' => wp_create_nonce( 'benchpress_nonce' ), |
| 33 | + 'site_name' => sanitize_title( get_bloginfo( 'name' ) ), |
| 34 | + 'datetime' => date( 'Y-m-d_H-i-s' ), |
| 35 | + ] ); |
| 36 | +} |
| 37 | +add_action( 'admin_enqueue_scripts', 'benchpress_enqueue_assets' ); |
| 38 | + |
| 39 | +/** |
| 40 | + * Enqueue custom admin styles for BenchPress plugin. |
| 41 | + * |
| 42 | + * This function loads the custom CSS file for the BenchPress plugin's |
| 43 | + * admin interface. It adds styling to the BenchPress menu icon in |
| 44 | + * the WordPress® admin sidebar, including hover effects. |
| 45 | + * |
| 46 | + * @since 1.0.0 |
| 47 | + * @return void |
| 48 | + */ |
| 49 | +function benchpress_enqueue_admin_styles() { |
| 50 | + wp_enqueue_style( |
| 51 | + 'benchpress-admin-style', |
| 52 | + plugin_dir_url( __FILE__ ) . '../assets/css/admin-style.css', |
| 53 | + [], |
| 54 | + BENCHPRESS_VERSION |
| 55 | + ); |
| 56 | +} |
| 57 | +add_action( 'admin_enqueue_scripts', 'benchpress_enqueue_admin_styles' ); |
0 commit comments