# Create the Build to Prefix the WordPress Plugin

PHP-Prefixer works based on Composer (opens new window) as the dependency management tool. It allows you to declare the libraries your project depends on and manages (install/update) them for you. For more information about Composer, please visit https://getcomposer.org/ (opens new window).

# Prefixing the "Hello Prefixed World Plugin" Project

In this guide, we will prefix the project "Hello Prefixed World Plugin." We prefix it with our prefix PPP.

The source code of the project can be found in this repository: https://github.com/PHP-Prefixer/hello-wp-world (opens new window)

The results of the prefixing process can be found in this repository: https://github.com/PHP-Prefixer/hello-wp-world_prefixed (opens new window)

# The "Hello Prefixed World Plugin" Project

The modified version of the Hello Dolly plugin shows a formatted date before the lyrics hello.php:

<?php

/**
 * @package Hello_Prefixed_World_For_Wp
 * @version 1.0.0
 */

....

// This just echoes the chosen line, we'll position it later.
function hello_dolly() {
	require_once __DIR__.'/vendor/autoload.php';

	$chosen = hello_prefixed_world_get_lyric();
	$lang   = '';
	if ( 'en_' !== substr( get_user_locale(), 0, 3 ) ) {
		$lang = ' lang="en"';
	}

    // The modified version of the Hello Dolly plugin shows a formatted date before the lyrics
	$now = \Carbon\Carbon::now();
	$formattedDate = $now->toDateTimeString();

	printf(
		'<p id="dolly"><span class="screen-reader-text">%s </span><span dir="ltr"%s>%s // %s</span></p>',
		__( 'Quote from Hello Dolly song, by Jerry Herman:', 'hello-dolly' ),
		$lang,
		$formattedDate,
		$chosen
	);
}

...

add_action( 'admin_head', 'dolly_css' );

# The PHP-Prefixer Configuration

In the composer.json schema, in the extra configuration, the PHP-Prefixer configuration is as follows:

    "extra": {
        "php-prefixer": {
            "project-name": "Hello Prefixed World for WordPress",
            "namespaces-prefix":: "PPP",
            "global-scope-prefix": "PPP_",

            "exclude-paths": [
                "bin/",
                "doctrine/inflector/docs",
                "voku/portable-ascii/build"
            ]
        }
    }

The configuration declares the project name and the prefix PPP used for namespaces and global objects (functions, etc.).

In particular, this schema has the attribute excludePaths to help package the plugin for distribution. The excludePaths remove folders that should not be included in the target prefixed plugin (commands, unit tests, library documentation, etc.).

# Verify Composer.json

To review the project:

  1. Download the source code from the repository.
  2. Go to the project directory.
  3. Run the following command to verify the schema and lock the project's dependencies that would be distributed:
~$ composer update --no-dev
...
Writing lock file
Generating autoload files
...

Then, compress the files in a new ZIP file or download the project's ZIP file from GitHub.

# Create a Build

You can now set up a new build and prefix the project in the "Dashboard/ Projects" area in a matter of minutes. Follow the steps below to set up a build and prefix the project ZIP file.

  1. Go to "Project."
  2. Click on "Create Build."
  3. Select the file to be prefixed.
  4. Upload and create the Build; click on "Create Build."

Create a Build

# Validating the Build

Once the Build is created, the PHP-Prefixer service automatically validates the project and continues with the next steps.

Validating the Build

# Prefixing the Build

Once the Build is validated, the PHP-Prefixer service prefixes the files and notifies when processing is completed.

Prefixing the Build

Congratulations, you’ve prefixed your "Hello Prefixed World Plugin" for the WordPress project!