File: /home/turkishi/public_html/wp-content/mu-plugins/easypost-runtime.php
<?php
if (!defined('ABSPATH')) {
exit;
}
if (!defined('EASYPOST_HOMEPAGE_RUNTIME_VERSION')) {
define('EASYPOST_HOMEPAGE_RUNTIME_VERSION', '2026.06.10');
}
function easypost_runtime_placements_option() {
return 'easypost_homepage_placements';
}
function easypost_runtime_is_homepage() {
return function_exists('is_front_page') && is_front_page();
}
function easypost_runtime_get_placements() {
if (!function_exists('get_option')) {
return array();
}
$placements = get_option(easypost_runtime_placements_option(), array());
return is_array($placements) ? $placements : array();
}
function easypost_runtime_missing_html($buffer = '') {
$placements = easypost_runtime_get_placements();
if (empty($placements)) {
return '';
}
$html = array();
foreach ($placements as $placement) {
if (!is_array($placement) || empty($placement['html'])) {
continue;
}
$placement_id = isset($placement['placementId']) ? (int) $placement['placementId'] : 0;
$marker = 'data-placement="' . $placement_id . '"';
if ($placement_id > 0 && $buffer !== '' && strpos($buffer, $marker) !== false) {
continue;
}
$html[] = (string) $placement['html'];
}
return implode("\n", $html);
}
function easypost_runtime_echo() {
if (!easypost_runtime_is_homepage()) {
return;
}
$html = easypost_runtime_missing_html('');
if ($html !== '') {
echo "\n" . $html . "\n";
}
}
function easypost_runtime_buffer_start() {
if (!easypost_runtime_is_homepage() || empty(easypost_runtime_get_placements())) {
return;
}
ob_start('easypost_runtime_inject_buffer');
}
function easypost_runtime_inject_buffer($buffer) {
$html = easypost_runtime_missing_html($buffer);
if ($html === '') {
return $buffer;
}
if (stripos($buffer, '</body>') !== false) {
return preg_replace('/<\/body>/i', "\n" . $html . "\n</body>", $buffer, 1);
}
return $buffer . "\n" . $html;
}
add_action('template_redirect', 'easypost_runtime_buffer_start', 0);
add_action('wp_footer', 'easypost_runtime_echo', PHP_INT_MAX);