WP User Frontend plugin supports some actions and filters by itself. That means you can extend this plugin without touching it’s code. Lets see how to do that.
Adding a input field
You can add your custom input fields in 5 areas in the post add form, they are:
- Top area: wpuf_add_post_form_top
- Before the post description: wpuf_add_post_form_description
- After the post description: wpuf_add_post_form_after_description
- After the tags area: wpuf_add_post_form_tags and
- At the bottom: wpuf_add_post_form_bottom
These are the action hooks and you can bind your function to display/process anything you want. Lets create a function that will add a text field before the post description area –
[php]
/**
* Add a field to the add post area
*
* @uses `wpuf_add_post_form_description` action hook
*
* @param string $post_type the post type of the post add screen
* @param object|null $post the post object
*/
function wpufe_artist( $post_type, $post = null) {
$artist = ( $post != null ) ? get_post_meta( $post->ID, ‘artists’, true ) : ”;
?>
<li>
<label for="song_artist">
Artist <span class="required">*</span>
</label>
<input class="requiredField" value="<?php echo esc_attr( $artist ); ?>" type="text" name="song_artist" id="song_artist" minlength="2" />
<div class="clear"></div>
</li>
<?php
}
[/php]
And we can show this field by binding the function in any of those 5 action hooks mentioned before.
[php]add_action( ‘wpuf_add_post_form_description’, ‘wpufe_artist’, 10, 2 );[/php]
These hooks can receive 2 parameters, the first one is the post_type and second one is the post object (only available on edit post area, otherwise set to NULL).
Validating the input
Now that we’ve added our field to the posting form area, we can validate that field if we want.
[php]
/**
* Validate the artist name
*
* @uses ‘wpuf_add_post_validation’ filter
*
* @param array $errors errors array
* @return array errors array
*/
function wpufe_artist_validation( $errors ) {
if( $_POST[‘song_artist’] == ” ) {
$errors[] = ‘Please enter the artist name’;
}
return $errors;
}
add_filter( ‘wpuf_add_post_validation’, ‘wpufe_artist_validation’ );
[/php]
use the “wpuf_add_post_validation” filter for validating the input and return the errors.
Note: For a reason, the errors are hidden by default. That means, if any validation fails and return errors, you’ll not see the errors.
There is a line in “wpuf-add-post.php” like this:
[php]//echo wpuf_error_msg( $errors ); [/php] it means the errors are not shown although if it has any. The reason behind this approach is to escape PHP’s “header already sent” message (for now).
for edit post validation, use this filter “wpuf_edit_post_validation” just like “wpuf_add_post_validation” filter
Processing the input
Now that you’ve validated the user input, it’s time to process the data.
There is a action hook wpuf_add_post_after_insert runs after the new post creation, it returns the post id. So you can grab the post ID and process as you want.
[php]
/**
* Add the artist after new post creation
*
* @uses `wpuf_add_post_after_insert` action hook
*
* @param int $post_id the newly created post id
*/
function wpufe_add_artist( $post_id ) {
update_post_meta( $post_id, ‘artist’, $_POST[‘song_artist’] );
}
add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_add_artist’ );
[/php]
for edit post area, use this action hook: “wpuf_edit_post_after_update”
Other options
Modifying the new post arguments:
You can modify the post arguments before running the wp_insert_post( $args )
function. For example, if you want to change the post status forcefully –
[php]
/**
* Modify the post array
*
* @uses `wpuf_add_post_args` filter hook
*
* @param array $my_post the post array
* @return array the post array
*/
function wpufe_change_post_status( $my_post ) {
$my_post[‘post_status’] = ‘pending’;
//want to change the post author?
$my_post[‘post_author’] = 1;
//must return
return $my_post;
}
add_filter( ‘wpuf_add_post_args’, ‘wpufe_change_post_status’ );
[/php]
for edit post area, use this filter: “wpuf_edit_post_args”
Redirecting after new post:
You can set the redirection url after the new post creation.
[php]
/**
* Change the direction url
*
* @uses `wpuf_after_post_redirect` filter hook
*
* @param string $url the redirection url
* return string new redirect url
*/
function wpufe_force_redirection( $url ) {
return home_url(‘/dashboard/’);
}
add_filter( ‘wpuf_after_post_redirect’, ‘wpufe_force_redirection’ );
[/php]
Showing info on dashboard:
There is a hook on the plugin dashboard area wpuf_dashboard. It accepts two parameter, the user id and the currently showing post_type.
[php]
/**
* Show in dashboard
*
* @uses `wpuf_dashboard` action hook
*
* @param int $user_id the current users user id
* @param string $post_type
*/
function weufe_dashboard_info( $user_id, $post_type ) {
$user = get_userdata( $user_id );
echo ‘Hello ‘ . $user->display_name . ‘, Having fun?’;
}
add_action( ‘wpuf_dashboard’, ‘weufe_dashboard_info’, 10, 2 );
[/php]
Disabling posting capability:
You can even block a specific user from posting and show him a message/cause. Helpful for blocking spammers.
Lets check if a user has a meta field “paid” with the value “yes”, so we can let the users posting who paid for something, others will see a message.
[php]
/**
* Check if the current user can post
*
* @return bool
*/
function wpufe_can_post() {
$user = wp_get_current_user();
$paid = get_user_meta( $user->ID, ‘paid’, true );
if( $paid == ‘yes’ ) {
return true;
}
return false;
}
/**
* Block the user if hasn’t the post capability
*
* @return string
*/
function wpufe_block_user( $can_post ) {
if( wpufe_can_post() ) {
return ‘yes’;
}
return ‘nope’;
}
add_filter( ‘wpuf_can_post’, ‘wpufe_block_user’ );
/**
* Show the message if can’t post
*
* @param string info message
* @return string info message
*/
function wpufe_show_message( $info ) {
if( !wpufe_can_post() ) {
$info = ‘Sorry, you have to pay first’;
}
return $info;
}
add_filter( ‘wpuf_addpost_notice’, ‘wpufe_show_message’ );
[/php]
Modifying the plugin options
You can also change the plugin options and add your own options to the plugin settings area. Lets take a look how to add “EURO” as a currency in the plugin options area.
[php]
/**
* Adds new currency to admin options
*
* @param array $fields admin options
*/
function wpufe_currency_filter( $fields ) {
foreach( $fields as $key => $val ) {
if( $val[‘name’] == ‘wpuf_sub_currency’ ) {
$fields[$key][‘options’][‘EUR’] = ‘EURO’;
}
}
return $fields;
}
add_filter( ‘wpuf_build_form_args’, ‘wpufe_currency_filter’ );
[/php]
The plugin settings are build from a big array, so you can add/modify the array. So handy!
This is really awesome. Thank you very much Tareq !
Question : on my site, I have a custom post type called “events”. I’d like to enable the user to choose between ordinary posts or events when wrtiting his post. Is it possible ? How could I do that ?
@MathieuRouault See the section about modifying the post argument, easily can be done.
@tareq Thank you Tareq for your quick reply. Unfortunately, I don’t see very clearly how you can enable the member to choose between two sorts of type while writing his post. Can you put me on the right track ?
@MathieuRouault Let me ask you a question, are you a developer?
Hi Tareq there is any option to create multiple forms for multiple custom post types? thanks for the amazing job…
@manquepierda when inserting the the shortcode [wpuf_addpost] you can set the post type [wpuf_shortcode post_type=”event”] and you can create multiple forms this way.
Thanks, thats nice but if I ve got different custom fields on differents custom post, we say like movies and actors, may I be able to create differents forms with differents categories and etc? Thanks, its an awesome plugin.
@manquepierda You can create different form, but can’t create different custom fields for different forms yet. I think it’ll be a good feature addition to the plugin. But you can hook on these different actions/filters and create the functionality as you need.
Ill be looking forward into that. I think that feature is so necessary.
Thanks BTW for this wonderful plug-in. 🙂
also, pricing for different category would be nice and post expiration countdown on admin panel would be nice too. 🙂
Thanks!
You can create different form
Sorry… how to do it?
Hello, can you tell me how to remove the attachments ul class=”wpuf-attachments” It’s making my thumbnail attachemnts show in a bulleted vertical list… not pretty.
Many thanks, this is the most comprehensive front end editor on wordpress.
@1159com If you don’t want to show the attachments, there is an option to disable in plugin settings.
@tareq Thank-you for your reply. Yes, I do want to show the attachments, but not in a vertical list. I want to show attachemnts in a horizontal list (block) Can you help please?
Thanks.
@1159com Use this CSS in your theme http://pastebin.com/mx3itBv0
@tareq Thank-you tareq. That code snippet worked, but I had to paste it into my themes CSS file. It did not work when pasted into the Plugin’s custom CSS field in the admin page. Maybe I need the ‘important!’ declaration??
Yes I was wondering if we can have the option to make the fields on the front end for posting required? Maybe have a validator that pops up if the field is empty.
Hello, I am using WP User Frontend, and it is reaaly good. But I have a problem with custom taxonomies – the ones I have in my WP database just does not show up in WP User Frontend. As I understand it, WP User Fronten cannot handle custom taxonomies in the present version. I have read the postings on the WordPress.org forum concerning WP User Frontend, and found people mentioning a solution to the problem. But then I have not been able to find out how they made it… Anyone in this forum that has suggestions???
1- Is it possible to select more than one category when creating a post? Holding down Ctrl won’t work
2- How can I make the new post editor start in VISUAL tab, instead of HTML?
3- How can I make the VISUAL editor pane larger, it automatically shrinks to a small size, even though I have a full page size.
Thanks for your support!
1. Nope, not possible currently
2. As far as I tested, the visual editor comes as default.
3. You need to tweak your CSS
@tareq ok, thanks …
Hi Tareq,
I am loving the WPUF plugin and am replacing my Gravity Forms submissions with WPUF as soon as I can figure out this one thing:
The Post Expirator field on the frontend submission form only allows a maximum of 72 hours. How can I change this?
Thanks for this awesome free plugin.
@DiaperDeal Day has been added on the new version instead of hours.
Heloo Sir…your plugin is very help full.
But when Installed it .It showing extra images (which I dont need) are displaying in our home pages and also in the posts please tell me the solution for this problem…
Hi Tareq,
I’m using this plugin and it all works fine until i try to add a custom field dropdown type.. there is no way of selecting the values when i select the dropdown type? All i need is to add the values in a dropdown and this plugin would be perfect!
Is it a bug?
Thanks
@lhodsden Somehow the JavaScript was not included in that page. Download the latest code from github, it has this fix.
https://github.com/tareq1988/WP-User-Frontend/zipball/master
@Tareq cheers works perfectly now! Much appreciated
First of all, the plugn works very well. Good job. But i have a issue. If the user is a administrator he can upload images at the frontend and there is also a preview. If another role tried to upload a image it will be stuck and only shows the filename and 100%.
When submitting the post the image is not uploaded.
Does anyone find a solution for this?
yeah I have the exact same problem can anyone please help out?
Hi Tareq, thanks for creating this great plugin. It’s so flexible, I came up with tons of new ideas.
But I was just wondering if it would be possible to get other pages from the wp-admin panel fronted. For example, I have a plugin that adds the page /wp-admin/admin.php?page=user_self_delete_user
And also, if there is a quick way to redirect users away from the Access Denied page, when back-office is restricted?
Hi Tareq I need help, I want to integrate custom taxonomies, my custom taxonomies already are created from the function.php of templae and are read from the same template and print. How can I do to insert a field input for custom taxonomies in the submission form?
Thank you very much!!
It was described in the post briefly. Please try to follow them.
thanks a lot, but only information, “get_post_meta” and “update_post_meta” functions can also be used for custom taxonomies?
Nope, they only works for posts.
and then?
if I use this code?
term_id, ‘new_metadata’, TRUE);
?>
I would like to add Post Visibility and Password Protected fields to the frontend, how to do that?
All the examples are given in the post. Try to follow that using actions and filters.
if I use this code for update Taxonomy?
term_id, 'new_metadata', TRUE);
?>
Is it possible to set post_format when adding post?
As I showed in the examples, it can be done.
Great!
One more question.
Is it possible to insert date picker?
Adding datepicker is quite easy. Import the required jquery-ui files in the header and customize wpuf function like follows:
<input type="text" class="datepicker" name="custom-field" id="wpcf-anecdote-date" value="" >
jQuery(document).ready(function() {
jQuery('.datepicker').datepicker();
});
thank you very much!
I posted the exact code to assign post formats on this support forum post.
Hope it can help someone.
Awesome plugin…..but one problem is there that it won’t support more than one post type for showing different custom fields on different form… can u tell me when this feature will get added in plugin… thanxxx
Really Great Plugin but can you help me like I have set ” New User Default Role ” to Contributor from the admin of the site and i have install a plugin “Author Advertising” which is displaying when i login as a Contributor at the admin area below the Dashboard but it isn’t display at front end into your plugin , same like the comments , media and tools isn’t display at front end in your plugin but these all things are display when we login with Contributor and go to admin of the Contributor so is this possible that i can display ” Author Advertising ” plugin at front end . This plugin only have 3 fileds where user add google adsence publisher id and some other things related to it.
I really very thankful to you for helping me.
Great plugin! I have a question for you: How can I configure plugin, so user can choose sub-category? I have three levels categories, and I need to let user to decide which one will post go to…(example: books>history>europe …beside books, there is more categories, and beside history there are more categories and so on…
Please help me, I need it!
Thank you!
There are 3 type of Category Selection type in the plugin settings. Try changing them.
thank you! That was just what I need!
One more question…is it possible to add up label in attachment section, where will be displayed text like: “Attached files:”?
So, user can clearly look for attachment section.
Hi,
I was wondering if there is way to enable first post to be for free and the rest forced to be paid?
Thanks,
Any ideas, directions to this issue?
Thanks,
hello…
installed your plugin and its great for my project … all works fine but i cant get content if i click on a user edit link in the frontend, only a blank wp page !
any suggestions ?
thanks
aleccs
Make sure that right shortcode is in the page.
[wpuf-edit-users]
Create a new Page “New Post” and insert shorcode [wpuf_addpost].
For a custom post type event, use it like [wpuf_addpost post_type=”event”]
Create a new Page “Edit” for editing posts and insert shorcode [wpuf_edit]
Create a new Page “Profile” for editing profile and insert shorcode [wpuf_editprofile]
Create a new Page “Dashboard” and insert shorcode [wpuf_dashboard]
To list custom post type event, use it like [wpuf_dashboard post_type=”event”]
Set the Edit Page option from Others tab on settings page.
To show the subscription info, insert the shortcdoe [wpuf_sub_info]
To show the subscription packs, insert the shortcode [wpuf_sub_pack]
i belive, you want Edit Profile shortcode? If that so, use: [wpuf_editprofile]
or, for post edit: [wpuf_edit]
Hi Tareq, thanks for this great plugin!!
I need some help, im trying to make it works without success, i need to add a custom taxonomy (im using taxonomy manager, my taxonomy name is “provincias”)
i added this function to my functions.php :
function wpufe_taxonomy( $post_type, $post = null) {
wp_dropdown_categories( ‘show_option_none=’ . __( ‘– Select –‘, ‘wpuf’ ) . ‘&hierarchical=1&taxonomy=provincias&hide_empty=0&orderby=name&name=provincias&id=cat&show_count=0&title_li=&use_desc_for_title=1&class=cat requiredField&exclude=’ . $exclude );
}
after that i add this in functions.php :
add_action( ‘wpuf_add_post_form_after_description’, ‘wpufe_taxonomy’, 10, 2 );
after that this:
if (function_exists(‘wpufe_taxonomy’)) {
add_action(‘save_post’, ‘save_taxonomy_data’);
}
at the end i added this to the same functions.php file:
function save_taxonomy_data($post_id) {
// verify this came from our screen and with proper authorization.
if ( !wp_verify_nonce( $_POST[‘taxonomy_noncename’], __FILE__ )) {
return $post_id; }
// verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything
if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE )
return $post_id;
// Check permissions
if ( ‘post’ == $_POST[‘post_type’] ) {
if ( !current_user_can( ‘edit_page’, $post_id ) )
return $post_id;
} else {
if ( !current_user_can( ‘edit_post’, $post_id ) )
return $post_id;
}
// OK, we’re authenticated: we need to find and save the data
$post = get_post($post_id);
if ($post->post_type == ‘post’) {
$select_name = $_POST[‘provincias’];
wp_set_object_terms( $post_id, $select_name, ‘provincias’ );
}
}
So, i can see the taxonomy (provincias) dropdown in the creation of a new post from frontend, but when i save, the selected taxonomy doesnt get saved.
Something is missing or bad coded?
You should be using the wpuf_add_post_after_insert hook instead of save_post hook.
Yes, i changed it, but still doesnt works :S
Tareq, let me know if you can check it and make it works please, i need a solution for this, please tell me how it will cost.
I guess is something stupid somewhere in the code but i dont know where and how.
Hi Tareq,
I am struggling with the following issue and not able to find solution..
http://wordpress.org/support/topic/plugin-wp-user-frontend-image-not-attached-to-post
When I create a new post within the wordpress admin, the add media link has the correct post id: /wp-admin/media-upload.php?post_id=21&TB_iframe=1
But when I create a post via wpuf page, the post_id is set to 0 : /wp-admin/media-upload.php?post_id=0&TB_iframe=1
That’s not a problem, make sure if you enabled the option “Show attachments in the post” from “Others” tab of the plugin settings.
Hello @Tareq,
I’ve checked “show attachment in the post” but the upload/media button didn’t work
Thankyou
I am trying to integrate this awesome plugin into my new site and when I loaded it to my site and set the pages and all the back-end information and went to my front-end to test I notice a few things but one really stood out. Where I used to have a search function when used it now refreshed the main page. Any idea where to look to resolve this issue? Note: I have already search through and tried all plugins and made sure there is no conflict.
Hi,
I’m having trouble with one aspect of the plugin – but the rest is working great, thank you!
The issue is that when I test in Sandbox the successful payment page redirects me to the same message that “You must purchase a pack before posting”. It says success in the url but the form doesn’t show.
Any help would be great!
Thanks!
Justin
Hi Tareq,
This is a great plugin and very well thought out. Putting the upload image and text directly into a post ready for approval is really helpful. I need to know one thing to see if it will solve an issue I have. I need to be able to allow users to be able to use the upload just as you have designed it but without logging into the back-end or registering, after all what is the point of a front-end upload if you have to log into the back-end to use it. So I’m sure you have this function but I can’t seem to get it working that way.
Any help and advise would be greatly appreciated.
Seamus
That option isn’t there yet, so you can’t find it.
Tareq,
I was able to add the Custom Fields as needed, however, the sort order isn’t working properly. While the order is properly reflected on the Edit Post Page, it does not display the proper order on the Custom Field Admin and Post Pages. Although I set the proper Order for the Event Location Zip Custom Field (10… The lowest number), it appears at the bottom of the Post Page.
Final Step: Event Location Zip Custom Field was created last, however, it does not appear at the top of the list. When created, the Event Location Zip Custom Field was assigned an order of 10.
Hi Tareq
Thanks for such a nice plugin.
Besides the basic functionality, actions and filters are really very much helpful in extending as per specific requirement.
I am stucked at one point
How can i change the default text for non logged in users on add post page.
You’ve to edit the plugin files, no other way around.
i would love to see this feature controlled from admin or by means of some filters.
Capability to reorder the form fields would also br very helpful.
AOA
Please reply me fast I am developing a website like http://www.olx.com.pk and I am using your plugin its a nice plugin but problem is that I want to show different form against each category is it possible if yes then please let me know how??
It’s not possible right now. Only one form is available at this moment.
I am using this plugin and think it is exactly what I need. Is there a way the user can preview their posts. I am using the frontend editor plugin as well and would like my users to click on a link to preview their posts and edit directly from that screen. Currently the only time a link to the post shows is when the I (the admin) changes the status to “publish”.
I would like to add another column that will provide a link to preview it. I am trying to add the following the plugin but it’s not working:
‘.__( ‘Preview/Edit’, ‘lup’ ).’
and
Edit
Any help would be great!
For some reason my my codes didn’t come up, but I am trying to use the following to create a second column
'.__( 'Preview/Edit', 'lup' ).'
and
Preview/Edit Post
Sallam , Plugin is nice but i wants that how user open any category then add new post in that category ? any solution for it .
Like http://www.abc.com/123 in this 123 cetagory user able to add post in 123 category or any category with different post form ,
Need urgent reply
Thanks
Nope, not possible right now.
First, awesome plugin! Perfect for what i´m planning to do with my website. But I have the same problem as Victor Torando, I what to add extra taxonomies to the post form.
I wonder if there is a “simple” solution or do I need to get in the all the files and add copies of the “category” and “tags” code snipets and customise them?
This is the post about how you can add extra taxonomies to the post form, not any alternative simple solution right now.
Hi Guys
I have assigned the Post Type to ‘portfolio’. Which all works fine.
BUT The Categories drop down still shows the ‘posts’ categories and not the portfolio-types categories!
How can I change this?
Thanks wp user front end. This is an very good plug in. I do have the themes wallpress with different post templates. In wordpress under adjustments there’s the option to Standard article post format collecting main. When I do adjust the individual post tempate there, it works in the back end but not in the front end ( wp user front end). Wp user front end will take the standart post format template.
I do work in the word press and php and I’m happy about every helpfull hint.
greetings Riccarda
Hellow….
Thanks for this awesome plugin..
Is it possible to use this plugin to allow users to create their own pages and manage it?
upload/insert tab does not display when user role contributor,author etc it only display when user role admin and editor on frontend. so how we can allow contributor to display upload/insert tab . please replay as soon
once the post pending to live by admin, is there any feature that user no longer to edit and delete that post, only they can able to view post.
i am using your plugin and am happy with using plugin.but i face some odd problem like when the payment transaction is complete with paypal then in the mozilla i get the alert like”information send on site is not encrypted page……..do you want to continue or cancel” (not click on continue or cancel)after that it successfully redirect to my payment success page.but in the database in transaction table record get save but not get transaction id,created date,.
when i click on “if you not redirect within 5 second then click here” then record get save perfect for transaction.
if i click on continue then i get two records in the transaction table one for correct transacton and one for without transaction id,created date.
In chrome and safari did not get pop up so record are save correctly in database.
so pls give some solution for my problem with mozilla.
or on which file or functon i look to solve this problem.
I actually had been browsing for creative concepts for my personal website and noticed your post,
“How to extend WP User Frontend | Tareq Hasan”, do
you really mind in cases where I really employ a number of ur points?
Thanks a lot ,Shaun
I have a few questions about your plugin. It’s working well in some aspects and not so well in others.
The main problem I’m having is that Admins have the ability to…
A. Upload images into the post
B. Embed YouTube videos, etc. in the post
…BUT. If you’re an author or contributor, etc. it doesn’t work!!
Any ideas how to fix this?
The user roles who doesn’t have the ability to post unfiltered_html can’t post any html codes. You can add these capabilities by some role based plugin like Role Scoper.
In version 1.1, if you disallow category selection, the default category is lost if the user updates the post. The fix is to change line 303 of wpuf-edit-post.php to
$post_category = array(wpuf_get_option( 'default_cat' ));
I hope this fix can make it into the next version. An amazingly strong plugin. Thank you!
Hi Tareq
I worked on multisite wp 3.4.2 , i using this plugin for front end posting, Problem is the image is not showing . in media it showed un attached
Tareq this is a great plugin however I’m trying to allow unregistered user to post on the front end.
I been able to allow the form to appear when logged out however the uploading image does not work.
could you help?
Hi I would like my user to be able to edit the url of the post or page from the frontend, how can I do this, I don’t see a setting in the backend, do I perhaps need to add a hook/filter? Thanks