Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b76b132
Clean up the uninstall.php file
JeroenSormani May 18, 2016
a772dc8
Revamping and improving settings.
JeroenSormani May 19, 2016
9b36c71
Ensure settings are migrated correctly
JeroenSormani May 19, 2016
ab75208
Ensure settings are migrated correctly
JeroenSormani May 19, 2016
e7a82a0
Fix merge conflicts
JeroenSormani May 20, 2016
599c8b1
Add docblocks for most of the functions
JeroenSormani May 21, 2016
5ad7f82
Do @todo tags
JeroenSormani Jun 17, 2016
56069fa
Small change - add @param tag type
JeroenSormani Jun 17, 2016
0cf526b
Clean up the uninstall.php file
JeroenSormani May 18, 2016
2c11756
Merge remote-tracking branch 'upstream/master' into uninstall-tweaks
JeroenSormani Jun 17, 2016
ac3677c
Fix error in uninstall process
JeroenSormani Jun 17, 2016
8afd373
Fix merge conflicts
JeroenSormani Jun 17, 2016
e6bbbac
Show settings saved notice
JeroenSormani Jun 17, 2016
2a201fd
Merge pull request #109 from JeroenSormani/docs
EnigmaWeb Jun 18, 2016
e740f42
Fix rebase conflicts
JeroenSormani Jun 20, 2016
ac33c4e
Ensure settings are migrated correctly
JeroenSormani May 19, 2016
43a689c
Ensure settings are migrated correctly
JeroenSormani May 19, 2016
9b948a3
Show settings saved notice
JeroenSormani Jun 17, 2016
ea1859c
Fix rebase conflicts
JeroenSormani Jun 20, 2016
5d4ff4c
Deafult settings sanitize callback
JeroenSormani Jun 20, 2016
8100abb
Merge pull request #106 from JeroenSormani/settings-revamp
EnigmaWeb Jun 20, 2016
3041a80
Fix plus icon image
JeroenSormani Jul 7, 2016
3d94b72
Fix uninstall error
JeroenSormani Sep 26, 2016
8ac525b
Clean up the uninstall.php file
JeroenSormani May 18, 2016
d4d502f
Fix error in uninstall process
JeroenSormani Jun 17, 2016
6e422de
Fix uninstall error
JeroenSormani Sep 26, 2016
8007e9d
Merge branch 'uninstall-tweaks' of https://github.com/JeroenSormani/w…
JeroenSormani Sep 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 99 additions & 28 deletions includes/admin/kbe-admin-functions.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


