GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Wordpress Gurus (https://gfy.com/showthread.php?t=1066502)

AdultKing 04-29-2012 10:35 PM

Wordpress Gurus
 
Is it possible for a plugin to capture the text of a post someone has just entered in their posts area then perform an operation on that text before it gets placed into the database ?

Examples, taking the text and adding or removing elements, taking the text and adding or removing particular words or phrases ?

brentbacardi 04-29-2012 10:43 PM

Pretty much anything on the web is possible if you have programming skills and unlimited time.

With that being said... Good Luck! :thumbsup

Brujah 04-29-2012 10:47 PM

Sure, you can hook into the save_post action.
http://codex.wordpress.org/Plugin_AP...ence/save_post

For a list of tons of other hooks:
http://codex.wordpress.org/Plugin_API/Action_Reference

AdultKing 04-29-2012 10:49 PM

Quote:

Originally Posted by Brujah (Post 18916139)
Sure, you can hook into the save_post action.
http://codex.wordpress.org/Plugin_AP...ence/save_post

For a list of tons of other hooks:
http://codex.wordpress.org/Plugin_API/Action_Reference

Heh, I just glanced across the areas I could hook into, obviously I should have been more thorough. Thanks Brujah :thumbsup

Brujah 04-29-2012 10:54 PM

Hmm, content_save_pre might be closer to what you need according to this:
http://wordpress.stackexchange.com/q...-prior-to-save

WordPress StackExchange has filled out really well with a lot of great information about customizing WP.

VenusBlogger 04-29-2012 10:59 PM

yup, its possible.

Brujah 04-29-2012 11:03 PM

Quote:

Originally Posted by VenusBlogger (Post 18916152)
yup, its possible.

The latest forum idiot? Easy enough to ignore.
https://gfy.com/profile.php?do=addlis...gnore&u=162926

AdultKing 04-29-2012 11:54 PM

Quote:

Originally Posted by Brujah (Post 18916149)
Hmm, content_save_pre might be closer to what you need according to this:
http://wordpress.stackexchange.com/q...-prior-to-save

WordPress StackExchange has filled out really well with a lot of great information about customizing WP.

Thanks for this, you're spot on. I had only just come to that conclusion myself after reading the replies to this:

http://wordpress.stackexchange.com/q...re-it-is-saved

I'm well on the way now. I hardly ever write any plugins myself but I just needed to whip something up for testing an idea real quick

thanks for the responses

just a punk 04-30-2012 01:37 AM

Quote:

Originally Posted by AdultKing (Post 18916125)
Is it possible for a plugin to capture the text of a post someone has just entered in their posts area then perform an operation on that text before it gets placed into the database ?

Examples, taking the text and adding or removing elements, taking the text and adding or removing particular words or phrases ?

Easily. I just made some custom plugin which attaches a featured image to every new post basing on the keywords in its title.

Paul Markham 04-30-2012 01:45 AM

Now you can add this info to your blog to teach newbies. LOL

AdultKing 04-30-2012 02:03 AM

Quote:

Originally Posted by CyberSEO (Post 18916291)
Easily. I just made some custom plugin which attaches a featured image to every new post basing on the keywords in its title.

Yep, took me 2 minutes once I found the right hook.

Quote:

Originally Posted by Paul Markham
Now you can add this info to your blog to teach newbies. LOL

Pity you didn't learn enough to fund your own retirement, instead leaching off the British taxpayers who did. :2 cents:

AllAboutCams 04-30-2012 02:27 AM

Quote:

Originally Posted by Brujah (Post 18916157)
The latest forum idiot? Easy enough to ignore.
https://gfy.com/profile.php?do=addlis...gnore&u=162926

Thank you

fris 04-30-2012 05:52 AM

you want wp_insert_post_data

i did this, so when you publish a post it took you back a year ;)

Code:

function back_to_the_future($data,$postarr) {
            $format = 'Y-m-d H:i:s';
        $old_date = $data['post_date'];
        $old_date_gmt = $data['post_date_gmt'];
            $new_date = date($format, strtotime('-1 year',strtotime($old_date)));
            $new_date_gmt = date( $format, strtotime('-1 year',strtotime($old_date_gmt)));
        $data['post_date'] = $new_date;
        $data['post_date_gmt'] = $new_date_gmt;
            return $data;
}

add_filter('wp_insert_post_data','back_to_the_future',99,2);

in your case you would want to use post_content

like so

Code:

function change_post_content($data,$postarr) {
        $post_content = strip_tags($data['post_content']);
        $data['post_post_content'] = $post_content;
            return $data;
}

add_filter('wp_insert_post_data','change_post_content',99,2);

which would strip html tags from post content, etc.

this will get you started.

AdultKing 04-30-2012 06:12 AM

Hey, thanks heaps for that fris.

AdultKing 04-30-2012 06:28 AM

Just for anyone else who is interested in the solution here, based on fris' excellent example this is changing the post content, you could replace ucwords with any function or series of functions to modify your post content.

Code:

<?php
/*
Plugin Name: Your own Plugin
Plugin URI: http://someurl.com
Description: Converts the fist letter of every word to upper case.
Author: Your Name
Version: 1.5
*/

function change_content($data,$postarr) {
            $old_content = $data['post_content'];
            $new_content = ucwords($old_content);
            $data['post_content'] = $new_content;
            return $data;
}

add_filter('wp_insert_post_data','change_content',99,2);


?>


fris 04-30-2012 07:50 AM

glad it worked out ;)


All times are GMT -7. The time now is 12:27 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123