Launching Perfecty Push Notifications
Tags: wordpress, php, sideprojects, javascript
Published: 2020-12-30 14:10:09

Recently, I wrote a post describing the review process for publishing a plugin in the WordPress Plugin Directory:

{% link rwngallego/sending-a-plugin-to-the-wordpress-plugin-directory-4hoe %}

I've created **Perfecty Push Notifications**, a WordPress plugin for sending Push notifications using [Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) from your server for free. You can check the [Github repo](https://github.com/rwngallego/perfecty-push-wp) and contribute ⚡️. In this post, I will describe what happened next in the review, and how the publishing of the plugin looked like.

## Getting the approval

Well, after addressing the initial suggestions from the WordPress plugin review team, I received another email suggesting the upgrade of the plugin dependencies:

![Perfecty Push dependencies](https://dev-to-uploads.s3.amazonaws.com/i/6bvfl79n8ezsuhf5cqr4.png)

At that time the `composer.json` dependencies looked like this:

```json
    "require": {
        "minishlink/web-push": "5.2.5",
        "ramsey/uuid": "^3.9"
    },
    "require-dev": {
        "mockery/mockery": "1.3",
        "phpunit/phpunit": "5.7.27",
        "wp-coding-standards/wpcs": "^2.3",
        "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
        "phpcompatibility/phpcompatibility-wp": "*"
    }
```

The problem with the upgrade was the initial plan to support `PHP 7.1`, which according to the [WordPress statistics](https://wordpress.org/about/stats/) had a 5.9% representation of the total WordPress websites. Some of the dependencies in the latest versions required `PHP>=7.2`, specially the [Push Server library](https://github.com/web-push-libs/web-push-php). So, that cut **5.9% potential users**:

![PHP versions intended for Perfecty Push](https://dev-to-uploads.s3.amazonaws.com/i/rvp0gae5gz7vd2dxhems.png)

However, I was able to compensate that **5.9%** loss by supporting WordPress starting from `5.2`, which initially I was not considering. That was a 6.4% gain:

![WordPress version supported by Perfecty Push](https://dev-to-uploads.s3.amazonaws.com/i/wvp8y87faz8mczvn89eb.png)

With that in mind, I submitted the second Release Candidate `1.0.0-rc1` with the suggested changes. You can take a look at all the changes I made here: [https://github.com/rwngallego/perfecty-push-wp/commit/2f2322f7848b6cb37465e5776d1f60c981b987d9](https://github.com/rwngallego/perfecty-push-wp/commit/2f2322f7848b6cb37465e5776d1f60c981b987d9)

![Perfecty Push release](https://dev-to-uploads.s3.amazonaws.com/i/26xm6tibxz5rxjpxfnjx.png)

In this RC, apart from the minor fixes required after the upgrade, I easily updated the [CI pipeline](https://github.com/rwngallego/perfecty-push-wp/blob/v1.0.0-rc1/.github/workflows/tests.yml) to support the aforementioned PHP/WordPress versions:

```yaml
    strategy:
      matrix:
        wordpress-version: ['5.2', '5.3', '5.4', '5.5', 'latest']
        php-versions: ['7.2', '7.3', '7.4']
```

Everything set, all the automated tests green ✅ (the matrix strategy rocks!):

![Perfecty Push Continuous Integration](https://dev-to-uploads.s3.amazonaws.com/i/lzhznbetlacvlnlmqsja.png)

And finally, their approval 🥳:

![Perfecty Push plugin approved](https://dev-to-uploads.s3.amazonaws.com/i/vc94b753e8v4sc73go24.png)

## Publishing

OK, I got access to the Wordpress Plugin directory SVN servers:

![Perfecty Push Notifications SVN](https://dev-to-uploads.s3.amazonaws.com/i/cxqvpy5lay9ayur23n2v.png)

**Something important here:** Once you get the plugin approved, you will need to read carefully all the guidelines related to the publishing, the directory assets (screenshots, logo, banner), the `README.txt` file and how the whole process works. For more information you can read:

- [https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/](https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/)
- [https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/](https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/)
- [https://developer.wordpress.org/plugins/wordpress-org/how-to-use-subversion/](https://developer.wordpress.org/plugins/wordpress-org/how-to-use-subversion/)
- [https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/)

I decided not to publish the plugin right ahead, specially because I noticed some potential improvements (and bugs of course), so I took some days and also prepared the design material. You can see the whole set of changes I made before sending the final version here:

[https://github.com/rwngallego/perfecty-push-wp/compare/v1.0.0-rc1...v1.0.1](https://github.com/rwngallego/perfecty-push-wp/compare/v1.0.0-rc1...v1.0.1)

In this case, I refactored some of the code, improved the usability, added more test scenarios and added the branding stuff. Now the release:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xk0j1x6po2gaa653wwin.png)

So, right now we have the `.zip file` and the release published on Github. To publish the plugin in the Wordpress Plugin Directory, you basically need to sync your development work with trunk, change the plugin version, create the tag and then check in the changes:

```bash
# change the version in README.txt:
Stable tag: 1.0.0

# change the version in your plugin entry file (`perfecty-push.php`):
 * Version:           1.0.0
 define( 'PERFECTY_PUSH_VERSION', '1.0.0' );

# checkout the upstream
mkdir dist/svn/
svn co https://plugins.svn.wordpress.org/your-plugin-name dist/svn/

# add the changes to trunk
cp -Rp admin includes languages lib public vendor composer.json composer.lock index.php LICENSE.txt perfecty-push.php README.txt uninstall.php dist/svn/trunk

# add the new files if any and check the diff:
cd dist/svn/
svn add --force .
svn stat
svn diff

# if you're happy with the changes, create the tag from trunk:
svn cp trunk tags/1.0.0

# check in your changes:
svn ci -m "Version $SVN_TAG"
```

Alternatively, I created two additional shell commands to sync and publish the svn package with `make svnsync` and `SVN_TAG=1.0.0 make svnpush`, which later I used to setup my [deployment pipeline](https://github.com/rwngallego/perfecty-push-wp/runs/1614160029?check_suite_focus=true):

```bash
create_dist() {
  rm -rf $DIST_PATH
  mkdir -p $SVN_PATH $OUTPUT_PATH
  rm -rf vendor && composer install --quiet --no-dev --optimize-autoloader
  cp index.php vendor/
  cp -Rp admin includes languages lib public vendor composer.json composer.lock index.php LICENSE.txt perfecty-push.php README.txt uninstall.php $OUTPUT_PATH
}

svnsync() {
  create_dist
  svn co -q https://plugins.svn.wordpress.org/perfecty-push-notifications $SVN_PATH
  cp assets/* "$SVN_PATH/assets/"

  # we don't sync vendor if the lock file is the same
  if [[ $(shasum composer.lock | head -c 40) == $(shasum "$OUTPUT_PATH/composer.lock" | head -c 40) ]]; then
    rsync -q -av $OUTPUT_PATH/* $SVN_PATH/trunk --exclude vendor
    echo "## no differences in /vendor, similar lock files ##"
  else
    rsync -q -av $OUTPUT_PATH/* $SVN_PATH/trunk
  fi

  (cd $SVN_PATH && svn add --force . && svn diff && svn stat)
}

svnpush() {
  if (cd $SVN_PATH && svn status | grep -e ^?); then
    echo "There are changes not added to the SVN"
    exit 1
  fi

  if [ -z "$SVN_TAG" ]; then
    echo "You need to provide the tag version as SVN_TAG=1.0.1"
    exit 1
  fi

  if [ -z "$SVN_USERNAME" ]; then
    echo "You need to provide the username as SVN_USERNAME=myname"
    exit 1
  fi

  if [ -z "$SVN_PASSWORD" ]; then
    echo "You need to provide the username as SVN_PASSWORD=mypassword"
    exit 1
  fi

  if [ ! -d "$SVN_PATH/tags" ]; then
    echo "You need to run svnsync first"
    exit 1
  fi

  if [ -d "$SVN_PATH/tags/$SVN_TAG" ]; then
    echo "The tag $SVN_TAG already exists"
    exit 1
  fi

  cd $SVN_PATH && svn cp trunk tags/$SVN_TAG && svn ci -m "Version $SVN_TAG" --username $SVN_USERNAME --password $SVN_PASSWORD
```

End result, **Perfecty Push Notifications** published in the WordPress Plugin directory 👏:

[https://wordpress.org/plugins/perfecty-push-notifications/](https://wordpress.org/plugins/perfecty-push-notifications/)

![Perfecty Push Notifications Wordpress plugin](https://dev-to-uploads.s3.amazonaws.com/i/kertgwigjmu034xr4gs1.png)

![Perfecty Push Notifications](https://dev-to-uploads.s3.amazonaws.com/i/yc2yeoh2psdq1aqt4j6o.png)

And a deployment pipeline **that deploys to Github and Wordpress by just tagging the new version!** 🚀

![Perfecty Push Deployment pipeline](https://dev-to-uploads.s3.amazonaws.com/i/kwj2ueq85d813aapmd0a.png)

## Using the plugin as an end-user

I installed the plugin in one website I have access to, and sent some notifications. In general, it takes about `2 or 3 minutes` to send about `2.000` notifications in a basic sever compared to a `t2.small`. As the plugin uses `wp-cron` to execute the jobs asynchronously, that timing includes the time gaps between job executions, so it would be less than that.

![Perfecty Push Notifications stats](https://dev-to-uploads.s3.amazonaws.com/i/9ncordzlioyejm85u8we.png)

If you're interested, I will publish another post describing the performance metrics of the plugin, for the moment you can see the impact on the server for one of those jobs:

![Perfecty Push Notifications metrics](https://dev-to-uploads.s3.amazonaws.com/i/rp4q94tao09rofxhjhc3.png)

So, descent results for a very first version! ✨

## Take the ride

Wrapping up, if you're still considering writing a plugin, I highly recommend you to take the ride. I created [Perfecty Push Notifications](https://wordpress.org/plugins/perfecty-push-notifications/) as an Open Source alternative for sending Push Notifications from your own Wordpress server for free. I don't know if it will succeed in the Plugin directory or not, **however all the things I've learned in the process were valuable, and specially important is the fact that I can share both, the knowledge and the joy of the trip with you** 🖖.

Feel free to use it in your websites or recommend it to your WordPress-fans folks. Have a nice one!

![Have a nice trip](https://dev-to-uploads.s3.amazonaws.com/i/imqh43gx07pgnrlr22h9.jpg)

## Photos

<span>Photo by <a href="https://unsplash.com/@billjelen?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Bill Jelen</a> on <a href="https://unsplash.com/s/photos/launch?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>

<span>Photo by <a href="https://unsplash.com/@r2x209?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Roman</a> on <a href="https://unsplash.com/s/photos/trip?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>