WP CLI Call to undefined function apply_filters()

Doing a BackupBuddy backup from the commandline using WP CLI on a GoDaddy server the other day I ran into a fatal error. A WP CLI Call to undefined function apply_filters() error to be precise. It did not allow me to backup from the command line at all. The site was running fine.

Anyways, the error I got running the command:

wp backupbuddy backup 2

was the following one:

Fatal error: Call to undefined function apply_filters() in /home/user/public_html/wordpress/wp-includes/load.php on line 317

Troubleshooting

Googling the issue I found out that many websites were displaying similar issues. And no solutions really but to remove the core files and replace them with a fresh set or turning off all plugins and checking if that helps. The basics. But then I stumbled upon this SO thread. There the suggestion was to see if wp cli could be updated. And then I remembered wp cli having some issues with Trellis and WordPress 4.6. And I thought, yeah, that could be it!

Updating WP CLI to 0.24.1

So I ran the updater using the following command:

wp cli update

and it worked updating it all:

 wp cli update

You have version 0.22.0. Would you like to update to 0.24.1? [y/n] y

Downloading from https://github.com/wp-cli/wp-cli/releases/download/v0.24.1/wp-cli-0.24.1.phar...

New version works. Proceeding to replace.

Success: Updated WP-CLI to 0.24.1

WP CLI BackupBuddy Re-Run

After that I ran the command to backup the site again:

wp backupbuddy backup 2

It did not spit out the same error again, but it did take its sweet time showing some feedback. After like 2 minutes it mentioned zip functionality it could not find as usual and then proceeded to do the backup.

Happy ending!

NB Reasons for using wp cli for BB backups on GoDaddy and installation instructions are mentioned here if you need them.

Trellis Media Migration

When you work with a Trellis WordPress LEMP setup to manage a client site migration is set up pretty well. You can use scripts for server provisioning and site deployment. However, there are certain things that will / should not be in your git repository. These items will not be synched. Media in the uploads folder is one of them. Let me explain the reasons behind this and how Trellis media migration can be achieved.

Bedrock Ignores Uploads

Certain files and or directories are ignored by default using a .gitignore in Bedrock. This is because they will not stay the same locally and and live. They are often too big to be kept there or they are managed and installed by composer. The complete ignore list for Bedrock is:

 

