Auto set owner when uploading private file

    • ciclick
      Participant
      # il y a 1 année et 9 mois

      Hi,

      We have purchased he Owner Restrictions add-on. Is it possible to allow a user to upload files in their personal area without having to assign themselves as owner?

      We have set the Owner Restriction settings to “Only themselves”: https://monosnap.com/file/FA9bHNGZn6Qra2gbA579Ko6W9j8RCQ

      but in the customer area the user still has to select himself. We would want to skip that step: https://monosnap.com/file/SKA7CvHeIqPVqeT4l1A81q42SBiPwt so the user only has to write a title and upload the document.

      Thank you very much.

    • Thomas
      Maître des clés
      # il y a 1 année et 9 mois

      Hi,

      The Owner Restriction add-on allows to customize content inside the fields, but doesn’t allow to set a default value.

      Your use case seems a bit uncommon. You can, out of the box, disable the Owner selection step that way:

      • in Settings > Capabilities > Uncheck ability to select an owner for role “subscriber” (or any role for which you want the step to disappear)
      • in Settings > {private post types} > Set the administrator of the site as the default owner (then, the whole owner selection step will disappear)

      Is there any specific reason for which you need to set the current user as the owner of the post? This could be doable by code, but I actually don’t know if it will lead or not to unattended side-effects. The problem is that an user will be both author and assigned user. So, for instance, with the notification add-on enabled, that user will, in this case, receive two notification mails when creating a post.

      I would recommend to automatically assign the post to the administrator instead.

      However, if you still want to try to automatically assign the post to the current user, you could create a custom WP plugin (see our code snippets documentation for that), and paste that code snippet into it. But as said, I think this could lead to unattended side-effects. To let that code snippet work, you still need to set capabilities accordingly (as explained above).

      /**
       * Set current user as default Owner
       *
       * @usage Settings > Capabilities > Uncheck ability to select an owner for role "subscriber"
       * @usage Settings > {private post types} > Set a default user as fallback
       *
       * @return array Force currently logged-in user as owner
       */
      function wpca_default_owner_is_current_user($owners, $post_type)
      {
      	
      	return ['usr' => [get_current_user_id()]];
      }
      add_filter('cuar/private-content/edit/default-owners', 'wpca_default_owner_is_current_user', 20, 2);

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

Vous lisez 1 fil de discussion

The topic ‘Auto set owner when uploading private file’ is closed to new replies.