Skip to content

Commit ae965f8

Browse files
Simple boilerplate plugin with vue
1 parent 2853bba commit ae965f8

30 files changed

+1140
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Plugin-Name

includes/Classes/AccessControl.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace PluginName\Classes;
4+
5+
6+
class AccessControl
7+
{
8+
public static function hasTopLevelMenuPermission()
9+
{
10+
$menuPermissions = array(
11+
'manage_options',
12+
'plugin_name_full_access',
13+
'plugin_name_can_view_menus'
14+
);
15+
foreach ($menuPermissions as $menuPermission) {
16+
if (current_user_can($menuPermission)) {
17+
return $menuPermission;
18+
}
19+
}
20+
return false;
21+
}
22+
}

includes/Classes/Activator.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace PluginName\Classes;
4+
5+
if (!defined('ABSPATH')) {
6+
exit;
7+
}
8+
9+
/**
10+
* Ajax Handler Class
11+
* @since 1.0.0
12+
*/
13+
class Activator
14+
{
15+
public function migrateDatabases($network_wide = false)
16+
{
17+
global $wpdb;
18+
if ($network_wide) {
19+
// Retrieve all site IDs from this network (WordPress >= 4.6 provides easy to use functions for that).
20+
if (function_exists('get_sites') && function_exists('get_current_network_id')) {
21+
$site_ids = get_sites(array('fields' => 'ids', 'network_id' => get_current_network_id()));
22+
} else {
23+
$site_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE site_id = $wpdb->siteid;");
24+
}
25+
// Install the plugin for all these sites.
26+
foreach ($site_ids as $site_id) {
27+
switch_to_blog($site_id);
28+
$this->migrate();
29+
restore_current_blog();
30+
}
31+
} else {
32+
$this->migrate();
33+
}
34+
35+
}
36+
37+
private function migrate()
38+
{
39+
$this->createBookmarkTable();
40+
}
41+
42+
public function createBookmarkTable()
43+
{
44+
global $wpdb;
45+
$charset_collate = $wpdb->get_charset_collate();
46+
$table_name = $wpdb->prefix . 'plugin-name';
47+
$sql = "CREATE TABLE $table_name (
48+
pl_id int(10) NOT NULL AUTO_INCREMENT,
49+
pl_name varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
50+
chart_values varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
51+
created_at timestamp NULL DEFAULT NULL,
52+
updated_at timestamp NULL DEFAULT NULL,
53+
PRIMARY KEY (chart_id)
54+
) $charset_collate;";
55+
56+
$this->runSQL($sql, $table_name);
57+
}
58+
59+
private function runSQL($sql, $tableName)
60+
{
61+
global $wpdb;
62+
if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
63+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
64+
dbDelta($sql);
65+
}
66+
}
67+
}

includes/Classes/AdminApp.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
4+
namespace PluginName\Classes;
5+
6+
if (!defined('ABSPATH')) {
7+
exit;
8+
}
9+
10+
/**
11+
* Admin App Renderer and Handler
12+
* @since 1.0.0
13+
*/
14+
class AdminApp
15+
{
16+
public function bootView()
17+
{
18+
echo "<div id='plugin_name_app'></div>";
19+
}
20+
}

includes/Classes/HelperClass.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace PluginName\Classes;
3+
4+
class HelperClass {
5+
6+
7+
}

