I’m not sure why you are using exit() in your
reactivatejs()` method as this breaks the method before it even loads your script (hopefully this is for debugging purposes).
I also do think that in is unnecessary to create a class to this, a simple spaghetti function would do perfectly. Anyways, if you need to use a class, the class’s constructor is not suppose to any work, the constructor is suppose to initialize the class. You would want to to take your action outside of the constructor. Also, when it comes to removing scripts and styles, you would want to deregister and dequeue.
Here are possible solutions:
CLOSURES – not really recommended as they cannot be removed
add_action( 'wp_enqueue_scripts', function ()
{
// Remove your script
wp_dequeue_script( 'twentyfourteen-script' );
wp_deregister_script( 'twentyfourteen-script' );
// Add new script
wp_enqueue_script( 'lets-be-unique-here', get_stylesheet_directory_uri() . '/js/functions.js', ['jquery'], '20140616', true );
}, 100 );
NORMAL SPAGHETTI
add_action( 'wp_enqueue_scripts', 'addjs', 100 );
function addjs()
{
// Remove your script
wp_dequeue_script( 'twentyfourteen-script' );
wp_deregister_script( 'twentyfourteen-script' );
// Add new script
wp_enqueue_script( 'lets-be-unique-here', get_stylesheet_directory_uri() . '/js/functions.js', ['jquery'], '20140616', true );
}
CLASS WITH ACTION OUTSIDE
class AddJS
{
public function addjs ()
{
// Remove your script
wp_dequeue_script( 'twentyfourteen-script' );
wp_deregister_script( 'twentyfourteen-script' );
// Add new script
wp_enqueue_script( 'lets-be-unique-here', get_stylesheet_directory_uri() . '/js/functions.js', ['jquery'], '20140616', true );
}
}
THEN
add_action( 'wp_enqueue_scripts', ['AddJS','addjs'], 100 );
OR
$addjs = new AddJS();
add_action( 'wp_enqueue_scripts', [$addjs,'addjs'], 100 );
CLASS WITH ACTION INSIDE CLASS
class AddJS
{
public function addAction ()
{
add_action( 'wp_enqueue_scripts', [$this,'addjs'], 100 );
}
public function addjs ()
{
// Remove your script
wp_dequeue_script( 'twentyfourteen-script' );
wp_deregister_script( 'twentyfourteen-script' );
// Add new script
wp_enqueue_script( 'lets-be-unique-here', get_stylesheet_directory_uri() . '/js/functions.js', ['jquery'], '20140616', true );
}
}
$addjs = new AddJS();
$addjs->addjs();