Giter Club home page Giter Club logo

wp-person-list's Introduction

Person Lister Plugin

Setup and installation

Usage

  • Install required modules: yarn (or npm install)
  • Build development version of app and watch for changes: yarn build (or npm run build)
  • Build production version of app:yarn prod (or npm run prod)

Explanation

Mixture of both WP Reactivate and Create Guten Blocks starter packages. WP Reactivate used for simple React & Wordpress REST API patterns and Create Guten Blocks used for pattern for creating guten blocks.

webpack.config.js

entry: {
   'js/blocks': path.resolve(__dirname, 'app/blocks.js'),
   'js/personslist': path.resolve(__dirname, 'app/personslist.js')
},

Bundling blocks for creating guten blocks on editor's side.
Bundling personslist for front-end jsx showing. Used dynamic blocks. Save function on block
returns null

includes/Block.php

wp_register_style( 'person_block_style', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css' );

Semantic UI have been used for UI framework. It works great with React and easy to make custom user interfaces.

register_block_type(
	'wrp-person-list/person-container', array(
		// Enqueue blocks.build.js in the editor only.
		'editor_script'   => 'react_lifecycle_block-cgb-block-js',
		'editor_style'    => 'person_block_style',
		'style'           => 'person_block_style',
		'render_callback' => function ( $attribute ) {
			wp_register_script( 'block-script', plugins_url( 'wpr-person-list/assets/js/personslist.js' ));
			wp_localize_script( 'block-script', 'wpr_object', $attribute );
			wp_enqueue_script( 'block-script' )
			return '<div id="render-person-block-container"></div>';
		}
	)
);

Simply returning dynamic block on div with id of render-person-block-container. Id is being selected and rendered on React Dom.

Finalize Work

I have tried to create some pattern that separates View from Business Logic. Custom Post Types are being used for creating Person model. These model objects are transferred into guten block using Wordpress Rest API. On Guten blocks, with the usage of dynamic blocks, the attributes are transferred into dynamic block and then again these attributes are transferred to React DOM using wp_localize_script function.

Technologies

Tech Description
React A JavaScript library for building user interfaces.
Babel Compiles next generation JS features to ES5. Enjoy the new version of JavaScript, today.
Webpack For bundling our JavaScript assets.
ESLint Pluggable linting utility for JavaScript and JSX

wp-person-list's People

Contributors

barash-asenov avatar dependabot[bot] avatar dnusca avatar ionofzion 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.