includes/Classes/Menu.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace PluginName\Classes;
4+
5+
6+
class Menu
7+
{
8+
public function register()
9+
{
10+
add_action( 'admin_menu', array($this, 'addMenus') );
11+
add_action('admin_enqueue_scripts', array($this, 'enqueueAssets'));
12+
}
13+
14+
public function addMenus()
15+
{
16+
$menuPermission = AccessControl::hasTopLevelMenuPermission();
17+
if (!$menuPermission) {
18+
return;
19+
}
20+
21+
$title = __('Plugin Name', 'textdomain');
22+
global $submenu;
23+
add_menu_page(
24+
$title,
25+
$title,
26+
$menuPermission,
27+
'plugun_name.php',
28+
array($this, 'render'),
29+
'dashicons-admin-site',
30+
25
31+
);
32+
33+
$submenu['plugun_name.php']['my_profile'] = array(
34+
__('Plugin Dashboard', 'textdomain'),
35+
$menuPermission,
36+
'admin.php?page=plugun_name.php#/',
37+
);
38+
$submenu['plugun_name.php']['settings'] = array(
39+
__('Settings', 'textdomain'),
40+
$menuPermission,
41+
'admin.php?page=plugun_name.php#/settings',
42+
);
43+
$submenu['plugun_name.php']['supports'] = array(
44+
__('Supports', 'textdomain'),
45+
$menuPermission,
46+
'admin.php?page=plugun_name.php#/supports',
47+
);
48+
}
49+
50+
public function render() {
51+
do_action('plugun_name/render_admin_app');
52+
wp_enqueue_script(
53+
'plugin-name',
54+
PLUGINNAME_URL . 'assets/js/plugin-name.js',
55+
array( 'jquery' ),
56+
PLUGINNAME_VERSION,
57+
true
58+
);
59+
}
60+
61+
public function enqueueAssets()
62+
{
63+
64+
wp_enqueue_script('plugin_name_boot', PLUGINNAME_URL.'assets/js/boot.js', array('jquery'), PLUGINNAME_VERSION, true);
65+
// 3rd party developers can now add their scripts here
66+
do_action('plugin_name/booting_admin_app');
67+
wp_enqueue_script('plugin_name_admin_app', PLUGINNAME_URL.'assets/js/plugin_name.js', array('wppayform_boot'), PLUGINNAME_VERSION, true);
68+
// wp_enqueue_style('plugin_name_admin_app', PLUGINNAME_URL.'assets/css/plugin_name-admin.css', array(), PLUGINNAME_VERSION);
69+
70+
$pluginNameAdminVars = apply_filters('plugin_name/admin_app_vars',array(
71+
// 'image_upload_url' => admin_url('admin-ajax.php?action=wpf_global_settings_handler&route=wpf_upload_image'),
72+
'assets_url' => PLUGINNAME_URL.'assets/',
73+
'ajaxurl' => admin_url('admin-ajax.php')
74+
));
75+
76+
wp_localize_script('plugin_name_boot', 'PluginNameAdmin', $pluginNameAdminVars);
77+
78+
}
79+
80+
}

includes/Classes/PostType.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: ah1
5+
* Date: 2019-06-16
6+
* Time: 11:23
7+
*/
8+
9+
namespace PluginName\Classes;
10+
11+
if ( ! defined( 'ABSPATH' ) ) {
12+
exit;
13+
}
14+
15+
/**
16+
* Register and initialize custom post type for plugun_name
17+
* @since 1.0.0
18+
*/
19+
20+
class PostType {
21+
public function __construct()
22+
{
23+
add_action('init', array( $this , 'register'));
24+
}
25+
26+
public function register()
27+
{
28+
$args = array(
29+
'capability_type' => 'post',
30+
'public' => false,
31+
'show_ui' => false,
32+
);
33+
register_post_type( 'plugun_name', $args );
34+
}
35+
36+
}

includes/Classes/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Silence is golden.

includes/autoload.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Autoloader
4+
*
5+
* @package WPPayForm
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
include 'global_functions.php';
12+
if ( ! function_exists( 'PluginNameAutoload' ) ) {
13+
/**
14+
* Plugin autoloader.
15+
*
16+
* Pattern (with or without <Subnamespace>):
17+
* <Namespace>/<Subnamespace>.../Class_Name (or Classname)
18+
* 'includes/subdir.../class-name.php' or '...classname.php'
19+
*
20+
* @since 3.0.0
21+
*
22+
* @param $class
23+
*/
24+
function PluginNameAutoload( $class ) {
25+
26+
// Do not load unless in plugin domain.
27+
$namespace = 'PluginName';
28+
if ( strpos( $class, $namespace ) !== 0 ) {
29+
return;
30+
}
31+
32+
// Converts Class_Name (class convention) to class-name (file convention).
33+
34+
// Remove the root namespace.
35+
$unprefixed = substr( $class, strlen( $namespace ) );
36+
37+
// Build the file path.
38+
$file_path = str_replace( '\\', DIRECTORY_SEPARATOR, $unprefixed );
39+
40+
$file = dirname( __FILE__ ) . $file_path . '.php';
41+
if ( file_exists( $file ) ) {
42+
require $file;
43+
}
44+
}
45+
// Register the autoloader.
46+
spl_autoload_register( 'PluginNameAutoload' );
47+
}

includes/global_functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+

index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Silence is golden.

languages/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
//

0 commit comments

Comments
 (0)