Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #28

Merged
merged 3 commits into from
Nov 13, 2024
Merged

Dev #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
=== RRZE Hello Lenny ===
Contributors: rrze-webteam
Plugin URI: https://github.com/RRZE-Webteam/rrze-hello-lenny/
Tags: hello lenny, shortcode, block, fun
Requires at least: 6.6
Tested up to: 6.6
Requires PHP: 8.2
Stable tag: 1.3.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Author: RRZE Webteam
Author URI: https://blogs.fau.de/webworking/
Text Domain: rrze-hello-lenny
Domain Path: /languages

[![Aktuelle Version](https://img.shields.io/github/package-json/v/rrze-webteam/rrze-hello-lenny/main?label=Version)](https://github.com/RRZE-Webteam/rrze-hello-lenny)
[![Release Version](https://img.shields.io/github/v/release/rrze-webteam/rrze-hello-lenny?label=Release+Version)](https://github.com/rrze-webteam/rrze-hello-lenny/releases/)
[![GitHub License](https://img.shields.io/github/license/rrze-webteam/rrze-hello-lenny)](https://github.com/RRZE-Webteam/rrze-hello-lenny)
[![GitHub issues](https://img.shields.io/github/issues/RRZE-Webteam/rrze-hello-lenny)](https://github.com/RRZE-Webteam/rrze-hello-lenny/issues)
![GitHub milestone details](https://img.shields.io/github/milestones/progress-percent/RRZE-Webteam/rrze-hello-lenny/3)
[![Aktuelle Version](https://img.shields.io/github/package-json/v/rrze-webteam/rrze-hello-lenny/main?label=Version)](https://github.com/RRZE-Webteam/rrze-hello-lenny) [![Release Version](https://img.shields.io/github/v/release/rrze-webteam/rrze-hello-lenny?label=Release+Version)](https://github.com/rrze-webteam/rrze-hello-lenny/releases/) [![GitHub License](https://img.shields.io/github/license/rrze-webteam/rrze-hello-lenny)](https://github.com/RRZE-Webteam/rrze-hello-lenny) [![GitHub issues](https://img.shields.io/github/issues/RRZE-Webteam/rrze-hello-lenny)](https://github.com/RRZE-Webteam/rrze-hello-lenny/issues) ![GitHub milestone details](https://img.shields.io/github/milestones/progress-percent/RRZE-Webteam/rrze-hello-lenny/3)

A plugin that brings Lenny to WordPress – with a shortcode and block.

This README.md file serves as a template: [GitHub Issue #8](https://github.com/RRZE-Webteam/rrze-hello-lenny/issues/8)

# RRZE Hello Lenny

This plugin is inspired by the famous "Hello Dolly" plugin and brings the dog Lenny to your WordPress site. It supports both a shortcode and a Gutenberg block.
This plugin is inspired by the "Hello Dolly" plugin and brings the dog Lenny to your WordPress site. It supports both a shortcode and a Gutenberg block.

## Using as a Block

Expand All @@ -39,5 +18,5 @@ You can use the shortcode `[rrze-hello-lenny]` to add Lenny anywhere in your con

```html
[hello-lenny]

```

66 changes: 66 additions & 0 deletions assets/js/random-bark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Use this file for JavaScript code that you want to run in the front-end
* on posts/pages that contain this block and wherever the shortcode is used.
*
* 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": "script-handle"
* }
* ```
*
* 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
*/

jQuery(document).ready(function ($) {
console.log("Wuff! Hello from the front-end!");
const cssClasses = [
"wouf-ucfirst",
"wouf-uppercase",
"wouf-lowercase",
"wouf-small",
"wouf-large",
"wouf-xlarge",
];

function getRandomClass() {
// Randomly select one CSS class
const randomIndex = Math.floor(Math.random() * cssClasses.length);
return cssClasses[randomIndex];
}

// Function to append "Wouf!" to the paragraph
function appendWouf() {
// Find the paragraph element inside the blockquote
const $blockquote = $(".rrze-hello-lenny p");
if ($blockquote.length === 0) {
return; // Exit if the blockquote element is not found
}

// Create a new span element with the "Wouf!" text and set the class attribute
const $span = $("<span>").text("Wouf!").attr("class", getRandomClass());

// Append the new span to the paragraph
$blockquote.append($span).append(" "); // Add a space after the "Wouf!"
}

// Function to schedule the appending of "Wouf!" after a random delay
function scheduleWouf() {
const randomDelay = Math.floor(Math.random() * 5000) + 1000; // Random delay between 1s and 5s
setTimeout(function () {
appendWouf();
scheduleWouf(); // Schedule the next "Wouf!" append
}, randomDelay);
}

// Start the initial "Wouf!" scheduling
scheduleWouf();
});
Binary file added assets/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion build/block.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/block.js

This file was deleted.

1 change: 0 additions & 1 deletion build/editor.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/editor.css

This file was deleted.

Empty file removed build/editor.js
Empty file.
1 change: 0 additions & 1 deletion build/frontend.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/frontend.css

This file was deleted.

Empty file removed build/frontend.js
Empty file.
37 changes: 37 additions & 0 deletions build/hello-lenny/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "rrze/hello-lenny",
"version": "0.1.0",
"title": "Hello Lenny",
"category": "widgets",
"icon": "smiley",
"description": "Example block scaffolded with Create Block tool.",
"example": {},
"supports": {
"html": false
},
"attributes": {
"cssClasses": {
"type": "string",
"default": ""
},
"backgroundColor": {
"type": "string",
"default": "#ffffff"
},
"borderColor": {
"type": "string",
"default": "#000000"
},
"textColor": {
"type": "string",
"default": "#000000"
}
},
"textdomain": "rrze-hello-lenny",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"viewScript": "lenny-random-bark"
}
1 change: 1 addition & 0 deletions build/hello-lenny/index-rtl.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/hello-lenny/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => '804655961add3d4f6934');
1 change: 1 addition & 0 deletions build/hello-lenny/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/hello-lenny/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/hello-lenny/style-index-rtl.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/hello-lenny/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions includes/BlockEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,35 @@ public function __construct($defaultAttributes)
{
$this->defaultAttributes = $defaultAttributes;
add_action('init', [$this, 'registerBlock']);
add_action('enqueue_block_assets', [$this, 'enqueueBlockAssets']);
// add_action('enqueue_block_assets', [$this, 'enqueueBlockAssets']);
}

public function registerBlock()
{
register_block_type('lenny/quote-block', [
'editor_script' => 'lenny-block-editor-script',
'editor_style' => 'lenny-block-editor-style',
'style' => 'lenny-block-style',
'render_callback' => [$this, 'renderBlock']
]);
register_block_type(
dirname(__DIR__) . '/build/hello-lenny',
array(
'render_callback' => array($this, 'renderBlock'),
)
);
}


public function enqueueBlockAssets()
{
if (!is_admin()) {
wp_enqueue_style('lenny-block-style');
}
// if (!is_admin()) {
// wp_enqueue_style('lenny-block-style');
// }
}

public function renderBlock($attributes)
{
// Sanitize attributes
$attributes['css_classes'] = !empty($attributes['cssClasses']) ? sanitize_hex_color($attributes['cssClasses']) : '';
$attributes['css_classes'] = !empty($attributes['cssClasses']) ? sanitize_text_field($attributes['cssClasses']) : '';
$attributes['background_color'] = !empty($attributes['backgroundColor']) ? sanitize_hex_color($attributes['backgroundColor']) : '';
$attributes['border_color'] = !empty($attributes['borderColor']) ? sanitize_hex_color($attributes['borderColor']) : '';

$attributes['text_color'] = !empty($attributes['textColor']) ? sanitize_hex_color($attributes['textColor']) : '';

wp_enqueue_script('lenny-random-bark');

return Shortcode::generateWuffOutput($attributes);
Expand Down
1 change: 1 addition & 0 deletions includes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static function getDefaultAttributes()
'css_classes' => '',
'background_color' => '#ffffff',
'border_color' => '#000000',
'text_color' => '#000000'
];
}
}
27 changes: 6 additions & 21 deletions includes/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Main
* The version of the plugin.
* @var string
*/
protected $pluginVersion;
protected $pluginVersion;

/**
* Assign values to variables.
Expand Down Expand Up @@ -59,7 +59,7 @@ protected function setPluginVersion()
{
$pluginData = get_file_data($this->pluginFile, ['Version' => 'Version'], false);
$this->pluginVersion = $pluginData['Version'] ?? '1.0.0';
}
}

/**
* Register assets.
Expand All @@ -69,32 +69,17 @@ public function registerAssets()
// Register scripts and styles
wp_register_script(
'lenny-random-bark',
plugins_url('src/js/random-bark.js', plugin_basename($this->pluginFile)),
plugin_dir_url($this->pluginFile) . 'assets/js/random-bark.js',
['jquery'],
filemtime(plugin_dir_path($this->pluginFile) . 'src/js/random-bark.js') ?: $this->pluginVersion,
$this->pluginVersion,
true
);

wp_register_style(
'lenny-frontend-style',
plugins_url('build/frontend.css', plugin_basename($this->pluginFile)),
[],
filemtime(plugin_dir_path($this->pluginFile) . 'build/frontend.css') ?: $this->pluginVersion
);

wp_register_script(
'lenny-block-editor-script',
plugins_url('build/block.js', plugin_basename($this->pluginFile)),
['wp-blocks', 'wp-element', 'wp-editor'],
filemtime(plugin_dir_path($this->pluginFile) . 'build/block.js') ?: $this->pluginVersion,
true
);

wp_register_style(
'lenny-block-editor-style',
plugins_url('build/editor.css', plugin_basename($this->pluginFile)),
plugins_url('build/hello-lenny/style-index.css', plugin_basename($this->pluginFile)),
[],
filemtime(plugin_dir_path($this->pluginFile) . 'build/editor.css') ?: $this->pluginVersion
$this->pluginVersion
);
}

Expand Down
Loading