The ms_deprecated_blogs_file() WordPress PHP function is used to check if a specific file is deprecated in a multisite setup.
Usage
ms_deprecated_blogs_file( $file );
Input:
$file = 'deprecated-file.php';
Output:
True if the file is deprecated, otherwise False.
Parameters
$file
(string) – The name of the file to be checked for deprecation.
More information
See WordPress Developer Resources: ms_deprecated_blogs_file()
Examples
Check if a file is deprecated
This example checks if a file named deprecated-file.php
is deprecated.
$file = 'deprecated-file.php'; $is_deprecated = ms_deprecated_blogs_file($file); if ($is_deprecated) { echo 'This file is deprecated.'; } else { echo 'This file is not deprecated.'; }
Conditionally load a file based on its deprecation status
This example loads a file named old-file.php
only if it is not deprecated. Otherwise, it loads new-file.php
.
$old_file = 'old-file.php'; $new_file = 'new-file.php'; if (!ms_deprecated_blogs_file($old_file)) { require_once($old_file); } else { require_once($new_file); }
Create a list of deprecated files
This example creates an array of deprecated files by checking each file in the list.
$files = array('file1.php', 'file2.php', 'file3.php'); $deprecated_files = array(); foreach ($files as $file) { if (ms_deprecated_blogs_file($file)) { $deprecated_files[] = $file; } } print_r($deprecated_files);
Check and display deprecation status for multiple files
This example checks the deprecation status of multiple files and displays a message for each file.
$files = array('file1.php', 'file2.php', 'file3.php'); foreach ($files as $file) { if (ms_deprecated_blogs_file($file)) { echo "The file $file is deprecated.<br>"; } else { echo "The file $file is not deprecated.<br>"; } }
Delete deprecated files from a folder
This example deletes all deprecated files from a specified folder.
$folder = '/path/to/your/folder/'; $files = scandir($folder); foreach ($files as $file) { if (ms_deprecated_blogs_file($file)) { unlink($folder . $file); echo "Deleted deprecated file: $file.<br>"; } }