Last active
April 12, 2021 20:18
-
-
Save ocjojo/2017860e29cffa6b2bf2e24a00260f69 to your computer and use it in GitHub Desktop.
Create a file in wordpress backend theme editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Create a file in WordPress from /wp-admin/theme-editor.php | |
| * If you only have access to the wordpess backend and no FTP. | |
| * | |
| * Visit any page in wordpress and use the query parameter ?fileguard=1 | |
| */ | |
| add_action('after_setup_theme', function() { | |
| /** Provide the file path */ | |
| $file = get_stylesheet_directory() . '/test.php'; | |
| if(!file_exists($file) && $_GET['fileguard'] ?? false) { | |
| error_reporting(E_ALL); | |
| ini_set("display_errors", 1); | |
| echo "Creating file: $file<br>"; | |
| mkdir(dirname($file), 0755, true /*recursive*/); | |
| echo "<br>"; | |
| echo file_put_contents($file, 'Hello world') ? "File created" : "Error creating file"; | |
| die(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment