PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | includes/class-wp-optimize-htaccess.php +37 -2 4.6.1 → 4.7.0 View file →
@@ -131,12 +131,47 @@
131 131 /**
132 132 * Write current $_file_tree content into .htaccess file.
133 133 */
134 134 public function write_file() {
135 - $content = implode(PHP_EOL, $this->get_flat_array($this->_file_tree));
136 135 if ($this->is_writable()) {
137 - @file_put_contents($this->_htaccess_file, $content); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Hosts like WP Engine restricts use of `.htaccess` file
136 + @file_put_contents($this->_htaccess_file, $this->get_content()); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Hosts like WP Engine restricts use of `.htaccess` file
138 137 }
138 + }
139 +
140 + /**
141 + * Get .htaccess content as a string.
142 + *
143 + * @return string
144 + */
145 + public function get_content() {
146 + return implode(PHP_EOL, $this->get_flat_array($this->_file_tree));
147 + }
148 +
149 + /**
150 + * Returns section content as a string
151 + *
152 + * @param string $section
153 + * @return string
154 + */
155 + public function get_section_content($section = 'WP-Optimize Browser Cache') {
156 + $section_index = $this->search_commented_section($section);
157 +
158 + if (false === $section_index) return '';
159 +
160 + $section_length = (false === $section_index['end']) ? null : ($section_index['end'] - $section_index['begin'] + 1);
161 + $section_array = array_slice($this->_file_tree, $section_index['begin'], $section_length);
162 +
163 + return implode(PHP_EOL, $this->get_flat_array($section_array));
164 + }
165 +
166 + /**
167 + * Recursive function that builds a flat array from a tree-structured .htaccess file array.
168 + * Get .htaccess hash
169 + *
170 + * @return string
171 + */
172 + public function get_hash() {
173 + return hash('sha256', serialize($this->_file_tree));
139 174 }
140 175
141 176 /**
142 177 * Recursive function used to prepare data for output - build flat array from $_file_tree.