Skip to content

Commit

Permalink
Added misc settings, tweaked notices
Browse files Browse the repository at this point in the history
  • Loading branch information
seb86 committed Sep 11, 2023
1 parent 2ca03a9 commit c6c2bcf
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
28 changes: 24 additions & 4 deletions includes/class-cocart-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ class Notices {
'check_php' => 'check_php_notice',
'check_wp' => 'check_wp_notice',
'check_wc' => 'check_woocommerce_notice',
'plugin_review' => 'plugin_review_notice',
'check_beta' => 'check_beta_notice',
'base_tables_missing' => 'base_tables_missing_notice',
'setup_wizard' => 'setup_wizard_notice',
'misc_plugin_review' => 'plugin_review_notice',
'misc_check_beta' => 'check_beta_notice',
);

/**
* Constructor
*
* @access public
*
* @since 1.2.0 Introduced.
* @version 3.1.0
* @since 1.2.0 Introduced.
* @since 4.0.0 Filtered notifications for misc announcements.
*/
public function __construct() {
self::$install_date = get_option( 'cocart_install_date', time() );
Expand All @@ -87,6 +87,7 @@ public function __construct() {
add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
add_action( 'wp_loaded', array( $this, 'timed_notices' ), 11 );

add_filter( 'cocart_show_admin_notice', array( $this, 'hide_misc_announcements' ) );
add_action( 'shutdown', array( $this, 'store_notices' ) );

// If the current user has capabilities then add notices.
Expand Down Expand Up @@ -508,6 +509,25 @@ public function setup_wizard_notice() {
include_once dirname( __FILE__ ) . '/views/html-notice-setup-wizard.php';
} // END setup_wizard_notice()

/**
* Hide plugin announcements that are miscellaneous
* if set via the settings.
*
* @access public
*
* @since 4.0.0 Introduced.
*
* @return bool
*/
public function hide_misc_announcements( $notice ) {
$hide_announcements = cocart_get_setting( 'misc', 'hide_announcements' );
if ( strpos( $notice, 'misc' ) !== false && $hide_announcements === 'yes' ) {
return false;
}

return true;
} // END hide_misc_announcements()

} // END class.

return new Notices();
3 changes: 3 additions & 0 deletions includes/class-cocart-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public static function prep_settings_page() {
*/
self::$settings = apply_filters( 'cocart_get_settings_pages', self::$settings );

// Misc settings always go last.
self::$settings['misc'] = include dirname( __FILE__ ) . '/settings/class-cocart-admin-settings-misc.php';

return self::$settings;
} // END prep_settings_page()

Expand Down
85 changes: 85 additions & 0 deletions includes/settings/class-cocart-admin-settings-misc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* CoCart Settings: Misc Settings.
*
* @author Sébastien Dumont
* @package CoCart\Admin\Settings
* @since 4.0.0
* @license GPL-2.0+
*/

namespace CoCart\Admin;

use CoCart\Admin\Settings;
use CoCart\Admin\SettingsPage as Page;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

class MiscSettings extends Page {

/**
* Constructor.
*
* @access public
*/
public function __construct() {
$this->id = 'misc';
$this->label = esc_html__( 'Misc', 'cart-rest-api-for-woocommerce' );

parent::__construct();
} // END __construct()

/**
* Get settings array.
*
* @access public
*
* @return array
*/
public function get_settings() {
$settings[] = array(
'id' => $this->id,
'type' => 'title',
);

$settings[] = array(
'title' => esc_html__( 'Hide Announcements', 'cart-rest-api-for-woocommerce' ),
'id' => 'hide_announcements',
'type' => 'checkbox',
'default' => 'no',
'desc' => esc_html__( 'Check this option to hide plugin announcements.', 'cart-rest-api-for-woocommerce' ),
);

$settings[] = array(
'title' => esc_html__( 'Uninstall Data', 'cart-rest-api-for-woocommerce' ),
'id' => 'uninstall_data',
'type' => 'checkbox',
'default' => 'no',
'desc' => esc_html__( 'Check this option to uninstall ALL plugin data when the plugin is uninstalled.', 'cart-rest-api-for-woocommerce' ),
);

$settings[] = array(
'id' => $this->id,
'type' => 'sectionend',
);

return $settings;
} // END get_settings()

/**
* Output the settings.
*
* @access public
*/
public function output() {
$settings = $this->get_settings();

Settings::output_fields( $this->id, $settings );
} // END output()

} // END class

return new MiscSettings();

0 comments on commit c6c2bcf

Please sign in to comment.