WC_Admin_Settings::check_download_folder_protection PHP Method

check_download_folder_protection() public static method

If using force or x-sendfile, this ensures the .htaccess is in place.
        public static function check_download_folder_protection()
        {
            $upload_dir = wp_upload_dir();
            $downloads_url = $upload_dir['basedir'] . '/woocommerce_uploads';
            $download_method = get_option('woocommerce_file_download_method');
            if ('redirect' == $download_method) {
                // Redirect method - don't protect
                if (file_exists($downloads_url . '/.htaccess')) {
                    unlink($downloads_url . '/.htaccess');
                }
            } else {
                // Force method - protect, add rules to the htaccess file
                if (!file_exists($downloads_url . '/.htaccess')) {
                    if ($file_handle = @fopen($downloads_url . '/.htaccess', 'w')) {
                        fwrite($file_handle, 'deny from all');
                        fclose($file_handle);
                    }
                }
            }
        }

Usage Example

コード例 #1
0
 /**
  * Save the settings
  */
 public static function save()
 {
     global $current_section, $current_tab;
     if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'wc-crm-settings')) {
         die(__('Action failed. Please refresh the page and retry.', 'woocommerce'));
     }
     // Trigger actions
     do_action('wc_crm_settings_save_' . $current_tab);
     do_action('wc_crm_update_options_' . $current_tab);
     do_action('wc_crm_update_options');
     self::add_message(__('Your settings have been saved.', 'woocommerce'));
     WC_Admin_Settings::check_download_folder_protection();
     // Re-add endpoints and flush rules
     WC()->query->init_query_vars();
     WC()->query->add_endpoints();
     flush_rewrite_rules();
     do_action('wc_crm_settings_saved');
 }