Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created October 15, 2020 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/39a8978f5cebbee719cef116a3d84003 to your computer and use it in GitHub Desktop.
Save pbrocks/39a8978f5cebbee719cef116a3d84003 to your computer and use it in GitHub Desktop.
Use this file to run php that also has access to WordPress functions by placing this file in a folder at the root of any WordPress installation.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Include WP</title>
<style type="text/css">
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
background: mintcream;
}
section {
margin: auto;
position: absolute;
top: 10%;
width: 60%;
left: 20%;
margin-bottom: 10%;
}
.grid-wrapper {
display: grid;
grid-template-columns: repeat(2, 1fr);
justify-content: center;
align-content: center;
}
grid {
border: 1px solid #444;
color: #444;
border-radius: 5px;
padding: 1rem;
font-size: 125%;
}
input {
background: white;
}
.item1 {
grid-column: 1 / -1;
background: white;
}
.item4 {
grid-column: 1 / -1;
border: none;
}
h1, .centered {
text-align: center;
}
h3 {
color: maroon;
}
h5 span {
color: #800000b8;
}
h5 {
color: gray;
}
pre {
white-space: pre-wrap;
}
pre > div {
margin-left: 1rem;
}
pre > span {
font-weight: 700;
}
button {
padding: 1rem;
font-size: 1.2rem;
background: aliceblue;
}
button:hover {
cursor: pointer;
}
</style>
</head>
<body>
<section>
<?php
$filename = '../wp-load.php';
if ( file_exists( $filename ) ) {
include $filename;
}
?>
<h1>Include WP</h1>
<div class="grid-wrapper">
<grid class="item1 centered">
<?php
if ( file_exists( $filename ) ) {
echo '<h2>This file loads WordPress</h2>';
echo '<h3>' . basename( __FILE__ ) . '</h3>';
}
?>
</grid>
<grid class="item4"></grid>
<grid class="item2">
<?php
if ( file_exists( $filename ) ) {
echo '<h4>whose path is</h4>';
echo '<h3>' . __DIR__ . '</h3>';
echo '<h5>this folder, <span>' . __DIR__ . '</span>,<br> is a sister to the wp-* folders</h5>';
}
?>
</grid>
<grid class="item3">
<?php
if ( file_exists( $filename ) ) {
echo '<h4>By including this file</h4>';
echo '<h3>' . $filename . '</h3>';
}
?>
</grid>
<grid class="item4"></grid>
<grid class="item1">
WordPress is loaded
<pre>
$filename = '../wp-load.php';
if ( file_exists( $filename ) ) {
include $filename;
}
</pre>
by placing this code at the top of your php file.
</grid>
<grid class="item4"></grid>
</div>
</section>
<script type="text/javascript">
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment