Jump To …

WordPress.php

We expect (but do not insist) the file to be PSR-compatible.

The name of the file must be $unique_name.php. If your name happens to be identical to another script, we will notify you and you must modify suitably.

The name of the class must be Netenberg_Script_$unique_name.

The class must derive from Netenberg_Script.

class Netenberg_Script_WordPress extends Netenberg_Script
{

This function is called as part of the actual installation process (Step 3).

$parameters is a dictionary that contains the values supplied by the user (Step 1) in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function install($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

This is an abstracted cURL object. You may use it for the sake of simplicity and also for ease of debugging. The full extent of this singleton is (will be made) available in the guide.

        $curl = new Netenberg_cURL;

You are encouraged to employ the usage of steps as follows:

 $step = 0;

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...
        $step = 0;

        $wp_config_php = sprintf(
            '%s/%s/wp-config.php',
            $parameters['document_root'],
            $parameters['directory']
        );

In this step, a fresh database is being created via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $parameters['mysql_hostname'],
            $parameters['mysql_username'],
            $parameters['mysql_password'],
            $parameters['mysql_database']
        ) = $control_panel->insertMySQL();

In this step, the source archive is being downloaded and extracted to the desired directory via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $operating_system->transpose(
            'http://wordpress.org/latest.tar.gz',
            array(
                'wordpress/*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),
            )
        );

In this step, we create wp-config.php (as a copy of wp-config-sample.php).

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $operating_system->mv(sprintf(
            '%s/%s/wp-config-sample.php',
            $parameters['document_root'],
            $parameters['directory']
        ), $wp_config_php);

In this step, we populate wp-config.php using $parameters.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $contents = file_get_contents($wp_config_php);
        $contents = preg_replace(
            '#localhost#', $parameters['mysql_hostname'], $contents
        );
        $contents = preg_replace(
            '#database_name_here#', $parameters['mysql_database'], $contents
        );
        $contents = preg_replace(
            '#username_here#', $parameters['mysql_username'], $contents
        );
        $contents = preg_replace(
            '#password_here#',  $parameters['mysql_password'], $contents
        );
        file_put_contents($wp_config_php, $contents);

In this step, we invoke the WordPress installation wizard (step=2).

$curl->request is a function used to send Request to the URL. $curl->request() takes 5 arguments, i.e. URL to which request has to be sent, METHOD i.e. GET or POST, POSTFIELDS, which is present only for POST method, otherwise an empty array, HTTP HEADERS, and OPTIONS

In this step we are making a POST Request to the URL http://%s/%s/wp-admin/install.php?step=2, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $curl_exec, $curl_errno, $curl_error, $curl_getinfo
        ) = $curl->request(
            sprintf(
                'http://%s/%s/wp-admin/install.php?step=2',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'Submit' => 'Install WordPress',

$parameters['admin_email'] refers to value entered in the Email Field before the actual installation process starts.

                'admin_email' => $parameters['admin_email'],

$parameters['admin_password'] refers to value entered in the Password Field before the actual installation process starts.

                'admin_password' => $parameters['admin_password'],

$parameters['admin_password'] refers to value entered in the Password (Repeat) Field before the actual installation process starts.

                'admin_password2' => $parameters['admin_password2'],
                'blog_public' => '1',

$parameters['username'] refers to value entered in the Username field before actual installationp process starts.

                'user_name' => $parameters['user_name'],

$parameters['weblog_title'] refers to value entered in the Title field before actual installation process starts.

                'weblog_title' => $parameters['weblog_title'],
            ),
            array(),
            array()
        );

In this step, we check if the installation was successful.

        if (strpos($curl_exec[1], 'WordPress has been installed') !== false) {

This indicates a success status (and is mandatory).

            log_('DEBUG', 'Success');

This allows the core system to register this installation within the user account (and is mandatory).

            return parent::install($parameters);
        }

This indicates a failure status (and is mandatory).

        log_('DEBUG', 'Failure');

        return false;
    }

This function validates the username. Here the function is checking whether username contains any special characters.

    public function getCallback($contents)
    {
        if (preg_match('#[`\=\[\]\;\',/~!\#$%^&*()+{}|:"<>?]#', $contents)) {
            return false;
        }

        return true;
    }

This function provides the category (and is mandatory).

    public function getCategory()
    {
        return _('Blogs');
    }

