Algunas configuraciones de Hosting usan una configuración inusual del propietario y los permisos de un sitio de WordPress.
Por ejemplo, tu configuración de Hosting puede usar PHP-FPM que se ejecuta como la cuenta de usuario, por lo que cuando PHP accede al sistema de archivos, crea archivos bajo su propio nombre. WordPress, por otro lado, puede requerir permisos diferentes que llevan a que las imágenes subidas a la galería se almacenen bajo el nombre del servidor web. Por tanto, después de crear un sitio de staging, puedes obtener errores de permisos.
WP Staging crea un sitio de staging con los permisos predeterminados de WordPress de 755 para archivos y 644 para carpetas. El propietario es el usuario del proceso PHP que creó el sitio de staging.
Para solucionarlo, puedes cambiar el propietario y los permisos de un sitio de staging después de crearlo usando esta función y filtro:
<?php
function changePermissionsAndOwner() {
$directory = '/path/to/your/directory';
$permissions = 0755;
$owner = 'username';
$group = 'groupname';
// Check if the path is a directory
if (is_dir($path)) {
// Create a RecursiveDirectoryIterator object
$directoryIterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
// Create a RecursiveIteratorIterator object
$iterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST);
// Iterate through each file and directory in the tree
foreach ($iterator as $item) {
// Change the permissions of the current item
chmod($item, $permissions);
// Change the owner and group of the current item
chown($item, $owner);
chgrp($item, $group);
}
// Change the permissions of the root directory
chmod($path, $permissions);
// Change the owner and group of the root directory
chown($path, $owner);
chgrp($path, $group);
} else {
echo "The path is not a directory.";
}
}
add_action('wpstg.clone_first_run', 'changePermissionsAndOwner', 10);
This will run on the first login to the staging site and change all files to the corresponding permissions.