Skip to content

Commit

Permalink
build(intial): initial build
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarshall511 committed Dec 9, 2023
1 parent a93db57 commit b3b60d4
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 20 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/wpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: WPCS check

on: pull_request

jobs:
phpcs:
name: WPCS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: WPCS check
uses: 10up/wpcs-action@stable
- name: Update summary
run: |
npm i -g github:10up/phpcs-json-to-md
phpcs-json-to-md --path ./phpcs.json --output ./phpcs.md
cat phpcs.md >> $GITHUB_STEP_SUMMARY
if: always()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.husky
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
117 changes: 117 additions & 0 deletions includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function setup() {
add_action( 'admin_enqueue_scripts', $n( 'admin_scripts' ) );
add_action( 'enqueue_block_editor_assets', $n( 'core_block_overrides' ) );
add_action( 'wp_enqueue_scripts', $n( 'styles' ) );
add_action( 'admin_menu', $n( 'add_options_page' ) );
add_action( 'admin_init', $n( 'register_settings' ) );

add_filter( 'script_loader_tag', $n( 'script_loader_tag' ), 10, 2 );
}
Expand Down Expand Up @@ -153,3 +155,118 @@ function script_loader_tag( $tag, $handle ) {

return $tag;
}

function add_options_page() {
add_submenu_page(
'options-general.php',
__( 'WordPress Plugin Scaffold Settings', 'wp-plugin-scaffold' ),
__( 'WP Plugin Scaffold', 'wp-plugin-scaffold' ),
'manage_options',
'wp-plugin-scaffold',
__NAMESPACE__ . '\options_page'
);
}

function options_page() {
$options = get_option( 'wp_plugin_scaffold' );
?>
<div class="wrap">
<h1><?php echo __( 'WordPress Plugin Scaffold Settings', 'wp-plugin-scaffold' ); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields( 'wp-plugin-scaffold' );
do_settings_sections( 'wp-plugin-scaffold' );
submit_button();
?>
</form>
</div>
<?php
}

function register_settings() {
$plugin_settings = [
'general' => [
'title' => __( 'General Settings', 'wp-plugin-scaffold' ),
'settings' => [
[
'title' => __( 'Open Name', 'wp-plugin-scaffold' ),
'field' => [
'key' => 'option',
'type' => 'text',
'classes' => 'regular-text ltr',
'placeholder' => __( 'Option placeholder', 'wp-plugin-scaffold' ),
],
],
],
],
];

register_setting( 'wp-plugin-scaffold', 'wp_plugin_scaffold' );

foreach ( $plugin_settings as $section_key => $section ) {
add_settings_section(
'wp_plugin_scaffold_' . $section_key,
$section['title'],
__NAMESPACE__ . '\settings_section',
'wp-plugin-scaffold'
);

if ( ! empty ( $section['settings'] ) ) {
foreach ( $section['settings'] as $key => $setting ) {
add_settings_field(
$setting['field']['key'],
$setting['title'],
__NAMESPACE__ . '\settings_field',
'wp-plugin-scaffold',
'wp_plugin_scaffold_' . $section_key,
$setting['field']
);
}
}
}
}

function settings_section() {
?>
<?php
}

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

$setting_name = 'wp_plugin_scaffold[' . $args['key'] . ']';

switch ( $args['type'] ) {
case 'url':
case 'text':
case 'password':
case 'number':
case 'email':
?>
<input
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; ?>
<?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 if ( ! empty( $args['min'] ) ) : ?>
min="<?php echo esc_attr( $args['min'] ); ?>"
<?php endif; ?>
<?php if ( ! empty( $args['max'] ) ) : ?>
max="<?php echo esc_attr( $args['max'] ); ?>"
<?php endif; ?>
<?php if ( ! empty( $args['step'] ) ) : ?>
step="<?php echo esc_attr( $args['step'] ); ?>"
<?php endif; ?>
/>
<?php
break;
}
}
49 changes: 49 additions & 0 deletions includes/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Database handlers.
*
* @package WPPluginScaffold
*/

namespace WPPluginScaffold\Database;

/**
* Set up the database
*
* @return void
*/
function setup() {
$n = function( $func ) {
return __NAMESPACE__ . "\\$func";
};

add_action( 'init', $n( 'update' ), 11 );
}

/**
* Run functions on plugin update/activation
*
* @return void
*/
function update() {
$previous_version = get_option( 'wp_plugin_scaffold_version', 0 );

if ( version_compare( $previous_version, '0.0.1', '<=' ) ) {
update_database();
}

update_option( 'wp_plugin_scaffold_version', WP_PLUGIN_SCAFFOLD_PLUGIN_VERSION );
}

function update_database() {
global $wpdb;

$table_name = $wpdb->prefix . 'wp_plugin_scaffold';

$sql = "CREATE TABLE $table_name (
);";

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
Loading

0 comments on commit b3b60d4

Please sign in to comment.