• Resolved strictly-software

    (@strictly-software)


    Hi

    Seeing I have massive problems with Jetpack on my site (see other posts from me) when emailed posts come into the site and then processed by a plugin called POSTIE (Publicize doesn’t work – and my auto tagger system doesn’t either)

    I wondered if there was any code I could use to automatically activate Jetpack and then de-activate at certain times of the day so that I could set up a CRON job to run a script to de-activate Jetpack before my emailed posts go in and then another to activate it AFTER the emailed posts have worked.

    I don’t know if simple activate / deactivate (register) actions would work or not or would it fail because I would need to re-link Jetpack to WordPress.com each time?

    Thanks

    https://www.ads-software.com/plugins/jetpack/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    would it fail because I would need to re-link Jetpack to WordPress.com each time?

    It would indeed. You won’t be able to automate that process I’m afraid. Re-linking Jetpack to WordPress.com requires a manual confirmation.

    You can, however, deactivate Jetpack modules instead, thanks to the deactivate_module function:
    https://www.ads-software.com/support/topic/programmatically-set-module-activationdeactivation?replies=3&view=all#post-4330043

    You can then use the activate_module to activate the module back:
    https://github.com/Automattic/jetpack/blob/3.5.3/class.jetpack.php#L2003

    Thread Starter strictly-software

    (@strictly-software)

    Hi

    I am getting Database locked errors when trying to follow the links.

    Do you have a code example snippet I could use in a plugin activated by a CRON job to deactivate / activate the Publicize plugin?

    Thanks

    Rob

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Do you have a code example snippet I could use in a plugin activated by a CRON job to deactivate / activate the Publicize plugin?

    To deactivate Publicize:

    function jeherve_kill_publicize() {
    	if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'publicize' ) ) {
    		Jetpack::deactivate_module(  'publicize' );
    	}
    }
    add_action( 'init', 'jeherve_kill_publicize' );

    And to activate it:

    function jeherve_activate_publicize() {
    	if ( class_exists( 'Jetpack' ) && ! Jetpack::is_module_active( 'publicize' ) ) {
    		Jetpack::activate_module(  'publicize' );
    	}
    }
    add_action( 'init', 'jeherve_activate_publicize' );

    However if you want to deactivate it before to post, and activate it back after posting, you’re probably better off deactivating Publicize and leaving it deactivated. There is no use activating it if you don’t use it.

    Thread Starter strictly-software

    (@strictly-software)

    Hi

    No it’s not that often. It’s just that there seems to be some sort of weird conflict between Jetpack and another plugin called Postie which accepts emails into the system as articles (with tags/categories/images etc) – and when Publicize is on I just get draft articles and they don’t get posted.

    I just want to turn it off before the emails go in, then turn it on again afterwards. I have my own plugin Strictly TweetBot which will tweet out the articles (linked to Facebook) – and then all the other articles come from feeds so there is no problem with Publicize.

    Thanks for the code!

    Rob

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Code to auto activate/de-activate Jetpack at certain times of the day’ is closed to new replies.