Hi,
sorry, but i am not exactly sure what you would like to do?
The users can edit the inactive Ads from a page with [adverts_manage] shortcode. If you would like to disallow access to some Adverts you can do that for example in the template_redirect action
add_action( "template_redirect", function() {
$user_can_see_advert = true;
if( is_singular( 'advert' ) && ! $user_can_see_advert ) {
wp_redirect( "https://link/to/some/other/page" );
exit;
}
} );
You just need to change the line $user_can_see_advert = true; to code which will check if the user can see the Advert and the “https://link/to/some/other/page” link to a link to which you will redirect users without valid access.
Ok thank you for that bit of code. However, the user cannot still make edits. I go to the manage ads page and it displayed this message:
“You do not have any Ads posted yet.”
But if I change the ad I just posted on from “Status: Pending Review” to ” Status: Published” it does appear on the same page upon refresh. If I can allow the user to make edits still with it pending review that’s basically what I’m looking for.
Let me try and make it super clear:
-I want to allow the advert poster ( lets call him Bill ) to make a post.
-The post is only visible to Bill even if he wants to share it.
-Bill can go back and edit the post to fill in a field that asks for another users username ( Lets call the user Joe ).
-When Bill enters Joe’s username It makes Joe the new author of the advert post, so Joe can make changes. ( I’m doing this in a custom validator ).
– Joe can then mark the post to be publically visible. ( I can do this part myself, so actually getting it marked for being public isn’t a big deal, but if you have a nice clean way to do it I’m all ears ).
I know it seems weird, but when it’s done it will totally make sense. I was wondering if its possible to only show the field requesting a username after you have already published the post and gone back to make an edit (Joe’s username in this case).
Basically Paid users need to take over for free users (Joe is a paid user and Bill is free) before the post is public. Thats the goal anyways.
Hi,
ohh ok, so if i understand correctly the main problem is that the Ad is not visible in the [adverts_manage] even though it is assigned to the user?
If so then you can add the “Pending Review” status to the list of statuses visible in [adverts_manage] by adding the code below in your theme functions.php file
add_filter( "adverts_sh_manage_list_statuses", function( $list ) {
$list[] = "pending";
return $list;
} );
It is possible to conditionally display a username field although it is not exactly clear for me when it should show, from the description i understand that only Bill should see it and once he will assign the Ad to Joe the user name field is no longer needed?
Also how should the WPAdverts know if the user is paid or free user?
That code snipped is perfect. Yup, that was what I needed there.
So I want the username field to only show after the post has actually been created. If they are adding it for the 1st time and it isn’t already saved in the database I don’t want to display it (as its meant to hand over authorship to Joe, and it doesn’t make sense to hand over authorship to a post before the post actually exists I’m thinking).
WHen BIll makes the post I have a shortcode that will send Joe a notification that someone in his area made the post. Joe will then contact bill through the info I provide in the notification and tell Bill to enter his username and give him authorship. Having the field there before this point may confuse new users, so I want to hide it.
Oh and to answer your question on paid users, I’m using the profile builder plugin that has a paid memberships addon, and then just pulling the metadata with $wpdb to find the subscription of the user from an ID.
Hi,
ok, so basically the Username field should be only in the [adverts_manage] field as only there the users can edit the Advert after posting it.
If so then you can add the field only when editing by using the code below
add_filter( "shortcode_atts_adverts_manage", function( $args ) {
add_filter( "adverts_form_load", "custom_username_field" );
return $args;
} );
function custom_username_field( $form ) {
if( $form['name'] != "advert" ) {
return $form;
}
$form["field"][] = array(
"name" => "adverts_custom_username",
"type" => "adverts_field_text",
"order" => 12,
"label" => __( "Username", "adverts" ),
);
return $form;
}
You are the best! Thank you.
Just for the future, is there somewhere in the documentation that I could have figured that out from? I want to try and figure this stuff out myself so I don’t keep bothering you with it. Either way top-notch support.
How to customize the forms is explained here
https://wpadverts.com/documentation/forms-api/
https://wpadverts.com/documentation/custom-fields/
The shortcode_atts_{$shortcode_name} is a standard WP filter executed on all shortcodes params which just happened to be useful in this case :).