Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
844 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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'; | ||
} | ||
|
||
// Define CONSTANTS | ||
define( 'PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); | ||
define( 'PLUGIN_URL', plugin_dir_url( __FILE__ ) ); | ||
define( 'PLUGIN', plugin_basename( __FILE__ ) ); | ||
|
||
use Inc\Base\Activate; | ||
use Inc\Base\Deactivate; | ||
|
||
/** | ||
* The code that runs during plugin activation | ||
*/ | ||
function activate_alecaddd_plugin() { | ||
Activate::activate(); | ||
} | ||
|
||
/** | ||
* The code that runs during plugin deactivation | ||
*/ | ||
function deactivate_alecaddd_plugin() { | ||
Deactivate::deactivate(); | ||
} | ||
|
||
register_activation_hook( __FILE__, 'activate_alecaddd_plugin' ); | ||
register_deactivation_hook( __FILE__, 'deactivate_alecaddd_plugin' ); | ||
|
||
/** | ||
* Initialize all the core classes of the plugin | ||
*/ | ||
if ( class_exists( 'Inc\\Init' ) ) { | ||
Inc\Init::register_services(); | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "alecaddd/alecaddd-plugin", | ||
"description": "Awesome starter plugin example", | ||
"type": "project", | ||
"license": "GPL", | ||
"authors": [ | ||
{ | ||
"name": "Alecaddd", | ||
"email": "castellani.ale@gmail.com" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": {}, | ||
"autoload": { | ||
"psr-4": {"Inc\\": "./inc"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
/** | ||
* @package AlecadddPlugin | ||
*/ | ||
namespace Inc\Base; | ||
|
||
class Activate | ||
{ | ||
public static function activate() { | ||
flush_rewrite_rules(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
/** | ||
* @package AlecadddPlugin | ||
*/ | ||
namespace Inc\Base; | ||
|
||
class Deactivate | ||
{ | ||
public static function deactivate() { | ||
flush_rewrite_rules(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* @package AlecadddPlugin | ||
*/ | ||
namespace Inc\Base; | ||
|
||
/** | ||
* | ||
*/ | ||
class Enqueue | ||
{ | ||
public function register() { | ||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); | ||
} | ||
|
||
function enqueue() { | ||
// enqueue all our scripts | ||
wp_enqueue_style( 'mypluginstyle', PLUGIN_URL . 'assets/mystyle.css' ); | ||
wp_enqueue_script( 'mypluginscript', PLUGIN_URL . 'assets/myscript.js' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* @package AlecadddPlugin | ||
*/ | ||
namespace Inc\Base; | ||
|
||
class SettingsLinks | ||
{ | ||
protected $plugin; | ||
|
||
public function __construct() | ||
{ | ||
$this->plugin = PLUGIN; | ||
} | ||
|
||
public function register() | ||
{ | ||
add_filter( "plugin_action_links_$this->plugin", array( $this, 'settings_link' ) ); | ||
} | ||
|
||
public function settings_link( $links ) | ||
{ | ||
$settings_link = '<a href="admin.php?page=alecaddd_plugin">Settings</a>'; | ||
array_push( $links, $settings_link ); | ||
return $links; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* @package AlecadddPlugin | ||
*/ | ||
namespace Inc; | ||
|
||
final class Init | ||
{ | ||
/** | ||
* Store all the classes inside an array | ||
* @return array Full list of classes | ||
*/ | ||
public static function get_services() | ||
{ | ||
return [ | ||
Pages\Admin::class, | ||
Base\Enqueue::class, | ||
Base\SettingsLinks::class | ||
]; | ||
} | ||
|
||
/** | ||
* Loop through the classes, initialize them, | ||
* and call the register() method if it exists | ||
* @return | ||
*/ | ||
public static function register_services() | ||
{ | ||
foreach ( self::get_services() as $class ) { | ||
$service = self::instantiate( $class ); | ||
if ( method_exists( $service, 'register' ) ) { | ||
$service->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* @package AlecadddPlugin | ||
*/ | ||
namespace Inc\Pages; | ||
|
||
/** | ||
* | ||
*/ | ||
class Admin | ||
{ | ||
public function register() { | ||
add_action( 'admin_menu', array( $this, 'add_admin_pages' ) ); | ||
} | ||
|
||
public function add_admin_pages() { | ||
add_menu_page( 'Alecaddd Plugin', 'Alecaddd', 'manage_options', 'alecaddd_plugin', array( $this, 'admin_index' ), 'dashicons-store', 110 ); | ||
} | ||
|
||
public function admin_index() { | ||
require_once PLUGIN_PATH . 'templates/admin.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is golden. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Alecaddd Plugin</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* Trigger this file on Plugin uninstall | ||
* | ||
* @package AlecadddPlugin | ||
*/ | ||
|
||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
die; | ||
} | ||
|
||
// Clear Database stored data | ||
$books = get_posts( array( 'post_type' => '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)" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// autoload.php @generated by Composer | ||
|
||
require_once __DIR__ . '/composer/autoload_real.php'; | ||
|
||
return ComposerAutoloaderInit51b523f56e298134d109fbc73bbc4aba::getLoader(); |
Oops, something went wrong.