PHP code example of madeinitalyslc / mit-wp-plugin

1. Go to this page and download the library: Download madeinitalyslc/mit-wp-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

madeinitalyslc / mit-wp-plugin example snippets



/**
 * Plugin Name: Stucture
 */

use MadeInItalySLC\WP\Plugin\PluginFactory;

if (file_exists( __DIR__.'/vendor/autoload.php')) {
	actory::create('stucture-wp-plugin');
    }
    
    return $stucture_wp_plugin;
}

$stucture = StucturePlugin();


$stucture
	->registerHooks(new \MadeInItalySLC\WP\Plugin\Provider\I18n())
	->registerHooks(new \MadeInItalySLC\WP\Plugin\Provider\VarDumpServer())
	->registerHooks(new \Structure\PostType\BookPostType());


namespace Structure\PostType;

class BookPostType extends AbstractHookProvider
{
	const POST_TYPE = 'book';

	public function registerHooks()
	{
		$this->addAction('init', 'registerPostType');
		$this->addAction('init', 'registerMeta');
	}

	protected function registerPostType()
	{
		register_post_type(static::POST_TYPE, $this->getArgs());
	}

	protected function registerMeta()
	{
		register_meta('post', 'isbn', [
			'type'              => 'string',
			'single'            => true,
			'sanitize_callback' => 'sanitize_text_field',
			'show_in_rest'      => true,
		]);
	}

	protected function getArgs()
	{
		return [
			'hierarchical'      => false,
			'public'            => true,
			'rest_base'         => 'books',
			'show_ui'           => true,
			'show_in_menu'      => true,
			'show_in_nav_menus' => false,
			'show_in_rest'      => true,
		];
	}
}


namespace Structure\Provider;

use MadeInItalySLC\WP\Plugin\AbstractHookProvider;

class Assets extends AbstractHookProvider
{
	public function registerHooks()
	{
		$this->addAction('wp_enqueue_scripts', 'enqueueAssets');
	}

	protected function enqueueAssets()
	{
		wp_enqueue_script(
			'structure',
			$this->getPlugin()->getUrl('assets/js/structure.js')
		);
	}
}