Skip to content

Instantly share code, notes, and snippets.

@ocjojo
Last active April 12, 2021 20:18
Show Gist options
  • Select an option

  • Save ocjojo/2017860e29cffa6b2bf2e24a00260f69 to your computer and use it in GitHub Desktop.

Select an option

Save ocjojo/2017860e29cffa6b2bf2e24a00260f69 to your computer and use it in GitHub Desktop.
Create a file in wordpress backend theme editor
<?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