gform_upload_root_htaccess_rules

Description

The gform_upload_root_htaccess_rules allows turning off or modifying rules added to the .htaccess file created for the base upload path. It runs daily during the regeneration of the .htaccess file.

Please consult your system administrator before using this filter.

Usage

The following would apply to all forms.

add_filter('gform_upload_root_htaccess_rules', 'my_filter_function');

Parameters

ParameterTypeDescription
$rulesMixedThe rules of what to parse or not to parse.

Examples

Prevent Gravity Forms from adding default rules to the file.

This will only stop Gravity Forms from adding the default rules to the .htaccess file created, after the removal of the existing .htaccess file is done daily by the cron task gravityforms_cron

add_filter( 'gform_upload_root_htaccess_rules', '__return_false' );

Add new rules to the .htaccess files

The example below would allow you to add new lines to the .htaccess being regenerated by cron task.

add_filter( 'gform_upload_root_htaccess_rules', function( $rules ) {
    $rules[] = 'a new line in the file';
    $rules[] = 'another new line';
    GFCommon::log_debug( __METHOD__ . '(): .htaccess rules => ' . print_r( $rules, true ) );
    return $rules;
} );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in common.php