Wordpress Gurus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdultKing
    Raise Your Weapon
    • Jun 2003
    • 15601

    #1

    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
    Confirmed User
    • Nov 2009
    • 1425

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

    With that being said... Good Luck!
    Go Fuck Yourself!

    Comment

    • Brujah
      Beer Money Baron
      • Jan 2001
      • 22157

      #3
      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

      Comment

      • AdultKing
        Raise Your Weapon
        • Jun 2003
        • 15601

        #4
        Originally posted by Brujah
        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

        Comment

        • Brujah
          Beer Money Baron
          • Jan 2001
          • 22157

          #5
          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.

          Comment

          • VenusBlogger
            So Fucking Banned
            • Nov 2011
            • 1540

            #6
            yup, its possible.

            Comment

            • Brujah
              Beer Money Baron
              • Jan 2001
              • 22157

              #7
              Originally posted by VenusBlogger
              yup, its possible.
              The latest forum idiot? Easy enough to ignore.
              http://gfy.com/profile.php?do=addlis...gnore&u=162926

              Comment

              • AdultKing
                Raise Your Weapon
                • Jun 2003
                • 15601

                #8
                Originally posted by Brujah
                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

                Comment

                • just a punk
                  So fuckin' bored
                  • Jun 2003
                  • 32393

                  #9
                  Originally posted by AdultKing
                  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.
                  Obey the Cowgod

                  Comment

                  • Paul Markham
                    Too old to care
                    • Jun 2001
                    • 52942

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



                    Blowout deal. 880 videos, 2,400 image sets, plus many RAW videos. $500.
                    PM me for a deal. Skype Paulmarkham70

                    Comment

                    • AdultKing
                      Raise Your Weapon
                      • Jun 2003
                      • 15601

                      #11
                      Originally posted by CyberSEO
                      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.

                      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.

                      Comment

                      • AllAboutCams
                        Femcams.com
                        • Jul 2011
                        • 12234

                        #12
                        Originally posted by Brujah
                        The latest forum idiot? Easy enough to ignore.
                        http://gfy.com/profile.php?do=addlis...gnore&u=162926
                        Thank you
                        Binance - Blockchain and Crypto Asset Exchange
                        Chaturbate make money in cams

                        Comment

                        • fris
                          Too lazy to set a custom title
                          • Aug 2002
                          • 55679

                          #13
                          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.
                          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                          Comment

                          • AdultKing
                            Raise Your Weapon
                            • Jun 2003
                            • 15601

                            #14
                            Hey, thanks heaps for that fris.

                            Comment

                            • AdultKing
                              Raise Your Weapon
                              • Jun 2003
                              • 15601

                              #15
                              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);
                              
                              
                              ?>

                              Comment

                              • fris
                                Too lazy to set a custom title
                                • Aug 2002
                                • 55679

                                #16
                                glad it worked out ;)
                                Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                                Comment

                                Working...