//=========> Enqueue color picker
/**
* Enqueue scripts.
*
* Enqueue the required stylesheets and javascripts in the admin.
*
* @param string $hook_suffix Current page ID.
*/
function kbe_admin_scripts( $hook_suffix ) {
// Settings page
if ( $hook_suffix == 'kbe_knowledgebase_page_kbe_options' ) {
Expand All @@ -22,53 +27,119 @@ function kbe_admin_scripts( $hook_suffix ) {
}
add_action( 'admin_enqueue_scripts', 'kbe_admin_scripts' );

//=========> Plugin menu
/**
* Add submenus.
*
* Add submenus for the custom added pages.
*
* @since 1.0
*/
function kbe_plugin_menu() {
add_submenu_page( 'edit.php?post_type=kbe_knowledgebase', 'Order', 'Order', 'manage_options', 'kbe_order', 'wp_kbe_order' );
add_submenu_page( 'edit.php?post_type=kbe_knowledgebase', 'Settings', 'Settings', 'manage_options', 'kbe_options', 'wp_kbe_options' );
}
add_action( 'admin_menu', 'kbe_plugin_menu' );

// Require File kbe_order.php
/**
* Output order page.
*
* Output the HTML for the 'order' page.
*
* @since 1.0
*/
function wp_kbe_order() {
require dirname( __FILE__ ) . '/kbe-order.php';
}

//=========> Require Files
// kbe_settings.php
/**
* Output settings page.
*
* Output the HTML for the settings page.
*
* @since 1.0
*/
function wp_kbe_options() {
require 'kbe-settings.php';
}

//=========> Register plugin settings

function kbe_register_settings() {
register_setting( 'kbe_settings', 'kbe_settings', 'kbe_validate_settings' );

// Register each setting for automated $_POST handling
foreach ( kbe_get_settings() as $id => $setting ) {

switch ( $setting['type'] ) {
case 'number' :
$sanitize_callback = 'absint';
break;
default:
case 'text' :
$sanitize_callback = 'sanitize_text_field';
break;
case 'title' :
$sanitize_callback = 'sanitize_title';
break;
case 'kbe_radio_switch' :
$sanitize_callback = 'sanitize_kbe_radio_switch';
break;
case 'color' :
$sanitize_callback = 'wp_kses_post';
break;

}
register_setting( 'kbe_settings', $id, $sanitize_callback );
}
}
add_action( 'admin_init', 'kbe_register_settings' );

/**
* Sanitize and validate plugin settings
* @param array $input
* @return array
* @since 1.1.0
*/
function kbe_validate_settings( $input ) {
$input['kbe_plugin_slug'] = isset( $input['kbe_plugin_slug'] ) ? sanitize_title( $input['kbe_plugin_slug'] ) : '';
$input['kbe_article_qty'] = intval( $input['kbe_article_qty'] );

$input['kbe_search_setting'] = isset( $input['kbe_search_setting'] ) && $input['kbe_search_setting'] ? 1 : 0 ;
$input['kbe_breadcrumbs_setting'] = isset( $input['kbe_breadcrumbs_setting'] ) && $input['kbe_breadcrumbs_setting'] ? 1 : 0 ;

$sidebar_positions = array( 0, 1, 2 );

$input['kbe_sidebar_home'] = isset( $input['kbe_sidebar_home'] ) && in_array( $input['kbe_sidebar_home'], $sidebar_positions ) ? intval( $input['kbe_sidebar_home'] ) : 0;
$input['kbe_sidebar_inner'] = isset( $input['kbe_sidebar_inner'] ) && in_array( $input['kbe_sidebar_inner'], $sidebar_positions ) ? intval( $input['kbe_sidebar_inner'] ) : 0;
function kbe_radio_switch_on_off( $v ) {
if ( $v == 1 ) {
return 1;
}
return 0;
}

$input['kbe_comments_setting'] = isset( $input['kbe_comments_setting'] ) && $input['kbe_comments_setting'] ? 1 : 0 ;
function kbe_radio_switch_lrn( $v ) {
if ( $v == 1 ) {
return 1;
} elseif ( $v == 2 ) {
return 2;
}
return 0;
}

$input['kbe_bgcolor'] = isset( $input['kbe_bgcolor'] ) ? $input['kbe_bgcolor'] : '';
function kbe_get_settings() {

return array(
'kbe_plugin_slug' => array(
'type' => 'title',
),
'kbe_article_qty' => array(
'type' => 'number',
),
'kbe_search_setting' => array(
'type' => 'kbe_radio_switch_on_off',
),
'kbe_breadcrumbs_setting' => array(
'type' => 'kbe_radio_switch_on_off',
),
'kbe_sidebar_home' => array(
'type' => 'kbe_radio_switch_lrn', // left, right, none option
),
'kbe_sidebar_inner' => array(
'type' => 'kbe_radio_switch_lrn', // left, right, none option
),
'kbe_comments_setting' => array(
'type' => 'kbe_radio_switch_on_off',
),
'kbe_bgcolor' => array(
'type' => 'color',
),
'kbe_wipe_uninstall' => array(
'type' => 'kbe_radio_switch_on_off',
),
);

return $input;
}

function kbe_migrations_check() {
Expand Down
52 changes: 20 additions & 32 deletions includes/admin/kbe-settings.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


$kbe_defaults = array(
'kbe_plugin_slug' => 'Knowledgebase',
'kbe_article_qty' => 5,
'kbe_search_setting' => 0,
'kbe_breadcrumbs_setting' => 0,
'kbe_sidebar_home' => 0,
'kbe_sidebar_inner' => 0,
'kbe_comments_setting' => 0,
'kbe_bgcolor' => '',
'kbe_wipe_uninstall' => 0,
);
$kbe_settings = wp_parse_args( get_option( 'kbe_settings' ), $kbe_defaults );

?><div id="wpbody">
<div id="wpbody-content">
<div class="wrap">

<h2><?php _e( 'Knowledgebase Display Settings', 'wp-knowledgebase' ); ?></h2><?php

settings_errors( 'general' );

global $wpdb;

$tbl_posts = $wpdb->prefix . 'posts';
Expand Down Expand Up @@ -64,19 +52,19 @@

?><table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top: 18px;">
<tr>
<td width="35%" valign="top">
<td width="40%" valign="top">
<label><?php _e( 'Knowledgebase Slug', 'wp-knowledgebase' ); ?></label>
</td>
<td colspan="3">
<input type="text" name="kbe_settings[kbe_plugin_slug]" id="kbe_plugin_slug" value="<?php echo esc_attr( $kbe_settings['kbe_plugin_slug'] ); ?>">
<input type="text" name="kbe_plugin_slug" id="kbe_plugin_slug" value="<?php echo esc_attr( get_option( 'kbe_plugin_slug', 'knowledgebase' ) ); ?>">
</td>
</tr>
<tr>
<td valign="top">
<label><?php _e( 'Number of articles to show', 'wp-knowledgebase' ); ?></label>
</td>
<td colspan="3">
<input type="text" name="kbe_settings[kbe_article_qty]" id="kbe_article_qty" value="<?php echo esc_attr( $kbe_settings['kbe_article_qty'] ); ?>">
<input type="text" name="kbe_article_qty" id="kbe_article_qty" value="<?php echo esc_attr( get_option( 'kbe_article_qty', 5 ) ); ?>">
<p>
<strong><?php _e( 'Note:', 'wp-knowledgebase' ); ?></strong>
<?php _e( 'Set the number of articles to show in each category on KB homepage', 'wp-knowledgebase' ); ?>
Expand All @@ -88,11 +76,11 @@
<label><?php _e( 'Knowledgebase search', 'wp-knowledgebase' ); ?></label>
</td>
<td width="15%">
<input type="radio" name="kbe_settings[kbe_search_setting]" id="kbe_search_setting" value="1" <?php checked( $kbe_settings['kbe_search_setting'], '1' ); ?>>
<input type="radio" name="kbe_search_setting" id="kbe_search_setting" value="1" <?php checked( get_option( 'kbe_search_setting', 0 ), '1' ); ?>>
<span><?php _e( 'On', 'wp-knowledgebase' ); ?></span>
</td>
<td width="15%">
<input type="radio" name="kbe_settings[kbe_search_setting]" id="kbe_search_setting" value="0" <?php checked( $kbe_settings['kbe_search_setting'], '0' ); ?>>
<input type="radio" name="kbe_search_setting" id="kbe_search_setting" value="0" <?php checked( get_option( 'kbe_search_setting', 0 ), '0' ); ?>>
<span><?php _e( 'Off', 'wp-knowledgebase' ); ?></span>
</td>
<td width="45%">&nbsp;</td>
Expand All @@ -102,11 +90,11 @@
<label><?php _e( 'Knowledgebase breadcrumbs', 'wp-knowledgebase' ); ?></label>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_breadcrumbs_setting]" id="kbe_breadcrumb_setting" value="1" <?php checked( $kbe_settings['kbe_breadcrumbs_setting'], '1' ); ?>>
<input type="radio" name="kbe_breadcrumbs_setting" id="kbe_breadcrumb_setting" value="1" <?php checked( get_option( 'kbe_breadcrumbs_setting', 0 ), '1' ); ?>>
<span><?php _e( 'On', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_breadcrumbs_setting]" id="kbe_breadcrumb_setting" value="0" <?php checked( $kbe_settings['kbe_breadcrumbs_setting'], '0' ); ?>>
<input type="radio" name="kbe_breadcrumbs_setting" id="kbe_breadcrumb_setting" value="0" <?php checked( get_option( 'kbe_breadcrumbs_setting', 0 ), '0' ); ?>>
<span><?php _e( 'Off', 'wp-knowledgebase' ); ?></span>
</td>
<td>&nbsp;</td>
Expand All @@ -116,15 +104,15 @@
<label><?php _e( 'Knowledgebase home page sidebar', 'wp-knowledgebase' ); ?></label>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_sidebar_home]" id="kbe_sidebar_home" value="1" <?php checked( $kbe_settings['kbe_sidebar_home'], 1 ); ?>>
<input type="radio" name="kbe_sidebar_home" id="kbe_sidebar_home" value="1" <?php checked( get_option( 'kbe_sidebar_home', 0 ), 1 ); ?>>
<span><?php _e( 'Left', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_sidebar_home]" id="kbe_sidebar_home" value="2" <?php checked( $kbe_settings['kbe_sidebar_home'], 2 ); ?>>
<input type="radio" name="kbe_sidebar_home" id="kbe_sidebar_home" value="2" <?php checked( get_option( 'kbe_sidebar_home', 0 ), 2 ); ?>>
<span><?php _e( 'Right', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_sidebar_home]" id="kbe_sidebar_home" value="0" <?php checked( $kbe_settings['kbe_sidebar_home'], 0 ); ?>>
<input type="radio" name="kbe_sidebar_home" id="kbe_sidebar_home" value="0" <?php checked( get_option( 'kbe_sidebar_home', 0 ), 0 ); ?>>
<span><?php _e( 'None', 'wp-knowledgebase' ); ?></span>
</td>
</tr>
Expand All @@ -133,15 +121,15 @@
<label><?php _e( 'Knowledgebase inner pages sidebar', 'wp-knowledgebase' ); ?></label>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_sidebar_inner]" id="kbe_sidebar_inner" value="1" <?php checked( $kbe_settings['kbe_sidebar_inner'], 1 ); ?>>
<input type="radio" name="kbe_sidebar_inner" id="kbe_sidebar_inner" value="1" <?php checked( get_option( 'kbe_sidebar_inner', 0 ), 1 ); ?>>
<span><?php _e( 'Left', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_sidebar_inner]" id="kbe_sidebar_inner" value="2" <?php checked( $kbe_settings['kbe_sidebar_inner'], 2 ); ?>>
<input type="radio" name="kbe_sidebar_inner" id="kbe_sidebar_inner" value="2" <?php checked( get_option( 'kbe_sidebar_inner', 0 ), 2 ); ?>>
<span><?php _e( 'Right', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_sidebar_inner]" id="kbe_sidebar_inner" value="0" <?php checked( $kbe_settings['kbe_sidebar_inner'], 0 ); ?>>
<input type="radio" name="kbe_sidebar_inner" id="kbe_sidebar_inner" value="0" <?php checked( get_option( 'kbe_sidebar_inner', 0 ), 0 ); ?>>
<span><?php _e( 'None', 'wp-knowledgebase' ); ?></span>
</td>
</tr>
Expand All @@ -150,11 +138,11 @@
<label><?php _e( 'Knowledgebase comments', 'wp-knowledgebase' ); ?></label>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_comments_setting]" id="kbe_comment_setting" value="1" <?php checked( $kbe_settings['kbe_comments_setting'], '1' ); ?>>
<input type="radio" name="kbe_comments_setting" id="kbe_comment_setting" value="1" <?php checked( get_option( 'kbe_comments_setting', 0 ), '1' ); ?>>
<span><?php _e( 'On', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_comments_setting]" id="kbe_comment_setting" value="0" <?php checked( $kbe_settings['kbe_comments_setting'], '0' ); ?>>
<input type="radio" name="kbe_comments_setting" id="kbe_comment_setting" value="0" <?php checked( get_option( 'kbe_comments_setting', 0 ), '0' ); ?>>
<span><?php _e( 'Off', 'wp-knowledgebase' ); ?></span>
</td>
<td>&nbsp;</td>
Expand All @@ -164,19 +152,19 @@
<label><?php _e( 'Knowledgebase theme color', 'wp-knowledgebase' ); ?></label>
</td>
<td colspan="3">
<input type="text" name="kbe_settings[kbe_bgcolor]" id="kbe_bgcolor" value="<?php echo esc_attr( $kbe_settings['kbe_bgcolor'] ); ?>" class="cp-field">
<input type="text" name="kbe_bgcolor" id="kbe_bgcolor" value="<?php echo esc_attr( get_option( 'kbe_bgcolor', '' ) ); ?>" class="cp-field">
</td>
</tr>
<tr>
<td valign="top">
<label><?php _e( 'Wipe all data on uninstall', 'wp-knowledgebase' ); ?></label>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_wipe_uninstall]" id="kbe_wipe_uninstall_on" value="1" <?php checked( $kbe_settings['kbe_wipe_uninstall'], '1' ); ?>>
<input type="radio" name="kbe_wipe_uninstall" id="kbe_wipe_uninstall_on" value="1" <?php checked( get_option( 'kbe_wipe_uninstall', 0 ), '1' ); ?>>
<span><?php _e( 'On', 'wp-knowledgebase' ); ?></span>
</td>
<td>
<input type="radio" name="kbe_settings[kbe_wipe_uninstall]" id="kbe_wipe_uninstall_off" value="0" <?php checked( $kbe_settings['kbe_wipe_uninstall'], '0' ); ?>>
<input type="radio" name="kbe_wipe_uninstall" id="kbe_wipe_uninstall_off" value="0" <?php checked( get_option( 'kbe_wipe_uninstall', 0 ), '0' ); ?>>
<span><?php _e( 'Off', 'wp-knowledgebase' ); ?></span>
</td>
<td>
Expand Down
Loading