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


Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1