• Resolved densdj

    (@densdj)


    Hi, Greg (sorry for my English)
    I am creating site with adverts, thank you for best plugin. I am going create custom fields like here: https://wpadverts.com/documentation/custom-fields/
    and there is “Hint: If you want to display the field in wp-admin or frontend only, use is_admin()function to decide if the field should be displayed or not.”
    Tell me please, hom to use this function, to hide fields( and info in it) from all users, but admin (that only i could write and see it)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i am glad you are liking the plugin so far, as for your question let me illustrate this with a code example.

    Let’s assume you want to add a field named “Admin Notes” to the Adverts the field will be filled from wp-admin / Classifieds panel only, in this case your adverts_form_load filter would look like this

    
    add_filter( "adverts_form_load", "my_adverts_form_load_admin_only" );
    function my_adverts_form_load_admin_only( $form ) {
        if( $form["name"] != "advert" ) {
            return $form;
        }
        if( is_admin() ) {
            $form["field"][] = array(            
                "name" => "my_admin_notes",
                "type" => "adverts_field_text",
                "order" => 25,
                "label" => "Admin Notes",
                "is_required" => false,
                "validator" => array()
            );   
        } 
        return $form;
    }
    

    Basically it comes down to just wrapping the $form["field"][] ... inside if( is_admin() ) { ... }.

    Thread Starter densdj

    (@densdj)

    Thank you, it works.
    One more question: is it possible in “All Classifieds” admin list, make search by admin notes, and by phone number too, in “Search Classifieds”. (To prevent users double adverts, and me not to forget admin notes, in time)

    Plugin Author Greg Winiarski

    (@gwin)

    This is possible but will require some custom programming.

    Please see the section “Displaying Custom Field in wp-admin List” here https://wpadverts.com/documentation/custom-fields/ it explains how to add columns to the “All Classifieds” and links to tutorials which dig deeper into customizing wp-admin lists.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Field only for admin’ is closed to new replies.