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


Generated: Tue Jan 22 01:02:31 2019 Cross-referenced by PHPXref 0.7.1