Skip to content

Commit 93534be

Browse files
committed
CPT added + filesnames changed
1 parent f947017 commit 93534be

17 files changed

+185
-46
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,36 @@ It's a precaution to avoid conflict.
2121

2222
## Features
2323

24-
Go through the files in `/lib/` and `/src/`. First one contains classes for extra features, while the latter is using essential features.
24+
Go through the files in `/lib/class-` and `/src/class-`. First one contains classes for extra features, while the latter is using essential features.
2525

2626
### `/lib` Files
2727

28-
`/lib/cron.php` :: `PLUGIN_CRON` to schedule operations.
28+
`/lib/class-cron.php` :: `PLUGIN_CRON` to schedule operations.
2929

30-
`/lib/api.php` :: `PLUGIN_API` to integrate 3rd party APIs.
30+
`/lib/class-api.php` :: `PLUGIN_API` to integrate 3rd party APIs.
3131

3232
`lib/table.php` :: `PLUGIN_TABLE` to display data tables.
3333

34-
`/lib/ajax.php` :: `PLUGIN_AJAX` to make AJAX requests.
34+
`/lib/class-ajax.php` :: `PLUGIN_AJAX` to make AJAX requests.
3535

36-
`/lib/upload.php` :: `PLUGIN_UPLOAD` to upload a file.
36+
`/lib/class-upload.php` :: `PLUGIN_UPLOAD` to upload a file.
3737

38-
`/lib/script.php` :: `PLUGIN_SCRIPT` to add required CSS and JS.
38+
`/lib/class-script.php` :: `PLUGIN_SCRIPT` to add required CSS and JS.
3939

4040
### `/src` Files
4141

42-
`/src/install.php` :: `PLUGIN_INSTALL` to handle activation process.
42+
`/src/class-install.php` :: `PLUGIN_INSTALL` to handle activation process.
4343

44-
`/src/db.php` :: `PLUGIN_DB` to install database tables.
44+
`/src/class-db.php` :: `PLUGIN_DB` to install database tables.
4545

46-
`/src/settings.php` :: `PLUGIN_SETTINGS` to create admin settings pages.
46+
`/src/class-settings.php` :: `PLUGIN_SETTINGS` to create admin settings pages.
4747

48-
`/src/widget.php` :: `PLUGIN_WIDGET` to add custom widget.
48+
`/src/class-cpt.php` :: `PLUGIN_CPT` to create custom post type.
4949

50-
`/src/metabox.php` :: `PLUGIN_METABOX` to add custom metabox in editor screen.
50+
`/src/class-widget.php` :: `PLUGIN_WIDGET` to add custom widget.
5151

52-
`/src/shortcode.php`:: `PLUGIN_SHORTCODE` to add and display shortcodes.
52+
`/src/class-metabox.php` :: `PLUGIN_METABOX` to add custom metabox in editor screen.
5353

54-
`/src/query.php`:: `PLUGIN_QUERY` to use post and user query. It uses `wp_pagenavi()` for breadceumbs
54+
`/src/class-shortcode.php`:: `PLUGIN_SHORTCODE` to add and display shortcodes.
55+
56+
`/src/class-query.php`:: `PLUGIN_QUERY` to use post and user query. It uses `wp_pagenavi()` for breadceumbs

