HEX
Server: Apache
System: Linux c265a.dattaweb.com 4.18.0-553.97.1.el8_10.x86_64 #1 SMP Mon Jan 26 05:26:16 EST 2026 x86_64
User: c2650654 (20026)
PHP: 8.3.31
Disabled: system, shell, exec, system_exec, shell_exec, mysql_pconnect, passthru, popen, proc_open, proc_close, proc_nice, proc_terminate, proc_get_status, escapeshellarg, escapeshellcmd, eval, dl, imap_mail, libvirt_connect, gnupg_init, unsetenv, apache_setenv, pcntl_exec, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_get_handler, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_getpriority, pcntl_setpriority, pcntl_async_signals, opcache_get_status, opcache_reset, opcache_get_configuration
Upload Files
File: /home/c2650654/public_html/wp-content/plugins/skydropx/includes/skydropx-image-handler.php
<?php
defined('ABSPATH') || exit;
//autoload images

/**
 * Register necessary images into the WordPress Media Library.
 */
function skydropx_register_images()
{
    $image_files = [
        'skydropx-logo.png' => 'skydropx-logo.png',
        'skydropx-success.png' => 'skydropx-success.png',
    ];

    foreach ($image_files as $image_name => $relative_path) {
        // Adjust the path to locate images in the assets/images directory
        $image_path = plugin_dir_path(dirname(__FILE__)) . 'assets/images/' . $relative_path;

        // Check if the image is already registered
        if (file_exists($image_path) && !skydropx_image_already_registered($image_name)) {
            skydropx_upload_image_to_media_library($image_path, $image_name);
        }
    }
}

/**
 * Check if the image is already registered in the Media Library.
 *
 * @param string $image_name The name of the image.
 * @return bool True if registered, false otherwise.
 */
function skydropx_image_already_registered($image_name)
{
    $query = new WP_Query([
        'post_type'      => 'attachment',
        'post_status'    => 'inherit',
        'posts_per_page' => 1, // Only need to know if it exists
        'meta_query'     => [
            [
                'key'   => '_wp_attachment_image_name',
                'value' => $image_name,
                'compare' => '=',
            ],
        ],
        'fields' => 'ids', // Only return IDs, minimal data
    ]);

    return $query->have_posts();
}

/**
 * Upload and register an image in the WordPress Media Library.
 *
 * @param string $file_path The full path to the image file.
 * @param string $file_name The file name.
 */
function skydropx_upload_image_to_media_library($file_path, $file_name)
{
    $file_type = wp_check_filetype($file_name);
    $allowed_mime_types = get_allowed_mime_types();

    if (!in_array($file_type['type'], $allowed_mime_types)) {
        return; // Skip invalid file types
    }

    $upload_dir = wp_upload_dir();
    $upload_file = $upload_dir['path'] . '/' . basename($file_name);

    if (!copy($file_path, $upload_file)) {
        return;
    }

    $attachment = [
        'guid'           => $upload_dir['url'] . '/' . basename($file_name),
        'post_mime_type' => $file_type['type'],
        'post_title'     => sanitize_file_name($file_name),
        'post_content'   => '',
        'post_status'    => 'inherit',
        'meta_input'     => [
            '_wp_attachment_image_name' => $file_name,
        ],
    ];

    $attachment_id = wp_insert_attachment($attachment, $upload_file);

    if (is_wp_error($attachment_id)) {
        return;
    }

    require_once ABSPATH . 'wp-admin/includes/image.php';
    $attach_data = wp_generate_attachment_metadata($attachment_id, $upload_file);

    wp_update_attachment_metadata($attachment_id, $attach_data);
}