Changes to directory structure

This commit is contained in:
Jeremy Rangel
2024-12-18 02:27:09 -08:00
parent d5a5f4e87b
commit 94d2c7c8a2
135 changed files with 335 additions and 5435 deletions

View File

@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
[*.{yml,yaml}]
indent_style = space
indent_size = 2

View File

@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Coverage directory used by tools like istanbul
coverage
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Output of `npm pack`
*.tgz
# Output of `wp-scripts plugin-zip`
*.zip
# dotenv environment variables file
.env

View File

@ -0,0 +1,97 @@
<?php
/**
* Plugin Name: Key Points
* Description: Example block scaffolded with Create Block tool.
* Requires at least: 6.6
* Requires PHP: 7.2
* Version: 0.1.0
* Author: The WordPress Contributors
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: key-points
*
* @package CreateBlock
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Enqueue block assets for the editor
function enqueue_key_points_block_assets() {
wp_enqueue_script(
'key-points-editor-script', // Handle for the block script
plugin_dir_url(__FILE__) . 'block.js', // Path to the block JS file
['wp-blocks', 'wp-element', 'wp-editor'], // Dependencies
filemtime(plugin_dir_path(__FILE__) . 'block.js'), // Cache-busting
true // Load script in the footer
);
}
add_action('enqueue_block_editor_assets', 'enqueue_key_points_block_assets');
// Render callback function to display the key points
// Render callback function to display the key points
// Render callback function to display the key points
function render_key_points_block($attributes, $content) {
// Ensure we're in the correct post context
if (!is_single()) {
return null; // Only render on single post pages
}
// Get the current post ID (Ensure the correct context)
$post_id = get_the_ID();
// Log for debugging purposes
error_log('Current Post ID: ' . $post_id);
// Get the key points stored as a serialized string in post meta
$key_points_serialized = get_post_meta($post_id, 'key_points', true);
// Log the serialized data
error_log('Key Points Serialized Data: ' . var_export($key_points_serialized, true)); // Log to debug
// Unserialize the data into an array
$key_points = !empty($key_points_serialized) ? unserialize($key_points_serialized) : [];
// Log the unserialized data
error_log('Key Points Unserialized Data: ' . var_export($key_points, true)); // Log to debug
// If no key points are available, return an error message
if (empty($key_points)) {
return null;
}
// Check if the headingTag attribute is set and wrap the heading accordingly
$heading_tag = !empty($attributes['headingTag']) ? $attributes['headingTag'] : 'h2'; // Default to h2 if not provided
$heading_font_size = !empty($attributes['headingFontSizeLarge']) ? $attributes['headingFontSizeLarge'] : '24px'; // Default size if not provided
$points_font_size = !empty($attributes['pointsFontSizeLarge']) ? $attributes['pointsFontSizeLarge'] : '16px'; // Default size if not provided
$list_style_type = !empty($attributes['listStyleType']) ? $attributes['listStyleType'] : 'disc'; // Default size if not provided
// Create the heading with font size applied
$heading = "<{$heading_tag} style='font-size: " . esc_attr($heading_font_size) . ";'>" . esc_html($attributes['heading']) . "</{$heading_tag}>";
// Create the <ul> list and populate it with the key points
$output = $heading; // Start with the heading
$output .= '<ul id="lcp-key-points" style="list-style-type: ' . esc_attr($list_style_type) . ';">';
foreach ($key_points as $point) {
// Avoid empty points
if (!empty($point)) {
$output .= '<li style="font-size: ' . esc_attr($points_font_size) . ';">' . esc_html($point) . '</li>';
}
}
$output .= '</ul>';
return $output;
}
// Register the block
function register_key_points_block() {
register_block_type(__DIR__ . '/build', [
'editor_script' => 'key-points-editor-script', // Script for the editor
'render_callback' => 'render_key_points_block', // PHP callback for frontend rendering
]);
}
add_action('init', 'register_key_points_block');

View File

@ -0,0 +1,20 @@
{
"name": "key-points",
"version": "0.1.0",
"description": "Example block scaffolded with Create Block tool.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"main": "build/index.js",
"scripts": {
"build": "wp-scripts build",
"format": "wp-scripts format",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"packages-update": "wp-scripts packages-update",
"plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start"
},
"devDependencies": {
"@wordpress/scripts": "^30.6.0"
}
}

View File

@ -0,0 +1,55 @@
=== Key Points ===
Contributors: The WordPress Contributors
Tags: block
Tested up to: 6.6
Stable tag: 0.1.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Example block scaffolded with Create Block tool.
== Description ==
This is the long description. No limit, and you can use Markdown (as well as in the following sections).
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.
== Installation ==
This section describes how to install the plugin and get it working.
e.g.
1. Upload the plugin files to the `/wp-content/plugins/key-points` directory, or install the plugin through the WordPress plugins screen directly.
1. Activate the plugin through the 'Plugins' screen in WordPress
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= What about foo bar? =
Answer to foo bar dilemma.
== Screenshots ==
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot
== Changelog ==
= 0.1.0 =
* Release
== Arbitrary section ==
You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
"installation." Arbitrary sections will be shown below the built-in sections outlined above.

View File

@ -0,0 +1,41 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "lcp/key-points",
"version": "0.1.0",
"title": "Key Points",
"category": "widgets",
"icon": "smiley",
"description": "Key points meta field for single posts",
"example": {},
"supports": {
"html": false
},
"attributes": {
"heading": {
"type": "string",
"default": "Key Points"
},
"headingTag": {
"type": "string",
"default": "h3"
},
"headingFontSizeLarge": {
"type": "string",
"default": "24px"
},
"pointsFontSizeLarge": {
"type": "string",
"default": "16px"
},
"listStyleType": {
"type": "string",
"default": "disc"
}
},
"textdomain": "key-points",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"viewScript": "file:./view.js"
}

View File

@ -0,0 +1,118 @@
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { SelectControl, FontSizePicker, TextControl } from '@wordpress/components';
import { useState, useEffect } from 'react';
import './editor.scss';
export default function Edit( { attributes, setAttributes } ) {
const { heading, pointsFontSizeLarge, headingFontSizeLarge, listStyleType } = attributes;
const fontSizes = [
{
name: __( 'Small', 'key-points' ),
slug: 'small',
size: '12px',
},
{
name: __( 'Medium', 'key-points' ),
slug: 'medium',
size: '16px',
},
{
name: __( 'Large', 'key-points' ),
slug: 'large',
size: '24px',
},
{
name: __( 'Extra Large', 'key-points' ),
slug: 'x-large',
size: '36px',
},
];
const listStyleTypeOptions = [
{ label: __( 'Disc', 'lcp' ), value: 'disc' },
{ label: __( 'Circle', 'lcp' ), value: 'circle' },
{ label: __( 'Square', 'lcp' ), value: 'square' },
{ label: __( 'None', 'lcp' ), value: 'none' },
];
// Static Lorem Ipsum key points (5 unique points)
const loremIpsumPoints = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
];
const [keyPoints, setKeyPoints] = useState(loremIpsumPoints); // Set initial key points to the Lorem Ipsum array
return (
<>
{/* Inspector Controls */}
<InspectorControls>
{/* List Style Dropdown */}
<SelectControl
label={ __( 'List Style', 'lcp' ) }
value={ listStyleType }
options={ listStyleTypeOptions }
onChange={ ( newValue ) => {
setAttributes( { listStyleType: newValue } );
} }
/>
{/* Heading Input */}
<TextControl
label={ __( 'Heading', 'lcp' ) }
value={ heading || '' }
onChange={ ( newHeading ) => setAttributes( { heading: newHeading } ) }
/>
{/* Font Size Picker for Points */}
<FontSizePicker
fontSizes={ fontSizes }
units={ ['px', 'em', 'rem', 'vw', 'vh'] }
value={ pointsFontSizeLarge }
onChange={ ( newFontSize ) => {
if ( typeof newFontSize === 'string' ) {
setAttributes( { pointsFontSizeLarge: newFontSize } );
}
} }
fallbackFontSize={ '16px' }
/>
{/* Font Size Picker for Heading */}
<FontSizePicker
fontSizes={ fontSizes }
units={ ['px', 'em', 'rem', 'vw', 'vh'] }
value={ headingFontSizeLarge }
onChange={ ( newFontSize ) => {
if ( typeof newFontSize === 'string' ) {
setAttributes( { headingFontSizeLarge: newFontSize } );
}
} }
fallbackFontSize={ '24px' }
/>
</InspectorControls>
{/* Block Content */}
<p { ...useBlockProps() }>
{ __( 'Key Points hello from the editor!', 'lcp' ) }
</p>
{ heading && <h2>{ heading }</h2> }
{/* Display key points */}
{ keyPoints && keyPoints.length > 0 && (
<ul style={{ listStyleType: listStyleType }}>
{keyPoints.map((point, index) => (
<li key={index} style={{ fontSize: pointsFontSizeLarge }}>
{point}
</li>
))}
</ul>
)}
</>
);
}

