| Server IP : 213.186.33.4 / Your IP : 216.73.216.222 Web Server : Apache System : Linux webm005.cluster103.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64 User : karinebmkh ( 644538) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/karinebmkh/www/wp-content/plugins/spotlight-social-photo-feeds/modules/Dev/ |
Upload File : |
<?php
namespace RebelCode\Spotlight\Instagram\Modules\Dev;
use RebelCode\Iris\Store;
/**
* Dev tool that deletes all media from the DB.
*/
class DevDeleteMedia
{
const NONCE_PARAM = 'sli_delete_media';
const NONCE_ACTION = 'sli_delete_media';
const ID_PARAM = 'id';
/** @var callable */
protected $action;
/** @var Store */
protected $store;
/** Constructor */
public function __construct(callable $action, Store $store)
{
$this->action = $action;
$this->store = $store;
}
/**
* @since 0.1
*/
public function __invoke()
{
$deleteNonce = $_GET[static::NONCE_PARAM] ?? $_POST[static::NONCE_PARAM] ?? null;
if (!$deleteNonce) {
return;
}
if (!wp_verify_nonce($deleteNonce, static::NONCE_ACTION)) {
wp_die('You cannot do that!', 'Unauthorized', [
'back_link' => true,
]);
}
$id = filter_input(INPUT_GET, self::ID_PARAM, FILTER_VALIDATE_INT) ? : null;
if (empty($id)) {
// Delete all
$result = ($this->action)();
add_action('admin_notices', function () use ($result) {
if ($result === false) {
echo '<div class="notice notice-error"><p>WordPress failed to delete the media</p></div>';
} else {
printf('<div class="notice notice-success"><p>Deleted %d records from the database</p></div>', $result);
}
});
} else {
// Delete single
$post = get_post($id);
if (!empty($post)) {
$this->store->delete($id);
}
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
$page = $page ? : 1;
wp_redirect(admin_url("admin.php?page=sli-dev&tab=posts&db_page=$page"));
die;
}
}
}