Plugin Directory

Changeset 874707


Ignore:
Timestamp:
03/13/2014 12:35:06 PM (12 years ago)
Author:
ibabar
Message:

Releasing version 2.0

Location:
guest-posts
Files:
1 added
2 edited
5 copied
1 moved

Legend:

Unmodified
Added
Removed
  • guest-posts/trunk/guest-posts.php

    r716800 r874707  
    11<?php
    2 /*
    3 Plugin Name: Guest Posts
    4 Plugin URI:
    5 Description: Give an opportunity to your unregistered readers to post on your Blog.
    6 Version: 1.1.1
    7 Author: ericgrld
    8 Author URI:
    9 Requires at least: 3.0
    10 Tested Up to: 3.5
    11 Stable Tag: 1.1.1
    12 License: GPL v2
    13 */
    14 
    15 
    16 
    17 function guestposts_shortcode( $atts ) {
    18     extract ( shortcode_atts (array(
    19         'cat' => '1',
    20         'author' => '1',
    21         'thanks' => get_bloginfo('home'),
    22     ), $atts ) );
    23 
    24     return '<form class="guests-post" action="'. plugin_dir_url("guest-posts.php") .'guest-posts/guest-posts-submit.php" method="post">
    25         <strong>' . __('Post Title:', 'guest-posts') . '</strong><br>
    26             <input type="text" name="title" size="60" required="required" placeholder="' . __('Post title here', 'guest-posts') . '"><br>
    27         <strong>' . __('Story', 'guest-posts') . '</strong>
    28         '. wp_nonce_field() .'
    29             <textarea rows="15" cols="72" required="required" name="story" placeholder="' . __('Start writing your post here', 'guest-posts') . '"></textarea><br>
    30         <strong>' . __('Tags', 'guest-posts') . '</strong><br>
    31             <input type="text" name="tags" size="60" placeholder="' . __('Comma Separated Tags', 'guest-posts') . '"><br><br>
    32         <strong>' . __('Your Name', 'guest-posts') . '</strong><br>
    33             <input type="text" name="author" size="60" required="required" placeholder="' . __('Your name here', 'guest-posts') . '"><br>
    34         <strong>' . __('Your Email', 'guest-posts') . '</strong><br>
    35             <input type="email" name="email" size="60" required="required" placeholder="' . __('Your Email Here', 'guest-posts') . '"><br>
    36         <strong>' . __('Your Website', 'guest-posts') . '</strong><br>
    37             <input type="text" name="site" size="60" placeholder="' . __('Your Website Here', 'guest-posts') . '"><br><br><br>
    38         <input type="hidden" value="'. $cat .'" name="category"><input type="hidden" value="'. $author .'" name="authorid">
    39         <input type="hidden" value="'. $thanks .'" name="thanks">
    40         <input type="hidden" value="'. str_replace('/wp-content/themes', '', get_theme_root()) .'/wp-blog-header.php" name="rootpath">
    41         <input type="submit" value="' . __('Submit The Post', 'guest-posts') . '"> <input type="reset" value="' . __('Reset', 'guest-posts') . '"><br>
     2/**
     3 * Plugin Name: Guest Posts
     4 * Plugin URI: http://www.ibabar.com/blog/guest-posts
     5 * Description: Give an opportunity to your unregistered readers to post on your Blog.
     6 * Version: 2.0
     7 * Author: ibabar
     8 * Author URI: http://www.ibabar.com
     9 * Requires at least: 3.0
     10 * Tested Up to: 3.8.1
     11 * Stable Tag: 2.0
     12 * License: GPL v2
     13 * Shortname: gp or gp_
     14 */
     15
     16
     17$guest_posts = new Guest_Posts();
     18class Guest_Posts{
     19
     20    private $category;
     21    private $author;
     22    public $thanks_page;
     23
     24    function __construct(){
     25        add_shortcode('guest-posts', array($this, 'gp_guestposts_shortcode'));
     26        add_action('wp_ajax_gp_submit_and_save_guests_post', array($this, 'gp_submit_and_save_guests_post_ajax_callback'));
     27        add_action('wp_ajax_nopriv_gp_submit_and_save_guests_post', array($this, 'gp_submit_and_save_guests_post_ajax_callback'));
     28        add_action('admin_menu', array($this, 'gp_register_option_page'));
     29        add_action('admin_init', array($this, 'gp_settings_page_content'));
     30    }
     31
     32    function gp_guestposts_shortcode( $atts ) {
     33        extract ( shortcode_atts (array(
     34            'cat' => '',
     35            'author' => '',
     36            'thanks' => '',
     37        ), $atts ) );
     38        $this->category = $cat;
     39        $this->author = $author;
     40        $this->thanks_page = $thanks;
     41
     42        ?>
     43        <form class="guests-post" id="guests-post" onsubmit="return false" method="post">
     44            <div class="info" style="display: none"></div>
     45            <strong><?php echo __('Post Title:', 'guest-posts') ?></strong><br>
     46            <input type="text" name="title" size="60" required="required" placeholder="<?php echo __('Post title here', 'guest-posts') ?>"><br>
     47            <strong><?php echo __('Story', 'guest-posts') ?></strong>
     48            <?php wp_nonce_field('gp_submit_and_save_guests_post', 'gp_submit_and_save_guests_post_unique_key') ?>
     49            <textarea rows="15" cols="72" required="required" name="story" placeholder="<?php echo __('Start writing your post here', 'guest-posts') ?>"></textarea><br>
     50            <strong><?php echo __('Tags', 'guest-posts') ?></strong><br>
     51            <input type="text" name="tags" size="60" placeholder="<?php echo __('Comma Separated Tags', 'guest-posts') ?>"><br><br>
     52            <strong><?php echo __('Your Name', 'guest-posts') ?></strong><br>
     53            <input type="text" name="author" size="60" required="required" placeholder="<?php echo __('Your name here', 'guest-posts') ?>"><br>
     54            <strong><?php echo __('Your Email', 'guest-posts') ?></strong><br>
     55            <input type="email" name="email" size="60" required="required" placeholder="<?php echo __('Your Email Here', 'guest-posts') ?>"><br>
     56            <strong><?php echo __('Your Website', 'guest-posts') ?></strong><br>
     57            <input type="text" name="site" size="60" placeholder="<?php echo __('Your Website Here', 'guest-posts') ?>"><br><br><br>
     58            <input type="hidden" value="<?php echo $this->category; ?>" name="category">
     59            <input type="hidden" value="<?php echo $this->author; ?>" name="authorid">
     60            <input type="hidden" value="<?php echo $this->thanks_page; ?>" name="thanks">
     61            <input type="submit" value="<?php echo __('Submit The Post', 'guest-posts') ?>"> <input type="reset" value="<?php echo __('Reset', 'guest-posts') ?>">
     62            <br>
    4263        </form>
    43         ';
    44     }
    45 add_shortcode( 'guest-posts', 'guestposts_shortcode' );
    46 
    47 ?>
     64        <script type="text/javascript">
     65            jQuery(document).ready(function($){
     66                jQuery('#guests-post').on('submit', function(event){
     67                    event.preventDefault();
     68                    jQuery.post(
     69                        '<?php echo admin_url("admin-ajax.php"); ?>',
     70                        jQuery('#guests-post').serialize() + '&action=gp_submit_and_save_guests_post',
     71                        function(response){
     72                            console.log(response);
     73                            if(response.dead){
     74                                jQuery('#guests-post').hide().children('.info').text(response.dead).show(1500);
     75                                return;
     76                            }
     77                            console.log('Passed Dead');
     78                            jQuery('#guests-post').hide().children('.info').text(response.success).show(1500);
     79                            if(response.redirect_to){
     80                                setInterval(function(){
     81                                    window.location.href = response.redirect_to;
     82                                }, 1500);
     83                            }
     84                        }, 'json'
     85                    );
     86                });
     87            });
     88        </script>
     89        <?php
     90        return '';
     91    }
     92
     93
     94    function gp_submit_and_save_guests_post_ajax_callback(){
     95        header('Content-Type: application/json');
     96        $title = $_POST["title"];
     97        $story = $_POST["story"];
     98        $tags = $_POST["tags"];
     99        $author = $_POST["author"];
     100        $email = $_POST["email"];
     101        $site = $_POST["site"];
     102
     103        if(empty($_POST["authorid"])) $authorid = get_option('gp_author_id'); else $authorid = $_POST["authorid"];
     104        if(!$authorid) $authorid = 1;
     105
     106        if(empty($_POST["category"])) $category = get_option('gp_post_category'); else $category = $_POST["category"];
     107        if(!$category) $category = array(1);
     108        if(!is_array($category)) $category = array($category);
     109
     110        if(empty($_POST["thanks"])) $redirect_to = get_option('gp_redirection_url'); else $redirect_to = $_POST["thanks"];
     111        if(!$redirect_to) $redirect_to = home_url();
     112
     113        $nonce = $_POST["gp_submit_and_save_guests_post_unique_key"];
     114
     115//Verify the form fields
     116        if(empty($title) || empty($story) || empty($author) || empty($email) || empty($nonce)) die(json_encode(array('dead'=>'Please fill the form.')));
     117        if (! wp_verify_nonce($nonce, 'gp_submit_and_save_guests_post') ) die(json_encode(array('dead'=>'Failed Security check')));
     118
     119        //Post Properties
     120        $new_post = array(
     121            'post_title'    => $title,
     122            'post_content'  => $story,
     123            'post_category' => $category,  // Usable for custom taxonomies too
     124            'tags_input'    => $tags,
     125            'post_status'   => 'pending',           // Choose: publish, preview, future, draft, etc.
     126            'post_type' => 'post',  //'post',page' or use a custom post type if you want to
     127            'post_author' => $authorid //Author ID
     128        );
     129//        var_dump($new_post);
     130        //save the new post
     131        $pid = wp_insert_post($new_post);
     132
     133        /* Insert Form data into Custom Fields */
     134        add_post_meta($pid, 'author', $author, true);
     135        add_post_meta($pid, 'author-email', $email, true);
     136        add_post_meta($pid, 'author-website', $site, true);
     137
     138        if($pid){
     139            die(json_encode(array(
     140                'success'       => 'Your post has been submitted successfully. Now redirecting..................',
     141                'redirect_to'   => $redirect_to
     142            )));
     143        }
     144        die(json_encode(array('dead'=>'Something went wrong')));
     145    }
     146
     147    function gp_register_option_page() {
     148        add_options_page(
     149            'Guest Posts Settings',
     150            'Guest Posts',
     151            'manage_options',
     152            'guest-posts-settings',
     153            array($this, 'gp_option_page_callback')
     154        );
     155
     156
     157    }
     158    function gp_option_page_callback() {
     159        echo '<div id="icon-options-general" class="icon32"></div><h2>Guest Post Settings</h2>';
     160        echo '<div class="wrap">';
     161        echo '<form method="post" action="options.php">';
     162        settings_fields( 'gp_settings_section' );
     163        do_settings_sections('guest-posts-settings');
     164        submit_button();
     165        echo '</form>';
     166        echo '</div>';
     167    }
     168
     169
     170    function gp_settings_page_content() {
     171
     172        add_settings_section(
     173            'gp_settings_section',
     174            'Guest Post Settings',
     175            array($this, 'gp_settings_section_callback'),
     176            'guest-posts-settings'
     177        );
     178
     179        add_settings_field(
     180            'gp_author_id',
     181            'Author ID to save posts',
     182            array($this, 'gp_author_id_callback'),
     183            'guest-posts-settings',
     184            'gp_settings_section'
     185        );
     186
     187        register_setting(
     188            'gp_settings_section',
     189            'gp_author_id'
     190        );
     191
     192        add_settings_field(
     193            'gp_post_category',
     194            'Select Caregories to Post',
     195            array($this, 'gp_post_category_callback'),
     196            'guest-posts-settings',
     197            'gp_settings_section'
     198        );
     199
     200        register_setting(
     201            'gp_settings_section',
     202            'gp_post_category'
     203        );
     204
     205        add_settings_field(
     206            'gp_redirection_url',
     207            'Redirection URl after submission',
     208            array($this, 'gp_redirection_url_callback'),
     209            'guest-posts-settings',
     210            'gp_settings_section'
     211        );
     212
     213        register_setting(
     214            'gp_settings_section',
     215            'gp_redirection_url'
     216        );
     217
     218
     219
     220    }
     221
     222    /** Callbacks */
     223
     224    function gp_settings_section_callback() {}
     225
     226    function gp_author_id_callback() {
     227        echo '<input type="text" required name="gp_author_id" value="'.get_option('gp_author_id').'" class="regular-text" />';
     228    }
     229
     230    function gp_post_category_callback() {
     231        $categories = get_categories(array('type' => 'post'));
     232        $selected_category = get_option('gp_post_category');
     233        if(!is_array($selected_category)) $selected_category = array($selected_category);
     234        ?>
     235        <style type="text/css" scoped>
     236            .selectcategories {
     237                height: 200px;
     238                width: 30%;
     239                min-width: 200px;
     240                padding-left: 8px;
     241                overflow-y: auto;
     242                border: 1px solid #ccc;
     243                border-right: 0;
     244                background-color: #FFF;
     245                padding-top: 5px;
     246            }
     247
     248        </style>
     249        <?php
     250        echo '<div class="selectcategories">';
     251        foreach($categories as $category) {
     252            $html = '<input type="checkbox" name="gp_post_category[]" value="'. $category->cat_ID .'" ';
     253            if(in_array($category->cat_ID, $selected_category)) $html .= 'checked="checked"';
     254            $html .= ' />'.$category->name.'<br />';
     255            echo $html;
     256        }
     257        echo '</div>';
     258    }
     259
     260    function gp_redirection_url_callback() {
     261        echo '<input type="text" required name="gp_redirection_url" value="'.get_option('gp_redirection_url').'" class="regular-text" />';
     262    }
     263
     264
     265}
  • guest-posts/trunk/readme.txt

    r716840 r874707  
    11=== Guest Posts ===
    2 Contributors: ericgrld
     2Contributors: ibabar
    33Donate link: http://donate.ibabar.com
    44Tags: guest post, post from front end, anonymous post, guest book, front end post, posts form for guests, guest blogger, post, posts
    55Requires at least: 3.0
    6 Tested Up to: 3.5.1
    7 Stable Tag: 1.1.1
     6Tested Up to: 3.8.1
     7Stable Tag: 2.0
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2626You can also show a custom Thank You message after submitting the post.
    2727
    28 The plugin is simple to install and use. Even a very novice user can install and use the plugin. And I'm sure you are good than that. ;)<br>
     28The plugin is simple to install and use. Even a very novice user can install and use the plugin. And I'm sure you are better than that. ;)<br>
    2929No need to edit any code.<br>
    30 For a easy installation guide checkout the <a
    31 href="http://wordpress.org/extend/plugins/guest-posts/installation/"><strong>Installation</strong></a> tab above.
     30For a easy installation guide checkout the <a href="http://wordpress.org/extend/plugins/guest-posts/installation/"><strong>Installation</strong></a> tab above.
    3231
    3332You can style the form if you wish. We have used just one class called "guest-posts". To style the form add CSS for the "guest-posts" class
    3433and it's sub elements into your theme.
    3534
     35<strong>Version 2.0, Now loaded with more features.</strong>
     36
    3637<strong>Upcoming Features</strong>
    3738<ul>
    38     <li>User selectable category</li>
    3939    <li>Captcha validation</li>
    40     <li>A nice Admin Panel</li>
    4140</ul>
    4241
     
    5251    <li>Activate the plugin</li>
    5352</ul>
    54 You: Oh God, 35 seconds gone and still I'm not done. What will I do now!!!!?<br>
    55 Me: Don't worry my boy, I'm here for you. Just follow me.
     53<strong>You:</strong> Oh God, 35 seconds gone and still I'm not done. What will I do now!!!!?<br>
     54<strong>Me:</strong> Don't worry my boy, I'm here for you. Just follow me.
    5655<ul>
    5756    <li>Create a new page called "Guest Posts" or whatever you like.</li>
     
    5958</ul>
    6059
    61 You: Is it really so simple? I still have 35 seconds left. What can I do at this time?<br>
    62 Me: Yes it's so simple. You may leave a review with 5 star feedback in this time. :)
     60<strong>You:</strong> Is it really so simple? I still have 35 seconds left. What can I do at this time?<br>
     61<strong>Me:</strong> Yes it's so simple. You may leave a review with 5 star feedback in this time. :)
    6362
     63Check out our new admin panel from <strong>Dashboard > Settings > Guest Posts</strong> for various post options.
    6464
    6565Optionally you can create a custom Thank you page and set it via thanks attribute. Example: [guest-posts
     
    7575
    7676
    77 For any further inquiry you can message me directly from <a href="http://en.ibabar.com">my blog</a>.
     77For any further inquiry you can message me directly from <a href="http://www.ibabar.com/blog">my blog</a>.
    7878
    7979
    8080== Frequently Asked Questions ==
    81 Do you have any question, I actually don't have anything in mind.
     81Do you have any question? I actually don't have anything in mind.
    8282
    8383== Upgrade Notice ==
    84 Nothing for now.
     84Upgrade from 1.x to 2.x: Now you have a nice Admin panel. Short code attributes is not mandatory.
    8585
    8686== Screenshots ==
    87871. Activating Guest Posts on a page.
    88 2. Guest Posts activated on Fronend.
     882. Guest Posts activated on Frontend.
     893. Guest Posts Admin Panel.
    8990
    9091
    9192== Changelog ==
     93Date: 13-03-2014
     94Released: 2.0
     95Release Note: Added new admin panel, ajaxified the post form.
     96
     97
    9298Date: 23-03-2013
    9399Released: 1.1.1
Note: See TracChangeset for help on using the changeset viewer.