Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. WordPress (Developer)
  3. Cron tasks

Cron tasks

Scheduled Pinned Locked Moved Solved WordPress (Developer)
35 Posts 3 Posters 3.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mdreiraM mdreira

    @girish As I don't understand anything about php, I don't really know what's going on. πŸ˜…

    Is the error you're seeing something on our side or is the side of plugin guys?

    girishG Offline
    girishG Offline
    girish
    Staff
    wrote on last edited by
    #26

    @mdreira I don't understand either. It seems that global variables get reset immediately after global xx when using WP CLI. I don't get why.

    1 Reply Last reply
    0
    • mdreiraM mdreira

      @girish As I don't understand anything about php, I don't really know what's going on. πŸ˜…

      Is the error you're seeing something on our side or is the side of plugin guys?

      girishG Offline
      girishG Offline
      girish
      Staff
      wrote on last edited by girish
      #27

      @mdreira OK, I found the issue. The usage of global is incorrect in the plugin. The global keyword is for stating the use of a global variable (as opposed to 'make this variable global').

      With that in mind, the code in the plugin's constant.php is like this:

      <?php
      
      $OIWE_API_URL = "http://apiv1.optimizador.io:80/";
      global $OIWE_API_URL ;
      
      

      The above code will break when the above file is included from a "function". This is the case when we use WP CLI where entire WordPress is loaded into a function. So, for example, the rough equivalent is:

      function load() {
          require_once(".../constants.php");
      }
      

      When it's like above, the global $OIWE_API_URL keyword then says, use OIWE_API_URL from global context, which is not the same as the one you defined one line above (it's a function local variable). So, the solution is to move the global keyword before setting it in constants.php. Like this:

      global $OIWE_API_URL ;
      $OIWE_API_URL = "http://apiv1.optimizador.io:80/";
      
      // .. do same for other constants in the file ..
      

      Of course, this is why globals are not used in WP plugins. You should use superglobals like $GLOBAL or define or database etc. See https://codex.wordpress.org/Global_Variables and https://onlinewebtutorblog.com/wordpress-global-variables-step-by-step-complete-guide/

      mdreiraM 1 Reply Last reply
      2
      • girishG girish

        @mdreira OK, I found the issue. The usage of global is incorrect in the plugin. The global keyword is for stating the use of a global variable (as opposed to 'make this variable global').

        With that in mind, the code in the plugin's constant.php is like this:

        <?php
        
        $OIWE_API_URL = "http://apiv1.optimizador.io:80/";
        global $OIWE_API_URL ;
        
        

        The above code will break when the above file is included from a "function". This is the case when we use WP CLI where entire WordPress is loaded into a function. So, for example, the rough equivalent is:

        function load() {
            require_once(".../constants.php");
        }
        

        When it's like above, the global $OIWE_API_URL keyword then says, use OIWE_API_URL from global context, which is not the same as the one you defined one line above (it's a function local variable). So, the solution is to move the global keyword before setting it in constants.php. Like this:

        global $OIWE_API_URL ;
        $OIWE_API_URL = "http://apiv1.optimizador.io:80/";
        
        // .. do same for other constants in the file ..
        

        Of course, this is why globals are not used in WP plugins. You should use superglobals like $GLOBAL or define or database etc. See https://codex.wordpress.org/Global_Variables and https://onlinewebtutorblog.com/wordpress-global-variables-step-by-step-complete-guide/

        mdreiraM Offline
        mdreiraM Offline
        mdreira
        translator
        wrote on last edited by
        #28

        @girish Then.. what should I do?.

        Do I have to tell the plugin guys that they should move the globals in constants.php file or rather use superglobals?

        I have no idea how to tell them this. Can we do something from our side?

        girishG 1 Reply Last reply
        0
        • mdreiraM mdreira

          @girish Then.. what should I do?.

          Do I have to tell the plugin guys that they should move the globals in constants.php file or rather use superglobals?

          I have no idea how to tell them this. Can we do something from our side?

          girishG Offline
          girishG Offline
          girish
          Staff
          wrote on last edited by
          #29

          @mdreira said in Cron tasks:

          @girish Then.. what should I do?.

          Sorry, I wasn't clear. Please send the plugin authors the link to my comment. There is nothing we can do, they have to fix the plugin. They can easily reproduce this by running cron tasks using the WP CLI tool outside Cloudron. WP CLI is pretty much part of standard WP - https://make.wordpress.org/cli/handbook/

          mdreiraM 2 Replies Last reply
          2
          • girishG girish

            @mdreira said in Cron tasks:

            @girish Then.. what should I do?.

            Sorry, I wasn't clear. Please send the plugin authors the link to my comment. There is nothing we can do, they have to fix the plugin. They can easily reproduce this by running cron tasks using the WP CLI tool outside Cloudron. WP CLI is pretty much part of standard WP - https://make.wordpress.org/cli/handbook/

            mdreiraM Offline
            mdreiraM Offline
            mdreira
            translator
            wrote on last edited by
            #30

            @girish you are the best!!

            1 Reply Last reply
            0
            • girishG girish

              @mdreira said in Cron tasks:

              @girish Then.. what should I do?.

              Sorry, I wasn't clear. Please send the plugin authors the link to my comment. There is nothing we can do, they have to fix the plugin. They can easily reproduce this by running cron tasks using the WP CLI tool outside Cloudron. WP CLI is pretty much part of standard WP - https://make.wordpress.org/cli/handbook/

              mdreiraM Offline
              mdreiraM Offline
              mdreira
              translator
              wrote on last edited by mdreira
              #31

              @girish Just one more question. I guess the problem with global variables is not only in constants.php file, right? Surely there are several files that are involved...

              I'm saying this, because I've repositioned the variables in constants.php file like you said, and it still doesn't work.

              girishG 1 Reply Last reply
              0
              • mdreiraM mdreira

                @girish Just one more question. I guess the problem with global variables is not only in constants.php file, right? Surely there are several files that are involved...

                I'm saying this, because I've repositioned the variables in constants.php file like you said, and it still doesn't work.

                girishG Offline
                girishG Offline
                girish
                Staff
                wrote on last edited by
                #32

                @mdreira TBH, I was only "guessing" what the solution might be after identifying the issue. I don't 100% know for sure if it solves the issue. Are you getting the same error? Did the plugin authors have any comments?

                mdreiraM 1 Reply Last reply
                0
                • girishG girish

                  @mdreira TBH, I was only "guessing" what the solution might be after identifying the issue. I don't 100% know for sure if it solves the issue. Are you getting the same error? Did the plugin authors have any comments?

                  mdreiraM Offline
                  mdreiraM Offline
                  mdreira
                  translator
                  wrote on last edited by
                  #33

                  @girish What I did was modify the constants file like this:
                  Captura de pantalla 2022-02-14 a las 20.02.52.jpg

                  Then I ran the cron:
                  Captura de pantalla 2022-02-14 a las 20.04.05.jpg

                  This time it didn't give any specific error message.

                  The plugin guys just thanked us for the feedback. I still don't have any concrete answer from them.

                  girishG 1 Reply Last reply
                  0
                  • mdreiraM mdreira

                    @girish What I did was modify the constants file like this:
                    Captura de pantalla 2022-02-14 a las 20.02.52.jpg

                    Then I ran the cron:
                    Captura de pantalla 2022-02-14 a las 20.04.05.jpg

                    This time it didn't give any specific error message.

                    The plugin guys just thanked us for the feedback. I still don't have any concrete answer from them.

                    girishG Offline
                    girishG Offline
                    girish
                    Staff
                    wrote on last edited by
                    #34

                    @mdreira I think one has to debug that plugin more to find other issues, I only found on of the main issues TBH. It's clear the plugin is not designed to work with WP CLI, so I think that it won't work inside Cloudron unless they fix the plugin.

                    I think if you really need this exact plugin, you have to switch to LAMP stack and then configure cron as however it works with this plugin. Another idea is to maybe make it possible to disable Cloudron's cron and use WP_CRON but this is not really an option for production sites.

                    mdreiraM 1 Reply Last reply
                    1
                    • girishG girish

                      @mdreira I think one has to debug that plugin more to find other issues, I only found on of the main issues TBH. It's clear the plugin is not designed to work with WP CLI, so I think that it won't work inside Cloudron unless they fix the plugin.

                      I think if you really need this exact plugin, you have to switch to LAMP stack and then configure cron as however it works with this plugin. Another idea is to maybe make it possible to disable Cloudron's cron and use WP_CRON but this is not really an option for production sites.

                      mdreiraM Offline
                      mdreiraM Offline
                      mdreira
                      translator
                      wrote on last edited by
                      #35

                      @girish It's a shame, I'll have to change the plugin

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Bookmarks
                      • Search