NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

php-console-log-scripts.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // If this file is called directly, abort.
  3. if ( !defined( 'WPINC' ) ) {
  4. die;
  5. }
  6. /**
  7. * @func wp_set_script_translations()
  8. *
  9. * Backport wp_set_script_translations() to WP < 5.0.0. Only if another plugin
  10. * or theme has not already backported it.
  11. *
  12. * @since 1.0.0
  13. */
  14. if ( !function_exists( 'wp_set_script_translations' ) ) {
  15. function wp_set_script_translations() {}
  16. }
  17. /**
  18. * @func php_console_log_script()
  19. *
  20. * Load php-console-log.js on all pages. Make php_console_log_array available as
  21. * javascript variable.
  22. *
  23. * @since 1.0.0
  24. *
  25. * @param string/array $php_var_to_console_log PHP string or array to be logged
  26. * to JavaScript console.
  27. */
  28. function php_console_log_script( $php_var_to_console_log ) {
  29. global $php_console_log_array;
  30. // register php-console-log.js
  31. wp_register_script(
  32. 'php-console-log',
  33. PHP_CONSOLE_LOG_PLUGIN_DIR_URL . 'js/php-console-log.js',
  34. ['jquery'],
  35. PHP_CONSOLE_LOG_VERSION
  36. );
  37. /**
  38. * @info Build default message sent to web console if PHP Console Log plugin
  39. * is active but do_action( 'php_console_log', 'My String or Array' ); is not
  40. * called. Built here, in PHP, for i18n backward compatibility with WP < 5.0.0
  41. *
  42. * @since 1.0.0
  43. */
  44. $cl_do_action = "do_action( 'php_console_log', 'My String or Array' );";
  45. $cl_new_line = "\n";
  46. $cl_indent = ' ';
  47. $cl_default_output = esc_html__(
  48. sprintf(
  49. '%3$sPlace the %1$s function anywhere in your WordPress plugin PHP code.%2$s%3$sThe value(s) you pass into %1$s will be logged to the web console in your browser.%2$s%3$sSee "Help" link found on plugins page in your WordPress Admin for more information.%2$s%2$s',
  50. $cl_do_action,
  51. $cl_new_line,
  52. $cl_indent
  53. )
  54. );
  55. // make php_console_log_array available as javascript variable
  56. wp_localize_script( 'php-console-log', 'phpConsoleLogI18n', [
  57. 'phpConsoleLogArray' => $php_console_log_array,
  58. 'File' => esc_html__( 'File', 'php-console-log' ),
  59. 'Line' => esc_html__( 'Line', 'php-console-log' ),
  60. 'Args' => esc_html__( 'Args', 'php-console-log' ),
  61. 'clDefaultOutput' => $cl_default_output,
  62. ] );
  63. // Load php-console-log.js on all pages
  64. wp_enqueue_script( 'php-console-log' );
  65. }
  66. /**
  67. * @info Load php-console-log.js on all pages of site
  68. * @since 1.0.0
  69. */
  70. add_action( 'wp_enqueue_scripts', 'php_console_log_script', 10, 1 );
  71. add_action( 'admin_enqueue_scripts', 'php_console_log_script', 10, 1 );
  72. add_action( 'login_enqueue_scripts', 'php_console_log_script', 10, 1 );