require-lib.php 985 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. function jetpack_require_lib( $slug ) {
  3. if ( !preg_match( '|^[a-z0-9/_.-]+$|i', $slug ) ) {
  4. trigger_error( "Cannot load a library with invalid slug $slug.", E_USER_ERROR );
  5. return;
  6. }
  7. $basename = basename( $slug );
  8. if ( defined( 'ABSPATH' ) && ! defined( 'WP_CONTENT_DIR' ) ) {
  9. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down
  10. }
  11. $lib_dir = WP_CONTENT_DIR . '/lib';
  12. /**
  13. * Filter the location of the library directory.
  14. *
  15. * @since 2.5.0
  16. *
  17. * @param string $lib_dir Path to the library directory.
  18. */
  19. $lib_dir = apply_filters( 'jetpack_require_lib_dir', $lib_dir );
  20. $choices = array(
  21. "$lib_dir/$slug.php",
  22. "$lib_dir/$slug/0-load.php",
  23. "$lib_dir/$slug/$basename.php",
  24. );
  25. foreach( $choices as $file_name ) {
  26. if ( is_readable( $file_name ) ) {
  27. require_once $file_name;
  28. return;
  29. }
  30. }
  31. trigger_error( "Cannot find a library with slug $slug.", E_USER_ERROR );
  32. }