Skip to content

Commit

Permalink
build(initial): initial build
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarshall511 committed Dec 15, 2023
1 parent 84eb8bb commit 124e127
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 17 deletions.
81 changes: 81 additions & 0 deletions create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh
slugify () {
echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z
}

read -p "What is the plugin's name? " plugin_name

read -p "What is the plugin's shortname? " plugin_short_name

read -p "What is the plugin's description? " plugin_description

read -p "What is the plugin's URI? " plugin_uri

read -p "What is the name of the plugin's author [Highfivery LLC]? " plugin_author
plugin_author=${plugin_author:-Highfivery LLC}

read -p "What is the name of the plugin's author URI [https://www.highfivery.com]? " plugin_author_uri
plugin_author_uri=${plugin_author_uri:-https://www.highfivery.com}

read -p "What license should the plugin use [GPL v2 or later]? " plugin_license
plugin_license=${plugin_license:-GPL v2 or later}

read -p "What's the license URI [https://www.gnu.org/licenses/gpl-2.0.html]? " plugin_license_uri
plugin_license_uri=${plugin_license_uri:-https://www.gnu.org/licenses/gpl-2.0.html}

plugin_slug=$(slugify "$plugin_name")
read -p "What is the plugin's text domain [$plugin_slug]? " text_domain
text_domain=${text_domain:-${plugin_slug}}

read -p "What is the name of the plugin's function prefix? " function_prefix

read -p "What is the plugin's contant name? " plugin_constant

read -p "What is the plugin's package name? " package_name

echo
# Header
echo -e "\033[1mPlugin Information:\033[0m"

# Body
printf "%-20s %s\n" "Name:" "$plugin_name"
printf "%-20s %s\n" "Shortname:" "$plugin_short_name"
printf "%-20s %s\n" "Description:" "$plugin_description"
printf "%-20s %s\n" "URI:" "$plugin_uri"
printf "%-20s %s\n" "Author:" "$plugin_author ($plugin_author_uri)"
printf "%-20s %s\n" "Plugin License:" "$plugin_license ($plugin_license_uri)"
printf "%-20s %s\n" "Text Domain:" "$text_domain"
printf "%-20s %s\n" "Function Prefix:" "$function_prefix"
printf "%-20s %s\n" "Constant:" "$plugin_constant"
printf "%-20s %s\n" "Package Name:" "$package_name"

# Footer
echo

read -r -p "Does this all look right? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
mkdir -p $text_domain
rsync -av --exclude='.git' --exclude='.husky' --exclude='docs' --exclude='node_modules' --exclude=$text_domain --exclude='LICENSE' --exclude='README.md' --exclude='create.sh' . $text_domain
cd $text_domain
mv wp-plugin-scaffold.php "$text_domain.php"
find ./ -type f -exec sed -i '' -e "s~WordPress Plugin Scaffold~$plugin_name~g" {} \;
find ./ -type f -exec sed -i '' -e "s~WPPluginScaffold~$package_name~g" {} \;
find ./ -type f -exec sed -i '' -e "s~A plugin WordPress scaffold to help you get started quickly.~$plugin_description~g" {} \;
find ./ -type f -exec sed -i '' -e "s~wp-plugin-scaffold~$text_domain~g" {} \;
find ./ -type f -exec sed -i '' -e "s~https://highfivery.com~$plugin_author_uri~g" {} \;
find ./ -type f -exec sed -i '' -e "s~https://project-website.tld~$plugin_uri~g" {} \;
find ./ -type f -exec sed -i '' -e "s~https://github.com/Highfivery/wp-plugin-scaffold~$plugin_uri~g" {} \;
find ./ -type f -exec sed -i '' -e "s~Highfivery~$plugin_author~g" {} \;
find ./ -type f -exec sed -i '' -e "s~WP_PLUGIN_SCAFFOLD~$plugin_constant~g" {} \;
find ./ -type f -exec sed -i '' -e "s~wp_plugin_scaffold~$function_prefix~g" {} \;
find ./ -type f -exec sed -i '' -e "s~https://www.gnu.org/licenses/gpl-2.0.html~$plugin_license_uri~g" {} \;
find ./ -type f -exec sed -i '' -e "s~GPL v2 or later~$plugin_license~g" {} \;
find ./ -type f -exec sed -i '' -e "s~WP Plugin Scaffold~$plugin_short_name~g" {} \;
cd ..
mv $text_domain ../
;;
*)
false
;;
esac
65 changes: 60 additions & 5 deletions includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function options_page() {
$options = get_option( 'wp_plugin_scaffold' );
?>
<div class="wrap">
<h1><?php echo __( 'WordPress Plugin Scaffold Settings', 'wp-plugin-scaffold' ); ?></h1>
<h1><?php echo esc_html( __( 'WordPress Plugin Scaffold Settings', 'wp-plugin-scaffold' ) ); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields( 'wp-plugin-scaffold' );
Expand Down Expand Up @@ -245,11 +245,29 @@ function settings_section() {
}

function settings_field( $args ) {
$value = get_option( 'wp_plugin_scaffold' );
$settings = get_option( 'wp_plugin_scaffold' );

$setting_name = 'wp_plugin_scaffold[' . $args['key'] . ']';
$value = ! empty( $settings[ $args['key'] ] ) ? $settings[ $args['key'] ] : false;

switch ( $args['type'] ) {
case 'textarea':
?>
<textarea
id="<?php echo esc_attr( $args['key'] ); ?>"
name="<?php echo esc_attr( $setting_name ); ?>"
<?php if ( ! empty( $args['rows'] ) ) : ?>
rows="<?php echo esc_attr( $args['rows'] ); ?>"
<?php endif; ?>
<?php if ( ! empty( $args['classes'] ) ) : ?>
class="<?php echo esc_attr( $args['classes'] ); ?>"
<?php endif; ?>
<?php if ( ! empty( $args['placeholder'] ) ) : ?>
placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>"
<?php endif; ?>
><?php echo wp_kses_post( $value ); ?></textarea>
<?php
break;
case 'url':
case 'text':
case 'password':
Expand All @@ -260,9 +278,7 @@ function settings_field( $args ) {
id="<?php echo esc_attr( $args['key'] ); ?>"
name="<?php echo esc_attr( $setting_name ); ?>"
type="<?php echo esc_attr( $args['type'] ); ?>"
<?php if ( ! empty( $args['value'] ) ) : ?>
value="<?php echo esc_attr( $args['value'] ); ?>"
<?php endif; ?>
value="<?php echo esc_attr( $value ); ?>"
<?php if ( ! empty( $args['classes'] ) ) : ?>
class="<?php echo esc_attr( $args['classes'] ); ?>"
<?php endif; ?>
Expand All @@ -281,5 +297,44 @@ class="<?php echo esc_attr( $args['classes'] ); ?>"
/>
<?php
break;
case 'select':
?>
<select
id="<?php echo esc_attr( $args['key'] ); ?>"
name="<?php echo esc_attr( $setting_name ); ?>"
<?php if ( ! empty( $args['multiple'] ) ) : ?>
multiple
<?php endif; ?>
<?php if ( ! empty( $args['classes'] ) ) : ?>
class="<?php echo esc_attr( $args['classes'] ); ?>"
<?php endif; ?>
>
<?php
foreach ( $args['options'] as $key => $label ) :
$selected = false;
if (
(
! empty( $value ) &&
! empty( $args['multiple'] ) &&
is_array( $value ) &&
in_array( $key, $value, true )
) ||
! empty( $value ) && $value === $key
) :
$selected = true;
endif;
?>
<option
value="<?php echo esc_attr( $key ); ?>"
<?php if ( $selected ) : ?>
selected="selected"
<?php endif; ?>
>
<?php echo esc_html( $label ); ?>
</option>
<?php endforeach; ?>
</select>
<?php
break;
}
}
12 changes: 0 additions & 12 deletions wp-plugin-scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-plugin-scaffold
*
* This is a plugin scaffold to help you get started quickly and should be copied
* to your new plugin. Run a search and replace on the following strings:
*
* WordPress Plugin Scaffold - Plugin name
* wp-plugin-scaffold - Text domain
* WP_PLUGIN_SCAFFOLD_PLUGIN - Contant prefix
* WPPluginScaffold - Namespace & package
* wp_plugin_scaffold - Function prefix
* https://project-website.tld - Project domain
* https://github.com/Highfivery/wp-plugin-scaffold - Git repo
* WP Plugin Scaffold - Shortname
*
* @package WPPluginScaffold
*/

Expand Down

0 comments on commit 124e127

Please sign in to comment.