# Application
web/app/plugins/*
!web/app/plugins/.gitkeep
web/app/mu-plugins/*/
web/app/upgrade
web/app/uploads/*
!web/app/uploads/.gitkeep

# WordPress
web/wp
web/.htaccess

# WP-CLI
db-sync
sql-dump-*.sql

# Dotenv
.env
.env.*
!.env.example

# Vendor (e.g. Composer)
vendor/*
!vendor/.gitkeep

# Node Package Manager
node_modules

# Vagrant
bin
.vagrant

One of the elements that are not in the repository and ignored using a .gitignore file are all the images and other media in the uploads folder. This is because they often take up too much space in a repo. And as said because often content on local server and remote server are not the same.

Synchronizing Media

Sometimes you do want to synch local media with the staging or remote server though. You may have set up a site with basic pages and posts including images and other files locally. In that case you do not just want to migrate the files and start from scratch. You then want to move the files, database and all media. To move all media files there are two things you can do. You can either sftp all files to the server as admin or use an Ansible Playbook to synchronise them.

SFTP Uploads

You can use SFTP and SCP to upload all to the server. Then you use SSH to move it to the right location and change the rights and permissions. Swalkinshaw suggested the following here:

  • SFTP uploads to /home/admin/uploads
  • SSH in as admin ssh admin@domain.com
  • sudo su (use your admin pw) to become root
  • chown -R web:www-data /home/admin/uploads
  • su web (now you’re the web user)
  • Move/copy uploads to proper dir/srv/www/domain.com/shared/uploads using mv

As you can see these steps require an (S)FTP program like Filezilla to upload all and the terminal to move things around and change permissions. For most Trellis users not an issue really.

Ansible Playbook to Synch Media

CFX in the same Roots Discourse thread mentioned a playbook that is available at Github Gist. The script was made by Louis-Michel Couture. With it you can synchronize your uploads content by just running the script with the following simple command:

ansible-playbook uploads.yml -i hosts/staging --extra-vars="site=example.com mode=push"

You do need to make sure the uploads.yml is in your site’s web root. And you of course need to change the domain. Push is for going from local server to staging or production.

Here is the whole script as in the gist:

---
- name: Sync uploads between environments
  hosts: web
  remote_user: "{{ web_user }}"

  vars:
    project: "{{ wordpress_sites[site] }}"
    project_root: "{{ www_root }}/{{ site }}"

  tasks:
  # ansible-playbook uploads.yml -i hosts/staging --extra-vars="site=example.com mode=push"
  - name: Push uploads
    synchronize:
      src: "{{ project.local_path }}/web/app/uploads/"
      dest: "{{ project_root }}/current/web/app/uploads/"
      rsync_opts: --exclude=.DS_Store
    when: mode is not defined or mode == "push"

  # ansible-playbook uploads.yml -i hosts/staging --extra-vars="site=example.com mode=pull"
  - name: Pull uploads
    synchronize:
      src: "{{ project_root }}/current/web/app/uploads/"
      dest: "{{ project.local_path }}/web/app/uploads/"
      mode: pull
      rsync_opts: --exclude=.DS_Store
    when: mode is defined and mode == "pull"

I did use it and it works well. You just do not see progress and it can take some time for all the files to have been uploaded.

My favorite

In the end I think I would pick sftp. It does show you progress and there is the option to gzip or zip all before upload. This will be quicker. You will then have to ssh into the server, but if you are good at it this will be quicker. the Ansible Playbook is the lazier or easier option, but it will take more time.

WPLMS Setup on Trellis

Been working on getting WPLMS to run on Roots Trellis. It is for a new exciting startup project I have been working on. To quote WPLMS:

WPLMS is a Learning Management System for WordPress . It is suitable for Training Centres, Corporate trainings, Course tutors, College, Academy, University, School and MOOC platform. It is an e Learning WordPress theme for course management, instructor and student management using which you can create and sell your courses online.

Let me show you here you can get it all done smoothly on a Trellis LEMP / Bedrock setup. And with the avoiding of as many mistakes as possible. No need to make the same mistakes I made.

Initial WPML Setup Pains

Have run in quite a few issues. First issue was that importing the dummy data would not go smoothly. This due to quite a few issues, but here then main ones:

  • WP Importer interfering with the import and general errors. Had to deactivate it.
  • Many deprecated errors running on PHP 7 in the theme
  • Quite a few PHP Notices due to undefined indexes or variables. And when you run locally with XDebug turned on like you normally have in Trellis that is a huge pain.

Even after the latest update there were stil some eventOn plugin errors due to using class and function with the same name, but those I did solve.

Today I am going to do it all over again with the latest update. Let’s get started.

NB If you do a clean installation you do not need the next step.

Resetting the Local Setup

To reset the local setup and start all over again without loosing the general setup nor plugins and themes I use the plugin called WordPress Database Reset . Awesome plugin recommended by Arul at Smartpixels. I added it to the composer.json file using this line:

"wpackagist-plugin/wordpress-database-reset":"*"

After that I ran a composer update to update the site plugins and themes in the composer file and to get the WordPress Database Reset plugin:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing wpackagist-plugin/wordpress-database-reset (3.0.2)
    Downloading: 100%         
Writing lock file
Generating autoload files

Once you installed it you can use it to reset all database tables and restart without the WPLMS theme so you can start anew like you would with a clean installation.

Raising PHP Memory Limit in Trellis

This update should have attended to all these PHP errors and will make debugging a lot easier again. I also raised the memory in trellis/roles/php/main.yml to 128:

php_memory_limit: 128M

If you don’t it won’t be possibly to install the theme smoothly due to the many components it uses.

Then I removed the theme using:

rm -rf wplms/

Recommended Plugins

NB The installation of most plugins can wait as the theme will ask you for it later on. And this is also recommended by WPLMS. Only if I did not activate the dummy data plugin I could not install with it.

I did add all the necessary plugins and activated them before activating the theme. This as I had them installed before during initial failed attempts. Do not forget to update them when need be! You will see that one plugin eventOn still has errors in file

eventON/includes/class-evo-widget-main.php

But that error you can fix by renaming the functions in question to

__construct()

See PHP 7 deprecated information here.

Dummy Data plugin

Especially the dummy data plugin needs to be active. Otherwise the Theme setup installer will not offer to set up the theme with dummy content. I picked dummy data 2 and installed this plugin.

Plugins in use

Here is a list of plugins I have installed minus WP Job Manager I added later on. The latter is for this project specifically so you do not need it nor every plugin listed here. BackupBuddy is great for backups for example, but not recommended for WPLMS.

 

Plugins List

BuddyPress does seem to have issues with WPLMS still as I see these errors after I installed all the plugins including BuddyPress

( ! ) Notice: Trying to get property of non-object in /srv/www/domain.com/current/web/app/plugins/vibe-course-module/includes/bp-course-activity.php on line 193
( ! ) Notice: Trying to get property of non-object in /srv/www/trainerolo.com/current/web/app/plugins/vibe-course-module/includes/bp-course-activity.php on line 199
( ! ) Warning: Cannot modify header information - headers already sent by (output started at /srv/www/domain.com/current/web/app/plugins/vibe-course-module/includes/bp-course-activity.php:193) in /srv/www/domain.com/current/web/wp/wp-includes/pluggable.php on line 1174

So I initially deactivated it as you will see a little later on.

Theme Installation

Uploading the plugin zip file from appearance > themes with the zipped file had issues too. I got this NGINX error:

413 Request Entity Too Large

Cybercity explains here how you can fix this NGINX limitation. The NGINX config files are Trellis / Ansible managed though so would be could to change the roles, not the config files manually. What I did in the end was simply unzip and add to the themes folder. In your case it should perhaps run just fine and then you can move on and see what I saw in the next step

After uploading the theme folder with all its content it installed just fine. I got to see:

WPLMS Setup with Sample Data

 

Awesome! After that I was able to install all without issues. Meaning the sample data did get installed this way as well. This did take quite some time though. So do not interfere or freak out because it does not get all done in 10 seconds.

Afterwards you will be asked to make sure your permalinks are correct and that the BP Core Components are installed properly.

BP Core Components Missing

When I went back to the dashboard I did see these errors:

WordPress database error: [Table 'domain_com_development.wp_bp_messages_recipients' doesn't exist]
SELECT SUM(unread_count) FROM wp_bp_messages_recipients WHERE user_id = 1 AND is_deleted = 0 AND sender_only = 0

WordPress database error: [Table 'domain_com_development.wp_bp_friends' doesn't exist]
SELECT initiator_user_id FROM wp_bp_friends WHERE friend_user_id = 1 AND is_confirmed = 0

This was because the core BP Components were not installed properly yet. The WPLMS installer will ask you to save permalinks and to save the components. It will ask this once the dummy data and theme in general has been installed. Once that is done all is fine and errors will have disappeared.

Revolution Slider Issues

Still after that the homepage looked horrible and I missed the slideshows. When I checked Slider Revolution I saw that I had 4 sliders of which 2 were duplicates. Also the background image for the homepage search slide would not load. By selecting the same dummy image again I was able to bring it back.

Duplicate Pages

Quite a few pages were imported several times somehow. So had to remove quite a few like the Activate or Members page. That shouldn’t really happen now should it? Well, not too hard to take care of this issue though. Just go to the pages list and remove all the duplicates.

Broken Header Due to Old Plugins

Also had an issue with a menu showing up below the main header. List a non styled menu on a white background.

Broken Navigation

And the header loading the most popular course somehow:

Header Showing Course

Simply logging out did not hide this type of header so it was not simply a logged in view. I found out later on this was due to me not having updated the plugins that come with the theme. Read my warning above.

NB Most of you will not have had this error either though as you would have the latest plugins of the bat. You will wind up having the pesky notices with the EventOn plugin for which I mentioned a solution earlier

End Result

End result will be a site that is using the dummy data you picked. I picked dummy data 2 and installed the plugin for that. But here are other options. Now you have a great base for your WP Learning Management System.

Main take aways:

  • Make sure you have enough RAM for PHP available
  • Use the latest theme package
  • Install and activate a dummy theme data plugin before activating and configuring theme

Further reading: Vibe Themes WPLMS Documentation

 

Envato Market Plugin

Found out about something really cool this morning. There is a plugin that allows you to update your Envato / Themeforest themes and plugins using a WordPress plugin called Envato market.

Downloading Envato Market Plugin

It is available at Github and can be downloaded here (will start downloading zip file right away). It is a neat plugin that will work right out of the box. Just upload it as a plugin you want to add that is not part of the repository as usual and activate it. There is nothing to it.

Envato Market Backend View

Once you have uploaded and activated the plugin you can choose Envato Market from the sidebar menu in the Dashboard. Then you will be asked to generate an Oauth token.

Global OAuth Personal Token

OAuth Token Generation

This token will allow the plugin access to your Envato account to do certain things like download and update your plugin. All the needed options will be selected right away.

envato market token options

You only need to agree with their terms. This is at the bottom on the page where you can check what access you will allow as shown above. As said just keep the defaults and agree. Then you will see this:

Envator Market Plugin Key

You do need to confirm again that you copied the key. Then you click on “Woohoo got it!” . After that you will be sent back to your Envato apps.

Managing your Envato App

This here below is the display of your Envato Apps management page. It is where you see with what tokens for what apps you are working with.

Envato - My Apps

As you can see the App page is a bit behind as we just created a token for an app (the plugin) to access, but the changes will show up at a later stage. If you have been using Envato apps for a while you will see a list display here.

Running  Updates

Once the key has been confirmed as generated by you you can choose the item to update from the Envato Market plugin page in your Dashboard. Et voila. In no time the plugin will have been updated. Just did this for Rocket Pure‘s HumbleShop theme and it worked like a charm!

Here is how the page looks in the Dashboard with the just updated theme:

Envato Market in Dashboard

Sage Theme Deployment

When you work on a Sage theme with Trellis for your server stack  the final step tends to be the deployment of the theme itself. The Sage theme does get pulled onto the server using Trellis, but the dist folder isn’t.

This folder dist is excluded. This is done using the .gitignore. This is done as it is considered better practice not to have your compiled CSS and scripts on the repository. And those files wind up in that directory. Therefore it is left out.

Sage Theme Deployment Preparation

I assume you already provisioned your server running

ansible-playbook server.yml -e env=production

and did the general deployment using:

./deploy.sh production domain.com

This already installed the LEMP server and WordPress and the them to begin with. See more information on Trellis setups here. I also assume you either installed online or imported the database with all the content.

Compiling all Assets for Production

Then, to have all the assets do a:

gulp --production

This to compile all files and remove source maps. This so you have all necessary CSS and JavaScript files without the unnecessary stuff for development of the theme.

Uploading Dist

Now to upload this dist folder as well I recommend using scp and the admin user. From the theme folder locally execute this command using the terminal:

scp -r dist/ admin@domain.com:/srv/www/domain.com/current/web/app/themes/theme-name/

This will copy over the dist folder with all its assets to your theme on the server. After that you will have no more 404s. The theme will load properly with all the CSS and JavaScript files present. Done!

NB Downside is that new deploys keep on removing the dist folder due to git setup.

Update: Better Alternative

Better alternative is to activate the build-before.yml hook file located in trellis/deploy-hooks.

# Placeholder `deploy_build_before` hook for building theme assets locally
# and then copying the files to the remote server
#
# Uncomment the lines below and replace `sage` with your theme folder:
---
- name: Run npm install
 command: npm install
 connection: local
 args:
 chdir: "{{ project.local_path }}/web/app/themes/sage"

- name: Run bower install
 command: bower install
 connection: local
 args:
 chdir: "{{ project.local_path }}/web/app/themes/sage"

- name: Run gulp
 command: gulp --production
 connection: local
 args:
 chdir: "{{ project.local_path }}/web/app/themes/sage"

- name: Copy project local files
 synchronize:
 src: "{{ project.local_path }}/web/app/themes/sage/dist"
 dest: "{{ deploy_helper.new_release_path }}/web/app/themes/sage"
 group: no
 owner: no
 rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r