-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjhosagid-plugin.php
116 lines (89 loc) · 2.93 KB
/
jhosagid-plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* @package JhosagidPlugin
*/
/*
Plugin Name: Jhosagid Plugin
Plugin URI: http://jhosagid.dev
Description: This is my first attempt on writing a custom Plugin for this amazing tutorial series.
Version: 1.0.0
Authot URI: http://jhosagid.com
License: GPL v2 or later
Text Domain: jhosagid-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 userl,
but WITHOUT'ANY'MMRRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License fbr 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.
*/
defined( 'ABSPATH' ) or die( 'Hey, you can/t access this file, yuo silly human!');
class JhosagidPlugin
{
// Public
// Protected
// can be accessed only within the class itself or extensions of that class
// Private
// can be accesssed only within the class itself
// Static
function __construct(){
// $this->create_post_type();
$this->print_stuff();
$this->print_stuff_private();
}
function register() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
}
protected function create_post_type() {
add_action( 'init', array($this, 'custom_post_type') );
}
function activate() {
// generate a CPT
$this->custom_post_type();
// flush rewrite rules
flush_rewrite_rules();
}
function deactivate() {
// flush rewrite rules
flush_rewrite_rules();
}
function custom_post_type(){
register_post_type( 'book', ['public' => true, 'label' => 'Books'] );
}
function print_stuff() {
var_dump(['test']);
}
private function print_stuff_private() {
echo 'Test';
}
function enqueue(){
// enqueue all our scripts
wp_enqueue_style( 'mypluginstyle', plugins_url( '/assets/mystyle.css', __FILE__ ) );
wp_enqueue_script( 'mypluginscript', plugins_url( '/assets/myscript.js', __FILE__ ) );
}
}
class SecondClass extends JhosagidPlugin
{
function register_post_type() {
$this->create_post_type();
}
}
$secondClass = new SecondClass();
$secondClass->register_post_type();
if ( class_exists( 'JhosagidPlugin' ) ) {
//instance
$jhosagidPlugin = new JhosagidPlugin();
$jhosagidPlugin->register();
}
// activate
register_activation_hook( __FILE__, array( $jhosagidPlugin, 'activate') );
// deactivate
register_deactivation_hook( __FILE__, array( $jhosagidPlugin, 'deactivate') );