Allow admin to bypass required fields in certain situations with ACF?












0















I've created an ACF frontend form using acf_form; these fields are added to the User record on the backend; however because this form has required fields this means the admin cannot make basic changes to the user on the backend unless the user has filled in this form.



So I'm wondering if it's possible in certain situations to allow the admin to bypass being required to fill in required fields and if so, how do I go about doing this?










share|improve this question



























    0















    I've created an ACF frontend form using acf_form; these fields are added to the User record on the backend; however because this form has required fields this means the admin cannot make basic changes to the user on the backend unless the user has filled in this form.



    So I'm wondering if it's possible in certain situations to allow the admin to bypass being required to fill in required fields and if so, how do I go about doing this?










    share|improve this question

























      0












      0








      0








      I've created an ACF frontend form using acf_form; these fields are added to the User record on the backend; however because this form has required fields this means the admin cannot make basic changes to the user on the backend unless the user has filled in this form.



      So I'm wondering if it's possible in certain situations to allow the admin to bypass being required to fill in required fields and if so, how do I go about doing this?










      share|improve this question














      I've created an ACF frontend form using acf_form; these fields are added to the User record on the backend; however because this form has required fields this means the admin cannot make basic changes to the user on the backend unless the user has filled in this form.



      So I'm wondering if it's possible in certain situations to allow the admin to bypass being required to fill in required fields and if so, how do I go about doing this?







      wordpress advanced-custom-fields acfpro






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 12:59









      BrettBrett

      6,24739114220




      6,24739114220
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Ok, found a way to do this - this is a way to do it for the User screen, it may differ for other post types.



          We not only have to disable server side validation, but also client side validation, to do this, we do something a little like this:



          add_action('acf/input/admin_head', 'my_acf_admin_head');

          function my_acf_admin_head() {

          if (!function_exists('get_current_screen')) {
          return;
          }

          // Get current page/screen
          $screen = get_current_screen();

          // Get current user
          $user = wp_get_current_user();

          if (is_object($screen) and is_a($screen, 'WP_Screen')) {

          if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
          ?>
          <script type="text/javascript">
          window.acf.validation.active = false;
          </script>
          <?php
          }

          }

          }


          This will add some Javascript to any page that matches our qualifers to disable ACF client-side validation.



          Now, to disable backend validation, we do something like this:



          add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);

          function my_acf_validate_save_post() {

          if (!function_exists('get_current_screen')) {
          return;
          }

          // Get current page/screen
          $screen = get_current_screen();

          // Get current user
          $user = wp_get_current_user();

          if (is_object($screen) and is_a($screen, 'WP_Screen')) {

          if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
          // clear all errors so they can bypass validation for user data
          acf_reset_validation_errors();
          }

          }

          }


          Note that because get_current_screen() isn't always available, these methods do not support front end forms.



          Also note that this code could definitely be improved to be a lot more DRY, but I will leave that up to you. :)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958999%2fallow-admin-to-bypass-required-fields-in-certain-situations-with-acf%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Ok, found a way to do this - this is a way to do it for the User screen, it may differ for other post types.



            We not only have to disable server side validation, but also client side validation, to do this, we do something a little like this:



            add_action('acf/input/admin_head', 'my_acf_admin_head');

            function my_acf_admin_head() {

            if (!function_exists('get_current_screen')) {
            return;
            }

            // Get current page/screen
            $screen = get_current_screen();

            // Get current user
            $user = wp_get_current_user();

            if (is_object($screen) and is_a($screen, 'WP_Screen')) {

            if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
            ?>
            <script type="text/javascript">
            window.acf.validation.active = false;
            </script>
            <?php
            }

            }

            }


            This will add some Javascript to any page that matches our qualifers to disable ACF client-side validation.



            Now, to disable backend validation, we do something like this:



            add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);

            function my_acf_validate_save_post() {

            if (!function_exists('get_current_screen')) {
            return;
            }

            // Get current page/screen
            $screen = get_current_screen();

            // Get current user
            $user = wp_get_current_user();

            if (is_object($screen) and is_a($screen, 'WP_Screen')) {

            if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
            // clear all errors so they can bypass validation for user data
            acf_reset_validation_errors();
            }

            }

            }


            Note that because get_current_screen() isn't always available, these methods do not support front end forms.



            Also note that this code could definitely be improved to be a lot more DRY, but I will leave that up to you. :)






            share|improve this answer




























              0














              Ok, found a way to do this - this is a way to do it for the User screen, it may differ for other post types.



              We not only have to disable server side validation, but also client side validation, to do this, we do something a little like this:



              add_action('acf/input/admin_head', 'my_acf_admin_head');

              function my_acf_admin_head() {

              if (!function_exists('get_current_screen')) {
              return;
              }

              // Get current page/screen
              $screen = get_current_screen();

              // Get current user
              $user = wp_get_current_user();

              if (is_object($screen) and is_a($screen, 'WP_Screen')) {

              if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
              ?>
              <script type="text/javascript">
              window.acf.validation.active = false;
              </script>
              <?php
              }

              }

              }


              This will add some Javascript to any page that matches our qualifers to disable ACF client-side validation.



              Now, to disable backend validation, we do something like this:



              add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);

              function my_acf_validate_save_post() {

              if (!function_exists('get_current_screen')) {
              return;
              }

              // Get current page/screen
              $screen = get_current_screen();

              // Get current user
              $user = wp_get_current_user();

              if (is_object($screen) and is_a($screen, 'WP_Screen')) {

              if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
              // clear all errors so they can bypass validation for user data
              acf_reset_validation_errors();
              }

              }

              }


              Note that because get_current_screen() isn't always available, these methods do not support front end forms.



              Also note that this code could definitely be improved to be a lot more DRY, but I will leave that up to you. :)






              share|improve this answer


























                0












                0








                0







                Ok, found a way to do this - this is a way to do it for the User screen, it may differ for other post types.



                We not only have to disable server side validation, but also client side validation, to do this, we do something a little like this:



                add_action('acf/input/admin_head', 'my_acf_admin_head');

                function my_acf_admin_head() {

                if (!function_exists('get_current_screen')) {
                return;
                }

                // Get current page/screen
                $screen = get_current_screen();

                // Get current user
                $user = wp_get_current_user();

                if (is_object($screen) and is_a($screen, 'WP_Screen')) {

                if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
                ?>
                <script type="text/javascript">
                window.acf.validation.active = false;
                </script>
                <?php
                }

                }

                }


                This will add some Javascript to any page that matches our qualifers to disable ACF client-side validation.



                Now, to disable backend validation, we do something like this:



                add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);

                function my_acf_validate_save_post() {

                if (!function_exists('get_current_screen')) {
                return;
                }

                // Get current page/screen
                $screen = get_current_screen();

                // Get current user
                $user = wp_get_current_user();

                if (is_object($screen) and is_a($screen, 'WP_Screen')) {

                if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
                // clear all errors so they can bypass validation for user data
                acf_reset_validation_errors();
                }

                }

                }


                Note that because get_current_screen() isn't always available, these methods do not support front end forms.



                Also note that this code could definitely be improved to be a lot more DRY, but I will leave that up to you. :)






                share|improve this answer













                Ok, found a way to do this - this is a way to do it for the User screen, it may differ for other post types.



                We not only have to disable server side validation, but also client side validation, to do this, we do something a little like this:



                add_action('acf/input/admin_head', 'my_acf_admin_head');

                function my_acf_admin_head() {

                if (!function_exists('get_current_screen')) {
                return;
                }

                // Get current page/screen
                $screen = get_current_screen();

                // Get current user
                $user = wp_get_current_user();

                if (is_object($screen) and is_a($screen, 'WP_Screen')) {

                if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
                ?>
                <script type="text/javascript">
                window.acf.validation.active = false;
                </script>
                <?php
                }

                }

                }


                This will add some Javascript to any page that matches our qualifers to disable ACF client-side validation.



                Now, to disable backend validation, we do something like this:



                add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);

                function my_acf_validate_save_post() {

                if (!function_exists('get_current_screen')) {
                return;
                }

                // Get current page/screen
                $screen = get_current_screen();

                // Get current user
                $user = wp_get_current_user();

                if (is_object($screen) and is_a($screen, 'WP_Screen')) {

                if (($screen->id == 'user-edit' or ($screen->id == 'user' and $screen->action == 'add')) and in_array('administrator', $user->roles)) {
                // clear all errors so they can bypass validation for user data
                acf_reset_validation_errors();
                }

                }

                }


                Note that because get_current_screen() isn't always available, these methods do not support front end forms.



                Also note that this code could definitely be improved to be a lot more DRY, but I will leave that up to you. :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 28 '18 at 17:38









                BrettBrett

                6,24739114220




                6,24739114220






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958999%2fallow-admin-to-bypass-required-fields-in-certain-situations-with-acf%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas

                    Can't read property showImagePicker of undefined in react native iOS