Skip to content

Commit f36a910

Browse files
committed
Settings
1 parent 29efcbc commit f36a910

12 files changed

Lines changed: 341 additions & 283 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
[![Build Status](https://travis-ci.org/nirjharlo/wp-plugin-framework.svg?branch=master)](https://travis-ci.org/nirjharlo/wp-plugin-framework)
33

44
A WordPress plugin framework base to build any standard WP plugin on top of it.
5-
It contains various items, such as Settings pages, Data tables, Widgets, Metaboxes, Custom Post Types, Shortcodes along with infrastructure for DB operations.
5+
It contains various items, such as Settings pages, Data tables, Widgets, Metaboxes, Custom Post Types, Shortcodes along with infrastructure for DB operations and CRON jobs.
66

77
There are extra classes for API integration and AJAX.
88

9-
This project is a demo for my WP skills.
9+
## Usage
10+

autoload.php

Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -107,62 +107,12 @@ public function db_uninstall() {
107107

108108

109109
//Include settings pages
110-
public function functionality() {
110+
public function settings() {
111111

112-
/*
113-
*
114-
* Add Settings functionality
115-
*
116-
if ( class_exists( 'PLUGIN_SETTINGS' ) ) {
117-
118-
$settings = new PLUGIN_SETTINGS();
119-
$settings->capability = 'manage_options';
120-
$settings->screen = ;
121-
$settings->menuPage = array( 'name' => '', 'heading' => '', 'slug' => '' );
122-
$settings->subMenuPage = array(
123-
array(
124-
'name' => '',
125-
'heading' => '',
126-
'slug' => '',
127-
'parent_slug' => '',
128-
'help' => true/false,
129-
'screen' => true/false ) );
130-
$settings->help = array(
131-
array( 'slug' => '',
132-
'help' => array(
133-
'info' => array(
134-
array(
135-
'id' => 'helpId',
136-
'title' => __( 'Title', 'textdomain' ),
137-
'content' => __( 'helpDescription', 'textdomain' ),
138-
),
139-
),
140-
'link' => '<p><a href="#">' . __( 'helpLink', 'textdomain' ) . '</a></p>',
141-
) ) );
142-
$settings->execute();
143-
144-
}
145-
*
146-
*/
147-
}
148-
149-
150-
151-
public function customization() {
152-
153-
/**
154-
*
155-
* Add customization files
156-
*
157-
require_once ('src/');
158-
require_once ('src/');
159-
require_once ('src/');
160-
*
161-
*/
112+
if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS();
162113
}
163114

164115

165-
166116
//Include widget classes
167117
public function widgets() {
168118

@@ -179,18 +129,35 @@ public function metabox() {
179129

180130

181131

182-
//Call the dependency files
183-
public function helpers() {
132+
//Include shortcode classes
133+
public function shortcode() {
134+
135+
if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE();
136+
}
137+
138+
139+
140+
//Add customization files
141+
public function customization() {
184142

185143
require_once ('src/install.php');
186144
require_once ('src/db.php');
145+
require_once ('src/settings.php');
146+
require_once ('src/widgets.php');
147+
require_once ('src/metabox.php');
148+
require_once ('src/shortcode.php');
149+
}
150+
151+
152+
153+
//Call the dependency files
154+
public function helpers() {
187155

188-
require_once ('vendor/api.php');
189-
require_once ('vendor/table.php');
190-
require_once ('vendor/ajax.php');
191-
require_once ('vendor/settings.php');
192-
require_once ('vendor/widgets.php');
193-
require_once ('vendor/metabox.php');
156+
require_once ('lib/cron.php');
157+
require_once ('lib/api.php');
158+
require_once ('lib/table.php');
159+
require_once ('lib/ajax.php');
160+
require_once ('lib/upload.php');
194161
}
195162

196163

@@ -210,6 +177,8 @@ public function __construct() {
210177

211178
$this->widgets();
212179
$this->metabox();
180+
$this->shortcode();
181+
$this->settings();
213182
}
214183
}
215184
} ?>
File renamed without changes.
File renamed without changes.

lib/cron.php

Whitespace-only changes.
File renamed without changes.

lib/upload.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
if ( ! defined( 'ABSPATH' ) ) exit;
3+
4+
//Widget class
5+
if ( ! class_exists( 'PLUGIN_UPLOAD' ) ) {
6+
7+
final class PLUGIN_UPLOAD extends WP_WIDGET {
8+
9+
10+
11+
// Add basic actions
12+
public function __construct() {
13+
14+
$widget_ops = array(
15+
'classname' => 'plugin_widget',
16+
'description' => __( 'Plugin widget', 'textdomain' ),
17+
);
18+
parent::__construct( 'my_widget_id', __( 'Plugin widget', 'textdomain' ), $widget_ops );
19+
}
20+
21+
22+
23+
//Outputs the content of the widget
24+
public function widget( $args, $instance ) {
25+
26+
echo $args['before_widget'];
27+
if ( ! empty( $instance['title'] ) ) {
28+
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
29+
}
30+
echo esc_html__( 'Hello, World!', 'textdomain' );
31+
echo $args['after_widget'];
32+
}
33+
34+
35+
36+
//Outputs the options form on admin
37+
public function form( $instance ) {
38+
39+
$title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Title', 'textdomain' ); ?>
40+
<p>
41+
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'textdomain' ); ?></label>
42+
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
43+
</p>
44+
<?php
45+
}
46+
47+
48+
49+
//Processing widget options on save
50+
public function update( $new_instance, $old_instance ) {
51+
52+
$instance = array();
53+
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
54+
return $instance;
55+
}
56+
}
57+
} ?>
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class PLUGIN_METABOX {
99

1010
public function __construct() {
1111

12-
//Adding the metabox
12+
//Adding the metabox. For custom post type use "add_meta_boxes_posttype" action
1313
add_action( 'add_meta_boxes', array( $this, 'register' ) );
1414
add_action( 'save_post', array( $this, 'save' ), 10, 2 );
1515
}
@@ -30,10 +30,9 @@ public function register() {
3030

3131

3232

33-
3433
public function render() {
3534

36-
<?php wp_nonce_field( basename( __FILE__ ), 'metaBoxName_nonce' ); ?>
35+
wp_nonce_field( basename( __FILE__ ), 'metaBoxName_nonce' ); ?>
3736

3837
<p>
3938
<label for="metaBoxName"><?php _e( "Custom Text", 'myPlugintextDomain' ); ?></label>

0 commit comments

Comments
 (0)