• Resolved fcaporal

    (@fcaporal)


    Hello,

    Is it possible, using the form and link plugins or programmatically, to give the option to logged in users on the frontend to control the visibility of custom fields in their profile? If not, can the administrator or programmer specify the visibility of individual custom fields in the directory?

    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Steven

    (@shazahm1hotmailcom)

    Apologies for the delay in my reply!!!

    If I understand correctly, sure. Here’s an example:

    // Check if the current user can manage options (by default an admin only capability).
    if ( current_user_can( 'manage_options' ) ) {
    
    	// Register the metabox and fields.
    	add_action(
    		'cn_metabox', 
    		static function() {
    
    			$atts = array(
    				'title'    => 'Metabox Name',         // Change this to a name which applies to your project.
    				'id'       => 'custom_one',           // Change this so it is unique to you project.
    				'context'  => 'normal',
    				'priority' => 'core',
    				'fields'   => array(
    					array(
    						'name'       => 'Field Name', // Change this field name to something which applies to you project.
    						'show_label' => TRUE,         // Whether or not to display the 'name'. Changing it to false will suppress the name.
    						'id'         => 'field_id',   // Change this so it is unique to you project. Each field id MUST be unique.
    						'type'       => 'text',       // This is the field type being added.
    						'size'       => 'regular',    // This can be changed to one of the following: 'small', 'regular', 'large'
    					),
    				),
    			);
    		 
    			cnMetaboxAPI::add( $atts );
    
    		}
    	);
    }

    The custom text field metabox will only display for admin. This way only an admin can edit the field contents.

    To display the field to the admin only, you would wrap the same user can check around the code that displays the field:

    I hope this helps; please let me know.

Viewing 1 replies (of 1 total)
  • The topic ‘Public, Private, Unlisted for custom fields’ is closed to new replies.