From 4778c04f1cb1410bfc7c59dc25b8889d8e43d5c3 Mon Sep 17 00:00:00 2001 From: Alecaddd Date: Mon, 8 Jan 2018 20:01:46 -0800 Subject: [PATCH] Lesson23 --- Lesson23/alecaddd-plugin.php | 63 + Lesson23/assets/myscript.js | 2 + Lesson23/assets/myscript.js.map | 1 + Lesson23/assets/mystyle.css | 3 + Lesson23/assets/mystyle.css.map | 1 + Lesson23/composer.json | 17 + Lesson23/gulpfile.js | 104 + Lesson23/inc/Api/Callbacks/AdminCallbacks.php | 52 + .../inc/Api/Callbacks/ManagerCallbacks.php | 37 + Lesson23/inc/Api/SettingsApi.php | 117 + Lesson23/inc/Base/Activate.php | 20 + Lesson23/inc/Base/BaseController.php | 34 + Lesson23/inc/Base/Deactivate.php | 12 + Lesson23/inc/Base/Enqueue.php | 23 + Lesson23/inc/Base/SettingsLinks.php | 22 + Lesson23/inc/Init.php | 48 + Lesson23/inc/Pages/Admin.php | 137 + Lesson23/index.php | 2 + Lesson23/package-lock.json | 9195 +++++++++++++++++ Lesson23/package.json | 59 + Lesson23/readme.md | 14 + Lesson23/src/js/myscript.js | 25 + Lesson23/src/scss/modules/checkbox.scss | 70 + Lesson23/src/scss/modules/tabs.scss | 50 + Lesson23/src/scss/mystyle.scss | 2 + Lesson23/templates/admin.php | 32 + Lesson23/templates/cpt.php | 1 + Lesson23/templates/taxonomy.php | 1 + Lesson23/templates/widget.php | 1 + Lesson23/uninstall.php | 24 + 30 files changed, 10169 insertions(+) create mode 100644 Lesson23/alecaddd-plugin.php create mode 100644 Lesson23/assets/myscript.js create mode 100644 Lesson23/assets/myscript.js.map create mode 100644 Lesson23/assets/mystyle.css create mode 100644 Lesson23/assets/mystyle.css.map create mode 100644 Lesson23/composer.json create mode 100644 Lesson23/gulpfile.js create mode 100644 Lesson23/inc/Api/Callbacks/AdminCallbacks.php create mode 100644 Lesson23/inc/Api/Callbacks/ManagerCallbacks.php create mode 100644 Lesson23/inc/Api/SettingsApi.php create mode 100644 Lesson23/inc/Base/Activate.php create mode 100644 Lesson23/inc/Base/BaseController.php create mode 100644 Lesson23/inc/Base/Deactivate.php create mode 100644 Lesson23/inc/Base/Enqueue.php create mode 100644 Lesson23/inc/Base/SettingsLinks.php create mode 100644 Lesson23/inc/Init.php create mode 100644 Lesson23/inc/Pages/Admin.php create mode 100644 Lesson23/index.php create mode 100644 Lesson23/package-lock.json create mode 100644 Lesson23/package.json create mode 100644 Lesson23/readme.md create mode 100644 Lesson23/src/js/myscript.js create mode 100644 Lesson23/src/scss/modules/checkbox.scss create mode 100644 Lesson23/src/scss/modules/tabs.scss create mode 100644 Lesson23/src/scss/mystyle.scss create mode 100644 Lesson23/templates/admin.php create mode 100644 Lesson23/templates/cpt.php create mode 100644 Lesson23/templates/taxonomy.php create mode 100644 Lesson23/templates/widget.php create mode 100644 Lesson23/uninstall.php diff --git a/Lesson23/alecaddd-plugin.php b/Lesson23/alecaddd-plugin.php new file mode 100644 index 0000000..9321153 --- /dev/null +++ b/Lesson23/alecaddd-plugin.php @@ -0,0 +1,63 @@ + li"),t=0;t li\");\n\n\tfor (var i = 0; i < tabs.length; i++) {\n\t\ttabs[i].addEventListener(\"click\", switchTab);\n\t}\n\n\tfunction switchTab(event) {\n\t\tevent.preventDefault();\n\n\t\tdocument.querySelector(\"ul.nav-tabs li.active\").classList.remove(\"active\");\n\t\tdocument.querySelector(\".tab-pane.active\").classList.remove(\"active\");\n\n\t\tvar clickedTab = event.currentTarget;\n\t\tvar anchor = event.target;\n\t\tvar activePaneID = anchor.getAttribute(\"href\");\n\n\t\tclickedTab.classList.add(\"active\");\n\t\tdocument.querySelector(activePaneID).classList.add(\"active\");\n\t}\n});\n\n},{}]},{},[1]);\n"]} \ No newline at end of file diff --git a/Lesson23/assets/mystyle.css b/Lesson23/assets/mystyle.css new file mode 100644 index 0000000..099f323 --- /dev/null +++ b/Lesson23/assets/mystyle.css @@ -0,0 +1,3 @@ +.nav-tabs{float:left;width:100%;margin:0;list-style-type:none;border-bottom:1px solid transparent}.nav-tabs>li{float:left;margin-bottom:-1px}.nav-tabs>li>a{margin-right:2px;line-height:1.5;padding:10px;border:1px solid transparent;border-radius:4px 4px 0 0;float:left;text-decoration:none}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>li.active>a,.nav-tabs>li.active>a:hover,.nav-tabs>li.active>a:focus{color:#555;cursor:default;background-color:#fff;border-color:transparent}.tab-content>.tab-pane{float:left;width:100%;display:none}.tab-content>.tab-pane.active{display:block;padding:10px;background-color:#fff;-webkit-box-shadow:0 5px 4px -2px rgba(0,0,0,0.15);box-shadow:0 5px 4px -2px rgba(0,0,0,0.15)}div.ui-toggle{margin:0;padding:0}div.ui-toggle input[type='checkbox']{display:none}div.ui-toggle input[type='checkbox']:checked+label{border-color:#009eea;background:#009eea;-webkit-box-shadow:inset 0 0 0 10px #009eea;box-shadow:inset 0 0 0 10px #009eea}div.ui-toggle input[type='checkbox']:checked+label>div{margin-left:20px}div.ui-toggle label{-webkit-transition:all 200ms ease;transition:all 200ms ease;display:inline-block;position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background:#8c8c8c;-webkit-box-shadow:inset 0 0 0 0 #009eea;box-shadow:inset 0 0 0 0 #009eea;border:2px solid #8c8c8c;border-radius:22px;width:40px;height:20px}div.ui-toggle label div{-webkit-transition:all 200ms ease;transition:all 200ms ease;background:#FFFFFF;width:20px;height:20px;border-radius:10px}div.ui-toggle label:hover,div.ui-toggle label>div:hover{cursor:pointer} + +/*# sourceMappingURL=mystyle.css.map */ diff --git a/Lesson23/assets/mystyle.css.map b/Lesson23/assets/mystyle.css.map new file mode 100644 index 0000000..431bc9e --- /dev/null +++ b/Lesson23/assets/mystyle.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["modules/tabs.scss","modules/checkbox.scss"],"names":[],"mappings":"AAAA,UACC,WACA,WACA,SACA,qBACA,mCAAoC,CALrC,aAQE,WACA,kBAAmB,CATrB,eAYG,iBACA,gBACA,aACA,6BACA,0BACA,WACA,oBAAqB,CAlBxB,qBAqBI,2BAA4B,CArBhC,8EA6BI,WACA,eACA,sBACA,wBAAyB,CACzB,uBAMH,WACA,WACA,YAAa,CAHd,8BAME,cACA,aACA,sBACA,mDAAA,AAA8C,0CAAA,CAC9C,cC3BD,SACA,SAAU,CAEV,qCACC,YAAa,CAED,mDACX,qBACA,mBACA,4CAAA,AA9BS,mCAAA,CAgCP,uDACD,gBAmCoB,CAlCpB,oBAKF,kCAAA,AACA,0BAAA,qBACA,kBA7BD,2BACA,yBACA,AACA,sBACA,qBACA,iBA4BC,mBACA,yCAAA,AACA,iCAAA,yBACA,mBACA,WACA,WAkBsB,CAhBtB,wBACC,kCAAA,AACA,0BAAA,mBACA,WACA,YACA,kBAA0B,CAnB5B,wDAwBE,cAAe,CACf","file":"mystyle.css","sourcesContent":[".nav-tabs {\n\tfloat: left;\n\twidth: 100%;\n\tmargin: 0;\n\tlist-style-type: none;\n\tborder-bottom: 1px solid transparent;\n\n\t> li {\n\t\tfloat: left;\n\t\tmargin-bottom: -1px;\n\n\t\t> a {\n\t\t\tmargin-right: 2px;\n\t\t\tline-height: 1.5;\n\t\t\tpadding: 10px;\n\t\t\tborder: 1px solid transparent;\n\t\t\tborder-radius: 4px 4px 0 0;\n\t\t\tfloat: left;\n\t\t\ttext-decoration: none;\n\n\t\t\t&:hover {\n\t\t\t\tborder-color: #eee #eee #ddd;\n\t\t\t}\n\t\t}\n\n\t\t&.active > a {\n\t\t\t&,\n\t\t\t&:hover,\n\t\t\t&:focus {\n\t\t\t\tcolor: #555;\n\t\t\t\tcursor: default;\n\t\t\t\tbackground-color: #fff;\n\t\t\t\tborder-color: transparent;\n\t\t\t}\n\t\t}\n\t}\n}\n\n.tab-content > .tab-pane {\n\tfloat: left;\n\twidth: 100%;\n\tdisplay: none;\n\n\t&.active {\n\t\tdisplay: block;\n\t\tpadding: 10px;\n\t\tbackground-color: #fff;\n\t\tbox-shadow: 0 5px 4px -2px rgba(0, 0, 0, 0.15);\n\t}\n}","$on: #009eea;\n$bg: #D9CB9E;\n$off: #8c8c8c;\n\n@mixin center {\n\tposition: absolute;\n\ttop: 50%;\n\tleft: 50%;\n\ttransform: translate(-50%, -50%);\n}\n\n@mixin userSelect($value) {\n\t-webkit-touch-callout: $value;\n\t-webkit-user-select: $value;\n\t-khtml-user-select: $value;\n\t-moz-user-select: $value;\n\t-ms-user-select: $value;\n\tuser-select: $value;\n}\n\n@mixin ui-toggle($height, $on, $off) {\n\tmargin: 0;\n\tpadding: 0;\n\n\tinput[type='checkbox'] {\n\t\tdisplay: none;\n\n\t\t&:checked + label {\n\t\t\tborder-color: $on;\n\t\t\tbackground: $on;\n\t\t\tbox-shadow: inset 0 0 0 #{$height / 2} $on;\n\n\t\t\t> div {\n\t\t\t\tmargin-left: $height;\n\t\t\t}\n\t\t}\n\t}\n\n\tlabel {\n\t\ttransition: all 200ms ease;\n\t\tdisplay: inline-block;\n\t\tposition: relative;\n\n\t\t@include userSelect(none);\n\n\t\tbackground: $off;\n\t\tbox-shadow: inset 0 0 0 0 $on;\n\t\tborder: 2px solid $off;\n\t\tborder-radius: $height + 2;\n\t\twidth: $height * 2;\n\t\theight: $height;\n\n\t\tdiv {\n\t\t\ttransition: all 200ms ease;\n\t\t\tbackground: #FFFFFF;\n\t\t\twidth: $height;\n\t\t\theight: $height;\n\t\t\tborder-radius: $height / 2;\n\t\t}\n\n\t\t&:hover,\n\t\t& > div:hover {\n\t\t\tcursor: pointer;\n\t\t}\n\t}\n}\n\ndiv.ui-toggle {\n\t@include ui-toggle(20px, $on, $off);\n}"]} \ No newline at end of file diff --git a/Lesson23/composer.json b/Lesson23/composer.json new file mode 100644 index 0000000..cc3cc19 --- /dev/null +++ b/Lesson23/composer.json @@ -0,0 +1,17 @@ +{ + "name": "alecaddd/alecaddd-plugin", + "description": "Awesome starter plugin example", + "type": "project", + "license": "GPL-3.0", + "authors": [ + { + "name": "Alecaddd", + "email": "castellani.ale@gmail.com" + } + ], + "minimum-stability": "dev", + "require": {}, + "autoload": { + "psr-4": {"Inc\\": "./inc"} + } +} diff --git a/Lesson23/gulpfile.js b/Lesson23/gulpfile.js new file mode 100644 index 0000000..d166c0c --- /dev/null +++ b/Lesson23/gulpfile.js @@ -0,0 +1,104 @@ +// Load Gulp...of course +var gulp = require( 'gulp' ); + +// CSS related plugins +var sass = require( 'gulp-sass' ); +var autoprefixer = require( 'gulp-autoprefixer' ); +var minifycss = require( 'gulp-uglifycss' ); + +// JS related plugins +var concat = require( 'gulp-concat' ); +var uglify = require( 'gulp-uglify' ); +var babelify = require( 'babelify' ); +var browserify = require( 'browserify' ); +var source = require( 'vinyl-source-stream' ); +var buffer = require( 'vinyl-buffer' ); +var stripDebug = require( 'gulp-strip-debug' ); + +// Utility plugins +var rename = require( 'gulp-rename' ); +var sourcemaps = require( 'gulp-sourcemaps' ); +var notify = require( 'gulp-notify' ); +var plumber = require( 'gulp-plumber' ); +var options = require( 'gulp-options' ); +var gulpif = require( 'gulp-if' ); + +// Browers related plugins +var browserSync = require( 'browser-sync' ).create(); +var reload = browserSync.reload; + +// Project related variables +var projectURL = 'https://test.dev'; + +var styleSRC = 'src/scss/mystyle.scss'; +var styleURL = './assets/'; +var mapURL = './'; + +var jsSRC = 'src/js/myscript.js'; +var jsURL = './assets/'; + +var styleWatch = 'src/scss/**/*.scss'; +var jsWatch = 'src/js/**/*.js'; +var phpWatch = '**/*.php'; + +// Tasks +gulp.task( 'browser-sync', function() { + browserSync.init({ + proxy: projectURL, + https: { + key: '/Users/alecaddd/.valet/Certificates/test.dev.key', + cert: '/Users/alecaddd/.valet/Certificates/test.dev.crt' + }, + injectChanges: true, + open: false + }); +}); + +gulp.task( 'styles', function() { + gulp.src( styleSRC ) + .pipe( sourcemaps.init() ) + .pipe( sass({ + errLogToConsole: true, + outputStyle: 'compressed' + }) ) + .on( 'error', console.error.bind( console ) ) + .pipe( autoprefixer({ browsers: [ 'last 2 versions', '> 5%', 'Firefox ESR' ] }) ) + .pipe( sourcemaps.write( mapURL ) ) + .pipe( gulp.dest( styleURL ) ) + .pipe( browserSync.stream() ); +}); + +gulp.task( 'js', function() { + return browserify({ + entries: [jsSRC] + }) + .transform( babelify, { presets: [ 'env' ] } ) + .bundle() + .pipe( source( 'myscript.js' ) ) + .pipe( buffer() ) + .pipe( gulpif( options.has( 'production' ), stripDebug() ) ) + .pipe( sourcemaps.init({ loadMaps: true }) ) + .pipe( uglify() ) + .pipe( sourcemaps.write( '.' ) ) + .pipe( gulp.dest( jsURL ) ) + .pipe( browserSync.stream() ); + }); + +function triggerPlumber( src, url ) { + return gulp.src( src ) + .pipe( plumber() ) + .pipe( gulp.dest( url ) ); +} + + gulp.task( 'default', ['styles', 'js'], function() { + gulp.src( jsURL + 'myscript.min.js' ) + .pipe( notify({ message: 'Assets Compiled!' }) ); + }); + + gulp.task( 'watch', ['default', 'browser-sync'], function() { + gulp.watch( phpWatch, reload ); + gulp.watch( styleWatch, [ 'styles' ] ); + gulp.watch( jsWatch, [ 'js', reload ] ); + gulp.src( jsURL + 'myscript.min.js' ) + .pipe( notify({ message: 'Gulp is Watching, Happy Coding!' }) ); + }); diff --git a/Lesson23/inc/Api/Callbacks/AdminCallbacks.php b/Lesson23/inc/Api/Callbacks/AdminCallbacks.php new file mode 100644 index 0000000..50db468 --- /dev/null +++ b/Lesson23/inc/Api/Callbacks/AdminCallbacks.php @@ -0,0 +1,52 @@ +plugin_path/templates/admin.php" ); + } + + public function adminCpt() + { + return require_once( "$this->plugin_path/templates/cpt.php" ); + } + + public function adminTaxonomy() + { + return require_once( "$this->plugin_path/templates/taxonomy.php" ); + } + + public function adminWidget() + { + return require_once( "$this->plugin_path/templates/widget.php" ); + } + + // public function alecadddOptionsGroup( $input ) + // { + // return $input; + // } + + // public function alecadddAdminSection() + // { + // echo 'Check this beautiful section!'; + // } + + public function alecadddTextExample() + { + $value = esc_attr( get_option( 'text_example' ) ); + echo ''; + } + + public function alecadddFirstName() + { + $value = esc_attr( get_option( 'first_name' ) ); + echo ''; + } +} \ No newline at end of file diff --git a/Lesson23/inc/Api/Callbacks/ManagerCallbacks.php b/Lesson23/inc/Api/Callbacks/ManagerCallbacks.php new file mode 100644 index 0000000..264188f --- /dev/null +++ b/Lesson23/inc/Api/Callbacks/ManagerCallbacks.php @@ -0,0 +1,37 @@ +managers as $key => $value ) { + $output[$key] = isset( $input[$key] ) ? true : false; + } + + return $output; + } + + public function adminSectionManager() + { + echo 'Manage the Sections and Features of this Plugin by activating the checkboxes from the following list.'; + } + + public function checkboxField( $args ) + { + $name = $args['label_for']; + $classes = $args['class']; + $option_name = $args['option_name']; + $checkbox = get_option( $option_name ); + $checked = isset($checkbox[$name]) ? ($checkbox[$name] ? true : false) : false; + + echo '
'; + } +} \ No newline at end of file diff --git a/Lesson23/inc/Api/SettingsApi.php b/Lesson23/inc/Api/SettingsApi.php new file mode 100644 index 0000000..96fbdbb --- /dev/null +++ b/Lesson23/inc/Api/SettingsApi.php @@ -0,0 +1,117 @@ +admin_pages) ) { + add_action( 'admin_menu', array( $this, 'addAdminMenu' ) ); + } + + if ( !empty($this->settings) ) { + add_action( 'admin_init', array( $this, 'registerCustomFields' ) ); + } + } + + public function addPages( array $pages ) + { + $this->admin_pages = $pages; + + return $this; + } + + public function withSubPage( string $title = null ) + { + if ( empty($this->admin_pages) ) { + return $this; + } + + $admin_page = $this->admin_pages[0]; + + $subpage = array( + array( + 'parent_slug' => $admin_page['menu_slug'], + 'page_title' => $admin_page['page_title'], + 'menu_title' => ($title) ? $title : $admin_page['menu_title'], + 'capability' => $admin_page['capability'], + 'menu_slug' => $admin_page['menu_slug'], + 'callback' => $admin_page['callback'] + ) + ); + + $this->admin_subpages = $subpage; + + return $this; + } + + public function addSubPages( array $pages ) + { + $this->admin_subpages = array_merge( $this->admin_subpages, $pages ); + + return $this; + } + + public function addAdminMenu() + { + foreach ( $this->admin_pages as $page ) { + add_menu_page( $page['page_title'], $page['menu_title'], $page['capability'], $page['menu_slug'], $page['callback'], $page['icon_url'], $page['position'] ); + } + + foreach ( $this->admin_subpages as $page ) { + add_submenu_page( $page['parent_slug'], $page['page_title'], $page['menu_title'], $page['capability'], $page['menu_slug'], $page['callback'] ); + } + } + + public function setSettings( array $settings ) + { + $this->settings = $settings; + + return $this; + } + + public function setSections( array $sections ) + { + $this->sections = $sections; + + return $this; + } + + public function setFields( array $fields ) + { + $this->fields = $fields; + + return $this; + } + + public function registerCustomFields() + { + // register setting + foreach ( $this->settings as $setting ) { + register_setting( $setting["option_group"], $setting["option_name"], ( isset( $setting["callback"] ) ? $setting["callback"] : '' ) ); + } + + // add settings section + foreach ( $this->sections as $section ) { + add_settings_section( $section["id"], $section["title"], ( isset( $section["callback"] ) ? $section["callback"] : '' ), $section["page"] ); + } + + // add settings field + foreach ( $this->fields as $field ) { + add_settings_field( $field["id"], $field["title"], ( isset( $field["callback"] ) ? $field["callback"] : '' ), $field["page"], $field["section"], ( isset( $field["args"] ) ? $field["args"] : '' ) ); + } + } +} \ No newline at end of file diff --git a/Lesson23/inc/Base/Activate.php b/Lesson23/inc/Base/Activate.php new file mode 100644 index 0000000..bf6df8c --- /dev/null +++ b/Lesson23/inc/Base/Activate.php @@ -0,0 +1,20 @@ +plugin_path = plugin_dir_path( dirname( __FILE__, 2 ) ); + $this->plugin_url = plugin_dir_url( dirname( __FILE__, 2 ) ); + $this->plugin = plugin_basename( dirname( __FILE__, 3 ) ) . '/alecaddd-plugin.php'; + + $this->managers = array( + 'cpt_manager' => 'Activate CPT Manager', + 'taxonomy_manager' => 'Activate Taxonomy Manager', + 'media_widget' => 'Activate Media Widget', + 'gallery_manager' => 'Activate Gallery Manager', + 'testimonial_manager' => 'Activate Testimonial Manager', + 'templates_manager' => 'Activate Templates Manager', + 'login_manager' => 'Activate Ajax Login/Signup', + 'membership_manager' => 'Activate Membership Manager', + 'chat_manager' => 'Activate Chat Manager' + ); + } +} \ No newline at end of file diff --git a/Lesson23/inc/Base/Deactivate.php b/Lesson23/inc/Base/Deactivate.php new file mode 100644 index 0000000..c13c98d --- /dev/null +++ b/Lesson23/inc/Base/Deactivate.php @@ -0,0 +1,12 @@ +plugin_url . 'assets/mystyle.css' ); + wp_enqueue_script( 'mypluginscript', $this->plugin_url . 'assets/myscript.js' ); + } +} \ No newline at end of file diff --git a/Lesson23/inc/Base/SettingsLinks.php b/Lesson23/inc/Base/SettingsLinks.php new file mode 100644 index 0000000..78ce823 --- /dev/null +++ b/Lesson23/inc/Base/SettingsLinks.php @@ -0,0 +1,22 @@ +plugin", array( $this, 'settings_link' ) ); + } + + public function settings_link( $links ) + { + $settings_link = 'Settings'; + array_push( $links, $settings_link ); + return $links; + } +} \ No newline at end of file diff --git a/Lesson23/inc/Init.php b/Lesson23/inc/Init.php new file mode 100644 index 0000000..bd1be4b --- /dev/null +++ b/Lesson23/inc/Init.php @@ -0,0 +1,48 @@ +register(); + } + } + } + + /** + * Initialize the class + * @param class $class class from the services array + * @return class instance new instance of the class + */ + private static function instantiate( $class ) + { + $service = new $class(); + + return $service; + } +} \ No newline at end of file diff --git a/Lesson23/inc/Pages/Admin.php b/Lesson23/inc/Pages/Admin.php new file mode 100644 index 0000000..2de01d6 --- /dev/null +++ b/Lesson23/inc/Pages/Admin.php @@ -0,0 +1,137 @@ +settings = new SettingsApi(); + + $this->callbacks = new AdminCallbacks(); + $this->callbacks_mngr = new ManagerCallbacks(); + + $this->setPages(); + + $this->setSubpages(); + + $this->setSettings(); + $this->setSections(); + $this->setFields(); + + $this->settings->addPages( $this->pages )->withSubPage( 'Dashboard' )->addSubPages( $this->subpages )->register(); + } + + public function setPages() + { + $this->pages = array( + array( + 'page_title' => 'Alecaddd Plugin', + 'menu_title' => 'Alecaddd', + 'capability' => 'manage_options', + 'menu_slug' => 'alecaddd_plugin', + 'callback' => array( $this->callbacks, 'adminDashboard' ), + 'icon_url' => 'dashicons-store', + 'position' => 110 + ) + ); + } + + public function setSubpages() + { + $this->subpages = array( + array( + 'parent_slug' => 'alecaddd_plugin', + 'page_title' => 'Custom Post Types', + 'menu_title' => 'CPT', + 'capability' => 'manage_options', + 'menu_slug' => 'alecaddd_cpt', + 'callback' => array( $this->callbacks, 'adminCpt' ) + ), + array( + 'parent_slug' => 'alecaddd_plugin', + 'page_title' => 'Custom Taxonomies', + 'menu_title' => 'Taxonomies', + 'capability' => 'manage_options', + 'menu_slug' => 'alecaddd_taxonomies', + 'callback' => array( $this->callbacks, 'adminTaxonomy' ) + ), + array( + 'parent_slug' => 'alecaddd_plugin', + 'page_title' => 'Custom Widgets', + 'menu_title' => 'Widgets', + 'capability' => 'manage_options', + 'menu_slug' => 'alecaddd_widgets', + 'callback' => array( $this->callbacks, 'adminWidget' ) + ) + ); + } + + public function setSettings() + { + $args = array( + array( + 'option_group' => 'alecaddd_plugin_settings', + 'option_name' => 'alecaddd_plugin', + 'callback' => array( $this->callbacks_mngr, 'checkboxSanitize' ) + ) + ); + + $this->settings->setSettings( $args ); + } + + public function setSections() + { + $args = array( + array( + 'id' => 'alecaddd_admin_index', + 'title' => 'Settings Manager', + 'callback' => array( $this->callbacks_mngr, 'adminSectionManager' ), + 'page' => 'alecaddd_plugin' + ) + ); + + $this->settings->setSections( $args ); + } + + public function setFields() + { + $args = array(); + + foreach ( $this->managers as $key => $value ) { + $args[] = array( + 'id' => $key, + 'title' => $value, + 'callback' => array( $this->callbacks_mngr, 'checkboxField' ), + 'page' => 'alecaddd_plugin', + 'section' => 'alecaddd_admin_index', + 'args' => array( + 'option_name' => 'alecaddd_plugin', + 'label_for' => $key, + 'class' => 'ui-toggle' + ) + ); + } + + $this->settings->setFields( $args ); + } +} \ No newline at end of file diff --git a/Lesson23/index.php b/Lesson23/index.php new file mode 100644 index 0000000..7e91415 --- /dev/null +++ b/Lesson23/index.php @@ -0,0 +1,2 @@ + (http://alecaddd.com)", + "repository": { + "type": "git", + "url": "https://github.com/Alecaddd/WordPressPlugin101" + }, + "keywords": [ + "wordpress", + "plugin", + "PHP", + "composer", + "gulp", + "es6", + "scss" + ], + "devDependencies": { + "babel-core": "^6.26.0", + "babel-preset-env": "^1.6.1", + "babelify": "^8.0.0", + "browser-sync": "^2.18.13", + "browserify": "^14.5.0", + "browserify-shim": "^3.8.14", + "gulp": "^3.9.1", + "gulp-autoprefixer": "^4.0.0", + "gulp-concat": "^2.5.2", + "gulp-if": "^2.0.2", + "gulp-notify": "^3.0.0", + "gulp-options": "^1.1.1", + "gulp-plumber": "^1.1.0", + "gulp-rename": "^1.2.0", + "gulp-sass": "^3.1.0", + "gulp-sourcemaps": "^2.6.1", + "gulp-strip-debug": "^1.1.0", + "gulp-uglify": "^3.0.0", + "gulp-uglifycss": "^1.0.9", + "vinyl-buffer": "^1.0.0", + "vinyl-source-stream": "^1.1.0" + }, + "babel": { + "presets": [ + "env" + ] + }, + "browserify": { + "transform": [ + "browserify-shim" + ] + }, + "browser": { + "jquery": "./node_modules/jquery/dist/jquery.js" + }, + "browserify-shim": { + "jquery": "$" + }, + "license": "GPL-3.0" +} diff --git a/Lesson23/readme.md b/Lesson23/readme.md new file mode 100644 index 0000000..2d10c74 --- /dev/null +++ b/Lesson23/readme.md @@ -0,0 +1,14 @@ +# Plugin 101 Series + +Full list of sections and features we will build during the series of Tutorials + +* Modular Administration Area +* CPT Manager +* Custom Taxonomy Manager +* Widget to Upload and Display media in sidebars +* Post and Pages Gallery integration +* Testimonial section: Comment in the front-end, Admins can approve comments, select which comments to display +* Custom template section +* Ajax based Login/Register system +* Membership protected area +* Chat system \ No newline at end of file diff --git a/Lesson23/src/js/myscript.js b/Lesson23/src/js/myscript.js new file mode 100644 index 0000000..8e258bf --- /dev/null +++ b/Lesson23/src/js/myscript.js @@ -0,0 +1,25 @@ +window.addEventListener("load", function() { + + // store tabs variables + var tabs = document.querySelectorAll("ul.nav-tabs > li"); + + for (var i = 0; i < tabs.length; i++) { + tabs[i].addEventListener("click", switchTab); + } + + function switchTab(event) { + event.preventDefault(); + + document.querySelector("ul.nav-tabs li.active").classList.remove("active"); + document.querySelector(".tab-pane.active").classList.remove("active"); + + var clickedTab = event.currentTarget; + var anchor = event.target; + var activePaneID = anchor.getAttribute("href"); + + clickedTab.classList.add("active"); + document.querySelector(activePaneID).classList.add("active"); + + } + +}); \ No newline at end of file diff --git a/Lesson23/src/scss/modules/checkbox.scss b/Lesson23/src/scss/modules/checkbox.scss new file mode 100644 index 0000000..2bb94e1 --- /dev/null +++ b/Lesson23/src/scss/modules/checkbox.scss @@ -0,0 +1,70 @@ +$on: #009eea; +$bg: #D9CB9E; +$off: #8c8c8c; + +@mixin center { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} + +@mixin userSelect($value) { + -webkit-touch-callout: $value; + -webkit-user-select: $value; + -khtml-user-select: $value; + -moz-user-select: $value; + -ms-user-select: $value; + user-select: $value; +} + +@mixin ui-toggle($height, $on, $off) { + margin: 0; + padding: 0; + + input[type='checkbox'] { + display: none; + + &:checked + label { + border-color: $on; + background: $on; + box-shadow: inset 0 0 0 #{$height / 2} $on; + + > div { + margin-left: $height; + } + } + } + + label { + transition: all 200ms ease; + display: inline-block; + position: relative; + + @include userSelect(none); + + background: $off; + box-shadow: inset 0 0 0 0 $on; + border: 2px solid $off; + border-radius: $height + 2; + width: $height * 2; + height: $height; + + div { + transition: all 200ms ease; + background: #FFFFFF; + width: $height; + height: $height; + border-radius: $height / 2; + } + + &:hover, + & > div:hover { + cursor: pointer; + } + } +} + +div.ui-toggle { + @include ui-toggle(20px, $on, $off); +} \ No newline at end of file diff --git a/Lesson23/src/scss/modules/tabs.scss b/Lesson23/src/scss/modules/tabs.scss new file mode 100644 index 0000000..4522cee --- /dev/null +++ b/Lesson23/src/scss/modules/tabs.scss @@ -0,0 +1,50 @@ +.nav-tabs { + float: left; + width: 100%; + margin: 0; + list-style-type: none; + border-bottom: 1px solid transparent; + + > li { + float: left; + margin-bottom: -1px; + + > a { + margin-right: 2px; + line-height: 1.5; + padding: 10px; + border: 1px solid transparent; + border-radius: 4px 4px 0 0; + float: left; + text-decoration: none; + + &:hover { + border-color: #eee #eee #ddd; + } + } + + &.active > a { + &, + &:hover, + &:focus { + color: #555; + cursor: default; + background-color: #fff; + border-color: transparent; + } + } + } +} + +.tab-content > .tab-pane { + float: left; + width: 100%; + display: none; + + &.active { + display: block; + padding: 10px; + background-color: #fff; + box-shadow: 0 5px 4px -2px rgba(0, 0, 0, 0.15); + } +} \ No newline at end of file diff --git a/Lesson23/src/scss/mystyle.scss b/Lesson23/src/scss/mystyle.scss new file mode 100644 index 0000000..bbf877c --- /dev/null +++ b/Lesson23/src/scss/mystyle.scss @@ -0,0 +1,2 @@ +@import 'modules/tabs'; +@import 'modules/checkbox'; \ No newline at end of file diff --git a/Lesson23/templates/admin.php b/Lesson23/templates/admin.php new file mode 100644 index 0000000..da6529a --- /dev/null +++ b/Lesson23/templates/admin.php @@ -0,0 +1,32 @@ +
+

Alecaddd Plugin

+ + + + +
+
+ +
+ +
+ +
+ +
+

Updates

+
+ +
+

About

+
+
+
\ No newline at end of file diff --git a/Lesson23/templates/cpt.php b/Lesson23/templates/cpt.php new file mode 100644 index 0000000..b3fd231 --- /dev/null +++ b/Lesson23/templates/cpt.php @@ -0,0 +1 @@ +

CPT Manager

\ No newline at end of file diff --git a/Lesson23/templates/taxonomy.php b/Lesson23/templates/taxonomy.php new file mode 100644 index 0000000..70b67a5 --- /dev/null +++ b/Lesson23/templates/taxonomy.php @@ -0,0 +1 @@ +

Taxonomies Manager

\ No newline at end of file diff --git a/Lesson23/templates/widget.php b/Lesson23/templates/widget.php new file mode 100644 index 0000000..006722d --- /dev/null +++ b/Lesson23/templates/widget.php @@ -0,0 +1 @@ +

Widgets Manager

\ No newline at end of file diff --git a/Lesson23/uninstall.php b/Lesson23/uninstall.php new file mode 100644 index 0000000..69fb64b --- /dev/null +++ b/Lesson23/uninstall.php @@ -0,0 +1,24 @@ + 'book', 'numberposts' => -1 ) ); + +foreach( $books as $book ) { + wp_delete_post( $book->ID, true ); +} + +// Access the database via SQL +global $wpdb; +$wpdb->query( "DELETE FROM wp_posts WHERE post_type = 'book'" ); +$wpdb->query( "DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts)" ); +$wpdb->query( "DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts)" ); \ No newline at end of file