Code Monkey home page Code Monkey logo

wp-best-practices's Introduction

WordPress best practices

Boilerplate code for WordPress plugins and themes based on best practices.

What's inside

  1. A WordPress.org compatible theme: Mo Theme.
  2. A WordPress.org 'compatible' plugin: Mo Plugin.
  3. A child theme using the plugin: Mo Pro Theme.

How it works

  • Mo Theme simply displays posts and comments as required by the WordPress.org theme store without styling.
  • Mo Plugin adds a custom post type together with a shortcode.
  • Mo Pro Theme extends Mo Theme and uses Mo Plugin:
    • Displays the shortcode added by the Mo Plugin.
    • Extends the homepage from Mo Theme by adding a sidebar.
    • Displays a widget in the sidebar with custom post types added by the Mo Plugin.
    • Displays a settings menu in the admin dashboard where all the above features can be disabled or enabled.

Why another boilerplate?

The answer is two fold.

There is no official alternative

WordPress has no such thing like this. They provide boilerplate for themes only. There is no boilerplate for plugins, child themes, and how to integrate them.

And, the WordPress boilerplate theme is not class based, in contrast with their recommendation in the Theme Developer Handbook.

Others perhaps have such a combo or maybe not. One of the best WordPress agencies 10up has nothing like this in their public Github repository.

Even if other shops have it, or have parts of it โ€” finding, learning, mixing it into a whole might be more time consuming than this learning by doing approach.

Components

Components are a web development best practice (see Google Material Design) not yet adapted by WordPress.

More Theme Baby has an award winning framework-agnostic component set which should work with WordPress too when WordPress follows the component model.

Best practices

  • Default WordPress files organization
  • Class based namespaces
  • Components
  • Loose coupling
  • Single responsibility principle
  • Optimized database operations
  • Documentation
  • Testing (Work in progress)

For details please check each theme's and the plugin's README.md.

Inspiration

Change log

See CHANGELOG.md.

wp-best-practices's People

Contributors

metamn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wp-best-practices's Issues

HTML element ID must be a single word

Describe the bug
Right now we can have IDs like <nav id="header-menu-hamburger header-menu-hamburger--closed"> instead of <nav id="header-menu-hamburger">

To Reproduce
Steps to reproduce the behavior:

$attributes = apply_filters(
	'mo_theme_header_menu_hamburger_nav_attributes',
	array(
		'block'         => 'header-menu-hamburger',
		'element'       => '',
		'modifier'      => 'closed',
		'display_class' => true,
		'display_id'    => true,
	)
);
$component->attributes->display( $attributes );

Expected behavior
Te get a <nav id="header-menu-hamburger" class="header-menu-hamburger header-menu-hamburger--closed"> result.

Create a settings page for the plugin in the Admin

Describe the solution you'd like
Create a settings page in the plugin where project features can be switched on or of..

Additional context
This is meant to be boilerplate code for the WordPress Options and Settings API.

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.