Learn about Centmin Mod LEMP Stack today
Register Now

Beta Branch update inc/wpsetup.inc add new mywpcmds routine

Discussion in 'Centmin Mod Github Commits' started by eva2000, Feb 10, 2016.

  1. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    update inc/wpsetup.inc add new mywpcmds routine

    Allow centmin mod users running centmin.sh menu option 22 to add their own custom wp-cli commands to customise their wordpress installations. For example using wp-cli command to install a specific wordpress language https://community.centminmod.com/posts/26045/.

    The centmin mod user before running centmin.sh menu option 22, will create a custom file at /etc/centminmod/customwp_domain.com.inc where domain.com is the intended centmin.sh menu option 22 vhost site domain for your wp installation. Then in that file add your wp-cli commands to the file wrapped in a shell function named mywpcmds() { yourcode }. i.e. for wp language install https://community.centminmod.com/posts/26045/ the new routine in inc/wpsetup.inc will check for /etc/centminmod/customwp_domain.com.inc file and then source include it into this routine and run the shell function named mywpcmds which contains your custom wp-cli cmds that will trigger and run

    For example to add a wordpress language to your centmin.sh menu option 22 wordpress installation, create file at /etc/centminmod/customwp_domain.com.inc and create a base function called mywpcmds. List of commands at Built-in Commands | WP-CLI

    Code:
    mywpcmds() {
    YOUR WP-CLI COMMANDS GO HERE
    }
    
    So if you want to install French language - a list of language codes for Wordpress at https://community.centminmod.com/posts/26045/, for domain.com you would create file named /etc/centminmod/customwp_domain.com.inc and add to it
    Code:
    mywpcmds() {
    wp core language install fr_FR --activate --allow-root
    }
    
    Then run centmin.sh menu option 22 to install wordpress on domain.com and automatically, the inc/wpsetup.inc routines will pick up the file at /etc/centminmod/customwp_domain.com.inc and source it into the install routine and run mywpcmds function and whatever commands are located in the function. They will be run relative to your wordpress web root directory which would be for domain.com at /home/nginx/domains/domain.com/public

    Continue reading...


    123.09beta01 branch
     
    Last edited: Feb 10, 2016
  2. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Technically mywpcmds shell function isn't limited to just wp-cli commands, you could run any usual shell commands you usually run in SSH as root user. For example, if you need to install French wordpress language + create a directory in your wordpress install at domain.com/mydir located at /home/nginx/domains/domain.com/public/mydir
    Code:
    mywpcmds() {
    wp core language install fr_FR --activate --allow-root
    mkdir -p mydir
    }
    if you need to download your own favicon.ico file to web root at /home/nginx/domains/domain.com/public
    Code:
    mywpcmds() {
    wget -cnv http://sitewhereyour/favicon.ico
    }
    or install your own wordpress plugin(s) from wordpress plugin directory at WordPress Plugins via wp plugin | WP-CLI i.e. install duplicate posts plugin wordpress.org/plugins/duplicate-post/
    Code:
    mywpcmds() {
    wp plugin install duplicate-post --allow-root
    }
    or install + activate duplicate-post plugin
    Code:
    mywpcmds() {
    wp plugin install duplicate-post --activate --allow-root
    }
    or install + activate a specific wordpress theme from wordpress theme directory at Theme Directory — Free WordPress Themes via wp theme | WP-CLI Like customizr at wordpress.org/themes/customizr/
    Code:
    mywpcmds() {
    wp theme install customizr --activate --allow-root
    }
     
    Last edited: Feb 10, 2016
  3. ethanpil

    ethanpil Active Member

    173
    55
    28
    Nov 8, 2015
    Ratings:
    +101
    Local Time:
    11:08 PM
    What do you think about including a default commands file for all installs besides the domain based file? So we can setup the plugins, settings and themes we like in all installs to use...
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    could add such an include sourced file after the domain vhost ones so it overrides the domain ones. Will test and see :)
     
  5. ethanpil

    ethanpil Active Member

    173
    55
    28
    Nov 8, 2015
    Ratings:
    +101
    Local Time:
    11:08 PM
    Why overrule, just in addition.... So we know for example, by default all new WP will get Yoast SEO and Wordfence, and then we can also setup unique plugins, themes for a new domain in the second file...
     
  6. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    i have to deal with all possible choice combinations, what if a user doesn't want the defaults on a few specific domain vhost installs ? they won't be able to set that

    i guess override is the wrong word, more priority

    • so if you want domain specific plugin, set in domain include file
    • if you want default for all domain vhosts, set int global include file
     
  7. ethanpil

    ethanpil Active Member

    173
    55
    28
    Nov 8, 2015
    Ratings:
    +101
    Local Time:
    11:08 PM
    ahh, yes priority. love it!! i cant wait to test it.
     
  8. ethanpil

    ethanpil Active Member

    173
    55
    28
    Nov 8, 2015
    Ratings:
    +101
    Local Time:
    11:08 PM
    I agree to have default custom commands and also domain specific commands. I have certain plugins I ALWAYS install in WP.

    First we can do
    /etc/centminmod/customwp_default.inc

    Then
    /etc/centminmod/customwp_domain.com.inc
     
  9. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    with shell scripting it's easy to make use of existing /etc/centminmod/customwp_domain.com.inc include file to reference and include another include file i.e. /etc/centminmod/customwp_default.inc

    in /etc/centminmod/customwp_default.inc file for example to post-install, install cutomizr wordpress theme via wp-cli command and then run the mywpdftcmds function referenced in /etc/centminmod/customwp_default.inc
    Code (Text):
    mywpcmds() {
      if [ -f /etc/centminmod/customwp_default.inc ]; then
        . /etc/centminmod/customwp_default.inc
      fi
    
      wp theme install customizr --activate --allow-root
      mywpdftcmds
    }
    

    then in /etc/centminmod/customwp_default.inc file add your own default mywpdftcmds function like install French language and create directory mydir in wordpress web root
    Code (Text):
    mywpdftcmds() {
      wp core language install fr_FR --activate --allow-root
      mkdir -p mydir
    }
    

    then when you run centmin.sh menu option 22 in 123.09beta01, after the base wordpress install and setup it will trigger mywpcmds function which will check if /etc/centminmod/customwp_default.inc exists and if it does source include (the dot .) the /etc/centminmod/customwp_default.inc file and any functions contained (i.e. mywpdftcmds)
     
    Last edited: Jul 25, 2016
  10. apidevlab

    apidevlab Member

    91
    33
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +58
    Local Time:
    1:08 PM
    1.11.1
    5.2.14-122
    Code (Text):
    if [ -f "${CONFIGSCANBASE}/customwp_${vhostname}.inc" ]; then
        # default is at /etc/centminmod/customwp_${vhostname}.inc
        source "${CONFIGSCANBASE}/customwp_${vhostname}.inc"


    EDIT: Have just spotted in the code, can confirm this means that a file customwp_${vhostname}.inc must be set BEFORE running wp install option 22

    I guess so but the reference to customwp_domain.com.inc threw me
     
    Last edited: Mar 28, 2017
  11. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yup has to be set before running centmin.sh menu option 22
     
  12. apidevlab

    apidevlab Member

    91
    33
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +58
    Local Time:
    1:08 PM
    1.11.1
    5.2.14-122
    P.S Despite setting WPPLUGINS_ALL='y' in custom_config.inc I NEVER see these plugins installed, can we give wpsetup.inc some love, am happy to try and work with you on it.
     
    Last edited: Mar 28, 2017
  13. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    ah need to check that :) that variable is 123.09beta01+ and higher only though
     
  14. apidevlab

    apidevlab Member

    91
    33
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +58
    Local Time:
    1:08 PM
    1.11.1
    5.2.14-122
    Happy to report that since I wrote that I was able to get the WPPLUGINS_ALL='y' to work. After some experimentation I have been able to setup the plugins I required and offer some additional themes via the current y/n option.

    Code (Text):
    if [[ "$magnustheme" = [yY] ]]; then
      cecho "------------------------------------------------------------" $boldgreen
      \wp theme install magnus --activate --allow-root
    #  cecho "------------------------------------------------------------" $boldgreen
    fi
    


    Just learning as I go really but the WP side of things is one of the most powerful and useful parts IMHO
     
  15. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    excellent to hear :D
     
  16. Mrbo

    Mrbo Member

    113
    7
    18
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    8:08 PM
    Hi, just found this great post. If I understand it right, if I want a global setup I just have to create the file customwp_default.inc and include what plugins and themes I want included?

    Do I need to add WPPLUGINS_ALL='y' to custom_config.inc?

    Lastly, is there a way to exclude all the default plugins that comes with the default wordpress installation through menu option 22?
     
  17. apidevlab

    apidevlab Member

    91
    33
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +58
    Local Time:
    1:08 PM
    1.11.1
    5.2.14-122
    The short answer (IFRC) is yes, it's been a while since I used Centminmod (busy with a 9/5 un-related job) but am pretty certain I just hacked into the main wp setup file and simply commented out the plugins I didn't need.

    Am sure @eva2000 will be along with a more elegant explanation...

    I am planning to dive back into CM over the next few weeks ESPECIALLY with WP as for my current projects this is my 'daily driver'
     
  18. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:08 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    @apidevlab thanks for chiming in :)

    no you don't need to enable that, hence all those extra wp plugins won't be installed
     
  19. Mrbo

    Mrbo Member

    113
    7
    18
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    8:08 PM
    Is it possible to define wp memory in wp-config.php? I checked this guide but i dont understand how to set up the command?

    Something like this?
    Code:
    wp config set define( 'WP_MEMORY_LIMIT', '128M' ); --placement=/* That's all, stop editing! Happy blogging. */ --raw
    wp config set define( 'WP_MAX_MEMORY_LIMIT', '256M' ); --placement=/* That's all, stop editing! Happy blogging. */ --raw
     
  20. Mrbo

    Mrbo Member

    113
    7
    18
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    8:08 PM
    If I use wp rocket + autoptimize and dont use cache enabler, redis or wp supercache can I comment them like this?

    Code:
    #include /usr/local/nginx/conf/wpincludes/${vhostname}/wpcacheenabler_${vhostname}.conf;
      #include /usr/local/nginx/conf/wpincludes/${vhostname}/wpsupercache_${vhostname}.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/${vhostname}/rediscache_${vhostname}.conf;  
    Then add this:
    include /usr/local/nginx/rocket-nginx/default.conf;

    and uncomment
    # Wordpress Permalinks
    # try_files \$uri \$uri/ ${WPSUBDIR}/index.php?q=\$uri&\$args;


    Also, I saw in another tread that you advised somebody to change the name:
    include /usr/local/nginx/conf/php-wpsc.conf; to this:
    include /usr/local/nginx/conf/php.conf;
    Should I also do that or just comment it?