View File

@ -0,0 +1,9 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-key-points {
border: 1px dotted #f00;
}

View File

@ -0,0 +1,39 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';
/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './style.scss';
/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';
import metadata from './block.json';
/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType( metadata.name, {
/**
* @see ./edit.js
*/
edit: Edit,
/**
* @see ./save.js
*/
save,
} );

View File

@ -0,0 +1,22 @@
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
*/
import { useBlockProps } from '@wordpress/block-editor';
/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save
*
* @return {Element} Element to render.
*/
export default function save() {
return (
null
);
}

View File

@ -0,0 +1,12 @@
/**
* The following styles get applied both on the front of your site
* and in the editor.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-key-points {
background-color: #21759b;
color: #fff;
padding: 2px;
}

View File

@ -0,0 +1,25 @@
/**
* Use this file for JavaScript code that you want to run in the front-end
* on posts/pages that contain this block.
*
* When this file is defined as the value of the `viewScript` property
* in `block.json` it will be enqueued on the front end of the site.
*
* Example:
*
* ```js
* {
* "viewScript": "file:./view.js"
* }
* ```
*
* If you're not making any changes to this file because your project doesn't need any
* JavaScript running in the front-end, then you should delete this file and remove
* the `viewScript` property from `block.json`.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script
*/
/* eslint-disable no-console */
console.log( 'Hello World! (from create-block-key-points block)' );
/* eslint-enable no-console */