[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> system.php (source)

   1  <?php
   2  
   3  /**
   4   * Makes all key/value pairs in $vars global variables
   5   */
   6  function gp_set_globals( $vars ) {
   7      foreach ( $vars as $name => $value ) {
   8          $GLOBALS[ $name ] = $value;
   9      }
  10  }
  11  
  12  /**
  13   * Initializes rewrite rules and provides the 'gp_init' action.
  14   *
  15   * @since 1.0.0
  16   */
  17  function gp_init() {
  18      gp_rewrite_rules();
  19  
  20      /**
  21       * Fires after GlotPress has finished loading but before any headers are sent.
  22       *
  23       * @since 1.0.0
  24       */
  25      do_action( 'gp_init' );
  26  }
  27  
  28  /**
  29   * Fires during the WP parse_request hook to check to see if we're on a GlotPress page, if so
  30   * we can abort the main WP_Query logic as we won't need it in GlotPress.
  31   * a matching page.
  32   *
  33   * @since 1.0.0
  34   */
  35  function gp_parse_request() {
  36      if ( is_glotpress() ) {
  37          add_filter( 'posts_request', 'gp_abort_main_wp_query', 10, 2 );
  38      }
  39  }
  40  
  41  /**
  42   * Prevents executing WP_Query's default queries on GlotPress requests.
  43   *
  44   * The following code effectively avoid running the main WP_Query queries by setting values before
  45   * they are run.
  46   *
  47   * @link http://wordpress.stackexchange.com/a/145386/40969 Original source.
  48   *
  49   * @since 1.0.0
  50   *
  51   * @param array    $sql  The complete SQL query.
  52   * @param WP_Query $wp_query The WP_Query instance (passed by reference).
  53   * @return string|false False if GlotPress request, SQL query if not.
  54   */
  55  function gp_abort_main_wp_query( $sql, WP_Query $wp_query ) {
  56      if ( $wp_query->is_main_query() ) {
  57          // Prevent SELECT FOUND_ROWS() query.
  58          $wp_query->query_vars['no_found_rows'] = true;
  59  
  60          // Prevent post term and meta cache update queries.
  61          $wp_query->query_vars['cache_results'] = false;
  62  
  63          return false;
  64      }
  65  
  66      return $sql;
  67  }
  68  
  69  /**
  70   * Deletes user's permissions when they are deleted from WordPress
  71   * via WP's 'deleted_user' action.
  72   *
  73   * @since 1.0.0
  74   */
  75  function gp_delete_user_permissions( $user_id ) {
  76      $permissions = GP::$permission->find_many( array( 'user_id' => $user_id ) );
  77  
  78      foreach ( $permissions as $permission ) {
  79          $permission->delete();
  80      }
  81  }


Generated: Thu Dec 26 01:01:15 2024 Cross-referenced by PHPXref 0.7.1