Skip to content

Commit

Permalink
Lesson22
Browse files Browse the repository at this point in the history
  • Loading branch information
Alecaddd committed Dec 31, 2017
1 parent e5031a3 commit 7e08457
Show file tree
Hide file tree
Showing 39 changed files with 10,744 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Lesson22/alecaddd-plugin.php
@@ -0,0 +1,63 @@
<?php
/**
* @package AlecadddPlugin
*/
/*
Plugin Name: Alecaddd Plugin
Plugin URI: http://alecaddd.com/plugin
Description: This is my first attempt on writing a custom Plugin for this amazing tutorial series.
Version: 1.0.0
Author: Alessandro "Alecaddd" Castellani
Author URI: http://alecaddd.com
License: GPLv2 or later
Text Domain: alecaddd-plugin
*/

/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Copyright 2005-2015 Automattic, Inc.
*/

// If this file is called firectly, abort!!!
defined( 'ABSPATH' ) or die( 'Hey, what are you doing here? You silly human!' );

// Require once the Composer Autoload
if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
}

/**
* The code that runs during plugin activation
*/
function activate_alecaddd_plugin() {
Inc\Base\Activate::activate();
}
register_activation_hook( __FILE__, 'activate_alecaddd_plugin' );

/**
* The code that runs during plugin deactivation
*/
function deactivate_alecaddd_plugin() {
Inc\Base\Deactivate::deactivate();
}
register_deactivation_hook( __FILE__, 'deactivate_alecaddd_plugin' );

/**
* Initialize all the core classes of the plugin
*/
if ( class_exists( 'Inc\\Init' ) ) {
Inc\Init::register_services();
}
2 changes: 2 additions & 0 deletions Lesson22/assets/myscript.js

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

1 change: 1 addition & 0 deletions Lesson22/assets/myscript.js.map

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

3 changes: 3 additions & 0 deletions Lesson22/assets/mystyle.css

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

1 change: 1 addition & 0 deletions Lesson22/assets/mystyle.css.map

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

17 changes: 17 additions & 0 deletions Lesson22/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"}
}
}
104 changes: 104 additions & 0 deletions Lesson22/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!' }) );
});
52 changes: 52 additions & 0 deletions Lesson22/inc/Api/Callbacks/AdminCallbacks.php
@@ -0,0 +1,52 @@
<?php
/**
* @package AlecadddPlugin
*/
namespace Inc\Api\Callbacks;

use Inc\Base\BaseController;

class AdminCallbacks extends BaseController
{
public function adminDashboard()
{
return require_once( "$this->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 '<input type="text" class="regular-text" name="text_example" value="' . $value . '" placeholder="Write Something Here!">';
}

public function alecadddFirstName()
{
$value = esc_attr( get_option( 'first_name' ) );
echo '<input type="text" class="regular-text" name="first_name" value="' . $value . '" placeholder="Write your First Name">';
}
}
35 changes: 35 additions & 0 deletions Lesson22/inc/Api/Callbacks/ManagerCallbacks.php
@@ -0,0 +1,35 @@
<?php
/**
* @package AlecadddPlugin
*/
namespace Inc\Api\Callbacks;

use Inc\Base\BaseController;

class ManagerCallbacks extends BaseController
{
public function checkboxSanitize( $input )
{
$output = array();

foreach ( $this->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 );
echo '<div class="' . $classes . '"><input type="checkbox" id="' . $name . '" name="' . $option_name . '[' . $name . ']" value="1" class="" ' . ($checkbox[$name] ? 'checked' : '') . '><label for="' . $name . '"><div></div></label></div>';
}
}

0 comments on commit 7e08457

Please sign in to comment.