From 6bc14385474322c2b70353e45beaa3eb6f85b159 Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 13:25:01 +0300
Subject: [PATCH 01/12] add the properties to the main clas with path/url data
---
README.md | 82 +-
assets/css/help-page.css | 1 +
assets/css/index.php | 2 +
{css => assets/css}/samplestyle-admin.css | 0
{css => assets/css}/samplestyle.css | 0
assets/index.php | 2 +
assets/js/index.php | 2 +
{js => assets/js}/samplescript-admin.js | 0
assets/js/samplescript.js | 3 +
dx-plugin-base.php | 907 ++++++++++--------
.../class-dx-plugin-settings.php | 8 +-
inc/dx-sample-widget.class.php | 24 +-
inc/index.php | 2 +
index.php | 2 +
js/samplescript.js | 1 -
lang/index.php | 2 +
{inc => template}/base-page-template.php | 6 +-
template/index.php | 2 +
{inc => template}/remote-page-template.php | 12 +-
19 files changed, 566 insertions(+), 492 deletions(-)
create mode 100644 assets/css/help-page.css
create mode 100644 assets/css/index.php
rename {css => assets/css}/samplestyle-admin.css (100%)
rename {css => assets/css}/samplestyle.css (100%)
create mode 100644 assets/index.php
create mode 100644 assets/js/index.php
rename {js => assets/js}/samplescript-admin.js (100%)
create mode 100755 assets/js/samplescript.js
rename dx-plugin-settings.class.php => inc/class-dx-plugin-settings.php (89%)
create mode 100644 inc/index.php
create mode 100644 index.php
delete mode 100755 js/samplescript.js
create mode 100644 lang/index.php
rename {inc => template}/base-page-template.php (62%)
create mode 100644 template/index.php
rename {inc => template}/remote-page-template.php (76%)
diff --git a/README.md b/README.md
index 73a2389..b9335d3 100755
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ This would add the `dx_add_JS` function do the hook responsible for adding scrip
public function dx_add_JS() {
wp_enqueue_script( 'jquery' );
// load custom JSes and put them in footer
- wp_register_script( 'samplescript', plugins_url( '/js/samplescript.js' , __FILE__ ), array('jquery'), '1.0', true );
+ wp_register_script( 'samplescript', $this->url_assets . 'js/samplescript.js', array('jquery'), '1.0', true );
wp_enqueue_script( 'samplescript' );
}
```
@@ -47,7 +47,7 @@ Calling a function for your backend is similar:
```php
public function dx_add_admin_JS( $hook ) {
wp_enqueue_script( 'jquery' );
- wp_register_script( 'samplescript-admin', plugins_url( '/js/samplescript-admin.js' , __FILE__ ), array('jquery'), '1.0', true );
+ wp_register_script( 'samplescript-admin', $this->url_assets . 'js/samplescript-admin.js', array('jquery'), '1.0', true );
wp_enqueue_script( 'samplescript-admin' );
}
```
@@ -72,10 +72,10 @@ Then, you can call the `wp_enqueue_style` function within your callback method i
```php
public function dx_add_admin_CSS( $hook ) {
- wp_register_style( 'samplestyle-admin', plugins_url( '/css/samplestyle-admin.css', __FILE__ ), array(), '1.0', 'screen' );
+ wp_register_style( 'samplestyle-admin', $this->url_assets . '/css/samplestyle-admin.css', array(), '1.0', 'screen' );
wp_enqueue_style( 'samplestyle-admin' );
if( 'toplevel_page_dx-plugin-base' === $hook ) {
- wp_register_style('dx_help_page', plugins_url( '/help-page.css', __FILE__ ) );
+ wp_register_style('dx_help_page', $this->url_assets . '/help-page.css' );
wp_enqueue_style('dx_help_page');
}
}
@@ -95,20 +95,22 @@ Then you can add top level or submenu pages to your dashboard menu:
```php
public function dx_admin_pages_callback() {
- add_menu_page(__( "Plugin Base Admin", 'dxbase' ), __( "Plugin Base Admin", 'dxbase' ), 'edit_themes', 'dx-plugin-base', array( $this, 'dx_plugin_base' ) );
- add_submenu_page( 'dx-plugin-base', __( "Base Subpage", 'dxbase' ), __( "Base Subpage", 'dxbase' ), 'edit_themes', 'dx-base-subpage', array( $this, 'dx_plugin_subpage' ) );
- add_submenu_page( 'dx-plugin-base', __( "Remote Subpage", 'dxbase' ), __( "Remote Subpage", 'dxbase' ), 'edit_themes', 'dx-remote-subpage', array( $this, 'dx_plugin_side_access_page' ) );
+ add_menu_page(__( "Plugin Base Admin", DXP_TD ), __( "Plugin Base Admin", DXP_TD ), 'edit_themes', 'dx-plugin-base', array( $this, 'dx_plugin_base' ) );
+ add_submenu_page( 'dx-plugin-base', __( "Base Subpage", DXP_TD ), __( "Base Subpage", DXP_TD ), 'edit_themes', 'dx-base-subpage', array( $this, 'dx_plugin_subpage' ) );
+ add_submenu_page( 'dx-plugin-base', __( "Remote Subpage", DXP_TD ), __( "Remote Subpage", DXP_TD ), 'edit_themes', 'dx-remote-subpage', array( $this, 'dx_plugin_side_access_page' ) );
}
```
It's up to you what would you hook exactly and what would be the capabilities required for your users, but that's the sample syntax that you'd need. Each of those pages is defined via a callback at the end of the function parameters list, that could either be plain HTML/PHP, or loading an external file including your logic:
```php
- // Earlier in your plugin header
- define( 'DXP_PATH_INCLUDES', dirname( __FILE__ ) . '/inc' );
+ // Earlier in your plugin setup
+ if( empty( $this->path_template ) ):
+ $this->path_template = trailingslashit( $this->path . 'template' );
+ endif;
// A class method for the callback
public function dx_plugin_side_access_page() {
- include_once( DXP_PATH_INCLUDES . '/remote-page-template.php' );
+ include_once( $this->path_template . 'remote-page-template.php' );
}
```
@@ -126,18 +128,18 @@ The function responsible for the registration has plenty of options to play with
public function dx_custom_post_types_callback() {
register_post_type( 'pluginbase', array(
'labels' => array(
- 'name' => __("Base Items", 'dxbase'),
- 'singular_name' => __("Base Item", 'dxbase'),
- 'add_new' => _x("Add New", 'pluginbase', 'dxbase' ),
- 'add_new_item' => __("Add New Base Item", 'dxbase' ),
- 'edit_item' => __("Edit Base Item", 'dxbase' ),
- 'new_item' => __("New Base Item", 'dxbase' ),
- 'view_item' => __("View Base Item", 'dxbase' ),
- 'search_items' => __("Search Base Items", 'dxbase' ),
- 'not_found' => __("No base items found", 'dxbase' ),
- 'not_found_in_trash' => __("No base items found in Trash", 'dxbase' ),
+ 'name' => __("Base Items", DXP_TD),
+ 'singular_name' => __("Base Item", DXP_TD),
+ 'add_new' => _x("Add New", 'pluginbase', DXP_TD ),
+ 'add_new_item' => __("Add New Base Item", DXP_TD ),
+ 'edit_item' => __("Edit Base Item", DXP_TD ),
+ 'new_item' => __("New Base Item", DXP_TD ),
+ 'view_item' => __("View Base Item", DXP_TD ),
+ 'search_items' => __("Search Base Items", DXP_TD ),
+ 'not_found' => __("No base items found", DXP_TD ),
+ 'not_found_in_trash' => __("No base items found in Trash", DXP_TD ),
),
- 'description' => __("Base Items for the demo", 'dxbase'),
+ 'description' => __("Base Items for the demo", DXP_TD),
'public' => true,
'publicly_queryable' => true,
'query_var' => true,
@@ -177,20 +179,20 @@ Then, our callback is registering the custom taxonomy and binds it so a custom p
register_taxonomy( 'pluginbase_taxonomy', 'pluginbase', array(
'hierarchical' => true,
'labels' => array(
- 'name' => _x( "Base Item Taxonomies", 'taxonomy general name', 'dxbase' ),
- 'singular_name' => _x( "Base Item Taxonomy", 'taxonomy singular name', 'dxbase' ),
- 'search_items' => __( "Search Taxonomies", 'dxbase' ),
- 'popular_items' => __( "Popular Taxonomies", 'dxbase' ),
- 'all_items' => __( "All Taxonomies", 'dxbase' ),
+ 'name' => _x( "Base Item Taxonomies", 'taxonomy general name', DXP_TD ),
+ 'singular_name' => _x( "Base Item Taxonomy", 'taxonomy singular name', DXP_TD ),
+ 'search_items' => __( "Search Taxonomies", DXP_TD ),
+ 'popular_items' => __( "Popular Taxonomies", DXP_TD ),
+ 'all_items' => __( "All Taxonomies", DXP_TD ),
'parent_item' => null,
'parent_item_colon' => null,
- 'edit_item' => __( "Edit Base Item Taxonomy", 'dxbase' ),
- 'update_item' => __( "Update Base Item Taxonomy", 'dxbase' ),
- 'add_new_item' => __( "Add New Base Item Taxonomy", 'dxbase' ),
- 'new_item_name' => __( "New Base Item Taxonomy Name", 'dxbase' ),
- 'separate_items_with_commas' => __( "Separate Base Item taxonomies with commas", 'dxbase' ),
- 'add_or_remove_items' => __( "Add or remove Base Item taxonomy", 'dxbase' ),
- 'choose_from_most_used' => __( "Choose from the most used Base Item taxonomies", 'dxbase' )
+ 'edit_item' => __( "Edit Base Item Taxonomy", DXP_TD ),
+ 'update_item' => __( "Update Base Item Taxonomy", DXP_TD ),
+ 'add_new_item' => __( "Add New Base Item Taxonomy", DXP_TD ),
+ 'new_item_name' => __( "New Base Item Taxonomy Name", DXP_TD ),
+ 'separate_items_with_commas' => __( "Separate Base Item taxonomies with commas", DXP_TD ),
+ 'add_or_remove_items' => __( "Add or remove Base Item taxonomy", DXP_TD ),
+ 'choose_from_most_used' => __( "Choose from the most used Base Item taxonomies", DXP_TD )
),
'show_ui' => true,
'query_var' => true,
@@ -218,7 +220,7 @@ Our callback method will register the metaboxes that we need, attached to a spec
// register side box
add_meta_box(
'dx_side_meta_box',
- __( "DX Side Box", 'dxbase' ),
+ __( "DX Side Box", DXP_TD ),
array( $this, 'dx_side_meta_box' ),
'pluginbase', // leave empty quotes as '' if you want it on all custom post add/edit screens
'side',
@@ -228,7 +230,7 @@ Our callback method will register the metaboxes that we need, attached to a spec
// register bottom box
add_meta_box(
'dx_bottom_meta_box',
- __( "DX Bottom Box", 'dxbase' ),
+ __( "DX Bottom Box", DXP_TD ),
array( $this, 'dx_bottom_meta_box' ),
'' // leave empty quotes as '' if you want it on all custom post add/edit screens or add a post type slug
);
@@ -239,7 +241,7 @@ The callback of our `add_meta_box` call includes everything that is to be displa
```php
public function dx_side_meta_box( $post, $metabox) {
- _e("
Side meta content here
", 'dxbase');
+ _e("
Side meta content here
", DXP_TD);
// Add some test data here - a custom field, that is
$dx_test_input = '';
@@ -248,7 +250,7 @@ The callback of our `add_meta_box` call includes everything that is to be displa
$dx_test_input = get_post_meta( $post->ID, 'dx_test_input', true );
}
?>
-
+
path_include . 'dx-sample-widget.class.php';
}
```
@@ -353,7 +355,7 @@ Arguments are available in the `$attr` array - the first argument of the callbac
/*
* Manage the attributes and the content as per your request and return the result
*/
- return __( 'Sample Output', 'dxbase');
+ return __( 'Sample Output', DXP_TD);
}
```
diff --git a/assets/css/help-page.css b/assets/css/help-page.css
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/assets/css/help-page.css
@@ -0,0 +1 @@
+
diff --git a/assets/css/index.php b/assets/css/index.php
new file mode 100644
index 0000000..6220032
--- /dev/null
+++ b/assets/css/index.php
@@ -0,0 +1,2 @@
+setup();
+
+ // add script and style calls the WP way
+ // it's a bit confusing as styles are called with a scripts hook
+ // @blamenacin - http://make.wordpress.org/core/2011/12/12/use-wp_enqueue_scripts-not-wp_print_styles-to-enqueue-scripts-and-styles-for-the-frontend/
+ add_action( 'wp_enqueue_scripts', array( $this, 'dx_add_JS' ) );
+ add_action( 'wp_enqueue_scripts', array( $this, 'dx_add_CSS' ) );
+
+ // add scripts and styles only available in admin
add_action( 'admin_enqueue_scripts', array( $this, 'dx_add_admin_JS' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'dx_add_admin_CSS' ) );
-
- // register admin pages for the plugin
- add_action( 'admin_menu', array( $this, 'dx_admin_pages_callback' ) );
-
- // register meta boxes for Pages (could be replicated for posts and custom post types)
- add_action( 'add_meta_boxes', array( $this, 'dx_meta_boxes_callback' ) );
-
- // register save_post hooks for saving the custom fields
- add_action( 'save_post', array( $this, 'dx_save_sample_field' ) );
-
- // Register custom post types and taxonomies
- add_action( 'init', array( $this, 'dx_custom_post_types_callback' ), 5 );
- add_action( 'init', array( $this, 'dx_custom_taxonomies_callback' ), 6 );
-
- // Register activation and deactivation hooks
- register_activation_hook( __FILE__, 'dx_on_activate_callback' );
- register_deactivation_hook( __FILE__, 'dx_on_deactivate_callback' );
-
- // Translation-ready
- add_action( 'plugins_loaded', array( $this, 'dx_add_textdomain' ) );
-
- // Add earlier execution as it needs to occur before admin page display
- add_action( 'admin_init', array( $this, 'dx_register_settings' ), 5 );
-
- // Add a sample shortcode
- add_action( 'init', array( $this, 'dx_sample_shortcode' ) );
-
- // Add a sample widget
- add_action( 'widgets_init', array( $this, 'dx_sample_widget' ) );
-
- /*
- * TODO:
- * template_redirect
- */
-
- // Add actions for storing value and fetching URL
- // use the wp_ajax_nopriv_ hook for non-logged users (handle guest actions)
- add_action( 'wp_ajax_store_ajax_value', array( $this, 'store_ajax_value' ) );
- add_action( 'wp_ajax_fetch_ajax_url_http', array( $this, 'fetch_ajax_url_http' ) );
-
- }
-
- /**
- *
- * Adding JavaScript scripts
- *
- * Loading existing scripts from wp-includes or adding custom ones
- *
- */
- public function dx_add_JS() {
- wp_enqueue_script( 'jquery' );
- // load custom JSes and put them in footer
- wp_register_script( 'samplescript', plugins_url( '/js/samplescript.js' , __FILE__ ), array('jquery'), '1.0', true );
- wp_enqueue_script( 'samplescript' );
- }
-
-
+ add_action( 'admin_enqueue_scripts', array( $this, 'dx_add_admin_CSS' ) );
+ // register admin pages for the plugin
+ add_action( 'admin_menu', array( $this, 'dx_admin_pages_callback' ) );
+
+ // register meta boxes for Pages (could be replicated for posts and custom post types)
+ add_action( 'add_meta_boxes', array( $this, 'dx_meta_boxes_callback' ) );
+
+ // register save_post hooks for saving the custom fields
+ add_action( 'save_post', array( $this, 'dx_save_sample_field' ) );
+
+ // Register custom post types and taxonomies
+ add_action( 'init', array( $this, 'dx_custom_post_types_callback' ), 5 );
+ add_action( 'init', array( $this, 'dx_custom_taxonomies_callback' ), 6 );
+
+ // Register activation and deactivation hooks
+ register_activation_hook( __FILE__, 'dx_on_activate_callback' );
+ register_deactivation_hook( __FILE__, 'dx_on_deactivate_callback' );
+
+ // Translation-ready
+ add_action( 'plugins_loaded', array( $this, 'dx_add_textdomain' ) );
+
+ // Add earlier execution as it needs to occur before admin page display
+ add_action( 'admin_init', array( $this, 'dx_register_settings' ), 5 );
+
+ // Add a sample shortcode
+ add_action( 'init', array( $this, 'dx_sample_shortcode' ) );
+
+ // Add a sample widget
+ add_action( 'widgets_init', array( $this, 'dx_sample_widget' ) );
+
+ /*
+ * TODO:
+ * template_redirect
+ */
+
+ // Add actions for storing value and fetching URL
+ // use the wp_ajax_nopriv_ hook for non-logged users (handle guest actions)
+ add_action( 'wp_ajax_store_ajax_value', array( $this, 'store_ajax_value' ) );
+ add_action( 'wp_ajax_fetch_ajax_url_http', array( $this, 'fetch_ajax_url_http' ) );
+
+ }
+
+ /**
+ * Setup the plugin main properties
+ */
+ protected function setup() {
+ //check all properties, if they are empty assign data accordingly
+ if ( empty( $this->version ) ):
+ $this->version = '1.7';
+ endif;
+ if( empty( $this->path ) ):
+ $this->path = trailingslashit( dirname( __FILE__ ) );
+ endif;
+ if( empty( $this->path_include ) ):
+ $this->path_include = trailingslashit( $this->path . 'inc' );
+ endif;
+ if( empty( $this->path_template ) ):
+ $this->path_template = trailingslashit( $this->path . 'template' );
+ endif;
+ if( empty( $this->url ) ):
+ $this->url = trailingslashit( plugins_url( '', __FILE__ ) );
+ endif;
+ if( empty( $this->url_assets ) ):
+ $this->url_assets = trailingslashit( $this->url . 'assets' );
+ endif;
+ }
+
+ /**
+ *
+ * Adding JavaScript scripts
+ *
+ * Loading existing scripts from wp-includes or adding custom ones
+ *
+ */
+ public function dx_add_JS() {
+ wp_enqueue_script( 'jquery' );
+ // load custom JSes and put them in footer
+ wp_register_script( 'samplescript', $this->url_assets . 'js/samplescript.js', array('jquery'), '1.0', true );
+ wp_enqueue_script( 'samplescript' );
+ }
+
+
/**
*
* Adding JavaScript scripts for the admin pages only
*
* Loading existing scripts from wp-includes or adding custom ones
*
- */
- public function dx_add_admin_JS( $hook ) {
- wp_enqueue_script( 'jquery' );
- wp_register_script( 'samplescript-admin', plugins_url( '/js/samplescript-admin.js' , __FILE__ ), array('jquery'), '1.0', true );
- wp_enqueue_script( 'samplescript-admin' );
- }
-
- /**
- *
- * Add CSS styles
- *
- */
- public function dx_add_CSS() {
- wp_register_style( 'samplestyle', plugins_url( '/css/samplestyle.css', __FILE__ ), array(), '1.0', 'screen' );
- wp_enqueue_style( 'samplestyle' );
- }
-
+ */
+ public function dx_add_admin_JS( $hook ) {
+ wp_enqueue_script( 'jquery' );
+ wp_register_script( 'samplescript-admin', $this->url_assets . 'js/samplescript-admin.js' , array('jquery'), '1.0', true );
+ wp_enqueue_script( 'samplescript-admin' );
+ }
+
+ /**
+ *
+ * Add CSS styles
+ *
+ */
+ public function dx_add_CSS() {
+ wp_register_style( 'samplestyle', $this->url_assets . 'css/samplestyle.css', array(), '1.0', 'screen' );
+ wp_enqueue_style( 'samplestyle' );
+ }
+
/**
*
* Add admin CSS styles - available only on admin
*
- */
- public function dx_add_admin_CSS( $hook ) {
- wp_register_style( 'samplestyle-admin', plugins_url( '/css/samplestyle-admin.css', __FILE__ ), array(), '1.0', 'screen' );
- wp_enqueue_style( 'samplestyle-admin' );
-
- if( 'toplevel_page_dx-plugin-base' === $hook ) {
- wp_register_style('dx_help_page', plugins_url( '/help-page.css', __FILE__ ) );
- wp_enqueue_style('dx_help_page');
- }
- }
-
- /**
- *
- * Callback for registering pages
- *
- * This demo registers a custom page for the plugin and a subpage
- *
- */
- public function dx_admin_pages_callback() {
- add_menu_page(__( "Plugin Base Admin", 'dxbase' ), __( "Plugin Base Admin", 'dxbase' ), 'edit_themes', 'dx-plugin-base', array( $this, 'dx_plugin_base' ) );
- add_submenu_page( 'dx-plugin-base', __( "Base Subpage", 'dxbase' ), __( "Base Subpage", 'dxbase' ), 'edit_themes', 'dx-base-subpage', array( $this, 'dx_plugin_subpage' ) );
- add_submenu_page( 'dx-plugin-base', __( "Remote Subpage", 'dxbase' ), __( "Remote Subpage", 'dxbase' ), 'edit_themes', 'dx-remote-subpage', array( $this, 'dx_plugin_side_access_page' ) );
- }
-
- /**
- *
- * The content of the base page
- *
- */
- public function dx_plugin_base() {
- include_once( DXP_PATH_INCLUDES . '/base-page-template.php' );
- }
-
- public function dx_plugin_side_access_page() {
- include_once( DXP_PATH_INCLUDES . '/remote-page-template.php' );
- }
-
- /**
- *
- * The content of the subpage
- *
- * Use some default UI from WordPress guidelines echoed here (the sample above is with a template)
- *
- * @see http://www.onextrapixel.com/2009/07/01/how-to-design-and-style-your-wordpress-plugin-admin-panel/
- *
- */
- public function dx_plugin_subpage() {
- echo '
';
- _e( "
DX Plugin Subpage
", 'dxbase' );
- _e( "I'm a subpage and I know it!", 'dxbase' );
- echo '
';
- }
-
- /**
- *
- * Adding right and bottom meta boxes to Pages
- *
- */
- public function dx_meta_boxes_callback() {
- // register side box
- add_meta_box(
- 'dx_side_meta_box',
- __( "DX Side Box", 'dxbase' ),
- array( $this, 'dx_side_meta_box' ),
- 'pluginbase', // leave empty quotes as '' if you want it on all custom post add/edit screens
- 'side',
- 'high'
- );
-
- // register bottom box
- add_meta_box(
- 'dx_bottom_meta_box',
- __( "DX Bottom Box", 'dxbase' ),
- array( $this, 'dx_bottom_meta_box' ),
- '' // leave empty quotes as '' if you want it on all custom post add/edit screens or add a post type slug
- );
- }
-
- /**
- *
- * Init right side meta box here
- * @param post $post the post object of the given page
- * @param metabox $metabox metabox data
- */
- public function dx_side_meta_box( $post, $metabox) {
- _e("
Side meta content here
", 'dxbase');
-
- // Add some test data here - a custom field, that is
- $dx_test_input = '';
- if ( ! empty ( $post ) ) {
- // Read the database record if we've saved that before
- $dx_test_input = get_post_meta( $post->ID, 'dx_test_input', true );
- }
- ?>
-
-
- Bottom meta content here
", 'dxbase' );
- }
-
- /**
- * Register custom post types
- *
- */
- public function dx_custom_post_types_callback() {
- register_post_type( 'pluginbase', array(
- 'labels' => array(
- 'name' => __("Base Items", 'dxbase'),
- 'singular_name' => __("Base Item", 'dxbase'),
- 'add_new' => _x("Add New", 'pluginbase', 'dxbase' ),
- 'add_new_item' => __("Add New Base Item", 'dxbase' ),
- 'edit_item' => __("Edit Base Item", 'dxbase' ),
- 'new_item' => __("New Base Item", 'dxbase' ),
- 'view_item' => __("View Base Item", 'dxbase' ),
- 'search_items' => __("Search Base Items", 'dxbase' ),
- 'not_found' => __("No base items found", 'dxbase' ),
- 'not_found_in_trash' => __("No base items found in Trash", 'dxbase' ),
- ),
- 'description' => __("Base Items for the demo", 'dxbase'),
- 'public' => true,
- 'publicly_queryable' => true,
- 'query_var' => true,
- 'rewrite' => true,
- 'exclude_from_search' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'menu_position' => 40, // probably have to change, many plugins use this
- 'supports' => array(
- 'title',
- 'editor',
- 'thumbnail',
- 'custom-fields',
- 'page-attributes',
- ),
- 'taxonomies' => array( 'post_tag' )
- ));
- }
-
-
- /**
- * Register custom taxonomies
- *
- */
- public function dx_custom_taxonomies_callback() {
- register_taxonomy( 'pluginbase_taxonomy', 'pluginbase', array(
- 'hierarchical' => true,
- 'labels' => array(
- 'name' => _x( "Base Item Taxonomies", 'taxonomy general name', 'dxbase' ),
- 'singular_name' => _x( "Base Item Taxonomy", 'taxonomy singular name', 'dxbase' ),
- 'search_items' => __( "Search Taxonomies", 'dxbase' ),
- 'popular_items' => __( "Popular Taxonomies", 'dxbase' ),
- 'all_items' => __( "All Taxonomies", 'dxbase' ),
- 'parent_item' => null,
- 'parent_item_colon' => null,
- 'edit_item' => __( "Edit Base Item Taxonomy", 'dxbase' ),
- 'update_item' => __( "Update Base Item Taxonomy", 'dxbase' ),
- 'add_new_item' => __( "Add New Base Item Taxonomy", 'dxbase' ),
- 'new_item_name' => __( "New Base Item Taxonomy Name", 'dxbase' ),
- 'separate_items_with_commas' => __( "Separate Base Item taxonomies with commas", 'dxbase' ),
- 'add_or_remove_items' => __( "Add or remove Base Item taxonomy", 'dxbase' ),
- 'choose_from_most_used' => __( "Choose from the most used Base Item taxonomies", 'dxbase' )
- ),
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => true,
- ));
-
- register_taxonomy_for_object_type( 'pluginbase_taxonomy', 'pluginbase' );
- }
-
- /**
- * Initialize the Settings class
- *
- * Register a settings section with a field for a secure WordPress admin option creation.
- *
- */
- public function dx_register_settings() {
- require_once( DXP_PATH . '/dx-plugin-settings.class.php' );
- new DX_Plugin_Settings();
- }
-
- /**
- * Register a sample shortcode to be used
- *
- * First parameter is the shortcode name, would be used like: [dxsampcode]
- *
- */
- public function dx_sample_shortcode() {
- add_shortcode( 'dxsampcode', array( $this, 'dx_sample_shortcode_body' ) );
- }
-
- /**
- * Returns the content of the sample shortcode, like [dxsamplcode]
- * @param array $attr arguments passed to array, like [dxsamcode attr1="one" attr2="two"]
- * @param string $content optional, could be used for a content to be wrapped, such as [dxsamcode]somecontnet[/dxsamcode]
- */
- public function dx_sample_shortcode_body( $attr, $content = null ) {
- /*
- * Manage the attributes and the content as per your request and return the result
- */
- return __( 'Sample Output', 'dxbase');
- }
-
- /**
- * Hook for including a sample widget with options
- */
- public function dx_sample_widget() {
- include_once DXP_PATH_INCLUDES . '/dx-sample-widget.class.php';
- }
-
- /**
- * Add textdomain for plugin
- */
- public function dx_add_textdomain() {
- load_plugin_textdomain( 'dxbase', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
- }
-
- /**
- * Callback for saving a simple AJAX option with no page reload
- */
- public function store_ajax_value() {
- if( isset( $_POST['data'] ) && isset( $_POST['data']['dx_option_from_ajax'] ) ) {
- update_option( 'dx_option_from_ajax' , $_POST['data']['dx_option_from_ajax'] );
- }
- die();
- }
-
- /**
- * Callback for getting a URL and fetching it's content in the admin page
- */
- public function fetch_ajax_url_http() {
+ */
+ public function dx_add_admin_CSS( $hook ) {
+ wp_register_style( 'samplestyle-admin', $this->url_assets . 'css/samplestyle-admin.css', array(), '1.0', 'screen' );
+ wp_enqueue_style( 'samplestyle-admin' );
+
+ if( 'toplevel_page_dx-plugin-base' === $hook ) {
+ wp_register_style('dx_help_page', $this->url_assets . 'css/help-page.css' );
+ wp_enqueue_style('dx_help_page');
+ }
+ }
+
+ /**
+ *
+ * Callback for registering pages
+ *
+ * This demo registers a custom page for the plugin and a subpage
+ *
+ */
+ public function dx_admin_pages_callback() {
+ add_menu_page(__( "Plugin Base Admin", DXP_TD ), __( "Plugin Base Admin", DXP_TD ), 'edit_themes', 'dx-plugin-base', array( $this, 'dx_plugin_base' ) );
+ add_submenu_page( 'dx-plugin-base', __( "Base Subpage", DXP_TD ), __( "Base Subpage", DXP_TD ), 'edit_themes', 'dx-base-subpage', array( $this, 'dx_plugin_subpage' ) );
+ add_submenu_page( 'dx-plugin-base', __( "Remote Subpage", DXP_TD ), __( "Remote Subpage", DXP_TD ), 'edit_themes', 'dx-remote-subpage', array( $this, 'dx_plugin_side_access_page' ) );
+ }
+
+ /**
+ *
+ * The content of the base page
+ *
+ */
+ public function dx_plugin_base() {
+ include_once( $this->path_template . 'base-page-template.php' );
+ }
+
+ public function dx_plugin_side_access_page() {
+ include_once( $this->path_template . 'remote-page-template.php' );
+ }
+
+ /**
+ *
+ * The content of the subpage
+ *
+ * Use some default UI from WordPress guidelines echoed here (the sample above is with a template)
+ *
+ * @see http://www.onextrapixel.com/2009/07/01/how-to-design-and-style-your-wordpress-plugin-admin-panel/
+ *
+ */
+ public function dx_plugin_subpage() {
+ echo '
';
+ _e( "
DX Plugin Subpage
", DXP_TD );
+ _e( "I'm a subpage and I know it!", DXP_TD );
+ echo '
';
+ }
+
+ /**
+ *
+ * Adding right and bottom meta boxes to Pages
+ *
+ */
+ public function dx_meta_boxes_callback() {
+ // register side box
+ add_meta_box(
+ 'dx_side_meta_box',
+ __( "DX Side Box", DXP_TD ),
+ array( $this, 'dx_side_meta_box' ),
+ 'pluginbase', // leave empty quotes as '' if you want it on all custom post add/edit screens
+ 'side',
+ 'high'
+ );
+
+ // register bottom box
+ add_meta_box(
+ 'dx_bottom_meta_box',
+ __( "DX Bottom Box", DXP_TD ),
+ array( $this, 'dx_bottom_meta_box' ),
+ '' // leave empty quotes as '' if you want it on all custom post add/edit screens or add a post type slug
+ );
+ }
+
+ /**
+ *
+ * Init right side meta box here
+ * @param post $post the post object of the given page
+ * @param metabox $metabox metabox data
+ */
+ public function dx_side_meta_box( $post, $metabox) {
+ _e("
Side meta content here
", DXP_TD);
+
+ // Add some test data here - a custom field, that is
+ $dx_test_input = '';
+ if ( ! empty ( $post ) ) {
+ // Read the database record if we've saved that before
+ $dx_test_input = get_post_meta( $post->ID, 'dx_test_input', true );
+ }
+ ?>
+
+
+ Bottom meta content here", DXP_TD );
+ }
+
+ /**
+ * Register custom post types
+ *
+ */
+ public function dx_custom_post_types_callback() {
+ register_post_type( 'pluginbase', array(
+ 'labels' => array(
+ 'name' => __("Base Items", DXP_TD),
+ 'singular_name' => __("Base Item", DXP_TD),
+ 'add_new' => _x("Add New", 'pluginbase', DXP_TD ),
+ 'add_new_item' => __("Add New Base Item", DXP_TD ),
+ 'edit_item' => __("Edit Base Item", DXP_TD ),
+ 'new_item' => __("New Base Item", DXP_TD ),
+ 'view_item' => __("View Base Item", DXP_TD ),
+ 'search_items' => __("Search Base Items", DXP_TD ),
+ 'not_found' => __("No base items found", DXP_TD ),
+ 'not_found_in_trash' => __("No base items found in Trash", DXP_TD ),
+ ),
+ 'description' => __("Base Items for the demo", DXP_TD),
+ 'public' => true,
+ 'publicly_queryable' => true,
+ 'query_var' => true,
+ 'rewrite' => true,
+ 'exclude_from_search' => true,
+ 'show_ui' => true,
+ 'show_in_menu' => true,
+ 'menu_position' => 40, // probably have to change, many plugins use this
+ 'supports' => array(
+ 'title',
+ 'editor',
+ 'thumbnail',
+ 'custom-fields',
+ 'page-attributes',
+ ),
+ 'taxonomies' => array( 'post_tag' )
+ ));
+ }
+
+
+ /**
+ * Register custom taxonomies
+ *
+ */
+ public function dx_custom_taxonomies_callback() {
+ register_taxonomy( 'pluginbase_taxonomy', 'pluginbase', array(
+ 'hierarchical' => true,
+ 'labels' => array(
+ 'name' => _x( "Base Item Taxonomies", 'taxonomy general name', DXP_TD ),
+ 'singular_name' => _x( "Base Item Taxonomy", 'taxonomy singular name', DXP_TD ),
+ 'search_items' => __( "Search Taxonomies", DXP_TD ),
+ 'popular_items' => __( "Popular Taxonomies", DXP_TD ),
+ 'all_items' => __( "All Taxonomies", DXP_TD ),
+ 'parent_item' => null,
+ 'parent_item_colon' => null,
+ 'edit_item' => __( "Edit Base Item Taxonomy", DXP_TD ),
+ 'update_item' => __( "Update Base Item Taxonomy", DXP_TD ),
+ 'add_new_item' => __( "Add New Base Item Taxonomy", DXP_TD ),
+ 'new_item_name' => __( "New Base Item Taxonomy Name", DXP_TD ),
+ 'separate_items_with_commas' => __( "Separate Base Item taxonomies with commas", DXP_TD ),
+ 'add_or_remove_items' => __( "Add or remove Base Item taxonomy", DXP_TD ),
+ 'choose_from_most_used' => __( "Choose from the most used Base Item taxonomies", DXP_TD )
+ ),
+ 'show_ui' => true,
+ 'query_var' => true,
+ 'rewrite' => true,
+ ));
+
+ register_taxonomy_for_object_type( 'pluginbase_taxonomy', 'pluginbase' );
+ }
+
+ /**
+ * Initialize the Settings class
+ *
+ * Register a settings section with a field for a secure WordPress admin option creation.
+ *
+ */
+ public function dx_register_settings() {
+ require_once( $this->path_include . '/class-dx-plugin-settings.php' );
+ new DX_Plugin_Settings();
+ }
+
+ /**
+ * Register a sample shortcode to be used
+ *
+ * First parameter is the shortcode name, would be used like: [dxsampcode]
+ *
+ */
+ public function dx_sample_shortcode() {
+ add_shortcode( 'dxsampcode', array( $this, 'dx_sample_shortcode_body' ) );
+ }
+
+ /**
+ * Returns the content of the sample shortcode, like [dxsamplcode]
+ * @param array $attr arguments passed to array, like [dxsamcode attr1="one" attr2="two"]
+ * @param string $content optional, could be used for a content to be wrapped, such as [dxsamcode]somecontnet[/dxsamcode]
+ */
+ public function dx_sample_shortcode_body( $attr, $content = null ) {
+ /*
+ * Manage the attributes and the content as per your request and return the result
+ */
+ return __( 'Sample Output', DXP_TD);
+ }
+
+ /**
+ * Hook for including a sample widget with options
+ */
+ public function dx_sample_widget() {
+ include_once $this->path_include . 'dx-sample-widget.class.php';
+ }
+
+ /**
+ * Add textdomain for plugin
+ */
+ public function dx_add_textdomain() {
+ load_plugin_textdomain( DXP_TD, false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
+ }
+
+ /**
+ * Callback for saving a simple AJAX option with no page reload
+ */
+ public function store_ajax_value() {
+ if( isset( $_POST['data'] ) && isset( $_POST['data']['dx_option_from_ajax'] ) ) {
+ update_option( 'dx_option_from_ajax' , $_POST['data']['dx_option_from_ajax'] );
+ }
+ die();
+ }
+
+ /**
+ * Callback for getting a URL and fetching it's content in the admin page
+ */
+ public function fetch_ajax_url_http() {
if( isset( $_POST['data'] ) && isset( $_POST['data']['dx_url_for_ajax'] ) ) {
- $ajax_url = $_POST['data']['dx_url_for_ajax'];
-
- $response = wp_remote_get( $ajax_url );
-
- if( is_wp_error( $response ) ) {
- echo json_encode( __( 'Invalid HTTP resource', 'dxbase' ) );
- die();
- }
-
- if( isset( $response['body'] ) ) {
- if( preg_match( '/(.*)<\/title>/', $response['body'], $matches ) ) {
- echo json_encode( $matches[1] );
- die();
- }
+ $ajax_url = $_POST['data']['dx_url_for_ajax'];
+
+ $response = wp_remote_get( $ajax_url );
+
+ if( is_wp_error( $response ) ) {
+ echo json_encode( __( 'Invalid HTTP resource', DXP_TD ) );
+ die();
+ }
+
+ if( isset( $response['body'] ) ) {
+ if( preg_match( '/(.*)<\/title>/', $response['body'], $matches ) ) {
+ echo json_encode( $matches[1] );
+ die();
+ }
}
- }
- echo json_encode( __( 'No title found or site was not fetched properly', 'dxbase' ) );
- die();
- }
-
-}
-
+ }
+ echo json_encode( __( 'No title found or site was not fetched properly', DXP_TD ) );
+ die();
+ }
+
+}
+
/**
* Register activation hook
@@ -448,7 +503,7 @@ function dx_on_activate_callback() {
*/
function dx_on_deactivate_callback() {
// do something when deactivated
-}
-
-// Initialize everything
-$dx_plugin_base = new DX_Plugin_Base();
+}
+
+// Initialize everything
+$dx_plugin_base = new DX_Plugin_Base();
diff --git a/dx-plugin-settings.class.php b/inc/class-dx-plugin-settings.php
similarity index 89%
rename from dx-plugin-settings.class.php
rename to inc/class-dx-plugin-settings.php
index ca2485d..80daa15 100755
--- a/dx-plugin-settings.class.php
+++ b/inc/class-dx-plugin-settings.php
@@ -25,14 +25,14 @@ public function register_settings() {
add_settings_section(
'dx_settings_section', // ID used to identify this section and with which to register options
- __( "Enable DX Templates", 'dxbase' ), // Title to be displayed on the administration page
+ __( "Enable DX Templates", DXP_TD ), // Title to be displayed on the administration page
array($this, 'dx_settings_callback'), // Callback used to render the description of the section
'dx-plugin-base' // Page on which to add this section of options
);
add_settings_field(
'dx_opt_in', // ID used to identify the field throughout the theme
- __( "Active: ", 'dxbase' ), // The label to the left of the option interface element
+ __( "Active: ", DXP_TD ), // The label to the left of the option interface element
array( $this, 'dx_opt_in_callback' ), // The name of the function responsible for rendering the option interface
'dx-plugin-base', // The page on which this option will be displayed
'dx_settings_section' // The name of the section to which this field belongs
@@ -40,7 +40,7 @@ public function register_settings() {
add_settings_field(
'dx_sample_text', // ID used to identify the field throughout the theme
- __( "DX Sample: ", 'dxbase' ), // The label to the left of the option interface element
+ __( "DX Sample: ", DXP_TD ), // The label to the left of the option interface element
array( $this, 'dx_sample_text_callback' ), // The name of the function responsible for rendering the option interface
'dx-plugin-base', // The page on which this option will be displayed
'dx_settings_section' // The name of the section to which this field belongs
@@ -48,7 +48,7 @@ public function register_settings() {
}
public function dx_settings_callback() {
- echo _e( "Enable me", 'dxbase' );
+ echo _e( "Enable me", DXP_TD );
}
public function dx_opt_in_callback() {
diff --git a/inc/dx-sample-widget.class.php b/inc/dx-sample-widget.class.php
index 2773644..d39af08 100755
--- a/inc/dx-sample-widget.class.php
+++ b/inc/dx-sample-widget.class.php
@@ -15,8 +15,8 @@ class DX_Sample_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'dx_sample_widget',
- __("DX Sample Widget", 'dxbase'),
- array( 'classname' => 'dx_widget_sample_single', 'description' => __( "Display a sample DX Widget", 'dxbase' ) ),
+ __("DX Sample Widget", DXP_TD),
+ array( 'classname' => 'dx_widget_sample_single', 'description' => __( "Display a sample DX Widget", DXP_TD ) ),
array( ) // you can pass width/height as parameters with values here
);
}
@@ -86,18 +86,18 @@ public function form ( $instance ) {
$sample_dropdown = esc_attr( $instance[ 'sample_dropdown' ] );
?>
-
-
+
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/template/index.php b/template/index.php
new file mode 100644
index 0000000..6220032
--- /dev/null
+++ b/template/index.php
@@ -0,0 +1,2 @@
+
-
+
-
+
-
+
-
+
From 1dcc0edd4673a0e22108ab73c958e1d8d370636e Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 13:29:28 +0300
Subject: [PATCH 02/12] add uninstall hook
---
dx-plugin-base.php | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/dx-plugin-base.php b/dx-plugin-base.php
index 72f64ab..a04d69e 100755
--- a/dx-plugin-base.php
+++ b/dx-plugin-base.php
@@ -105,10 +105,6 @@ public function __construct() {
add_action( 'init', array( $this, 'dx_custom_post_types_callback' ), 5 );
add_action( 'init', array( $this, 'dx_custom_taxonomies_callback' ), 6 );
- // Register activation and deactivation hooks
- register_activation_hook( __FILE__, 'dx_on_activate_callback' );
- register_deactivation_hook( __FILE__, 'dx_on_deactivate_callback' );
-
// Translation-ready
add_action( 'plugins_loaded', array( $this, 'dx_add_textdomain' ) );
@@ -496,6 +492,7 @@ public function fetch_ajax_url_http() {
function dx_on_activate_callback() {
// do something on activation
}
+register_activation_hook( __FILE__, 'dx_on_activate_callback' );
/**
* Register deactivation hook
@@ -504,6 +501,16 @@ function dx_on_activate_callback() {
function dx_on_deactivate_callback() {
// do something when deactivated
}
+register_deactivation_hook( __FILE__, 'dx_on_deactivate_callback' );
+
+/**
+ * Register uninstall hook
+ *
+ */
+function dx_on_uninstall_callback(){
+ // do something when plugin is uninstalling
+}
+register_uninstall_hook( __FILE__, 'dx_on_uninstall_callback' );
// Initialize everything
$dx_plugin_base = new DX_Plugin_Base();
From a7ea632bced83ae8f5b782d6a5b6153cd57028dd Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 13:55:44 +0300
Subject: [PATCH 03/12] add custom hooks in base page template for example
---
dx-plugin-base.php | 25 +++++++++++++++++++++++++
template/base-page-template.php | 5 ++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/dx-plugin-base.php b/dx-plugin-base.php
index a04d69e..97d38c7 100755
--- a/dx-plugin-base.php
+++ b/dx-plugin-base.php
@@ -127,6 +127,12 @@ public function __construct() {
add_action( 'wp_ajax_store_ajax_value', array( $this, 'store_ajax_value' ) );
add_action( 'wp_ajax_fetch_ajax_url_http', array( $this, 'fetch_ajax_url_http' ) );
+ //hook to the base page setting page form , and add content in form before and after the elements
+ add_action( 'dx_base_page_template_form_before_settings', array( $this, 'base_page_template_form_before' ) );
+ add_action( 'dx_base_page_template_form_after_settings', array( $this, 'base_page_template_form_after' ) );
+
+ //change the to the base page setting page form submit button text (value)
+ add_filter( 'dx_base_page_template_form_submit_button', array( $this, 'base_page_template_form_submit_button' ) );
}
/**
@@ -154,6 +160,25 @@ protected function setup() {
endif;
}
+ /**
+ * Adding the content in form before it elemnts
+ */
+ public function base_page_template_form_before() {
+ _e( 'Sample example, of adding a custom hook. This will add conternt before form elements.', DXP_TD );
+ }
+
+ /**
+ * Adding the content in form after it elemnts
+ */
+ public function base_page_template_form_after() {
+ _e( 'Sample example, of adding a custom hook. This will add conternt after form elements.', DXP_TD );
+ echo ' ';
+ }
+
+ public function base_page_template_form_submit_button( $value ) {
+ return __( 'Save settings', DXP_TD );
+ }
+
/**
*
* Adding JavaScript scripts
diff --git a/template/base-page-template.php b/template/base-page-template.php
index 86d27a6..f29f549 100644
--- a/template/base-page-template.php
+++ b/template/base-page-template.php
@@ -5,10 +5,13 @@
\ No newline at end of file
From e6ac1b2e7a2e09750493fd08035b6effc77808c9 Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 14:00:20 +0300
Subject: [PATCH 04/12] file are not used
---
samplescript.js | 1 -
samplestyle.css | 3 ---
2 files changed, 4 deletions(-)
delete mode 100755 samplescript.js
delete mode 100755 samplestyle.css
diff --git a/samplescript.js b/samplescript.js
deleted file mode 100755
index 51e1a51..0000000
--- a/samplescript.js
+++ /dev/null
@@ -1 +0,0 @@
-/* sample script here */
\ No newline at end of file
diff --git a/samplestyle.css b/samplestyle.css
deleted file mode 100755
index c0342a7..0000000
--- a/samplestyle.css
+++ /dev/null
@@ -1,3 +0,0 @@
-@CHARSET "UTF-8";
-
-/* Sample CSS styles below */
\ No newline at end of file
From e1537aa44c3a05cb5dee95d20f32fc957ba0db17 Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 14:15:38 +0300
Subject: [PATCH 05/12] add info abot custom hooks in readme
---
README.md | 42 ++++++++++++++++++++++++++++++++++++++++++
dx-plugin-base.php | 6 ++++++
2 files changed, 48 insertions(+)
diff --git a/README.md b/README.md
index b9335d3..edc5f90 100755
--- a/README.md
+++ b/README.md
@@ -358,6 +358,48 @@ Arguments are available in the `$attr` array - the first argument of the callbac
return __( 'Sample Output', DXP_TD);
}
```
+### Creating a Custom Hooks
+
+There are can be created the custom hooks in plugin code for the access from others plugins, of from it self
+It can be done, using the do_action and apply_filters function in needed place by adding:
+
+```php
+
+```
+ And
+
+```php
+ " />
+```
+
+Thats hooks can be called from the plugin or theme functions.php.
+
+For example
+
+```php
+ add_action( 'dx_base_page_template_form_before_settings', array( $this, 'base_page_template_form_before' ) );
+```
+
+And the callback for the hook
+
+```php
+ public function base_page_template_form_before() {
+ _e( 'Sample example, of adding a custom hook. This will add conternt before form elements.', DXP_TD );
+ }
+```
+
+Also there are can be changed the submit button value (text)
+
+```php
+ add_filter( 'dx_base_page_template_form_submit_button', array( $this, 'base_page_template_form_submit_button' ) );
+```
+The callback
+
+```php
+ public function base_page_template_form_submit_button( $value ) {
+ return __( 'Save settings', DXP_TD );
+ }
+```
### Fetching AJAX Data Remotely
diff --git a/dx-plugin-base.php b/dx-plugin-base.php
index 97d38c7..14fabab 100755
--- a/dx-plugin-base.php
+++ b/dx-plugin-base.php
@@ -175,6 +175,12 @@ public function base_page_template_form_after() {
echo ' ';
}
+ /**
+ * Callback for the filter the submit button text in base page template
+ *
+ * @param string $value
+ * @return string The new value of the submit button
+ */
public function base_page_template_form_submit_button( $value ) {
return __( 'Save settings', DXP_TD );
}
From 84a83825568a805ccdea0804ef2fde0afa6fe7c5 Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 15:05:06 +0300
Subject: [PATCH 06/12] fix typo
---
dx-plugin-base.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dx-plugin-base.php b/dx-plugin-base.php
index 14fabab..0a3ea48 100755
--- a/dx-plugin-base.php
+++ b/dx-plugin-base.php
@@ -164,14 +164,14 @@ protected function setup() {
* Adding the content in form before it elemnts
*/
public function base_page_template_form_before() {
- _e( 'Sample example, of adding a custom hook. This will add conternt before form elements.', DXP_TD );
+ _e( 'Sample example, of adding a custom hook. This will add content before form elements.', DXP_TD );
}
/**
* Adding the content in form after it elemnts
*/
public function base_page_template_form_after() {
- _e( 'Sample example, of adding a custom hook. This will add conternt after form elements.', DXP_TD );
+ _e( 'Sample example, of adding a custom hook. This will add content after form elements.', DXP_TD );
echo ' ';
}
From b392ad47b5ed4d0e6a7ded1d9d07125c14916fd1 Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 15:06:38 +0300
Subject: [PATCH 07/12] add check of the user input and the sanitize it
---
inc/class-dx-plugin-settings.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/inc/class-dx-plugin-settings.php b/inc/class-dx-plugin-settings.php
index 80daa15..9c15ade 100755
--- a/inc/class-dx-plugin-settings.php
+++ b/inc/class-dx-plugin-settings.php
@@ -107,7 +107,9 @@ public function is_enabled() {
* @param array $input
*/
public function dx_validate_settings( $input ) {
-
+ array_walk_recursive($input, function( &$item, $key ){//senitizy the user input before saving to the DB
+ $item = esc_attr( $item );
+ });
return $input;
}
}
From 2b8252339aa39da83a28f30510795d85675e538e Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 15:36:28 +0300
Subject: [PATCH 08/12] add sample description for input fields
---
inc/class-dx-plugin-settings.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/inc/class-dx-plugin-settings.php b/inc/class-dx-plugin-settings.php
index 9c15ade..9374c1d 100755
--- a/inc/class-dx-plugin-settings.php
+++ b/inc/class-dx-plugin-settings.php
@@ -67,6 +67,8 @@ public function dx_opt_in_callback() {
$out = '';
}
+ $out .= sprintf( '
%s
', __( 'Cehckbox description text sample.', DXP_TD ) );
+
echo $out;
}
@@ -80,6 +82,7 @@ public function dx_sample_text_callback() {
}
$out = '';
+ $out .= sprintf( '
%s
', __( 'Input description text sample.', DXP_TD ) );
echo $out;
}
From a26eaca86cfb043001b62ff2efda84bff33b67cb Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 18:22:49 +0300
Subject: [PATCH 09/12] add wp_query, wp_user_query and meta query for example
Implement , using the hierarchical model of shortcodes
---
README.md | 155 ++++++++++++++++++++++++++++++++++++++++++++-
dx-plugin-base.php | 139 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 291 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index edc5f90..e7ad9a1 100755
--- a/README.md
+++ b/README.md
@@ -343,6 +343,14 @@ The shortcode callback can interact with WordPress and all underlying APIs and r
[sample_shortcode arg1="first" arg2="second"]content[/sample_shortcode]
```
+Also You can add another shortcodes in shortcode like:
+
+[dxsampcode]
+[dxsampcode_wp_query]Query Title[/dxsampcode_wp_query]
+[dxsampcode_wp_user_query]User Query Title[/dxsampcode_wp_user_query]
+[dxsampcode_wp_meta_query]Meta Query Title[/dxsampcode_wp_meta_query]
+[/dxsampcode]
+
Arguments are available in the `$attr` array - the first argument of the callback, and a `$content` is also provided if you wrap a chunk of text with your shortcode opening and closing tags.
```php
@@ -355,9 +363,154 @@ Arguments are available in the `$attr` array - the first argument of the callbac
/*
* Manage the attributes and the content as per your request and return the result
*/
- return __( 'Sample Output', DXP_TD);
+ ob_start();
+ ?>
+
+
+
Date: Wed, 1 Jun 2016 18:32:22 +0300
Subject: [PATCH 10/12] update readme txt
---
readme.txt | 155 ++++++++++++++++++++++++++++-------------------------
1 file changed, 83 insertions(+), 72 deletions(-)
diff --git a/readme.txt b/readme.txt
index a7bdfac..a7b3b90 100755
--- a/readme.txt
+++ b/readme.txt
@@ -1,72 +1,83 @@
-=== DX Plugin Base ===
-Contributors: nofearinc, devrix
-Tags: plugin, base, startup, framework, foundation, skeleton, backbone, starter, sample, example
-Requires at least: 3.1
-Tested up to: 4.3
-Stable tag: 1.6
-License: GPLv2 or later
-
-Startup plugin code for new plugin, including the archetype of standard features, admin and core functions to be used in new plugins.
-
-== Description ==
-
-This is a fully-functional sample skeleton plugin for plugin developers.
-
-[youtube https://www.youtube.com/watch?v=FfQpGD_MUbk]
-
-It serves as a startup code providing reference and working codebase for:
-
-* defining custom post types and taxonomies
-* creating admin pages
-* sample code of the Settings API implementation for admin pages
-* registration of activate/deactivate hooks
-* adding metaboxes on pages
-* creating sample shortcode
-* creating sample widget
-* creating AJAX requests storing sample data in the database
-* creating AJAX requests for fetching remote data with the HTTP API
-* adding frontend styles/scripts the right way
-* adding admin styles/scripts the right way
-* defining common constants for further use
-
-and more. **Use it freely as your plugin startup snippet**.
-
-Take the code as is for test and learning or use it when creating plugins for a solid base. To be extended with
-widget and shortcode samples.
-
-== Installation ==
-
-Upload the DX Plugin Base plugin to your blog and activate it. It would work as is.
-
-Extend or comment whenever appropriate based on your assignment.
-
-== FAQ ==
-
-= Is it compatible with latest WordPress? =
-
-Yes, it is, as well as with the latest PHP.
-
-I've removed the 'pass-by-reference' call for all array( $this, ... ) entries as it's deprecated since 5.3.0. If you happen to use 5.2.4, you can replace all $this in arrays with &$this or better update PHP version.
-
-== Changelog ==
-
-= 1.6 =
-* Widget update for PHP compatibility with 4.3
-
-= 1.5 =
-* Add custom fields to metaboxes
-* Save custom fields
-
-= 1.4 =
-* Refreshing
-
-= 1.3 =
-* Add page with AJAX options
-* Introduce AJAX call for storing data to DB
-* Introduce AJAX call to fetch title from remote HTTP resouce
-
-= 1.2 =
-* Fix small issues and prevent some unexpected activities
-
-= 1.0 =
-* Initial commit
+=== DX Plugin Base ===
+Contributors: nofearinc, devrix
+Tags: plugin, base, startup, framework, foundation, skeleton, backbone, starter, sample, example
+Requires at least: 3.1
+Tested up to: 4.5.2
+Stable tag: 1.7
+License: GPLv2 or later
+
+Startup plugin code for new plugin, including the archetype of standard features, admin and core functions to be used in new plugins.
+
+== Description ==
+
+This is a fully-functional sample skeleton plugin for plugin developers.
+
+[youtube https://www.youtube.com/watch?v=FfQpGD_MUbk]
+
+It serves as a startup code providing reference and working codebase for:
+
+* defining custom post types and taxonomies
+* creating admin pages
+* sample code of the Settings API implementation for admin pages
+* registration of activate/deactivate hooks
+* adding metaboxes on pages
+* creating sample shortcode
+* creating sample widget
+* creating AJAX requests storing sample data in the database
+* creating AJAX requests for fetching remote data with the HTTP API
+* adding frontend styles/scripts the right way
+* adding admin styles/scripts the right way
+* defining common constants for further use
+
+and more. **Use it freely as your plugin startup snippet**.
+
+Take the code as is for test and learning or use it when creating plugins for a solid base. To be extended with
+widget and shortcode samples.
+
+== Installation ==
+
+Upload the DX Plugin Base plugin to your blog and activate it. It would work as is.
+
+Extend or comment whenever appropriate based on your assignment.
+
+== FAQ ==
+
+= Is it compatible with latest WordPress? =
+
+Yes, it is, as well as with the latest PHP.
+
+I've removed the 'pass-by-reference' call for all array( $this, ... ) entries as it's deprecated since 5.3.0. If you happen to use 5.2.4, you can replace all $this in arrays with &$this or better update PHP version.
+
+== Changelog ==
+
+= 1.7 =
+* Add properties with the plugin dir/url to not call every time according functions
+* Add WP_Query, WP_User_Query and meta query for example
+* Add hierarchical shortcodes example
+* Move template files to template folder
+* Move css/js files to assets folder
+* Sanitizing the user input before save to the DB
+* Add example of the custom hooks in to the base page template (action), and the filter for the save button value
+* Add uninstall hook
+* Add the description example for the inputs in the base page template (settings page)
+
+= 1.6 =
+* Widget update for PHP compatibility with 4.3
+
+= 1.5 =
+* Add custom fields to metaboxes
+* Save custom fields
+
+= 1.4 =
+* Refreshing
+
+= 1.3 =
+* Add page with AJAX options
+* Introduce AJAX call for storing data to DB
+* Introduce AJAX call to fetch title from remote HTTP resouce
+
+= 1.2 =
+* Fix small issues and prevent some unexpected activities
+
+= 1.0 =
+* Initial commit
From 0c6fd32b308a794076424b02b9f1fda1deba9aee Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Wed, 1 Jun 2016 18:45:50 +0300
Subject: [PATCH 11/12] update readme md
---
README.md | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index e7ad9a1..b2a5175 100755
--- a/README.md
+++ b/README.md
@@ -345,11 +345,13 @@ The shortcode callback can interact with WordPress and all underlying APIs and r
Also You can add another shortcodes in shortcode like:
-[dxsampcode]
-[dxsampcode_wp_query]Query Title[/dxsampcode_wp_query]
-[dxsampcode_wp_user_query]User Query Title[/dxsampcode_wp_user_query]
-[dxsampcode_wp_meta_query]Meta Query Title[/dxsampcode_wp_meta_query]
-[/dxsampcode]
+```php
+ [dxsampcode]
+ [dxsampcode_wp_query]Query Title[/dxsampcode_wp_query]
+ [dxsampcode_wp_user_query]User Query Title[/dxsampcode_wp_user_query]
+ [dxsampcode_wp_meta_query]Meta Query Title[/dxsampcode_wp_meta_query]
+ [/dxsampcode]
+```
Arguments are available in the `$attr` array - the first argument of the callback, and a `$content` is also provided if you wrap a chunk of text with your shortcode opening and closing tags.
From 743e3a33f448825b8e4c50bfca3c35170197cc26 Mon Sep 17 00:00:00 2001
From: MeatMAN
Date: Mon, 13 Jun 2016 13:27:57 +0300
Subject: [PATCH 12/12] add options page example
---
dx-plugin-base.php | 23 ++++++++++++++
inc/class-dx-plugin-settings.php | 54 ++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/dx-plugin-base.php b/dx-plugin-base.php
index 3d8c487..40c36ba 100755
--- a/dx-plugin-base.php
+++ b/dx-plugin-base.php
@@ -249,6 +249,12 @@ public function dx_admin_pages_callback() {
add_menu_page(__( "Plugin Base Admin", DXP_TD ), __( "Plugin Base Admin", DXP_TD ), 'edit_themes', 'dx-plugin-base', array( $this, 'dx_plugin_base' ) );
add_submenu_page( 'dx-plugin-base', __( "Base Subpage", DXP_TD ), __( "Base Subpage", DXP_TD ), 'edit_themes', 'dx-base-subpage', array( $this, 'dx_plugin_subpage' ) );
add_submenu_page( 'dx-plugin-base', __( "Remote Subpage", DXP_TD ), __( "Remote Subpage", DXP_TD ), 'edit_themes', 'dx-remote-subpage', array( $this, 'dx_plugin_side_access_page' ) );
+
+ /**
+ * Add options page
+ * @todo change me
+ */
+ add_options_page( __( 'Options of base plugin', DXP_TD ), __( 'Base Plugin options', DXP_TD ), 'manage_options', 'dx_base_plugin_options', array( $this, 'dx_base_plugin_options_cb' ) );
}
/**
@@ -263,6 +269,23 @@ public function dx_plugin_base() {
public function dx_plugin_side_access_page() {
include_once( $this->path_template . 'remote-page-template.php' );
}
+
+ /**
+ * Callback for the add options page
+ *
+ * @since 1.7
+ */
+ public function dx_base_plugin_options_cb() {
+ ?>
+
+
+ />
+
+
+
+
+