insert_with_markers [ WordPress Function ]
insert_with_markers ( $filename, $marker, $insertion )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: extract_from_markers, wp_insert_term, register_importer, get_importers, get_the_terms
{@internal Missing Short Description}}
Inserts an array of strings into a file (.htaccess ), placing it between BEGIN and END markers. Replaces existing marked info. Retains surrounding data. Creates file if none exists.
Source
<?php
function insert_with_markers( $filename, $marker, $insertion ) {
if (!file_exists( $filename ) || is_writeable( $filename ) ) {
if (!file_exists( $filename ) ) {
$markerdata = '';
} else {
$markerdata = explode( "\n", implode( '', file( $filename ) ) );
}
if ( !$f = @fopen( $filename, 'w' ) )
return false;
$foundit = false;
if ( $markerdata ) {
$state = true;
foreach ( $markerdata as $n => $markerline ) {
if (strpos($markerline, '# BEGIN ' . $marker) !== false)
$state = false;
if ( $state ) {
if ( $n + 1 < count( $markerdata ) )
fwrite( $f, "{$markerline}\n" );
else
fwrite( $f, "{$markerline}" );
}
if (strpos($markerline, '# END ' . $marker) !== false) {
fwrite( $f, "# BEGIN {$marker}\n" );
if ( is_array( $insertion ))
foreach ( $insertion as $insertline )
fwrite( $f, "{$insertline}\n" );
fwrite( $f, "# END {$marker}\n" );
$state = true;
$foundit = true;
}
}
}
if (!$foundit) {
fwrite( $f, "\n# BEGIN {$marker}\n" );
foreach ( $insertion as $insertline )
fwrite( $f, "{$insertline}\n" );
fwrite( $f, "# END {$marker}\n" );
}
fclose( $f );
return true;
} else {
return false;
}
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- #11903 (insert_with_markers is not threadsafe) – WordPress Trac
From wp-admin/includes/misc.php the function insert_with_markers may be called multiple times on a busy server and if the htaccess is already in the process of ...
core.trac.wordpress.org - WordPress › Support » Extract_From_Markers / Insert_With_Markers?
Hi,. I just found these two WP functions within plugins that insert lines into . htaccess or robots.txt and which I find very useful for me: extract_from_markers(); ...
wordpress.org - insert_with_markers | A HitchHackers guide through WordPress
Feb 12, 2011 ... function insert_with_markers( $filename, $marker, $insertion ) {}. Inserts an array of strings into a file (.htaccess ), placing it between BEGIN and ...
hitchhackerguide.com - /wp-admin/includes/misc.php source - PHP Cross Reference ...
Jun 1, 2011 ... 66 */ 67 function insert_with_markers( $filename, $marker, $insertion ) { 68 if (! file_exists( $filename ) || is_writeable( $filename ) ) { 69 if ...
xref.yoast.com