From 80a25697454b2f4e37715b166fe52d3227694d15 Mon Sep 17 00:00:00 2001 From: ap7 Date: Thu, 30 May 2019 00:59:44 +0800 Subject: [PATCH] Initial core block override and custom blocks - Add Carbon Fields custom-panel block. - Overide core/quote block - PHP dependency cleanup. - Remove extra spaces in README.md - Initial folder structure --- README.md | 2 +- composer.lock | 98 +++++++++++++++++- functions.php | 21 ++-- inc/custom-blocks.php | 28 ++++++ template-parts/blocks/class-core-blocks.php | 106 ++++++++++++++++++++ template-parts/blocks/custom-panel.php | 41 ++++++++ 6 files changed, 284 insertions(+), 12 deletions(-) create mode 100644 inc/custom-blocks.php create mode 100644 template-parts/blocks/class-core-blocks.php create mode 100644 template-parts/blocks/custom-panel.php diff --git a/README.md b/README.md index 5f129ee..b6911ed 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ After WordPress setup follow these steps: ## Dependecies - [UIKit 3](https://github.com/uikit/uikit) - A lightweight and modular front-end framework for developing fast and powerful web interfaces -- [Carbon Fields ](https://github.com/htmlburger/carbon-fields) - A developer-oriented library for WordPress custom fields for all types of WordPress content. +- [Carbon Fields](https://github.com/htmlburger/carbon-fields) - A developer-oriented library for WordPress custom fields for all types of WordPress content. ## Roadmap ([See v1](https://github.com/wpugph/gutenberg-starter-theme/projects/1)) - Integrate UIKit 3 diff --git a/composer.lock b/composer.lock index b45696d..4b77705 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "26923ec677545ba9c5ca2f0f58926ebc", + "content-hash": "693654def3afa37136a178c3237404c4", "packages": [ { "name": "htmlburger/carbon-fields", @@ -139,6 +139,102 @@ "homepage": "http://carbonfields.net/", "time": "2019-04-11T09:46:37+00:00" }, + { + "name": "paquettg/php-html-parser", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/paquettg/php-html-parser.git", + "reference": "77e4a44b0916690b4300fe9abf98fd05bbba48f0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paquettg/php-html-parser/zipball/77e4a44b0916690b4300fe9abf98fd05bbba48f0", + "reference": "77e4a44b0916690b4300fe9abf98fd05bbba48f0", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "paquettg/string-encode": "~1.0.0", + "php": ">=7.1" + }, + "require-dev": { + "mockery/mockery": "^1.2", + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^7.5.1" + }, + "type": "library", + "autoload": { + "psr-0": { + "PHPHtmlParser": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gilles Paquette", + "email": "paquettg@gmail.com", + "homepage": "http://gillespaquette.ca" + } + ], + "description": "An HTML DOM parser. It allows you to manipulate HTML. Find tags on an HTML page with selectors just like jQuery.", + "homepage": "https://github.com/paquettg/php-html-parser", + "keywords": [ + "dom", + "html", + "parser" + ], + "time": "2019-02-10T01:35:49+00:00" + }, + { + "name": "paquettg/string-encode", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/paquettg/string-encoder.git", + "reference": "a8708e9fac9d5ddfc8fc2aac6004e2cd05d80fee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paquettg/string-encoder/zipball/a8708e9fac9d5ddfc8fc2aac6004e2cd05d80fee", + "reference": "a8708e9fac9d5ddfc8fc2aac6004e2cd05d80fee", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5.1" + }, + "type": "library", + "autoload": { + "psr-0": { + "stringEncode": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gilles Paquette", + "email": "paquettg@gmail.com", + "homepage": "http://gillespaquette.ca" + } + ], + "description": "Facilitating the process of altering string encoding in PHP.", + "homepage": "https://github.com/paquettg/string-encoder", + "keywords": [ + "charset", + "encoding", + "string" + ], + "time": "2018-12-21T02:25:09+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.4.2", diff --git a/functions.php b/functions.php index c61028f..3d83cfb 100644 --- a/functions.php +++ b/functions.php @@ -12,17 +12,15 @@ /** * Autoload Carbon Fields. - * - * @return void */ -function crb_load() { - require_once get_template_directory() . '/vendor/autoload.php'; - \Carbon_Fields\Carbon_Fields::boot(); -} -add_action( 'after_setup_theme', 'crb_load' ); +require_once get_template_directory() . '/vendor/autoload.php'; +\Carbon_Fields\Carbon_Fields::boot(); +// Load theme constants. require get_template_directory() . '/inc/defines.php'; -require get_template_directory() . '/inc/theme-options.php'; + +// Setup and load custom block containers. +require get_template_directory() . '/inc/custom-blocks.php'; if ( ! function_exists( 'themewpugph_setup' ) ) : /** @@ -33,6 +31,9 @@ function crb_load() { * as indicating support for post thumbnails. */ function themewpugph_setup() { + + require get_template_directory() . '/inc/theme-options.php'; + /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. @@ -111,8 +112,8 @@ function themewpugph_setup() { ) ); - // Adding support for core block visual styles. - add_theme_support( 'wp-block-styles' ); + // Don't load core block visual styles. + // add_theme_support( 'wp-block-styles' ); // Add support for full and wide align images. add_theme_support( 'align-wide' ); diff --git a/inc/custom-blocks.php b/inc/custom-blocks.php new file mode 100644 index 0000000..ec43531 --- /dev/null +++ b/inc/custom-blocks.php @@ -0,0 +1,28 @@ +loadHTML( self::$block_content ); + + // The main quote block. + $quote = $doc->getElementsByTagName( 'blockquote' )->item( 0 ); + $quote->removeAttribute( 'class' ); + $quote->setAttribute( 'cite', '#' ); + + // Wrap cite to footer tag. + $cite = $quote->removeChild( + $quote->getElementsByTagName( 'cite' )->item( 0 ) + ); + $footer = $doc->createElement( 'footer', '' ); + $footer->appendChild( $cite ); + + // Append new footer to main quote block. + $quote->appendChild( $footer ); + + return $doc->saveHTML(); + } +} + +// Initialize core blocks override. +Core_Blocks::init(); diff --git a/template-parts/blocks/custom-panel.php b/template-parts/blocks/custom-panel.php new file mode 100644 index 0000000..be8beeb --- /dev/null +++ b/template-parts/blocks/custom-panel.php @@ -0,0 +1,41 @@ +add_fields( + array( + Field::make( 'text', 'heading', __( 'Panel Heading', 'themewpugph' ) ), + Field::make( 'image', 'image', __( 'Panel Image', 'themewpugph' ) ), + Field::make( 'textarea', 'content', __( 'Panel Content', 'themewpugph' ) ), + Field::make( 'text', 'url', __( 'Panel Link', 'themewpugph' ) ), + ) + ) + ->set_category( 'layout' ) + ->set_icon( 'layout' ) + ->set_description( __( 'A simple panel block.', 'themewpugph' ) ) + ->set_render_callback( + function ( $fields, $attributes, $inner_blocks ) { + ?> +
+
+ +
+
+

+

+

+
+
+ +