Using WordPress ‘dashboard_php_nag_class()’ PHP function

The dashboard_php_nag_class() WordPress PHP function is used to add an additional class to the PHP nag if the current version is insecure. It returns an array of meta box classes.

Usage

Here’s a simple way to use the dashboard_php_nag_class() function. Assume we have an array of classes named $classes.

$classes = array("class1", "class2", "class3");
$classes = dashboard_php_nag_class($classes);

In this example, the function would add an additional class to the PHP nag in the array $classes if the current version is insecure.

Parameters

  • $classes (string, required) – An array of meta box classes.

More information

See WordPress Developer Resources: dashboard_php_nag_class

Examples

Add an additional class to the PHP nag

This example shows how the dashboard_php_nag_class() function can add an additional class to PHP nag. We will begin with an array of classes and apply the function to it.

$classes = array("class1", "class2", "class3"); // define your array of classes
$classes = dashboard_php_nag_class($classes); // add an additional class to PHP nag if the current version is insecure

Checking if a class has been added

This example checks if an additional class has been added to the PHP nag.

$classes = array("class1", "class2", "class3"); 
$classes = dashboard_php_nag_class($classes); 

if (in_array('insecure', $classes)) { 
  echo "The current PHP version is insecure!";
} 

Adding a new class to the array

In this example, we will add a new class to the array and check if the function adds the ‘insecure’ class.

$classes = array("class1", "class2", "class3", "newClass"); 
$classes = dashboard_php_nag_class($classes); 

if (in_array('insecure', $classes)) { 
  echo "The current PHP version is insecure!";
} 

Checking the length of the array

This example checks the length of the array after applying the function.

$classes = array("class1", "class2", "class3"); 
$classes = dashboard_php_nag_class($classes); 

echo count($classes); 

Outputting all classes

This example outputs all classes in the array after applying the function.

$classes = array("class1", "class2", "class3"); 
$classes = dashboard_php_nag_class($classes); 

foreach($classes as $class) {
  echo $class . "\n";
}