Skip to content

Commit

Permalink
Add settings page and notice type options
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Aug 31, 2018
1 parent d452fa5 commit 11c5823
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 62 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "thanks-to-it/popup-notices-for-woocommerce-ttt",
"name": "thanks-to-it/popup-notices-for-woocommerce",
"type": "wordpress-plugin",
"description": "Turn your WooCommerce notices into popups",
"keywords": [
Expand Down
14 changes: 11 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you are interested in contributing - head over to the [Popup Notices for WooC

== Installation ==

1. Upload the entire 'popup-notices-for-woocommerce-ttt' folder to the '/wp-content/plugins/' directory.
1. Upload the entire 'popup-notices-for-woocommerce' folder to the '/wp-content/plugins/' directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Start by visiting plugin settings at WooCommerce > Settings > Wish List.

Expand All @@ -42,13 +42,21 @@ If you are interested in contributing - head over to the [Popup Notices for WooC

== Changelog ==

= 1.0.1 - 29/08/2018 =
= 1.0.1 - 30/08/2018 =
* Fix plugin slug and text domain
* Add settings page
* Add error notices option
* Add success notices option
* Add info notices option

= 1.0.0 - 25/08/2018 =
* Initial Release.

== Upgrade Notice ==

= 1.0.1 =
* Fix plugin slug and text domain
* Fix plugin slug and text domain
* Add settings page
* Add error notices option
* Add success notices option
* Add info notices option
20 changes: 11 additions & 9 deletions src/assets/dist/frontend/js/ttt-pnwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var ttt_pnwc = {
ttt_pnwc.checkExistingElements('.woocommerce-error li');
ttt_pnwc.checkExistingElements('.woocommerce-message');
ttt_pnwc.checkExistingElements('.woocommerce-info');

},
checkExistingElements: function (selector) {
var element = jQuery(selector);
Expand All @@ -49,20 +48,23 @@ var ttt_pnwc = {
}
},
readNotice: function (element, index, total, selector) {
var noticeType = 'message';
var noticeType = 'success';

if (selector.indexOf('error') > -1) {
noticeType = 'error';
} else if (selector.indexOf('info') > -1) {
noticeType = 'info';
}

if (index <= total) {
ttt_pnwc.storeMessage(element, noticeType);
}
if (index == total) {
ttt_pnwc.clearPopupMessages();
ttt_pnwc.addMessagesToPopup();
ttt_pnwc.openPopup(element);
if (ttt_pnwc_info.types[noticeType] === 'yes') {
if (index <= total) {
ttt_pnwc.storeMessage(element, noticeType);
}
if (index == total) {
ttt_pnwc.clearPopupMessages();
ttt_pnwc.addMessagesToPopup();
ttt_pnwc.openPopup(element);
}
}
},
clearPopupMessages: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/dist/frontend/js/ttt-pnwc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/assets/src/frontend/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var ttt_pnwc = {
ttt_pnwc.checkExistingElements('.woocommerce-error li');
ttt_pnwc.checkExistingElements('.woocommerce-message');
ttt_pnwc.checkExistingElements('.woocommerce-info');

},
checkExistingElements: function (selector) {
var element = jQuery(selector);
Expand All @@ -49,20 +48,23 @@ var ttt_pnwc = {
}
},
readNotice: function (element, index, total, selector) {
var noticeType = 'message';
var noticeType = 'success';

if (selector.indexOf('error') > -1) {
noticeType = 'error';
} else if (selector.indexOf('info') > -1) {
noticeType = 'info';
}

if (index <= total) {
ttt_pnwc.storeMessage(element, noticeType);
}
if (index == total) {
ttt_pnwc.clearPopupMessages();
ttt_pnwc.addMessagesToPopup();
ttt_pnwc.openPopup(element);
if (ttt_pnwc_info.types[noticeType] === 'yes') {
if (index <= total) {
ttt_pnwc.storeMessage(element, noticeType);
}
if (index == total) {
ttt_pnwc.clearPopupMessages();
ttt_pnwc.addMessagesToPopup();
ttt_pnwc.openPopup(element);
}
}
},
clearPopupMessages: function () {
Expand Down
105 changes: 74 additions & 31 deletions src/classes/class-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Admin_Settings extends \WC_Settings_Page {
*/
public function __construct() {
$this->id = 'ttt-pnwc';
$this->label = __( 'Notices', 'popup-notices-for-woocommerce-ttt' );
$this->label = __( 'Popup Notices', 'popup-notices-for-woocommerce' );

add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
Expand All @@ -42,8 +42,8 @@ public function __construct() {
public function get_sections() {

$sections = array(
'' => __( 'Section 1', 'popup-notices-for-woocommerce-ttt' ),
'second' => __( 'Section 2', 'popup-notices-for-woocommerce-ttt' )
'' => __( 'General', 'popup-notices-for-woocommerce' ),
//'second' => __( 'Section 2', 'popup-notices-for-woocommerce' )
);

return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
Expand All @@ -69,10 +69,10 @@ public function get_settings( $current_section = '' ) {
*
* @param array $settings Array of the plugin settings
*/
$settings = apply_filters( 'myplugin_section2_settings', array(
/*$settings = apply_filters( 'myplugin_section2_settings', array(
array(
'name' => __( 'Group 1', 'popup-notices-for-woocommerce-ttt' ),
'name' => __( 'Group 1', 'popup-notices-for-woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'myplugin_group1_options',
Expand All @@ -81,8 +81,8 @@ public function get_settings( $current_section = '' ) {
array(
'type' => 'checkbox',
'id' => 'myplugin_checkbox_1',
'name' => __( 'Do a thing?', 'popup-notices-for-woocommerce-ttt' ),
'desc' => __( 'Enable to do something', 'popup-notices-for-woocommerce-ttt' ),
'name' => __( 'Do a thing?', 'popup-notices-for-woocommerce' ),
'desc' => __( 'Enable to do something', 'popup-notices-for-woocommerce' ),
'default' => 'no',
),
Expand All @@ -92,7 +92,7 @@ public function get_settings( $current_section = '' ) {
),
array(
'name' => __( 'Group 2', 'popup-notices-for-woocommerce-ttt' ),
'name' => __( 'Group 2', 'popup-notices-for-woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'myplugin_group2_options',
Expand All @@ -101,14 +101,14 @@ public function get_settings( $current_section = '' ) {
array(
'type' => 'select',
'id' => 'myplugin_select_1',
'name' => __( 'What should happen?', 'popup-notices-for-woocommerce-ttt' ),
'name' => __( 'What should happen?', 'popup-notices-for-woocommerce' ),
'options' => array(
'something' => __( 'Something', 'popup-notices-for-woocommerce-ttt' ),
'nothing' => __( 'Nothing', 'popup-notices-for-woocommerce-ttt' ),
'idk' => __( 'IDK', 'popup-notices-for-woocommerce-ttt' ),
'something' => __( 'Something', 'popup-notices-for-woocommerce' ),
'nothing' => __( 'Nothing', 'popup-notices-for-woocommerce' ),
'idk' => __( 'IDK', 'popup-notices-for-woocommerce' ),
),
'class' => 'wc-enhanced-select',
'desc_tip' => __( 'Don\'t ask me!', 'popup-notices-for-woocommerce-ttt' ),
'desc_tip' => __( 'Don\'t ask me!', 'popup-notices-for-woocommerce' ),
'default' => 'idk',
),
Expand All @@ -117,7 +117,7 @@ public function get_settings( $current_section = '' ) {
'id' => 'myplugin_group2_options'
),
) );
) );*/

} else {

Expand All @@ -128,32 +128,75 @@ public function get_settings( $current_section = '' ) {
*
* @param array $settings Array of the plugin settings
*/
$settings = apply_filters( 'myplugin_section1_settings', array(
$settings = apply_filters( 'ttt_pnwc_settings_general', array(

array(
'name' => __( 'Important Stuff', 'popup-notices-for-woocommerce-ttt' ),
'name' => __( 'Popup Notices General Options', 'popup-notices-for-woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'myplugin_important_options',
//'desc' => __( 'General Options', 'popup-notices-for-woocommerce' ),
'id' => 'ttt_pnwc_opt_general',
),

array(
'type' => 'select',
'id' => 'myplugin_select_1',
'name' => __( 'Choose your favorite', 'popup-notices-for-woocommerce-ttt' ),
'options' => array(
'vanilla' => __( 'Vanilla', 'popup-notices-for-woocommerce-ttt' ),
'chocolate' => __( 'Chocolate', 'popup-notices-for-woocommerce-ttt' ),
'strawberry' => __( 'Strawberry', 'popup-notices-for-woocommerce-ttt' ),
),
'class' => 'wc-enhanced-select',
'desc_tip' => __( 'Be honest!', 'popup-notices-for-woocommerce-ttt' ),
'default' => 'vanilla',
'type' => 'checkbox',
'id' => 'ttt_pnwc_opt_enable',
'name' => __( 'Enable Plugin', 'popup-notices-for-woocommerce' ),
'desc' => sprintf( __( 'Enables %s plugin', 'popup-notices-for-woocommerce' ), '<strong>' . __( 'Popup Notices for WooCommerce', 'popup-notices-for-woocommerce' ) . '</strong>' ),
//'class' => 'wc-enhanced-select',
'default' => 'yes',
),
array(
'type' => 'checkbox',
'id' => 'ttt_pnwc_opt_default_notices_enable',
'name' => __( 'Hide default notices', 'popup-notices-for-woocommerce' ),
'desc' => __( 'Hides default WooCommerce notices', 'popup-notices-for-woocommerce' ),
'custom_attributes' => apply_filters( 'ttt_pnwc_license_type_data', array( 'disabled' => 'disabled' ), 'disabled_attribute_if_free' ),
'default' => 'no',
),
array(
'type' => 'checkbox',
'id' => 'ttt_pnwc_opt_ajax',
'name' => __( 'AJAX Popup', 'popup-notices-for-woocommerce' ),
'desc' => __( 'Displays Popup notices from AJAX requests', 'popup-notices-for-woocommerce' ),
'desc_tip' => __( 'Notices displayed without reloading the page.', 'popup-notices-for-woocommerce' ) . '<br />' . __( 'e.g Error notices displayed on cart update or if something goes wrong in checkout', 'popup-notices-for-woocommerce' ),
'custom_attributes' => apply_filters( 'ttt_pnwc_license_type_data', array( 'disabled' => 'disabled' ), 'disabled_attribute_if_free' ),
'default' => 'no',
),
array(
'type' => 'sectionend',
'id' => 'ttt_pnwc_opt_general'
),

// Notice Types
array(
'name' => __( 'Notice Types', 'popup-notices-for-woocommerce' ),
'type' => 'title',
'desc' => __( 'Notice types that can be displayed on Popups', 'popup-notices-for-woocommerce' ),
'id' => 'ttt_pnwc_opt_types',
),
array(
'type' => 'checkbox',
'id' => 'ttt_pnwc_opt_type_error_enable',
'name' => __( 'Enable error notices', 'popup-notices-for-woocommerce' ),
'desc' => __( 'Enables error notices', 'popup-notices-for-woocommerce' ),
'default' => 'yes',
),
array(
'type' => 'checkbox',
'id' => 'ttt_pnwc_opt_type_success_enable',
'name' => __( 'Enable success notices', 'popup-notices-for-woocommerce' ),
'desc' => __( 'Enables success notices', 'popup-notices-for-woocommerce' ),
'default' => 'yes',
),
array(
'type' => 'checkbox',
'id' => 'ttt_pnwc_opt_type_info_enable',
'name' => __( 'Enable info notices', 'popup-notices-for-woocommerce' ),
'desc' => __( 'Enables info notices', 'popup-notices-for-woocommerce' ),
'default' => 'yes',
),
array(
'type' => 'sectionend',
'id' => 'myplugin_important_options'
'id' => 'ttt_pnwc_opt_types'
),

) );
Expand Down
65 changes: 57 additions & 8 deletions src/classes/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Popup Notices for WooCommerce (TTT) - Core Class
*
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
* @author Thanks to IT
*/
Expand Down Expand Up @@ -79,23 +79,61 @@ public function get_plugin_dir() {
/**
* Initializes
*
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
*
* @return Core
*/
public function init() {
//add_filter( 'woocommerce_get_settings_pages', array( $this, 'create_admin_settings' ), 15 );
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
$this->set_admin();

if ( 'yes' === get_option( 'ttt_pnwc_opt_enable', 'yes' ) ) {
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );

// Modal
$modal = new Modal();
$modal->init();
}
}

/**
* Sets admin
* @version 1.0.1
* @since 1.0.1
*/
private function set_admin() {
add_filter( 'woocommerce_get_settings_pages', array( $this, 'create_admin_settings' ), 15 );

// Add settings link on plugins page
$path = $this->plugin_info['path'];
add_filter( 'plugin_action_links_' . plugin_basename( $path ), array( $this, 'add_action_links' ) );
}

// Modal
$modal = new Modal();
$modal->init();
/**
* Adds action links
*
* @version 1.0.1
* @since 1.0.1
*
* @param $links
*
* @return array
*/
public function add_action_links( $links ) {
$mylinks = array(
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=ttt-pnwc' ) . '">Settings</a>',
);

if ( false === apply_filters( 'ttt_pnwc_license_type_data', true, 'is_free' ) ) {
$mylinks[] = '<a href="https://wpfactory.com/item/popup-notices-for-woocommerce/">' . __( 'Unlock All', 'product-input-fields-for-woocommerce' ) . '</a>';
}

return array_merge( $mylinks, $links );
}

/**
* Adds scripts
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
*/
public function add_scripts() {
Expand All @@ -115,6 +153,17 @@ public function add_scripts() {
$js_ver = date( "ymd-Gis", filemtime( $plugin_dir . $js_file ) );
wp_register_script( 'ttt-pnwc', $plugin_url . $js_file, array( 'jquery' ), $js_ver, true );
wp_enqueue_script( 'ttt-pnwc' );

// Localize script
$localize_script = array(
'types' => array(
'error' => get_option( 'ttt_pnwc_opt_type_error_enable', 'yes' ),
'info' => get_option( 'ttt_pnwc_opt_type_info_enable', 'yes' ),
'success' => get_option( 'ttt_pnwc_opt_type_success_enable', 'yes' ),
)
);
wp_localize_script( 'ttt-pnwc', 'ttt_pnwc_info', apply_filters( 'ttt_pnwc_localize_script', $localize_script ) );

}

/**
Expand Down

0 comments on commit 11c5823

Please sign in to comment.