Want to subscribe to topics you're interested in?
Become a Member

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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    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

    168
    47
    28
    Nov 8, 2015
    Ratings:
    +87
    Local Time:
    9:18 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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    could add such an include sourced file after the domain vhost ones so it overrides the domain ones. Will test and see :)
     
    • Like Like x 1
  5. ethanpil

    ethanpil Active Member

    168
    47
    28
    Nov 8, 2015
    Ratings:
    +87
    Local Time:
    9:18 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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    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

    168
    47
    28
    Nov 8, 2015
    Ratings:
    +87
    Local Time:
    9:18 PM
    ahh, yes priority. love it!! i cant wait to test it.
     
  8. ethanpil

    ethanpil Active Member

    168
    47
    28
    Nov 8, 2015
    Ratings:
    +87
    Local Time:
    9:18 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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    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
    • Like Like x 1
    • Winner Winner x 1
  10. apidevlab

    apidevlab Member

    88
    30
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +54
    Local Time:
    12:18 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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    yup has to be set before running centmin.sh menu option 22
     
  12. apidevlab

    apidevlab Member

    88
    30
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +54
    Local Time:
    12:18 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

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    ah need to check that :) that variable is 123.09beta01+ and higher only though
     
  14. apidevlab

    apidevlab Member

    88
    30
    18
    Mar 22, 2016
    /dev/null
    Ratings:
    +54
    Local Time:
    12:18 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
     
    • Like Like x 1
  15. eva2000

    eva2000 Administrator Staff Member

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    9:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    excellent to hear :D