Skip to content

Calling core and using it

Jakub edited this page Aug 23, 2017 · 5 revisions

Next step is to initialize your new class which extends ShellPress.

The best place to do that is your plugin root file.

Let's say it's this file: www_root/wp-content/plugins/pizza/pizza.php.

To initialize core, we need to call initShellPress() method of our class. Remember, we don't have autoloading yet, so we need to include our class and call its full name.

<?php
//    pizza.php

//  ( . . . )

//  We don't have autoloading yet!

if( ! class_exists( 'Bakery\Pizza\App' ) ){

    require_once( __DIR__ . '/App.php' );

    myname\pluginname\src\App::initShellPress( __FILE__, 'pluginname', '1.0.0' );

}

//  ( . . . )

You will not believe me, but that's all!

Now it's time for some cool stuff. As you noticed, our core class App is static. This means we can use it everywhere in our project.

Let's say we are deep in file structure and want to prefix some string. The only thing we need to do is to call our full class name and use methods we like.

Example:

<?php
namespace Bakery\Pizza\SomeFolderName;

use Bakery\Pizza\App;

class Peperoni {

    public function __construct() {
         
        $myNiceString = App::getPrefix( '_flour' );    //    It will produce string: pizza_flour

    }

}

Clone this wiki locally