| Server IP : 159.203.156.69 / Your IP : 216.73.216.37 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/php/green-estate-prod/wp-content/themes/spaciaz/inc/modules/ |
Upload File : |
<?php
if (!defined('ABSPATH')) {
exit;
}
if (!class_exists('Spaciaz_Elementor_Media_Custom_Field')) :
/**
* The main Spaciaz_Elementor_Css_Filters class
*/
class Spaciaz_Elementor_Media_Custom_Field {
public function __construct() {
add_filter('attachment_fields_to_edit', [$this, 'attachment_fields'], 10, 2);
add_action('wp_ajax_save-attachment-compat', [$this, 'ajax_media_fields'], 0, 1);
add_action('edit_attachment', [$this, 'update_attachment_meta'], 1);
}
public function update_attachment_meta($post_id) {
$nonce = $_REQUEST['nonce_attachment_spaciaz_custom_media_link'] ?? false;
// Bail if the nonce check fails.
if (empty($nonce) || !wp_verify_nonce($nonce, 'update_attachment_spaciaz_custom_media_link')) {
return;
}
$spaciaz_custom_media_link = isset($_POST['attachments'][$post_id]['spaciaz_custom_media_link'])
? wp_kses_post($_POST['attachments'][$post_id]['spaciaz_custom_media_link'])
: false;
update_post_meta($post_id, 'spaciaz_custom_media_link', $spaciaz_custom_media_link);
return;
}
public function ajax_media_fields() {
$nonce = $_REQUEST['nonce_attachment_spaciaz_custom_media_link'] ?? false;
// Bail if the nonce check fails.
if (empty($nonce) || !wp_verify_nonce($nonce, 'update_attachment_spaciaz_custom_media_link')) {
return;
}
// Bail if the post ID is empty.
$post_id = intval($_POST['id']);
if (empty($post_id)) {
return;
}
// Update the post.
$meta = $_POST['attachments'][$post_id]['spaciaz_custom_media_link'] ?? '';
$meta = wp_kses_post($meta);
update_post_meta($post_id, 'spaciaz_custom_media_link', $meta);
clean_post_cache($post_id);
}
public function attachment_fields($fields, $post) {
$meta = get_post_meta($post->ID, 'spaciaz_custom_media_link', true);
$fields['spaciaz_custom_media_link'] = [
'label' => esc_html__('Custom Link', 'spaciaz'),
'input' => 'text',
'value' => $meta,
'show_in_edit' => true,
'extra_rows' => [
'nonce' => wp_nonce_field(
'update_attachment_spaciaz_custom_media_link', // Action.
'nonce_attachment_spaciaz_custom_media_link', // Nonce name.
true, // Output referer?
false // Echo?
),
],
];
return $fields;
}
}
endif;
new Spaciaz_Elementor_Media_Custom_Field();