Commit c7f74212 authored by Varun Sridharan's avatar Varun Sridharan

New Version of plugin

* Redeveloping The Plugin.
* Created Custom Post Type
* Created Custom Taxonomy {Category & Tags}
* Created Shortcode
* Project Output Like Select , Radio [Single or grouped]
* Price Box Output
* Customizable Template
parent ac36be3c
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
*
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package @TODO
* @subpackage @TODO
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Admin {
/**
* Initialize the class and set its properties.
* @since 0.1
*/
public function __construct() {
WC_QD()->load_files(WC_QD_PATH.'admin/includes/*.php');
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ),99);
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_init', array( $this, 'init_admin_class' ));
add_action( 'plugins_loaded', array( $this, 'init' ) );
add_filter( 'plugin_row_meta', array($this, 'plugin_row_links' ), 10, 2 );
add_filter( 'woocommerce_get_settings_pages', array($this,'settings_page') );
}
/**
* Inits Admin Sttings
*/
public function init_admin_class(){
$this->functions = new WooCommerce_Quick_Donation_Admin_Function;
//$this->notice = new WordPress_Admin_Notice_Handler;
# new WooCommerce_Plugin_Boiler_Plate_Admin_Settings;
}
/**
* Add a new integration to WooCommerce.
*/
public function settings_page( $integrations ) {
foreach(glob(WC_QD_PATH.'admin/woocommerce-settings*.php' ) as $file){
$integrations[] = require_once($file);
}
return $integrations;
}
/**
* Register the stylesheets for the admin area.
*/
public function enqueue_styles() {
if(in_array($this->current_screen() , $this->get_screen_ids())) {
wp_enqueue_style(WC_QD_SLUG.'_core_style',plugins_url('css/style.css',__FILE__) , array(), WC_QD()->version, 'all' );
}
}
/**
* Register the JavaScript for the admin area.
*/
public function enqueue_scripts() {
if(in_array($this->current_screen() , $this->get_screen_ids())) {
wp_enqueue_script(WC_QD_SLUG.'_core_script', plugins_url('js/script.js',__FILE__), array('jquery'), WC_QD()->version, false );
}
}
/**
* Gets Current Screen ID from wordpress
* @return string [Current Screen ID]
*/
public function current_screen(){
$screen = get_current_screen();
return $screen->id;
}
/**
* Returns Predefined Screen IDS
* @return [Array]
*/
public function get_screen_ids(){
$screen_ids = array();
$screen_ids[] = 'edit-product';
$screen_ids[] = 'product';
return $screen_ids;
}
/**
* Adds Some Plugin Options
* @param array $plugin_meta
* @param string $plugin_file
* @since 0.11
* @return array
*/
public function plugin_row_links( $plugin_meta, $plugin_file ) {
if ( WC_QD_FILE == $plugin_file ) {
$plugin_meta[] = sprintf('<a href="%s">%s</a>', '#', __('Settings',WC_QD_TXT) );
$plugin_meta[] = sprintf('<a href="%s">%s</a>', '#', __('F.A.Q',WC_QD_TXT) );
$plugin_meta[] = sprintf('<a href="%s">%s</a>', '#', __('View On Github',WC_QD_TXT) );
$plugin_meta[] = sprintf('<a href="%s">%s</a>', '#', __('Report Issue',WC_QD_TXT) );
$plugin_meta[] = sprintf('&hearts; <a href="%s">%s</a>', '#', __('Donate',WC_QD_TXT) );
$plugin_meta[] = sprintf('<a href="%s">%s</a>', 'http://varunsridharan.in/plugin-support/', __('Contact Author',WC_QD_TXT) );
}
return $plugin_meta;
}
}
?>
\ No newline at end of file
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
*
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package @TODO
* @subpackage @TODO
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
#class WooCommerce_Plugin_Boiler_Plate_Admin_Settings extends WooCommerce_Plugin_Boiler_Plate_Admin {
#public function __construct() {
#}
#}
?>
\ No newline at end of file
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
*
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package @TODO
* @subpackage @TODO
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Admin_Function {
public function __construct(){
add_action( 'post_row_actions', array($this,'protect_donation_product'),99,2);
}
/**
* Protects Donation Product By
* @filter_user post_row_actions
* @param Array $actions Refer WP.org
* @param Array $post Refer WP.org
* @return Array Refer WP.org
* @since 1.0
*/
public function protect_donation_product($actions,$post) {
if('product' == $post->post_type) {
if($post->ID == WC_QD()->donation_id){
unset($actions['inline hide-if-no-js']);
unset($actions['trash']);
unset($actions['duplicate']);
$actions['trash'] = '<a href="javascript:alert(\'Remove Woocommerce Quick Donation Plugin To Remove This Product \');"> Trash </a>';
}
}
return $actions;
}
}
\ No newline at end of file
<?php
/**
* WooCommerce General Settings
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WooCommerce_Advanced_Settings' ) ) :
/**
* WC_Admin_Settings_General
*/
class WooCommerce_Advanced_Settings extends WC_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'wc_intergation_advanced';
$this->label = __( 'WC Advanced Intergation', 'woocommerce' );
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_filter( 'woocommerce_sections_'.$this->id, array( $this, 'output_sections' ));
add_filter( 'woocommerce_settings_'.$this->id, array( $this, 'output_settings' ));
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Simple Inputs', 'woocommerce' ),
'advanced_input' => __( 'Advanced Inputs','woocommerce' ),
'predefined_input' => __('Predefined Inputs','woocommerce' ),
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
public function output_settings(){
global $current_section;
$settings = $this->get_settings( $current_section );
WC_Admin_Settings::output_fields( $settings );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings($section = null) {
var_dump($section);
$settings = array(
array(
'title' => __( 'Simple Inputs', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'wc_advanced_simple_inputs_intergation'
),
array(
'title' => __( 'Text Box', 'woocommerce' ),
'desc' => __( 'This is a simple textbox', 'woocommerce' ),
'id' =>'wc_simple_textbox',
'css' => 'min-width:350px;',
'default' => 'Simple TextBox',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'TextArea', 'woocommerce' ),
'id' => 'wc_simple_textarea',
'default' => __( 'Simple TextArea.', 'woocommerce' ),
'type' => 'textarea',
'css' => 'width:350px; height: 65px;',
'autoload' => false
),
array(
'title' => __( 'Radio Buttons', 'woocommerce' ),
'desc' => __( 'A Simple Radio Button', 'woocommerce' ),
'id' => 'wc_simple_radio',
'default' => 'all',
'type' => 'radio',
'desc_tip' => true,
'options' => array(
'option1' => __( 'option 1', 'woocommerce' ),
'option2' => __( 'option 2', 'woocommerce' )
)
),
array(
'title' => __( 'Option 1', 'woocommerce' ),
'id' => 'wc_simple_checkbox_1',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Option 2', 'woocommerce' ),
'id' => 'wc_simple_checkbox_2',
'default' => 'no',
'type' => 'checkbox',
),
array( 'type' => 'sectionend', 'id' => 'wc_advanced_simple_inputs_intergation'),
);
return $settings;
}
/**
* Save settings
*/
public function save() {
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
}
}
endif;
return new WooCommerce_Advanced_Settings();
<?php
/**
* WooCommerce General Settings
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WooCommerce_Simple_Settings' ) ) :
/**
* WC_Admin_Settings_General
*/
class WooCommerce_Simple_Settings extends WC_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'wc_intergation_simple';
$this->label = __( 'WC Simple Intergation', 'woocommerce' );
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$settings = array(
array(
'title' => __( 'Simple Options', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'wc_simple_intergation'
),
array(
'title' => __( 'Text Box', 'woocommerce' ),
'desc' => __( 'This is a simple textbox', 'woocommerce' ),
'id' =>'wc_simple_textbox',
'css' => 'min-width:350px;',
'default' => 'GB',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'TextArea', 'woocommerce' ),
'desc' => '',
'id' => 'wc_simple_textarea',
'default' => __( 'SOme Value.', 'woocommerce' ),
'type' => 'textarea',
'css' => 'width:350px; height: 65px;',
'autoload' => false
),
array(
'title' => __( 'Radio Buttons', 'woocommerce' ),
'desc' => __( 'A Simple Radio Button', 'woocommerce' ),
'id' => 'wc_simple_radio',
'default' => 'all',
'type' => 'radio',
'desc_tip' => true,
'options' => array(
'all' => __( 'Sell to all countries', 'woocommerce' ),
'specific' => __( 'Sell to specific countries only', 'woocommerce' )
)
),
array(
'title' => __( 'Checbox', 'woocommerce' ),
'desc' => __( 'A Simple Checkbox', 'woocommerce' ),
'id' => 'wc_simple_checkboxx',
'default' => 'no',
'type' => 'checkbox'
),
array( 'type' => 'sectionend', 'id' => 'wc_simple_intergation'),
);
return $settings;
}
/**
* Save settings
*/
public function save() {
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
}
}
endif;
return new WooCommerce_Simple_Settings();
<?php
/*
Name: Admin Notice Helper
URI: https://github.com/iandunn/admin-notice-helper
Version: 0.2
Author: Ian Dunn
Author URI: http://iandunn.name
License: GPLv2
*/
/*
* Copyright 2014 Ian Dunn (email : ian@iandunn.name)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Access denied.' );
}
if ( ! class_exists( 'Admin_Notice_Helper' ) ) {
class Admin_Notice_Helper {
// Declare variables and constants
protected static $instance;
protected $notices, $notices_were_updated;
/**
* Constructor
*/
protected function __construct() {
$this->init();
//add_action( 'init', array( $this, 'init' )); // needs to run before other plugin's init callbacks so that they can enqueue messages in their init callbacks
add_action( 'admin_notices', array( $this, 'print_notices' ) );
add_action( 'shutdown', array( $this, 'shutdown' ) );
}
/**
* Provides access to a single instances of the class using the singleton pattern
*
* @mvc Controller
* @author Ian Dunn <ian@iandunn.name>
* @return object
*/
public static function get_singleton() {
if ( ! isset( self::$instance ) ) {
self::$instance = new Admin_Notice_Helper();
}
return self::$instance;
}
/**
* Initializes variables
*/
public function init() {
$default_notices = array( 'update' => array(), 'error' => array() );
$this->notices = array_merge( $default_notices, get_option( 'anh_notices', array() ) );
$this->notices_were_updated = false;
}
/**
* Queues up a message to be displayed to the user
*
* @param string $message The text to show the user
* @param string $type 'update' for a success or notification message, or 'error' for an error message
*/
public function enqueue( $message, $type = 'update' ) {
if(!empty($this->notices)){
if(isset( $this->notices[ $type ])){
if ( in_array( $message, array_values( $this->notices[ $type ] ) ) ) {
return;
}
}
}
$this->notices[ $type ][] = (string) apply_filters( 'anh_enqueue_message', $message );
$this->notices_were_updated = true;
}
/**
* Displays updates and errors
*/
public function print_notices() {
foreach ( array( 'update', 'error' ) as $type ) {
if ( count( $this->notices[ $type ] ) ) {
$class = 'update' == $type ? 'updated' : 'error';
?>
<div class="anh_message <?php esc_attr_e( $class ); ?>">
<?php foreach ( $this->notices[ $type ] as $notice ) : ?>
<p><?php echo wp_kses( $notice, wp_kses_allowed_html( 'post' ) ); ?></p>
<?php endforeach; ?>
</div>
<?php
$this->notices[ $type ] = array();
$this->notices_were_updated = true;
}
}
}
/**
* Writes notices to the database
*/
public function shutdown() {
if ( $this->notices_were_updated ) {
update_option( 'anh_notices', $this->notices );
}
}
} // end Admin_Notice_Helper
Admin_Notice_Helper::get_singleton(); // Create the instance immediately to make sure hook callbacks are registered in time
if ( ! function_exists( 'wc_qd_notice' ) ) {
function wc_qd_notice( $message, $type = 'update' ) {
Admin_Notice_Helper::get_singleton()->enqueue( $message, $type );
}
}
}
?>
\ No newline at end of file
<?php
class WC_QD_INSTALL{
/**
* Inits Install Hook
*/
public static function init(){
$donation_exist = self::check_donation_exists();
if($donation_exist){
return true;
}
$post_id = self::create_donation();
update_option(WC_QD_DB.'product_id',$post_id);
}
/**
* Checks Donation Product Exists
*/
public static function check_donation_exists(){
$exist = get_option(WC_QD_DB.'product_id');
if($exist && get_post_status ($exist)){
return true;
}
return false;
}
public static function create_donation(){
$userID = 1;
if(get_current_user_id()){
$userID = get_current_user_id();
}
$post = array(
'post_author' => $userID,
'post_content' => 'Used For Donation',
'post_status' => 'publish',
'post_title' => 'Donation',
'post_type' => 'product',
);
$post_id = wp_insert_post($post);
update_post_meta($post_id, '_stock_status', 'instock');
update_post_meta($post_id, '_tax_status', 'none');
update_post_meta($post_id, '_tax_class', 'zero-rate');
update_post_meta($post_id, '_visibility', 'hidden');
update_post_meta($post_id, '_stock', '');
update_post_meta($post_id, '_virtual', 'yes');
update_post_meta($post_id, '_featured', 'no');
update_post_meta($post_id, '_manage_stock', "no" );
update_post_meta($post_id, '_sold_individually', "yes" );
update_post_meta($post_id, '_sku', 'checkout-donation');
return $post_id;
}
}
?>
<?php
if ( ! defined( 'WPINC' ) ) { die; }
class WC_QD_Post_Types {
public static function init(){
add_action( 'init', array(__CLASS__,'register_donation_posttype'),5);
add_action( 'init', array(__CLASS__,'register_donation_category'),5);
add_action( 'init', array(__CLASS__,'register_donation_tags' ), 5 );
}
public static function register_donation_posttype(){
$args = array(
'label' => __( 'Quick Donation Project', WC_QD_TXT ),
'description' => __( 'WooCommerce Donation Projects', WC_QD_TXT ),
'labels' => self::get_post_types_labels(),
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', ),
'taxonomies' => array( 'donation_category', 'donation_tags' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-smiley',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => self::get_posttype_rewrite(),
'capability_type' => 'page',
);
register_post_type( WC_QD_PT, $args );
}
public static function get_post_types_labels() {
return array(
'name' => _x( 'Quick Donation Projects', 'Post Type General Name', WC_QD_TXT ),
'singular_name' => _x( 'Quick Donation Project', 'Post Type Singular Name', WC_QD_TXT ),
'menu_name' => __( 'Quick Donation', WC_QD_TXT ),
'name_admin_bar' => __( 'Quick Donation', WC_QD_TXT ),
'parent_item_colon' => __( 'Parent Project :', WC_QD_TXT ),
'all_items' => __( 'All Project', WC_QD_TXT ),
'add_new_item' => __( 'Add New Project', WC_QD_TXT ),
'add_new' => __( 'Add Project', WC_QD_TXT ),
'new_item' => __( 'New Project', WC_QD_TXT ),
'edit_item' => __( 'Edit Project', WC_QD_TXT ),
'update_item' => __( 'Update ProjectNot found in Trash', WC_QD_TXT ),
'view_item' => __( 'View Project', WC_QD_TXT ),
'search_items' => __( 'Search Project', WC_QD_TXT ),
'not_found' => __( 'No Project Found', WC_QD_TXT ),
'not_found_in_trash' => __( 'No Project Found in Trash', WC_QD_TXT ),
);
}
public static function get_posttype_rewrite(){
return array(
'slug' => 'donations',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
}
public static function register_donation_category(){
$labels = array(
'name' => _x( 'Project Categories', 'Taxonomy General Name', WC_QD_TXT ),
'singular_name' => _x( 'Project Category', 'Taxonomy Singular Name', WC_QD_TXT ),
'menu_name' => __( 'Categories', WC_QD_TXT ),
'all_items' => __( 'All Categories', WC_QD_TXT ),
'parent_item' => __( 'Parent Category', WC_QD_TXT ),
'parent_item_colon' => __( 'Parent Category:', WC_QD_TXT ),
'new_item_name' => __( 'New Category Name', WC_QD_TXT ),
'add_new_item' => __( 'Add New Project Category', WC_QD_TXT ),
'edit_item' => __( 'Edit Category', WC_QD_TXT ),
'update_item' => __( 'Update Category', WC_QD_TXT ),
'view_item' => __( 'View Category', WC_QD_TXT ),
'separate_items_with_commas' => __( 'Separate Categories with commas', WC_QD_TXT ),
'add_or_remove_items' => __( 'Add or remove Categories', WC_QD_TXT ),
'choose_from_most_used' => __( 'Choose from the most used', WC_QD_TXT ),
'popular_items' => __( 'Popular Categories', WC_QD_TXT ),
'search_items' => __( 'Search Categories', WC_QD_TXT ),
'not_found' => __( 'Not Found', WC_QD_TXT ),
);
$rewrite = array(
'slug' => 'donation/category',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
//'update_count_callback' => 'f',
);
register_taxonomy( WC_QD_CAT, array( WC_QD_PT ), $args );
}
public static function register_donation_tags() {
$labels = array(
'name' => _x( 'Project Tags', 'Taxonomy General Name', WC_QD_TXT ),
'singular_name' => _x( 'Project Tag', 'Taxonomy Singular Name', WC_QD_TXT ),
'menu_name' => __( 'Tags', WC_QD_TXT ),
'all_items' => __( 'All Tags', WC_QD_TXT ),
'parent_item' => __( 'Parent Tag', WC_QD_TXT ),
'parent_item_colon' => __( 'Parent Tag :', WC_QD_TXT ),
'new_item_name' => __( 'New Tag Name', WC_QD_TXT ),
'add_new_item' => __( 'Add New Tag', WC_QD_TXT ),
'edit_item' => __( 'Edit Tag ', WC_QD_TXT ),
'update_item' => __( 'Update Tags', WC_QD_TXT ),
'view_item' => __( 'View Tag', WC_QD_TXT ),
'separate_items_with_commas' => __( 'Separate Tags with commas', WC_QD_TXT ),
'add_or_remove_items' => __( 'Add or remove Tags', WC_QD_TXT ),
'choose_from_most_used' => __( 'Choose from the most used', WC_QD_TXT ),
'popular_items' => __( 'Popular Tags', WC_QD_TXT ),
'search_items' => __( 'Search Tags', WC_QD_TXT ),
'not_found' => __( 'Not Found', WC_QD_TXT ),
);
$rewrite = array(
'slug' => 'donation/tags',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
// 'update_count_callback' => 'f',
);
register_taxonomy( 'wcqd_tags', array(WC_QD_PT ), $args );
}
}
WC_QD_Post_Types::init();
?>
\ No newline at end of file
<?php
/**
* functionality of the plugin.
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Functions {
protected static $project_db_list = null;
/**
* Get Donation Project List From DB
*/
public function get_donation_project_list(){
if(self::$project_db_list != null || self::$project_db_list != ''){
return self::$project_db_list;
}
$args = array(
'posts_per_page' => 0,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => WC_QD_PT,
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
self::$project_db_list = get_posts($args);
return self::$project_db_list;
}
public function get_porject_list($grouped = false){
$list = $this->get_donation_project_list();
$projects = array();
foreach($list as $project){
if($grouped){
$term = get_the_terms( $project->ID, WC_QD_CAT );
$projects[$term[0]->name][$project->ID] = $project->post_title;
} else {
$projects[$project->ID] = $project->post_title;
}
}
return $projects;
}
public function generate_donation_selbox($grouped = false,$type = 'select'){
global $id, $name, $class, $field_output, $is_grouped, $project_list,$attributes;
$field_output = '';
$id = 'donation_project';
$name = 'wc_qd_donate_project_name';
$class = apply_filters('wcqd_project_name_'.$type.'_class',array(),$type);
$custom_attributes = apply_filters('wcqd_project_name_'.$type.'_attribute',array(),$type);
$is_grouped = $grouped;
$project_list = $this->get_porject_list($grouped);
$class = implode(' ',$class);
$attributes = '';
foreach($custom_attributes as $attr_key => $attr_val) {
$attributes .= $attr_key.'="'.$attr_val.'" ';
}
$this->load_template('field-'.$type.'.php', WC_QD_TEMPLATE.'fields/' );
return $field_output;
}
public function generate_price_box(){
global $id, $name, $class, $field_output,$attributes,$value;
$field_output = '';
$id = 'donation_price';
$name = 'wc_qd_donate_project_price';
$class = apply_filters('wcqd_project_price_text_class',array(),'text');
$custom_attributes = apply_filters('wcqd_project_price_text_attribute',array(),'text');
$value = '';
$class = implode(' ',$class);
$attributes = '';
foreach($custom_attributes as $attr_key => $attr_val) {
$attributes .= $attr_key.'="'.$attr_val.'" ';
}
$this->load_template('field-text.php',WC_QD_TEMPLATE . 'fields/' );
return $field_output;
}
public function load_template($file,$path){
$wc_get_template = function_exists('wc_get_template') ? 'wc_get_template' : 'woocommerce_get_template';
$wc_get_template( $file,array(), '', $path);
}
}
<?php
/**
* functionality of the plugin.
*
* @link @TODO
* @since 1.0
*
* @package @TODO
* @subpackage @TODO
*
* @package @TODO
* @subpackage @TODO
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Shortcode {
public function __construct() {
add_shortcode( 'wc_quick_donation', array($this, 'shortcode_handler' ));
}
public function shortcode_handler($settings){
global $donation_box,$donation_price,$currency;
$settings = shortcode_atts( array(
'type' => 'radio',
'grouped' => true,
), $settings );
$donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type']);
$donation_price = WC_QD()->f()->generate_price_box();
$currency = get_woocommerce_currency_symbol();
WC_QD()->f()->load_template('donation_form.php',WC_QD_TEMPLATE);
}
}
\ No newline at end of file
=== Woocommerce Role Based Price ===
Contributors: varunms
Author URI: http://varunsridharan.in/
Plugin URL: https://wordpress.org/plugins/woocommerce-plugin-boiler-plate/
Tags: WooCommerce
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=36Y7KSYPF7KTU
Requires at least: 3.0
Tested up to: 4.3
WC requires at least: 1.0
WC tested up to: 2.4.6
Stable tag: 2.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
A Simple Plugin Boiler Plate for woocommerce
== Description ==
A Simple Plugin Boiler Plate for woocommerce
== Screenshots ==
== Installation ==
= Minimum Requirements =
* WordPress 3.8 or greater
* PHP version 5.2.4 or greater
* MySQL version 5.0 or greater
= Automatic installation =
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don't need to leave your web browser. To do an automatic install of WooCommerce Role Based Price, log in to your WordPress dashboard, navigate to the Plugins menu and click Add New.
In the search field type "WooCommerce Role Based Price" and click Search Plugins. Once you've found our plugin you can view details about it such as the the point release, rating and description. Most importantly of course, you can install it by simply clicking "Install Now"
= Manual installation =
The manual installation method involves downloading our plugin and uploading it to your Web Server via your favourite FTP application. The WordPress codex contains [instructions on how to do this here](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation).
1. Installing alternatives:
* via Admin Dashboard:
* Go to 'Plugins > Add New', search for "WooCommerce Role Based Price", click "install"
* OR via direct ZIP upload:
* Upload the ZIP package via 'Plugins > Add New > Upload' in your WP Admin
* OR via FTP upload:
* Upload `woocommerce-quick-buy` folder to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
== Changelog ==
= 0.1 =
* Base Version
<?php
global $donation_box,$donation_price,$currency;
?>
<form method="post">
<table>
<tr>
<td> Donation Project </td>
<td> <?php echo $donation_box; ?></td>
</tr>
<tr>
<td>Donation Amount <?php echo $currency; ?></td>
<td><?php echo $donation_price; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="donation_add" value="Add Donation"/></td>
</tr>
</table>
</form>
\ No newline at end of file
<?php
global $id, $name, $class, $field_output, $is_grouped, $project_list,$attributes;
foreach($project_list as $id => $val){
if(is_array($val)){
$field_output .= ' <fieldset> <legend>'.$id.'</legend>';
foreach($val as $k =>$v){
$field_output .= $v.' : <input type="radio" name="'.$name.'" value="'.$k.'" >';
}
$field_output .= '</fieldset>';
} else {
$field_output .= $val.' : <input type="radio" name="'.$name.'" value="'.$id.'" >';
}
}
<?php
global $id, $name, $class, $field_output, $is_grouped, $project_list,$attributes;
$field_output = '<select id="'.$id.'" name="'.$name.'" class="'.$class.'" '.$attributes.'>';
foreach($project_list as $id => $val){
if(is_array($val)){
$field_output .= ' <optgroup label="'.$id.'">';
foreach($val as $k =>$v){
$field_output .= '<option value="'.$k.'">'.$v.'</option>';
}
$field_output .= ' </optgroup>';
} else {
$field_output .= '<option value="'.$id.'">'.$val.'</option>';
}
}
$field_output .= '</select>';
\ No newline at end of file
<?php
global $id, $name, $class, $field_output,$attributes,$value;
$field_output = '<input type="text" id="'.$id.'" name="'.$name.'" class="'.$class.'" '.$attributes.' value="'.$value.'" />';
?>
\ No newline at end of file
<?php
/**
* WooCommerce Uninstall
*
* Uninstalling WooCommerce deletes user roles, pages, tables, and options.
*
* @author WooThemes
* @category Core
* @package WooCommerce/Uninstaller
* @version 2.3.0
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
?>
\ No newline at end of file
<?php
/**
* Plugin Name: WooCommerce Quick Donation
* Plugin URI: https://wordpress.org/plugins/woocommerce-plugin-boiler-plate/
* Description: Sample Plugin For WooCommerce
* Version: 3.0
* Author: Varun Sridharan
* Author URI: http://varunsridharan.in
* Text Domain: woocommerce-quick-donation
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: @TODO
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation {
/**
* @var string
*/
public $version = '0.1';
/**
* @var WooCommerce The single instance of the class
* @since 2.1
*/
protected static $_instance = null;
public static $is_donation_product_exist = true;
protected static $f = null;
public static $shortcode = null;
public $donation_id = null;
/**
* Creates or returns an instance of this class.
*/
public static function get_instance() {
if ( null == self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
/**
* Class Constructor
*/
public function __construct() {
$this->define_constant();
$this->donation_id = get_option(WC_QD_DB.'product_id');
$this->load_required_files();
register_activation_hook( __FILE__,array('WC_QD_INSTALL','INIT') );
add_action( 'init', array( $this, 'init' ));
}
/**
* Triggers When INIT Action Called
*/
public function init(){
$this->init_class();
$this->check_donation_product_exist();
add_action('plugins_loaded', array( $this, 'after_plugins_loaded' ));
add_filter('load_textdomain_mofile', array( $this, 'load_plugin_mo_files' ), 10, 2);
}
private function check_donation_product_exist(){
$install = new WC_QD_INSTALL;
if(! $install->check_donation_exists()){
self::$is_donation_product_exist = false;
wc_qd_notice('WooCommerce Donation Product Not Exist','error');
}
}
/**
* Loads Required Plugins For Plugin
*/
private function load_required_files(){
$this->load_files(WC_QD_PATH.'includes/class-admin-notice.php');
$this->load_files(WC_QD_PATH.'includes/class-post-*.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-shortcode-handler.php');
if($this->is_request('admin')){
$this->load_files(WC_QD_PATH.'admin/class-*.php');
}
}
/**
* Inits loaded Class
*/
private function init_class(){
self::$f = new WooCommerce_Quick_Donation_Functions;
self::$shortcode = new WooCommerce_Quick_Donation_Shortcode;
if($this->is_request('admin')){
$this->admin = new WooCommerce_Quick_Donation_Admin;
}
}
/**
* Function Get Call Admin
*/
public function admin(){
return $this->admin;
}
public function f(){
return self::$f;
}
/**
* Loads The Files From Given Path
*/
public function load_files($path,$type = 'require'){
foreach( glob( $path ) as $files ){
if($type == 'require'){
require_once( $files );
} else if($type == 'include'){
include_once( $files );
}
}
}
/**
* Set Plugin Text Domain
*/
public function after_plugins_loaded(){
load_plugin_textdomain(WC_QD_TXT, false, WC_QD_LANG );
}
/**
* load translated mo file based on wp settings
*/
public function load_plugin_mo_files($mofile, $domain) {
if (WC_QD_TXT === $domain)
return WC_QD_LANG.'/'.get_locale().'.mo';
return $mofile;
}
/**
* Define Required Constant
*/
private function define_constant(){
$this->define('WC_QD','WooCommerce Quick Donation'); # Plugin Name
$this->define('WC_QD_SLUG','wc-qd'); # Plugin Slug
$this->define('WC_QD_PATH',plugin_dir_path( __FILE__ )); # Plugin DIR
$this->define('WC_QD_TEMPLATE',WC_QD_PATH.'template/'); # Plugin Template DIR
$this->define('WC_QD_LANG',WC_QD_PATH.'languages');
$this->define('WC_QD_TXT','woocommerce-quick-donation'); #plugin lang Domain
$this->define('WC_QD_URL',plugins_url('', __FILE__ ));
$this->define('WC_QD_FILE',plugin_basename( __FILE__ ));
$this->define('WC_QD_DB','wc_qd_');
$this->define('WC_QD_PT','wcqd_project');
$this->define('WC_QD_CAT','wcqd_category');
$this->define('WC_QD_TAG','wcqd_tags');
}
/**
* Define constant if not already set
* @param string $name
* @param string|bool $value
*/
protected function define($key,$value){
if(!defined($key)){
define($key,$value);
}
}
/**
* What type of request is this?
* string $type ajax, frontend or admin
* @return bool
*/
private function is_request( $type ) {
switch ( $type ) {
case 'admin' :
return is_admin();
case 'ajax' :
return defined( 'DOING_AJAX' );
case 'cron' :
return defined( 'DOING_CRON' );
case 'frontend' :
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
}
}
}
function WC_QD(){
return WooCommerce_Quick_Donation::get_instance();
}
$GLOBALS['woocommerce_quick_donation'] = WC_QD();
?>
\ No newline at end of file
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