Support

Account

Forum Replies Created

  • The problem is that the custom “setup” function is overriding the ACF one, which prevents ACF from listening to the “change” event of the TinyMCE instance.

    Without this listener, the ACF Block won’t be able to detect a “change”, which prevents it from saving/updating.

    The solution is to create a backup of the original setup function and call that within the custom one. Like so:

    function custom_acf_tinymce() {
    ?>
    <script>
    acf.add_filter('wysiwyg_tinymce_settings', function(mceInit, id, $field) {
    	var _setup = mceInit.setup;
    	mceInit.setup = function(editor) {
    		_setup.apply(this, arguments);
    		editor.on('click', function(e) {
    			console.log('Editor was clicked');
    		});
    	};
    	return mceInit;
    });
    </script>
    <?php
    }
    add_action('acf/input/admin_footer', 'custom_acf_tinymce');
  • I needed to do almost exactly the same thing as the original poster and luckily I found this thread.

    +1 Thanks John!

  • Hi John,

    Thanks for your input. Using your method for logging the $_POST data, this is the result:

    Array
    (
        [name] => test.png
        [action] => upload-attachment
        [_wpnonce] => dee97d17e2
        [_acfuploader] => field_5a856f0eb49d7
    )

    So, there’s nothing being sent about the origin page, just the ACF field’s key.

    I guess the only and easiest way is just to create an array of all the fields (potentially only about 10, not that many in my use case). This is how I’ve solved it:

    $fields = array('field_1', 'field_2', 'field_3');
    
    foreach ($fields as $field) {
        add_filter("acf/upload_prefilter/name=$field", function($errors) {
            add_filter('upload_dir', function($uploads) {
                $dir = '/options';
                $uploads['url'] = $uploads['baseurl'] . $dir;
                $uploads['path'] = $uploads['basedir'] . $dir;
                return $uploads;
            });
            return $errors;
        });
    }
  • Yeah, after I published my thread I noticed that a “-2” was added to the end of the page URL slug, so I naturally got curious, removed the “-2” and found your original thread from 2014. 🙂

    I guess that 2018 would finally be the year that ACF would get a native code field. Fingers crossed.

  • I submitted a new ticket and Elliot replied that he’ll consider adding it in a future version. 🙂

    I was also playing around with the new WordPress code editor in the Customizer and it works pretty good, I love that there’s also support for real-time code linting.

Viewing 5 posts - 1 through 5 (of 5 total)