Using WordPress ‘incompatible_sql_modes’ PHP filter

The incompatible_sql_modes WordPress PHP Filter allows you to modify the list of incompatible SQL modes that should be excluded.

Usage

add_filter('incompatible_sql_modes', 'my_custom_incompatible_sql_modes');

function my_custom_incompatible_sql_modes($incompatible_modes) {
    // your custom code here
    return $incompatible_modes;
}

Parameters

  • $incompatible_modes (array) – An array of incompatible SQL modes.

More information

See WordPress Developer Resources: incompatible_sql_modes

Examples

Remove a specific SQL mode from the list

Remove the ONLY_FULL_GROUP_BY mode from the list of incompatible modes.

add_filter('incompatible_sql_modes', 'remove_only_full_group_by');

function remove_only_full_group_by($incompatible_modes) {
    $key = array_search('ONLY_FULL_GROUP_BY', $incompatible_modes);
    if ($key !== false) {
        unset($incompatible_modes[$key]);
    }
    return $incompatible_modes;
}

Add a new SQL mode to the list

Add the NO_ZERO_DATE mode to the list of incompatible modes.

add_filter('incompatible_sql_modes', 'add_no_zero_date_mode');

function add_no_zero_date_mode($incompatible_modes) {
    $incompatible_modes[] = 'NO_ZERO_DATE';
    return $incompatible_modes;
}

Clear the list of incompatible SQL modes

Clear the list of incompatible modes entirely, allowing all SQL modes.

add_filter('incompatible_sql_modes', 'clear_incompatible_sql_modes');

function clear_incompatible_sql_modes($incompatible_modes) {
    return array();
}

Replace the entire list of incompatible SQL modes

Replace the list of incompatible modes with a custom list.

add_filter('incompatible_sql_modes', 'replace_incompatible_sql_modes');

function replace_incompatible_sql_modes($incompatible_modes) {
    $custom_modes = array('STRICT_TRANS_TABLES', 'NO_ZERO_IN_DATE');
    return $custom_modes;
}

Conditionally modify the list of incompatible SQL modes

Modify the list of incompatible modes based on a condition, such as the current user’s role.

add_filter('incompatible_sql_modes', 'conditionally_modify_sql_modes');

function conditionally_modify_sql_modes($incompatible_modes) {
    if (current_user_can('manage_options')) {
        $incompatible_modes[] = 'NO_ENGINE_SUBSTITUTION';
    }
    return $incompatible_modes;
}