This function provides the description (and is mandatory).

    public function getDescription()
    {
        return _('WordPress is web software you can use to create a beautiful website or blog. WordPress is a powerful semantic publishing platform, and it comes with a great set of features designed to make your experience as a publisher on the Internet as easy, pleasant and appealing as possible. We are proud to offer you a freely distributed, standards-compliant, fast, light and free content management system, with sensible default settings and features, and an extremely customizable core.');
    }

This function provides the details of an installed copy (and is mandatory).

$parameters is a dictionary that contains domain, directory, and document_root.

    public function getDetails($parameters)
    {
        $version_php = sprintf(
            '%s/%s/wp-includes/version.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($version_php)) {
            return false;
        }
        $contents = file_get_contents($version_php);

This statemnt performs a regular expression match on version of the installed copy on the contents of version.php file.

        preg_match('#wp_version\s*=\s*\'([\d+\.]+)\'#', $contents, $version);

        return array(
            'version' => $version[1],
        );
    }

This function builds the form presented to the user (Step 1) (and is mandatory). It is built upon the Zend_Form component of Zend Framework.

    public function getForm()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is an abstracted form object derived from Zend_Form. The full extent of this class is (will be made) available in the guide.

        $form = new Netenberg_Form();

This statement adds the domain selector (and is mandatory).

        $form->addElement('select', 'domain', array(
            'label' => _('Domain'),
            'multiOptions' => $control_panel->getDomains(),
            'required' => true,
        ));

This statement adds the directory selector (and is mandatory).

        $form->addElement('text', 'directory', array(
            'description' => _('Leave this field empty if you want to install in the web root for the domain you\'ve selected (i.e., http://domain.com/ ). If you\'d like to install in a subdirectory, please enter the path to the directory relative to the web root for your domain. The final destination subdirectory should not exist, but all others can exist (e.g., http://domain.com/some/sub/directory - In this case, "directory" should not already exist).'),
            'filters' => array(new Netenberg_Filter_Directory()),
            'label' => _('Directory'),
            'validators' => array(new Netenberg_Validate_Directory()),
        ));

This statement adds the username textfield (and is mandatory).

        $form->addElement('text', 'user_name', array(
            'description' => sprintf(_('maximum %d characters; must not contain any special characters except hyphen, period, underscore'), 60),
            'label' => _('Username'),
            'required' => true,
            'validators' => array(

This validator statement checks whether username field contains more than 60 characters.

                array('StringLength', false, array(
                    'max' => 60,
                )),

This validator statement checks whether username field contains any special characters by calling getCallback function which is written above.

                array('Callback', false, array(
                    'callback' => array($this, 'getCallback'),
                )),
            )
        ));

This statement adds the password textfield (and is mandatory).

        $form->addElement('password', 'admin_password', array(
            'description' => sprintf(_('minimum %d characters'), 7),
            'label' => _('Password'),
            'required' => true,
            'validators' => array(
                array('StringLength', false, array(
                    'min' => 7,
                )),
            )
        ));

This statement adds the password repeat textfield (and is mandatory).

        $form->addElement('password', 'admin_password2', array(
            'label' => _('Password (Repeat)'),
            'required' => true,

This validator statement checks whether this field is identical to value of Password Textfield.

            'validators' => array(
                array('Identical', false, array(
                    'token' => 'admin_password',
                )),
            ),
        ));

This statement adds the email (and is mandatory).

        $form->addElement('text', 'admin_email', array(
            'label' => _('Email'),
            'required' => true,

This validator statement checks whether this field contains a valid Email Address.

            'validators' => array(
                array('EmailAddress', false),
            ),
        ));

This statement adds the Title of the Wordpress Site (and is mandatory).

        $form->addElement('text', 'weblog_title', array(
            'label' => _('Title'),
            'required' => true,
        ));

This statement adds the Submit button to the form (and is mandatory).

        $form->addElement('button', 'submit');

This statement adds the Reset button to the form (and is mandatory).

        $form->addElement('button', 'reset');

This statement places the domain and directory selectors under the display group Location Details.

        $form->addDisplayGroup(
            array('domain', 'directory'),
            'location_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => 'Location Details',
            )
        );

This statement places the user_name, admin_password, admin_password2 and admin_email under the display group Administrator Details.

        $form->addDisplayGroup(
            array(
                'user_name',
                'admin_password',
                'admin_password2',
                'admin_email',
            ),
            'administrator_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Administrator Details'),
            )
        );

