Notifications
Clear all

Hidden Custom Topic Field

10 Posts
4 Users
4 Likes
746 Views
Posts: 5
Customer
Topic starter
(@shaleed-tonge)
Member
Joined: 4 years ago

Hi. 

I'm still looking for a way to add a contact form to my "listing". I've disabled the reply system in that specific forum and its topics, and I would like to add a third-party contact form short code in a custom field. The only thing is. I'll need this field to be hidden from the users and only visible to admin in backend. In the front-end, the user will be able to see the short code rendered in the content using a text editor post type or something similar.

Maybe if I can add the short code as a default text. 

Is this possible? 

9 Replies
Posts: 32
Customer
(@lynne-benedict)
Member
Joined: 2 years ago

I really would love to see an answer to this question as well. We hoped with topic custom fields plugin we could store some hidden information for admin consumption only as well.  

Reply
Posts: 4168
 Tom
Admin
(@tomson)
Famed Member
Joined: 9 years ago

@lynne-benedict,

The only way is using the hook which will be available in the next wpForo version. I mean in the 2.1.0 version. The hook code should be used as PHP through Code Snippets plugin, or it should be added in functions.php file of current active WordPress theme:

add_filter('wpforo_topic_fields_filter', function( $display, $field ){
// Unique Key Names of fields you want to display only to admins
$admin_only_fields = ['field_key_1', 'field_key_2'];
if( !empty( $admin_only_fields ) && !current_user_can( 'administrator' ) ){
if( in_array( $field, $admin_only_fields, true ) ) return false;
}
return $display;
}, 10, 2);

 

In the script above, you should change the field_key_1 and filed_key_2 to the keys of your fields.

wpForo topic custom fields key

If you cannot wait till the next wpForo update (2.1.0 or to 2.0.10 version), then you can manually add the change in /wp-content/plugins/wpforo/classes/Posts.php file which will allow you to use the hook mentioned above:

Find this line:

if( $postmeta = wpfval( $postmetas, $field ) ) {

Replace it to this:

$display = apply_filters( 'wpforo_topic_fields_filter', true, $field, $post );
if( $display && $postmeta = wpfval( $postmetas, $field ) ) {
Reply
5 Replies
Customer
(@shaleed-tonge)
Joined: 4 years ago

Member
Posts: 5

@tomson I'll see how it works out. Thanks

Reply
Customer
(@lynne-benedict)
Joined: 2 years ago

Member
Posts: 32

@tomson I am going to try this as well. Thank you

Reply
Marco Rosini
Customer
(@marco-rosini)
Joined: 2 years ago

Member
Posts: 20

Hi @tomson, but what if I just wanted to hide the item from unregistered users? What should I put in place of $admin_only_fields

Reply
Marco Rosini
Customer
(@marco-rosini)
Joined: 2 years ago

Member
Posts: 20

I'm sorry @tomson if I insist, but for me this thing is almost fundamental. I have to hide the link field in some posts from guests. That is, the field must be visible only to registered users. Can I use the code above to do this? If the answer is yes, how should I change the entry, to point to the registered users instead of the administrator?

Reply
 Tom
Admin
(@tomson)
Joined: 9 years ago

Famed Member
Posts: 4168

@marco-rosini,

If you want to hide some field for guests, you should use this script:

add_filter('wpforo_topic_fields_filter', function( $display, $field ){
// Comma separated Unique Key Names of fields you want to hide from guests (no logged-in visitors)
$fields = ['field_key_1', 'field_key_2'];
if( !empty( $fields ) && !is_user_logged_in() ){
if( in_array( $field, $fields, true ) ) return false;
}
return $display;
}, 10, 2);

Don't forget to change field_key_1 and field_key_2 to the field keys you need. if you need to leave only one filed, then it should look like this:

$fields = ['field_key_1'];

 

 

Reply
Marco Rosini
Posts: 20
Customer
(@marco-rosini)
Member
Joined: 2 years ago

Ok .. I made a first attempt and I changed your code like this:

// WP foro hide link for guest
add_filter('wpforo_topic_fields_filter', function( $display, $field ){
// Comma separated Unique Key Names of fields you want to hide from guests (no logged-in visitors)
$fields = ['download_mirror'];
if( !empty( $fields ) && !is_user_logged_in() ){
if( in_array( $field, $fields, true ) ) return false;
}
return $display;
}, 10, 2);

where I simply replaced

['field_key_1', 'field_key_2']

with

['download_mirror']

and it seems to work..

by chance it would be possible to add a disclaimer like:

"subscribe to fully view the resource"

It would be perfect this way.

 

 

Reply
1 Reply
 Tom
Admin
(@tomson)
Joined: 9 years ago

Famed Member
Posts: 4168

@marco-rosini,

There is no an easy way to add disclaimer here. You should use "admin note" in wpForo > Tools >  Admin Note tab and show it for certain usergroup on the top of the forum:

Reply
Share:
Scroll to top