Commit b8063aa9 authored by Varun Sridharan's avatar Varun Sridharan

Updated Class

[admin/class-admin-init.php]
* Added woocommerce_screen_ids
* Removed Admin Notice Handler Class Init
* Added Plugins Settings Page ID To WC Screen ID

[admin/class-admin-settings.php & admin/class-donation-settings.php]
* Working To Get A Prefect Settings Page

[admin/includes/class-admin-functions.php]
* Changed WC_QD()->donation_id to WC_QD_ID

[includes/class-quick-donation-process.php]
* Created Class To Process Front End Donation Form

[includes/class-shortcode-handler.php]
* Created 2 Actions
1. wc_quick_donation_before_donation_form
2. wc_quick_donation_after_donation_form

[woocommerce-quick-donation.php]
* Changed $donation_id from dynimic to static
* Added WC_QD_ID defined variable
* Rearranged Few Loading Files
parent c7f74212
...@@ -28,17 +28,19 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -28,17 +28,19 @@ class WooCommerce_Quick_Donation_Admin {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_init', array( $this, 'init_admin_class' )); add_action( 'admin_init', array( $this, 'init_admin_class' ));
add_action( 'plugins_loaded', array( $this, 'init' ) ); add_action( 'plugins_loaded', array( $this, 'init' ) );
add_filter( 'plugin_row_meta', array($this, 'plugin_row_links' ), 10, 2 ); add_filter( 'plugin_row_meta', array($this, 'plugin_row_links' ), 10, 2 );
add_filter( 'woocommerce_get_settings_pages', array($this,'settings_page') );
add_filter('woocommerce_screen_ids',array($this,'set_wc_screen_ids'));
} }
/** /**
* Inits Admin Sttings * Inits Admin Sttings
*/ */
public function init_admin_class(){ public function init_admin_class(){
$this->functions = new WooCommerce_Quick_Donation_Admin_Function; $this->functions = new WooCommerce_Quick_Donation_Admin_Function;
//$this->notice = new WordPress_Admin_Notice_Handler;
# new WooCommerce_Plugin_Boiler_Plate_Admin_Settings; # new WooCommerce_Plugin_Boiler_Plate_Admin_Settings;
} }
...@@ -73,6 +75,13 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -73,6 +75,13 @@ class WooCommerce_Quick_Donation_Admin {
} }
public function set_wc_screen_ids($screen){
$screen[] = 'wcqd_project_page_wc_qd_settings';
return $screen;
}
/** /**
* Gets Current Screen ID from wordpress * Gets Current Screen ID from wordpress
* @return string [Current Screen ID] * @return string [Current Screen ID]
...@@ -90,6 +99,7 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -90,6 +99,7 @@ class WooCommerce_Quick_Donation_Admin {
$screen_ids = array(); $screen_ids = array();
$screen_ids[] = 'edit-product'; $screen_ids[] = 'edit-product';
$screen_ids[] = 'product'; $screen_ids[] = 'product';
$screen_ids[] = 'wcqd_project_page_wc_qd_settings';
return $screen_ids; return $screen_ids;
} }
......
<?php <?php
/** /**
* The admin-specific functionality of the plugin. * Settings API CLass For WC Quick Donation
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* *
* The admin-specific functionality of the plugin. * @version 1.1
* *
* Defines the plugin name, version, and two examples hooks for how to * @author Tareq Hasan <tareq@weDevs.com>
* enqueue the admin-specific stylesheet and JavaScript. * @link http://tareq.weDevs.com Tareq's Planet
* *
* @package @TODO * @package WooCommerce_Quick_Donation
* @subpackage @TODO * @subpackage WooCommerce_Quick_Donation/Admin/Settings_API
* @author Varun Sridharan <varunsridharan23@gmail.com> * @author Varun Sridharan <varunsridharan23@gmail.com>
*/ */
if ( ! defined( 'WPINC' ) ) { die; } if ( ! defined( 'WPINC' ) ) { die; }
#class WooCommerce_Plugin_Boiler_Plate_Admin_Settings extends WooCommerce_Plugin_Boiler_Plate_Admin {
#public function __construct() { if ( !class_exists( 'WooCommerce_Quick_Donation_Settings_Api' ) ):
class WooCommerce_Quick_Donation_Settings_Api {
/**
* settings sections array
*
* @var array
*/
private $settings_sections = array();
/**
* Settings fields array
*
* @var array
*/
private $settings_fields = array();
/**
* Singleton instance
*
* @var object
*/
private static $_instance;
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
}
/**
* Enqueue scripts and styles
*/
function admin_enqueue_scripts() {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_media();
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'jquery' );
}
/**
* Set settings sections
*
* @param array $sections setting sections array
*/
function set_sections( $sections ) {
$this->settings_sections = $sections;
return $this;
}
/**
* Add a single section
*
* @param array $section
*/
function add_section( $section ) {
$this->settings_sections[] = $section;
return $this;
}
/**
* Set settings fields
*
* @param array $fields settings fields array
*/
function set_fields( $fields ) {
$this->settings_fields = $fields;
return $this;
}
function add_field( $section, $field ) {
$defaults = array(
'name' => '',
'label' => '',
'desc' => '',
'type' => 'text'
);
$arg = wp_parse_args( $field, $defaults );
$this->settings_fields[$section][] = $arg;
return $this;
}
/**
* Initialize and registers the settings sections and fileds to WordPress
*
* Usually this should be called at `admin_init` hook.
*
* This function gets the initiated settings sections and fields. Then
* registers them to WordPress and ready for use.
*/
function admin_init() {
//register settings sections
foreach ( $this->settings_sections as $section ) {
if ( false == get_option( $section['id'] ) ) {
add_option( $section['id'] );
}
if ( isset($section['desc']) && !empty($section['desc']) ) {
$section['desc'] = '<div class="inside">'.$section['desc'].'</div>';
$callback = create_function('', 'echo "'.str_replace('"', '\"', $section['desc']).'";');
} else if ( isset( $section['callback'] ) ) {
$callback = $section['callback'];
} else {
$callback = null;
}
add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
}
//register settings fields
foreach ( $this->settings_fields as $section => $field ) {
foreach ( $field as $option ) {
$type = isset( $option['type'] ) ? $option['type'] : 'text';
$args = array(
'id' => $option['name'],
'label_for' => $args['label_for'] = "{$section}[{$option['name']}]",
'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
'name' => $option['label'],
'section' => $section,
'size' => isset( $option['size'] ) ? $option['size'] : null,
'options' => isset( $option['options'] ) ? $option['options'] : '',
'std' => isset( $option['default'] ) ? $option['default'] : '',
'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
'type' => $type,
);
add_settings_field( $section . '[' . $option['name'] . ']', $option['label'], array( $this, 'callback_' . $type ), $section, $section, $args );
}
}
// creates our settings in the options table
foreach ( $this->settings_sections as $section ) {
register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
}
}
/**
* Get field description for display
*
* @param array $args settings field args
*/
public function get_field_description( $args ) {
if ( ! empty( $args['desc'] ) ) {
$desc = sprintf( '<p class="description">%s</p>', $args['desc'] );
} else {
$desc = '';
}
return $desc;
}
/**
* Displays a text field for a settings field
*
* @param array $args settings field args
*/
function callback_text( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
$type = isset( $args['type'] ) ? $args['type'] : 'text';
$html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"/>', $type, $size, $args['section'], $args['id'], $value );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a url field for a settings field
*
* @param array $args settings field args
*/
function callback_url( $args ) {
$this->callback_text( $args );
}
/**
* Displays a number field for a settings field
*
* @param array $args settings field args
*/
function callback_number( $args ) {
$this->callback_text( $args );
}
/**
* Displays a checkbox for a settings field
*
* @param array $args settings field args
*/
function callback_checkbox( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$html = '<fieldset>';
$html .= sprintf( '<label for="wpuf-%1$s[%2$s]">', $args['section'], $args['id'] );
$html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
$html .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
$html .= sprintf( '%1$s</label>', $args['desc'] );
$html .= '</fieldset>';
echo $html;
}
/**
* Displays a multicheckbox a settings field
*
* @param array $args settings field args
*/
function callback_multicheck( $args ) {
$value = $this->get_option( $args['id'], $args['section'], $args['std'] );
$html = '<fieldset>';
foreach ( $args['options'] as $key => $label ) {
$checked = isset( $value[$key] ) ? $value[$key] : '0';
$html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
$html .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );
$html .= sprintf( '%1$s</label><br>', $label );
}
$html .= $this->get_field_description( $args );
$html .= '</fieldset>';
echo $html;
}
/**
* Displays a multicheckbox a settings field
*
* @param array $args settings field args
*/
function callback_radio( $args ) {
$value = $this->get_option( $args['id'], $args['section'], $args['std'] );
$html = '<fieldset>';
foreach ( $args['options'] as $key => $label ) {
$html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
$html .= sprintf( '<input type="radio" class="radio" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );
$html .= sprintf( '%1$s</label><br>', $label );
}
$html .= $this->get_field_description( $args );
$html .= '</fieldset>';
echo $html;
}
/**
* Displays a selectbox for a settings field
*
* @param array $args settings field args
*/
function callback_select( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
$html = sprintf( '<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id'] );
foreach ( $args['options'] as $key => $label ) {
$html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $value, $key, false ), $label );
}
$html .= sprintf( '</select>' );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a textarea for a settings field
*
* @param array $args settings field args
*/
function callback_textarea( $args ) {
$value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
$html = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]">%4$s</textarea>', $size, $args['section'], $args['id'], $value );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a textarea for a settings field
*
* @param array $args settings field args
* @return string
*/
function callback_html( $args ) {
echo $this->get_field_description( $args );
}
/**
* Displays a rich text textarea for a settings field
*
* @param array $args settings field args
*/
function callback_wysiwyg( $args ) {
$value = $this->get_option( $args['id'], $args['section'], $args['std'] );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : '500px';
echo '<div style="max-width: ' . $size . ';">';
$editor_settings = array(
'teeny' => true,
'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
'textarea_rows' => 10
);
if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
$editor_settings = array_merge( $editor_settings, $args['options'] );
}
wp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );
echo '</div>';
echo $this->get_field_description( $args );
}
/**
* Displays a file upload field for a settings field
*
* @param array $args settings field args
*/
function callback_file( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
$id = $args['section'] . '[' . $args['id'] . ']';
$label = isset( $args['options']['button_label'] ) ?
$args['options']['button_label'] :
__( 'Choose File' );
$html = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
$html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a password field for a settings field
*
* @param array $args settings field args
*/
function callback_password( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
$html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a color picker field for a settings field
*
* @param array $args settings field args
*/
function callback_color( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
$html = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Sanitize callback for Settings API
*/
function sanitize_options( $options ) {
foreach( $options as $option_slug => $option_value ) {
$sanitize_callback = $this->get_sanitize_callback( $option_slug );
// If callback is set, call it
if ( $sanitize_callback ) {
$options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
continue;
}
}
return $options;
}
/**
* Get sanitization callback for given option slug
*
* @param string $slug option slug
*
* @return mixed string or bool false
*/
function get_sanitize_callback( $slug = '' ) {
if ( empty( $slug ) ) {
return false;
}
// Iterate over registered fields and see if we can find proper callback
foreach( $this->settings_fields as $section => $options ) {
foreach ( $options as $option ) {
if ( $option['name'] != $slug ) {
continue;
}
// Return the callback name
return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
}
}
return false;
}
/**
* Get the value of a settings field
*
* @param string $option settings field name
* @param string $section the section name this field belongs to
* @param string $default default text if it's not found
* @return string
*/
function get_option( $option, $section, $default = '' ) {
$options = get_option( $section );
if ( isset( $options[$option] ) ) {
return $options[$option];
}
return $default;
}
/**
* Show navigations as tab
*
* Shows all the settings section labels as tab
*/
function show_navigation() {
$html = '<h2 class="nav-tab-wrapper">';
foreach ( $this->settings_sections as $tab ) {
$html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
}
$html .= '</h2>';
echo $html;
}
/**
* Show the section settings forms
*
* This function displays every sections in a different form
*/
function show_forms() {
?>
<div class="metabox-holder">
<?php foreach ( $this->settings_sections as $form ) { ?>
<div id="<?php echo $form['id']; ?>" class="group" style="display: none;">
<form method="post" action="options.php">
<?php
do_action( 'wsa_form_top_' . $form['id'], $form );
settings_fields( $form['id'] );
do_settings_sections( $form['id'] );
do_action( 'wsa_form_bottom_' . $form['id'], $form );
?>
<div style="padding-left: 10px">
<?php submit_button(); ?>
</div>
</form>
</div>
<?php } ?>
</div>
<?php
$this->script();
}
/**
* Tabbable JavaScript codes & Initiate Color Picker
*
* This code uses localstorage for displaying active tabs
*/
function script() {
?>
<script>
jQuery(document).ready(function($) {
//Initiate Color Picker
$('.wp-color-picker-field').wpColorPicker();
// Switches option sections
$('.group').hide();
var activetab = '';
if (typeof(localStorage) != 'undefined' ) {
activetab = localStorage.getItem("activetab");
}
if (activetab != '' && $(activetab).length ) {
$(activetab).fadeIn();
} else {
$('.group:first').fadeIn();
}
$('.group .collapsed').each(function(){
$(this).find('input:checked').parent().parent().parent().nextAll().each(
function(){
if ($(this).hasClass('last')) {
$(this).removeClass('hidden');
return false;
}
$(this).filter('.hidden').removeClass('hidden');
});
});
if (activetab != '' && $(activetab + '-tab').length ) {
$(activetab + '-tab').addClass('nav-tab-active');
}
else {
$('.nav-tab-wrapper a:first').addClass('nav-tab-active');
}
$('.nav-tab-wrapper a').click(function(evt) {
$('.nav-tab-wrapper a').removeClass('nav-tab-active');
$(this).addClass('nav-tab-active').blur();
var clicked_group = $(this).attr('href');
if (typeof(localStorage) != 'undefined' ) {
localStorage.setItem("activetab", $(this).attr('href'));
}
$('.group').hide();
$(clicked_group).fadeIn();
evt.preventDefault();
});
$('.wpsa-browse').on('click', function (event) {
event.preventDefault();
var self = $(this);
// Create the media frame.
var file_frame = wp.media.frames.file_frame = wp.media({
title: self.data('uploader_title'),
button: {
text: self.data('uploader_button_text'),
},
multiple: false
});
file_frame.on('select', function () {
attachment = file_frame.state().get('selection').first().toJSON();
self.prev('.wpsa-url').val(attachment.url);
});
// Finally, open the modal
file_frame.open();
});
});
</script>
<style type="text/css">
/** WordPress 3.8 Fix **/
.form-table th { padding: 20px 10px; }
#wpbody-content .metabox-holder { padding-top: 5px; }
</style>
<?php
}
}
endif;
#}
#}
......
<?php
/**
* WordPress settings API demo class
*
* @author Tareq Hasan
*/
if ( !class_exists('WeDevs_Settings_API_Test' ) ):
class WeDevs_Settings_API_Test {
private $settings_api;
function __construct() {
$this->settings_api = new WooCommerce_Quick_Donation_Settings_Api;
add_action( 'admin_init', array($this, 'admin_init') );
add_action( 'admin_menu', array($this, 'admin_menu') );
}
function admin_init() {
//set the settings
$this->settings_api->set_sections( $this->get_settings_sections() );
$this->settings_api->set_fields( $this->get_settings_fields() );
//initialize settings
$this->settings_api->admin_init();
}
function admin_menu() {
add_submenu_page( 'edit.php?post_type='.WC_QD_PT, 'Settings' , 'Settings', 'delete_posts', 'wc_qd_settings', array($this, 'plugin_page') );
}
function get_settings_sections() {
$sections = array(
array(
'id' => 'wedevs_basics',
'title' => __( 'Basic Settings', 'wedevs' ),
'desc' => 'TESTff'
),
array(
'id' => 'wedevs_advanced',
'title' => __( 'Advanced Settings', 'wedevs' )
),
array(
'id' => 'wedevs_others',
'title' => __( 'Other Settings', 'wpuf' )
)
);
return $sections;
}
/**
* Returns all the settings fields
*
* @return array settings fields
*/
function get_settings_fields() {
$settings_fields = array(
'wedevs_basics' => array(
array(
'name' => 'text_val',
'label' => __( 'Text Input', 'wedevs' ),
'desc' => __( 'Text input description', 'wedevs' ),
'type' => 'text',
'default' => 'Title',
'sanitize_callback' => 'intval'
),
array(
'name' => 'number_input',
'label' => __( 'Number Input', 'wedevs' ),
'desc' => __( 'Number field with validation callback `intval`', 'wedevs' ),
'type' => 'number',
'default' => 'Title',
'sanitize_callback' => 'intval'
),
array(
'name' => 'textarea',
'label' => __( 'Textarea Input', 'wedevs' ),
'desc' => __( 'Textarea description', 'wedevs' ),
'type' => 'textarea'
),
array(
'name' => 'checkbox',
'label' => __( 'Checkbox', 'wedevs' ),
'desc' => __( 'Checkbox Label', 'wedevs' ),
'type' => 'checkbox'
),
array(
'name' => 'radio',
'label' => __( 'Radio Button', 'wedevs' ),
'desc' => __( 'A radio button', 'wedevs' ),
'type' => 'radio',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'multicheck',
'label' => __( 'Multile checkbox', 'wedevs' ),
'desc' => __( 'Multi checkbox description', 'wedevs' ),
'type' => 'multicheck',
'options' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
'four' => 'Four'
)
),
array(
'name' => 'selectbox',
'label' => __( 'A Dropdown', 'wedevs' ),
'desc' => __( 'Dropdown description', 'wedevs' ),
'type' => 'select',
'default' => 'no',
'size' => 'wc-enhanced-select small',
'style' => 'width:50%',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'password',
'label' => __( 'Password', 'wedevs' ),
'desc' => __( 'Password description', 'wedevs' ),
'type' => 'password',
'default' => ''
),
array(
'name' => 'file',
'label' => __( 'File', 'wedevs' ),
'desc' => __( 'File description', 'wedevs' ),
'type' => 'file',
'default' => '',
'options' => array(
'button_label' => 'Choose Image'
)
)
),
'wedevs_advanced' => array(
array(
'name' => 'color',
'label' => __( 'Color', 'wedevs' ),
'desc' => __( 'Color description', 'wedevs' ),
'type' => 'color',
'default' => ''
),
array(
'name' => 'password',
'label' => __( 'Password', 'wedevs' ),
'desc' => __( 'Password description', 'wedevs' ),
'type' => 'password',
'default' => ''
),
array(
'name' => 'wysiwyg',
'label' => __( 'Advanced Editor', 'wedevs' ),
'desc' => __( 'WP_Editor description', 'wedevs' ),
'type' => 'wysiwyg',
'default' => ''
),
array(
'name' => 'multicheck',
'label' => __( 'Multile checkbox', 'wedevs' ),
'desc' => __( 'Multi checkbox description', 'wedevs' ),
'type' => 'multicheck',
'default' => array('one' => 'one', 'four' => 'four'),
'options' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
'four' => 'Four'
)
),
array(
'name' => 'selectbox',
'label' => __( 'A Dropdown', 'wedevs' ),
'desc' => __( 'Dropdown description', 'wedevs' ),
'type' => 'select',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'password',
'label' => __( 'Password', 'wedevs' ),
'desc' => __( 'Password description', 'wedevs' ),
'type' => 'password',
'default' => ''
),
array(
'name' => 'file',
'label' => __( 'File', 'wedevs' ),
'desc' => __( 'File description', 'wedevs' ),
'type' => 'file',
'default' => ''
)
),
'wedevs_others' => array(
array(
'name' => 'text',
'label' => __( 'Text Input', 'wedevs' ),
'desc' => __( 'Text input description', 'wedevs' ),
'type' => 'text',
'default' => 'Title'
),
array(
'name' => 'textarea',
'label' => __( 'Textarea Input', 'wedevs' ),
'desc' => __( 'Textarea description', 'wedevs' ),
'type' => 'textarea'
),
array(
'name' => 'checkbox',
'label' => __( 'Checkbox', 'wedevs' ),
'desc' => __( 'Checkbox Label', 'wedevs' ),
'type' => 'checkbox'
),
array(
'name' => 'radio',
'label' => __( 'Radio Button', 'wedevs' ),
'desc' => __( 'A radio button', 'wedevs' ),
'type' => 'radio',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'multicheck',
'label' => __( 'Multile checkbox', 'wedevs' ),
'desc' => __( 'Multi checkbox description', 'wedevs' ),
'type' => 'multicheck',
'options' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
'four' => 'Four'
)
),
array(
'name' => 'selectbox',
'label' => __( 'A Dropdown', 'wedevs' ),
'desc' => __( 'Dropdown description', 'wedevs' ),
'type' => 'select',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'password',
'label' => __( 'Password', 'wedevs' ),
'desc' => __( 'Password description', 'wedevs' ),
'type' => 'password',
'default' => ''
),
array(
'name' => 'file',
'label' => __( 'File', 'wedevs' ),
'desc' => __( 'File description', 'wedevs' ),
'type' => 'file',
'default' => ''
)
)
);
return $settings_fields;
}
function plugin_page() {
echo '<div class="wrap">';
$this->settings_api->show_navigation();
$this->settings_api->show_forms();
echo '</div>';
}
/**
* Get all the pages
*
* @return array page names with key value pairs
*/
function get_pages() {
$pages = get_pages();
$pages_options = array();
if ( $pages ) {
foreach ($pages as $page) {
$pages_options[$page->ID] = $page->post_title;
}
}
return $pages_options;
}
}
endif;
new WeDevs_Settings_API_Test();
...@@ -33,10 +33,7 @@ class WooCommerce_Quick_Donation_Admin_Function { ...@@ -33,10 +33,7 @@ class WooCommerce_Quick_Donation_Admin_Function {
public function protect_donation_product($actions,$post) { public function protect_donation_product($actions,$post) {
if('product' == $post->post_type) { if('product' == $post->post_type) {
if($post->ID == WC_QD_ID){
if($post->ID == WC_QD()->donation_id){
unset($actions['inline hide-if-no-js']); unset($actions['inline hide-if-no-js']);
unset($actions['trash']); unset($actions['trash']);
unset($actions['duplicate']); unset($actions['duplicate']);
......
<?php
/**
* functionality of the plugin.
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
public $is_donation_exists = false;
function __construct(){
parent::__construct();
// add_action( 'wp_loaded',array($this,'on_wp_loaded'),20);
add_filter( 'woocommerce_get_price', array($this,'get_price'),10,2);
}
public function on_wp_loaded(){
if($this->check_donation_exists_cart()){ $this->is_donation_exists = true; }
$this->process_donation();
}
public function process_donation(){
if(isset($_POST['donation_add'])){
global $woocommerce;
$donation = isset($_POST['wc_qd_donate_project_price']) ? $_POST['wc_qd_donate_project_price'] : false;
$projects = isset($_POST['wc_qd_donate_project_name']) && !empty($_POST['wc_qd_donate_project_name']) ? $_POST['wc_qd_donate_project_name'] : false;
$donate_price = floatval($donation);
$woocommerce->session->jc_donation = $donate_price;
$woocommerce->session->projects = $projects;
$woocommerce->cart->add_to_cart(self::$donation_id);
}
}
/**
* Checks If Donation Product Exists In Cart
*/
public function check_donation_exists_cart(){
global $woocommerce;
$found = false;
if( sizeof($woocommerce->cart->get_cart()) > 0){
foreach($woocommerce->cart->get_cart() as $cart_item_key=>$values){
$_product = $values['data'];
if($_product->id == self::$donation_id)
$found = true;
}
}
return $found;
}
/**
* Gets Donation Current Price
* @param $price
* @param $product
* @returns 0 | price
*/
public function get_price($price, $product){
global $woocommerce;
if($this->is_donation_exists){
if($product->id == self::$donation_id){
return isset($woocommerce->session->jc_donation) ? floatval($woocommerce->session->jc_donation) : 0;
}
}
return $price;
}
}
\ No newline at end of file
...@@ -24,14 +24,16 @@ class WooCommerce_Quick_Donation_Shortcode { ...@@ -24,14 +24,16 @@ class WooCommerce_Quick_Donation_Shortcode {
public function shortcode_handler($settings){ public function shortcode_handler($settings){
global $donation_box,$donation_price,$currency; global $donation_box,$donation_price,$currency;
$settings = shortcode_atts( array( $settings = shortcode_atts( array(
'type' => 'radio', 'type' => 'select',
'grouped' => true, 'grouped' => false,
), $settings ); ), $settings );
$donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type']); $donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type']);
$donation_price = WC_QD()->f()->generate_price_box(); $donation_price = WC_QD()->f()->generate_price_box();
$currency = get_woocommerce_currency_symbol(); $currency = get_woocommerce_currency_symbol();
do_action('wc_quick_donation_before_doantion_form',$settings['type'],$settings['grouped']);
WC_QD()->f()->load_template('donation_form.php',WC_QD_TEMPLATE); WC_QD()->f()->load_template('donation_form.php',WC_QD_TEMPLATE);
do_action('wc_quick_donation_after_doantion_form',$settings['type'],$settings['grouped']);
} }
} }
\ No newline at end of file
...@@ -28,7 +28,7 @@ class WooCommerce_Quick_Donation { ...@@ -28,7 +28,7 @@ class WooCommerce_Quick_Donation {
public static $is_donation_product_exist = true; public static $is_donation_product_exist = true;
protected static $f = null; protected static $f = null;
public static $shortcode = null; public static $shortcode = null;
public $donation_id = null; public static $donation_id = null;
/** /**
* Creates or returns an instance of this class. * Creates or returns an instance of this class.
...@@ -45,7 +45,10 @@ class WooCommerce_Quick_Donation { ...@@ -45,7 +45,10 @@ class WooCommerce_Quick_Donation {
*/ */
public function __construct() { public function __construct() {
$this->define_constant(); $this->define_constant();
$this->donation_id = get_option(WC_QD_DB.'product_id'); self::$donation_id = get_option(WC_QD_DB.'product_id');
$this->define('WC_QD_ID',intval(get_option(WC_QD_DB.'product_id')));
$this->load_required_files(); $this->load_required_files();
register_activation_hook( __FILE__,array('WC_QD_INSTALL','INIT') ); register_activation_hook( __FILE__,array('WC_QD_INSTALL','INIT') );
...@@ -79,7 +82,9 @@ class WooCommerce_Quick_Donation { ...@@ -79,7 +82,9 @@ class WooCommerce_Quick_Donation {
$this->load_files(WC_QD_PATH.'includes/class-install.php'); $this->load_files(WC_QD_PATH.'includes/class-install.php');
$this->load_files(WC_QD_PATH.'includes/class-quick-donation-functions.php'); $this->load_files(WC_QD_PATH.'includes/class-quick-donation-functions.php');
$this->load_files(WC_QD_PATH.'includes/class-quick-donation-process.php');
$this->load_files(WC_QD_PATH.'includes/class-shortcode-handler.php'); $this->load_files(WC_QD_PATH.'includes/class-shortcode-handler.php');
if($this->is_request('admin')){ if($this->is_request('admin')){
$this->load_files(WC_QD_PATH.'admin/class-*.php'); $this->load_files(WC_QD_PATH.'admin/class-*.php');
} }
...@@ -92,6 +97,7 @@ class WooCommerce_Quick_Donation { ...@@ -92,6 +97,7 @@ class WooCommerce_Quick_Donation {
private function init_class(){ private function init_class(){
self::$f = new WooCommerce_Quick_Donation_Functions; self::$f = new WooCommerce_Quick_Donation_Functions;
self::$shortcode = new WooCommerce_Quick_Donation_Shortcode; self::$shortcode = new WooCommerce_Quick_Donation_Shortcode;
$this->donation = new WooCommerce_Quick_Donation_Process;
if($this->is_request('admin')){ if($this->is_request('admin')){
$this->admin = new WooCommerce_Quick_Donation_Admin; $this->admin = new WooCommerce_Quick_Donation_Admin;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment