retesere20

inject-loader-into-wp-config

Feb 25th, 2020
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if ($this->definedTRUE('force_wpconfig_loader_inject') && function_exists('sanitize_text_field') && empty($GLOBALS['goto_my_wpConfig']) && !defined("include_my_custom_wpConfig")){
  2. $filter = function ($path){return str_replace(array('/','\\'),DIRECTORY_SEPARATOR, $path); };
  3.  
  4. //add in wp-config
  5. $str='define("include_my_custom_wpConfig",true); if(file_exists($a=__DIR__."/'.str_replace( $filter(ABSPATH),'', $filter($loader_file)).'")){ include_once($a); }';
  6. $wp_config=ABSPATH.'wp-config.php';
  7. //$new_content= preg_replace('/define\(\'DB_COLLATE(.*?)\);/', '$0'."\r\n\r\n".$str, $this->file_get_contents($wp_config), 1);
  8. $new_content= str_replace('/* That\'s all, stop editing', $str."\r\n\r\n".'/* That\'s all, stop editing', $this->file_get_contents($wp_config));
  9. $this->file_put_contents($wp_config,$new_content);
  10.  
  11. //create file
  12. $loader_file=$filter(dirname(dirname(__DIR__)).'/custom_files/__loader_wp_config.php');
  13. if(!file_exists($loader_file)) {
  14. $this->file_put_contents($loader_file, '<?php
  15. // check if this file is included IN WP-CONFIG
  16. if (defined("include_my_custom_wpConfig")) {
  17. if (!defined("my_wp_cofnig_called")) { define("my_wp_cofnig_called", 1);
  18. define("WP_DEBUG", 0);
  19. define("WP_DEBUG_DISPLAY", 0);
  20. return;
  21. }
  22. }
  23. ?>'
  24. );
  25. }
  26.  
  27. $GLOBALS['goto_my_wpConfig']=1;
  28. }
RAW Paste Data