1. Go to this page and download the library: Download lin3s/wp-foundation 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/ */
lin3s / wp-foundation example snippets
(...)
use LIN3S\WPFoundation\Ajax\Ajax;
final class MyAwesomeAjax extends Ajax
{
/**
* {@inheritdoc}
*/
protected $action = 'my_awesome_ajax';
/**
* {@inheritdoc}
*/
public function ajax()
{
(...)
die('returning data');
}
}
(...)
use LIN3S\WPFoundation\Configuration\Acf\Acf;
final class Acf extends BaseAcf
{
/**
* {@inheritdoc}
*/
public function wyswygToolbars()
{
return [
'basic' => [1 => ['bold', 'italic']],
'lin3s' => [1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink']],
];
}
}
(...)
use LIN3S\WPFoundation\Configuration\Assets\Assets as BaseAssets;
final class Assets extends BaseAssets
{
/**
* {@inheritdoc}
*/
public function productionAssets()
{
$this
->addScript('app.min', self::BUILD_JS, ['jquery', 'jquery.counterup', 'sidr']);
}
/**
* {@inheritdoc}
*/
public function developmentAssets()
{
$this
->addScript('jquery.sidr.min', self::VENDOR . '/sidr')
->addScript('waypoints', self::VENDOR . '/jquery-waypoints')
->addScript('jquery.counterup', self::VENDOR . '/Counter-Up')
->addScript('counter', self::ASSETS_JS, ['jquery', 'jquery.sidr.min', 'waypoints', 'jquery.counterup'])
->addScript('typekit', self::ASSETS_JS, [], '1.0.0', false)
->addScript('menu')
->addScript('accordion')
->addScript('post-ajax', self::ASSETS_JS, [], '1.0.0', false, 'postsAjax')
}
/**
* {@inheritdoc}
*/
public function adminAssets()
{
$this->addStylesheet('adminCss');
$this->addScript('adminScript');
}
}
(...)
use LIN3S\WPFoundation\Configuration\Mailer\MailInterface;
use Timber;
final class ContactMail implements MailInterface
{
/**
* {@inheritdoc}
*/
public static function mail($request)
{
wp_mail(
MAILER_TO,
'Contact'
Timber::compile('mail/mail.twig', ['request' => $request]),
['Content-Type: text/html; charset=UTF-8']
);
}
}
// src/App/App.php
use LIN3S\WPFoundation\Configuration\Menus\Menus
class App extends Theme {
public function classes() {
(...)
new Menus([
self::MENU_AWESOME => 'Awesome menu'
]
}
}
(...)
use LIN3S\WPFoundation\Configuration\Theme\Theme;
final class AwesomeTheme extends Theme
{
/**
* {@inheritdoc}
*/
public function classes()
{
new Assets();
new Acf();
new Mailer();
new Menus();
new CustomPostType();
}
/**
* {@inheritdoc}
*/
public function templates($templates)
{
return array_merge($templates, [
'index' => 'Index',
'customs' => 'Customs',
]);
}
/**
* {@inheritdoc}
*/
public function context(array $context)
{
$context['mainMenu'] = new TimberMenu('main-menu');
$data['lang'] = ICL_LANGUAGE_CODE;
return $context;
}
}
// src/App/App.php
class App extends Theme {
public function classes() {
(...)
new Fields(
PostTypes::CUSTOM_POST_TYPE,
[
Fully\Qualified\Namespace\Components\CustomFieldComponent::class,
],
new PostTypeFieldConnector(PostTypes::CUSTOM_POST_TYPE)
['editor'],
['comments']
);
}
}
(...)
use LIN3S\WPFoundation\PostTypes\Field\FieldComponent;
final class CustomFieldComponent extends FieldComponent
{
/**
* {@inheritdoc}
*/
public static function definition($aName)
{
return [
'key' => sprintf('field_%s_component', $aName),
(...)
]);
}
}
(...)
use LIN3S\WPFoundation\PostTypes\Fields\PageFields as BasePageFields;
final class PageFields extends BasePageFields
{
/**
* {@inheritdoc}
*/
private $name = 'my_awesome_template;
/**
* {@inheritdoc}
*/
public function components()
{
return [
'Fully\Qualified\Namespace\Components\CustomFieldComponent',
];
];
}
(...)
use LIN3S\WPFoundation\PostTypes\RewriteRules\RewriteRules;
final class CustomRewriteRules extends RewriteRules
{
/**
* {@inheritdoc}
*/
public function rewriteRules()
{
add_rewrite_rule(
'^custom-base-url/([^/]*)/([^/]*)/([^/]*)/?$',
'index.php?category=$matches[1]&subcategory=$matches[2]&custom=$matches[3]',
'top'
);
add_rewrite_rule(
'^custom-base-url/([^/]*)/([^/]*)/?$',
'index.php?category=$matches[1]&subcategory=$matches[2]',
'top'
);
}
/**
* {@inheritdoc}
*/
public function rewriteTags()
{
add_rewrite_tag('%category%', '([^/]*)');
add_rewrite_tag('%subcategory%', '([^/]*)');
add_rewrite_tag('%custom%', '([^/]*)');
}
/**
* {@inheritdoc}
*/
public function templateInclude($template)
{
$controller = new CustomController();
$method = '';
if (get_query_var('category') !== ''
&& get_query_var('subcategory') !== ''
&& get_query_var('custom') != ''
) {
$method = 'showAction';
} elseif (get_query_var('category') !== ''
&& get_query_var('subcategory') !== ''
) {
$method = 'listAction';
}
return $method === '' ? $template : $controller->$method();
}
}