I guess you copied that code from somewhere. Just from reading through it, I don’t see wppf_gallery_ids
set anywhere aside from the init
function, which means that it can’t update anything as the check is empty. I see two options: Either update it during selection within the select
function, or just push wppf_new_ids
into the wppf_gallery_ids
array.
To me it seems that both variables wppf_new_ids/_gallery_ids
have pretty much the same functionality and one could get dropped.
Aside from that, you should wrap your whole piece of code in a self executing function and push the globals into it:
( function( $ ) {
'use strict';
// your code
} )( jQuery || {} );
That also means that you can use $
instead of jQuery
.
Another thing that I’d avoid is polluting the global namespace. When you just add GalleryControl
like you did, then you already have window.GalleryControl
set. With such a generic name, a collision with other code will likely happen yesterday than tomorrow. Better style is to use your own, already existing namespace on the window
object: wppf
. That means your final wrapper could look like this:
( function( $ ) {
'use strict';
var gallery;
gallery.init = function() {
//
};
gallery.frame = function() {
//
};
gallery.select = function() {
//
};
gallery.updateFrame = function() {
//
};
window.wppf = window.wppf || {};
window.wppf.gallery = window.wppf.gallery || {};
window.wppf.gallery = new gallery();
} )( jQuery || {} );
More on that topic in excellent article about JS Objects.