[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> assets-loader.php (source)

   1  <?php
   2  /**
   3   * Defines default styles and scripts.
   4   *
   5   * @package GlotPress
   6   * @since 1.0.0
   7   */
   8  
   9  /**
  10   * Registers the GlotPress styles and loads the base style sheet.
  11   */
  12  function gp_register_default_styles() {
  13      $url = gp_plugin_url( 'assets/css' );
  14  
  15      $suffix = SCRIPT_DEBUG ? '.css' : '.min.css';
  16  
  17      // Register our base style.
  18      wp_register_style( 'gp-base', $url . '/style' . $suffix, array(), '20200501' );
  19  
  20      // Register the table sorter theme style.
  21      wp_register_style( 'tablesorter-theme', $url . '/tablesorter.theme.glotpress' . $suffix, array(), '20161011' );
  22  }
  23  
  24  add_action( 'init', 'gp_register_default_styles' );
  25  
  26  /**
  27   * Register the GlotPress scripts.
  28   */
  29  function gp_register_default_scripts() {
  30      $url = gp_plugin_url( 'assets/js' );
  31  
  32      $suffix = SCRIPT_DEBUG ? '.js' : '.min.js';
  33  
  34      // Register our standard scripts.
  35      wp_register_script( 'tablesorter', $url . '/vendor/jquery.tablesorter' . $suffix, array( 'jquery' ), '2.31.3' );
  36      wp_register_script( 'gp-common', $url . '/common' . $suffix, array( 'jquery' ), '20150430' );
  37      wp_add_inline_script(
  38          'gp-common',
  39          sprintf(
  40              '$gp.l10n = %s',
  41              wp_json_encode(
  42                  array(
  43                      'dismiss' => __( 'Dismiss', 'glotpress' ),
  44                  )
  45              )
  46          )
  47      );
  48  
  49      wp_register_script( 'gp-editor', $url . '/editor' . $suffix, array( 'gp-common', 'jquery-ui-tooltip' ), '20200424' );
  50      wp_register_script( 'gp-glossary', $url . '/glossary' . $suffix, array( 'gp-editor' ), '20160329' );
  51      wp_register_script( 'gp-translations-page', $url . '/translations-page' . $suffix, array( 'gp-editor' ), '20200424' );
  52      wp_register_script( 'gp-mass-create-sets-page', $url . '/mass-create-sets-page' . $suffix, array( 'gp-editor' ), '20150430' );
  53  }
  54  
  55  add_action( 'init', 'gp_register_default_scripts' );
  56  
  57  /**
  58   * Enqueue one or more styles.
  59   *
  60   * @since 2.2.0
  61   *
  62   * @param string|array $handles A single style handle to enqueue or an array or style handles to enqueue.
  63   */
  64  function gp_enqueue_styles( $handles ) {
  65      // Make sure $handles is an array to simplify the next loop.
  66      $handles = (array) $handles;
  67  
  68      // Loop through each handle we've been asked to enqueue.
  69      foreach ( $handles as $handle ) {
  70          gp_enqueue_style( $handle );
  71      }
  72  }
  73  
  74  /**
  75   * Enqueue one or more styles.
  76   *
  77   * @since 1.0.0
  78   *
  79   * @param string $handle A single style handle to enqueue.
  80   */
  81  function gp_enqueue_style( $handle ) {
  82      if ( ! in_array( $handle, GP::$styles, true ) ) {
  83          // Store the handle name in the global array.
  84          GP::$styles[] = $handle;
  85  
  86          // Actually enqueue the handle via WordPress.
  87          wp_enqueue_style( $handle );
  88      }
  89  }
  90  
  91  /**
  92   * Enqueue one or more scripts.
  93   *
  94   * @since 2.2.0
  95   *
  96   * @param string|array $handles A single script handle to enqueue or an array of enqueue handles to enqueue.
  97   */
  98  function gp_enqueue_scripts( $handles ) {
  99      // Make sure $handles is an array to simplify the next loop.
 100      $handles = (array) $handles;
 101  
 102      // Loop through each handle we've been asked to enqueue.
 103      foreach ( $handles as $handle ) {
 104          gp_enqueue_script( $handle );
 105      }
 106  }
 107  
 108  /**
 109   * Enqueue one or more scripts.
 110   *
 111   * @since 1.0.0
 112   *
 113   * @param string $handle A single script handle to enqueue.
 114   */
 115  function gp_enqueue_script( $handle ) {
 116      if ( ! in_array( $handle, GP::$scripts, true ) ) {
 117          // Store the handle name in the global array.
 118          GP::$scripts[] = $handle;
 119  
 120          // Actually enqueue the handle via WordPress.
 121          wp_enqueue_script( $handle );
 122      }
 123  }
 124  
 125  /**
 126   * Print the styles that have been enqueued.
 127   *
 128   * Only output the styles that GlotPress has registered, otherwise we'd be sending any style that the WordPress theme or plugins may have enqueued.
 129   *
 130   * @since 2.2.0
 131   */
 132  function gp_print_styles() {
 133      wp_print_styles( GP::$styles );
 134  }
 135  
 136  /**
 137   * Print the scripts that have been enqueued.
 138   *
 139   * Only output the scripts that GlotPress has registered, otherwise we'd be sending any scripts that the WordPress theme or plugins may have enqueued.
 140   *
 141   * @since 2.2.0
 142   */
 143  function gp_print_scripts() {
 144      wp_print_scripts( GP::$scripts );
 145  }


Generated: Mon Sep 21 01:01:49 2020 Cross-referenced by PHPXref 0.7.1