autoload.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
* Follow: https://codex.wordpress.org/Plugin_API for details
77
*
88
* @author Nirjhar Lo
9-
* @version 1.2.1
10-
* @copyright (c) 2020 Nirjhar Lo
11-
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE
129
* @package wp-plugin-framework
1310
*/
1411
if ( ! class_exists( 'PLUGIN_BUILD' ) ) {
@@ -18,7 +15,7 @@ final class PLUGIN_BUILD {
1815
/**
1916
* @var String
2017
*/
21-
protected $version = '1.2.1';
18+
protected $version = '1.3';
2219

2320

2421
/**
@@ -96,6 +93,10 @@ public function installation() {
9693
$install->plugin_page_links = self::$plugin_page_links;
9794
$install->execute();
9895
}
96+
97+
//If CPT exists, include taht and flush the rewrite rules
98+
if ( class_exists( 'PLUGIN_CPT' ) ) new PLUGIN_CPT();
99+
flush_rewrite_rules();
99100
}
100101

101102

@@ -220,6 +221,17 @@ public function cron_uninstall() {
220221
}
221222

222223

224+
/**
225+
* Install Custom post types
226+
*
227+
* @return Void
228+
*/
229+
public function cpt() {
230+
231+
if ( class_exists( 'PLUGIN_CPT' ) ) new PLUGIN_CPT();
232+
}
233+
234+
223235
/**
224236
* Include scripts
225237
*
@@ -283,13 +295,14 @@ public function shortcode() {
283295
*/
284296
public function functionality() {
285297

286-
require_once( 'src/install.php' );
287-
require_once( 'src/db.php' );
288-
require_once( 'src/query.php' );
289-
require_once( 'src/settings.php' );
290-
require_once( 'src/widget.php' );
291-
require_once( 'src/metabox.php' );
292-
require_once( 'src/shortcode.php' );
298+
require_once( 'src/class-install.php' );
299+
require_once( 'src/class-db.php' );
300+
require_once( 'src/class-query.php' );
301+
require_once( 'src/class-settings.php' );
302+
require_once( 'src/class-widget.php' );
303+
require_once( 'src/class-metabox.php' );
304+
require_once( 'src/class-shortcode.php' );
305+
require_once( 'src/class-cpt.php' );
293306
}
294307

295308

@@ -301,12 +314,12 @@ public function functionality() {
301314
*/
302315
public function helpers() {
303316

304-
require_once( 'lib/cron.php' );
305-
require_once( 'lib/api.php' );
306-
require_once( 'lib/table.php' );
307-
require_once( 'lib/ajax.php' );
308-
require_once( 'lib/upload.php' );
309-
require_once( 'lib/script.php' );
317+
require_once( 'lib/class-cron.php' );
318+
require_once( 'lib/class-api.php' );
319+
require_once( 'lib/class-table.php' );
320+
require_once( 'lib/class-ajax.php' );
321+
require_once( 'lib/class-upload.php' );
322+
require_once( 'lib/class-script.php' );
310323
}
311324

312325

@@ -330,6 +343,7 @@ public function init() {
330343

331344
add_action( 'init', array( $this, 'installation' ) );
332345
add_action( 'init', array( $this, 'custom_cron_hook_cb' ) );
346+
add_action( 'init', array( $this, 'cpt' ) );
333347

334348
$this->scripts();
335349
$this->widgets();

lib/ajax.php renamed to lib/class-ajax.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Use this class in admin or user side
55
*
66
* @author Nirjhar Lo
7-
* @version 1.2.1
87
* @package wp-plugin-framework
98
*/
109
if ( ! defined( 'ABSPATH' ) ) exit;

lib/api.php renamed to lib/class-api.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* $data = $api->parse();
1414
*
1515
* @author Nirjhar Lo
16-
* @version 1.2.1
1716
* @package wp-plugin-framework
1817
*/
1918
if ( ! class_exists( 'PLUGIN_API' ) ) {

lib/cron.php renamed to lib/class-cron.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Add Cron schedules and cron task callback
66
*
77
* @author Nirjhar Lo
8-
* @version 1.2.1
98
* @package wp-plugin-framework
109
*/
1110
if ( ! class_exists( 'PLUGIN_CRON' ) ) {

lib/script.php renamed to lib/class-script.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Add scripts to the plugin. CSS and JS.
44
*
55
* @author Nirjhar Lo
6-
* @version 1.2.1
76
* @package wp-plugin-framework
87
*/
98
if ( ! defined( 'ABSPATH' ) ) exit;

lib/table.php renamed to lib/class-table.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* $my_plugin_name_table->display();
88
*
99
* @author Nirjhar Lo
10-
* @version 1.2.1
1110
* @package wp-plugin-framework
1211
*/
1312
if ( ! class_exists( 'PLUGIN_TABLE' ) ) {

lib/upload.php renamed to lib/class-upload.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Plugin upload for WordPress front end or backend
66
*
77
* @author Nirjhar Lo
8-
* @version 1.2.1
98
* @package wp-plugin-framework
109
*/
1110
if ( ! class_exists( 'PLUGIN_UPLOAD' ) ) {

src/class-cpt.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
if ( ! defined( 'ABSPATH' ) ) exit;
3+
4+
/**
5+
* Custom post type class
6+
*
7+
* @author Nirjhar Lo
8+
* @package wp-plugin-framework
9+
*/
10+
if ( ! class_exists( 'PLUGIN_CPT' ) ) {
11+
12+
class PLUGIN_CPT {
13+
14+
/**
15+
* @var Array
16+
*/
17+
private $labels;
18+
19+
/**
20+
* @var Array
21+
*/
22+
private $args;
23+
24+
/**
25+
* @var String
26+
*/
27+
private static $menu_svg = '';
28+
29+
30+
/**
31+
* Integrate the shortcode
32+
*
33+
* @return Void
34+
*/
35+
public function __construct() {
36+
37+
$this->labels = $this->labels();
38+
$this->args = $this->args( $this->labels );
39+
40+
//register_post_type( 'cpt_name', $this->args );
41+
//add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) );
42+
}
43+
44+
45+
/**
46+
* Define the labels
47+
*
48+
* @return Array
49+
*/
50+
public function labels() {
51+
52+
$labels = array(
53+
'name' => _x( '', 'Post Type General Name', 'textdomain' ),
54+
'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ),
55+
'menu_name' => __( '', 'textdomain' ),
56+
'parent_item_colon' => __( '', 'textdomain' ),
57+
'all_items' => __( '', 'textdomain' ),
58+
'view_item' => __( '', 'textdomain' ),
59+
'add_new_item' => __( '', 'textdomain' ),
60+
'add_new' => __( '', 'textdomain' ),
61+
'edit_item' => __( '', 'textdomain' ),
62+
'update_item' => __( '', 'textdomain' ),
63+
'search_items' => __( '', 'textdomain' ),
64+
'not_found' => __( '', 'textdomain' ),
65+
'not_found_in_trash' => __( '', 'textdomain' ),
66+
);
67+
68+
return $labels;
69+
}
70+
71+
72+
/**
73+
* Define the arguments
74+
*
75+
* @param Array $labels
76+
*
77+
* @return Array
78+
*/
79+
public function args( $labels ) {
80+
81+
$args = array(
82+
'label' => __( '', 'textdomain' ),
83+
'description' => __( '', 'textdomain' ),
84+
'labels' => $labels,
85+
'supports' => array( 'title', 'editor', 'thumbnail' ),
86+
'taxonomies' => array( 'topics', 'post_tag' ),
87+
'hierarchical' => true,
88+
'public' => true,
89+
'rewrite' => array( 'slug' => 'slug_name' ),
90+
'show_ui' => true,
91+
'show_in_menu' => true,
92+
'menu_icon' => 'data:image/svg+xml;base64,' . self::$menu_svg,
93+
'show_in_nav_menus' => true,
94+
'show_in_admin_bar' => true,
95+
'menu_position' => 5,
96+
'can_export' => true,
97+
'has_archive' => true,
98+
'exclude_from_search' => false,
99+
'publicly_queryable' => true,
100+
'capability_type' => 'post',
101+
'show_in_rest' => true,
102+
);
103+
104+
return $args;
105+
}
106+
107+
108+
/**
109+
* Modify the cpt messages
110+
*
111+
* @param Array $messages
112+
*
113+
* @return Array
114+
*/
115+
public function cpt_updated_messages( $messages ) {
116+
117+
global $post, $post_ID;
118+
119+
$messages['cpt_name'] = array(
120+
0 => '',
121+
1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ),
122+
2 => __( 'field updated.', 'textdomain' ),
123+
3 => __( 'field deleted.', 'textdomain' ),
124+
4 => __( 'CPT updated.', 'textdomain' ),
125+
5 => ( isset( $_GET['revision'] ) ? sprintf( __( 'CPT restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false ),
126+
6 => sprintf( __( 'CPT published. <a href="%s">View Cpt</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ),
127+
7 => __( 'CPT saved.', 'textdomain' ),
128+
8 => sprintf( __( 'CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
129+
9 => sprintf( __( 'CPT scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview cpt</a>', 'textdomain' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
130+
10 => sprintf( __( 'CPT draft updated. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
131+
);
132+
133+
return $messages;
134+
}
135+
}
136+
}

src/db.php renamed to src/class-db.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* DB installation class
66
*
77
* @author Nirjhar Lo
8-
* @version 1.2.1
98
* @package wp-plugin-framework
109
*/
1110
if ( ! class_exists( 'PLUGIN_DB' ) ) {

0 commit comments

Comments
 (0)