This statement places the weblog_title under the display group Other Deatils.

        $form->addDisplayGroup(
            array('weblog_title'),
            'other_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Other Details'),
            )
        );

This statement places the Submit and Reset buttons at end of the form.

        $form->addDisplayGroup(
            array('submit', 'reset'),
            'buttons',
            array(
                'decorators' => $form->getButtonGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
            )
        );

        return $form;
    }

This function provides the image (and is mandatory).

    public function getImage()
    {
        return 'http://s.wordpress.org/style/images/wp-header-logo.png';
    }

This function provides the name (and is mandatory). The name must be unique.

    public function getName()
    {
        return 'WordPress';
    }

This function provides the post-installation overview (and is mandatory).

$parameters is a dictionary that contains the values supplied by the user like domain, directory and username and/or password and/or email etc.

    public function getItems($parameters)
    {
        return array(

This statement provides the URL for Backend page. Backend page is a login-page which is used to login into Administrator's Account.

            _('Backend') => array(
                sprintf(
                    '<a href="http://%s/%s/wp-login.php" target="_blank">http://%s/%s/wp-login.php</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
                sprintf(_('Username: %s'), $parameters['user_name']),
                sprintf(_('Password: %s'), $parameters['admin_password']),
            ),

This statement provides the URL for the Frontend page. Frontend page is a page which end-user can see when he/she opens the website.

            _('Frontend') => array(
                sprintf(
                    '<a href="http://%s/%s" target="_blank">http://%s/%s</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
            ),
        );
    }

This function provides the requirements (and is mandatory).

    public function getRequirements()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

        $apache = $control_panel->getApache();
        $mysql = $control_panel->getMySQL();
        $php = $control_panel->getPHP();

        return array(

This statement checks whether enough space is available in your account to install this script.

            'Disk Space' => (
                $control_panel->getSize() >= $this->getSize()
            )? true: false,

This statement checks whether installed Apache's version is greater than 1.

            'Apache 1+' => (
                strpos($apache, 'Apache/1') !== false
                or
                strpos($apache, 'Apache/2') !== false
            )? true: false,

This statement checks whether installed MySQL's version is greater than 5.

            'MySQL 5.0+' => (
                strpos($mysql, 'Distrib 5') !== false
            )? true: false,

This statement checks whether installed PHP's version is greater than 5.2.4

            'PHP 5.2.4+' => (preg_match(
                '#PHP Version\s*=>\s*(5\.2\.[4-9]|5\.2\.[0-9]{2}|5\.[3-9])#',
                $php
            ) === 1)? true: false,
        );
    }

This function provides the size (in bytes) (and is mandatory).

    public function getSize()
    {
        return 14365491;
    }

This function provides the slug (and is mandatory). The slug must be unique.

    public function getSlug()
    {
        return 'word-press';
    }

This function provides the URLs (and is mandatory).

We expect(but do not insist)URLs for four pages to be part of the array. They are URLs of Home, Community, Documentation and Support or Forum pages.

    public function getUrls()
    {
        return array(
            _('Home') => 'http://wordpress.org',
            _('Documentation') => 'http://codex.wordpress.org/Main_Page',
            _('Support') => 'http://wordpress.org/support',
        );
    }

This function provides the version (and is mandatory).

    public function getVersion()
    {
        return '3.7.1';
    }

This function is called as part of the actual uninstallation process

$parameters is a dictionary that contains the values supplied by the user in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function uninstall($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

        $wp_config_php = sprintf(
            '%s/%s/wp-config.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($wp_config_php)) {
            return false;
        }

This statement fetches the contents of wp-config.php

        $contents = file_get_contents($wp_config_php);

This statement performs a regular expression match to fetch database name from the contents of wp-config.php

        preg_match('#DB_NAME\',\s*\'([^\']*)#', $contents, $database);

This statement performs a regular expression match to fetch database username from the contents of wp-config.php

        preg_match('#DB_USER\',\s*\'([^\']*)#', $contents, $mysql_username);

In this step, we remove the database via the control panel singleton.

        $control_panel->deleteMySQL($mysql_username[1], $database[1]);

In this step, we remove the directory via the operating system singleton.

        $operating_system->dispose(sprintf(
            '%s/%s', $parameters['document_root'], $parameters['directory']
        ));

This allows the core system to unregister this installation within the user account (and is mandatory).

        return parent::uninstall($parameters);
    }
}