admin管理员组文章数量:1122832
The users of my site mainly share documents by inserting links into content (pages/posts) using the built in editor. These files include everything from pdfs to word documents. The users currently get/copy these links from a php file manager like FileRun. My goal is to have the users instead use a path from mapped network drive such as \testdrive\Folder1\Folder2\test.txt. The following function has been written to handle replacing the mapped network drive files to an internet link such as "/".
<?php
function test_test_url_parse($string)
{
// Called by test_test_url_parse_wrapper()
// The nature of preg_replace means this needs a seperate function
$bits=explode("\\",$string);
$bobs=array();
foreach ($bits as $bit)
{
$bobs[]=urlencode($bit);
}
return "\"/".implode("/",$bobs)."\"";
}
function test_test_url_parse_wrapper($string)
{
//Finds/replaces UCNs with URLs in the provided string.
$pattern1="~\"[a-z]{1}:\\\([^\"]+)\"~ie";
return preg_replace($pattern1, "test_test_url_parse('$1')", $string);
}
?>
Where could I put a function like this to automatically look through the content of a page or a post and replace the filepath accordingly? Would there theoretically be any way to put this just in the child theme? Currently when I upload media such as photos, it is already putting the files into the path "/". I'm really looking for have function go through the post/page content and perform essentially a constant "search and replace"
The users of my site mainly share documents by inserting links into content (pages/posts) using the built in editor. These files include everything from pdfs to word documents. The users currently get/copy these links from a php file manager like FileRun. My goal is to have the users instead use a path from mapped network drive such as \testdrive\Folder1\Folder2\test.txt. The following function has been written to handle replacing the mapped network drive files to an internet link such as "http://page.test.org/files/".
<?php
function test_test_url_parse($string)
{
// Called by test_test_url_parse_wrapper()
// The nature of preg_replace means this needs a seperate function
$bits=explode("\\",$string);
$bobs=array();
foreach ($bits as $bit)
{
$bobs[]=urlencode($bit);
}
return "\"http://page.test.org/files/".implode("/",$bobs)."\"";
}
function test_test_url_parse_wrapper($string)
{
//Finds/replaces UCNs with URLs in the provided string.
$pattern1="~\"[a-z]{1}:\\\([^\"]+)\"~ie";
return preg_replace($pattern1, "test_test_url_parse('$1')", $string);
}
?>
Where could I put a function like this to automatically look through the content of a page or a post and replace the filepath accordingly? Would there theoretically be any way to put this just in the child theme? Currently when I upload media such as photos, it is already putting the files into the path "http://page.test.org/files/". I'm really looking for have function go through the post/page content and perform essentially a constant "search and replace"
Share Improve this question edited Mar 27, 2013 at 23:29 s_ha_dum 65.5k13 gold badges84 silver badges174 bronze badges asked Mar 26, 2013 at 21:33 UkrVolk11UkrVolk11 11 silver badge1 bronze badge2 Answers
Reset to default 0There is somewhat similar answer in the below mentioned link:
Removing any and all inline styles from the_content()
where some inline style are being removed with the help of preg_replace and wordpress hooks (wp_insert_post_data & the_content).
Similarly any part of the content can be modified with the as the same done in this (Removing any and all inline styles from the_content()) case.
I know this is an old question, but it was bumped to the homepage (for some reason).
I wouldn't do it constantly, since this would check all the page every time a page is loaded, which would be a lot of redundant operations, when users are simply browsing around.
I would do it on the save_post-hook.
As such:
function custom_check_URL( $post_ID, $post, $update ) {
if ( 'publish' === $post->post_status || 'page' === $post->post_type) {
// CHECK AND MODIFY YOUR URL'S HERE.
}
}
add_action( 'save_post', 'custom_check_URL', 10, 3 );
I'm not 100% certain what you were checking for or replacing it with, so I didn't include it in this answer.
本文标签: Automatically search and replace link in content (pagesposts)
版权声明:本文标题:Automatically search and replace link in content (pagesposts)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736290670a1928562.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论