GithubHelp home page GithubHelp logo

nemesis's Introduction

Nemesis Package

What is this package?

This package is to provide base classes for use when developing new websites with ACF.

Common classes will include

  • Base fields for ACF

Using this package

To use this package you will need to run the following.

composer require nanosoup/nemesis

This will install the package based on the current state of the master branch.

Using ACF Base fields

When creating a field group you are able to utilise the base fields provided by Nemesis by doing the following:

<?php
/**
 * Setup functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package ThemeName
 */

namespace ThemeName\Namespace;

use NanoSoup\Nemesis\BaseFields;

/**
 * Class ACFFields
 */
class ACFFields extends BaseFields
{
    ...
}

This will then make all the base fieds available to you so you can then register a field group using these fields like this:

<?php

namespace ACF\FieldGroups;

use NanoSoup\Nemesis\ACF\BaseFields;

/**
 * Class Testimonials
 * @package ACF\FieldGroups
 */
class Testimonials extends BaseFields
{
    /**
     *
     */
    public function init()
    {
        add_action('acf/init', [$this, 'registerFieldGroup']);
    }

    /**
     *
     */
    public function registerFieldGroup()
    {
        acf_add_local_field_group([
            'key' => 'group_block_testimonial',
            'title' => 'Block: Testimonial',
            'fields' => [
                $this->textarea('block_testimonial', 'Testimonial'),
                $this->text('block_testimonial', 'Author'),
                $this->image('block_testimonial', 'Avatar')
            ],
            'location' => [
                [
                    [
                        'param' => 'block',
                        'operator' => '==',
                        'value' => 'acf/testimonial',
                    ]
                ]
            ],
            'menu_order' => 0,
            'position' => 'normal',
            'style' => 'default',
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'hide_on_screen' => '',
            'active' => 1,
            'description' => '',
        ]);
    }
}

Using Blocks (Gutenberg)

We have included helpers for programmatically creating blocks to be used within the Gutenberg editor within Nemesis.

The interface defines what methods need to be available in your new "Block" and the Block class makes the base "Add Block" functionality available to you.

To create a new block you would do something like this:

<?php

namespace ACF\Blocks;

use ACF\Block;
use ACF\BlockInterface;
use Timber\Timber;

/**
 * Class Testimonials
 * @package ACF\Blocks
 */
class Testimonials extends Block implements BlockInterface
{
    /**
     * @return mixed|void
     */
    public function init()
    {
        add_action('init', [$this, 'registerBlock']);
    }

    /**
     * @return mixed|void
     */
    public function registerBlock()
    {
        $this->newBlock('testimonial', 'Testimonial', [$this, 'renderBlock']);
    }

    /**
     * @param $block
     * @return mixed|void
     */
    public function renderBlock($block)
    {
        $vars['block'] = $block;
        $vars['fields'] = get_fields();

        $vars['fields']['avatar'] = new \Timber\Image($vars['fields']['avatar']);

        Timber::render( get_stylesheet_directory() . '/classes/ACF/Blocks/views/content-testimonials.twig', $vars );
    }
}

Note: this above example is built with the assumption you are using Timber - if not you would just need to modify your render method to either output HTML or locate your template a different way.

Structure of this package

The folder structure of this package is an outline for how you should be laying out the classes in your website.

Everything should be in dedicated folders to keep everything distinctly separate. The only class outside of a directory should be the Setup class.

Contributing

To contribute to this package please fork this repor and then submit your pull request to be reviewed

nemesis's People

Contributors

hobbitcodes avatar wisemanh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.