initial commit
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 27 Mar 2019 19:30:38 +0000 (15:30 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 27 Mar 2019 19:30:38 +0000 (15:30 -0400)
funds.js [new file with mode: 0644]
glm-funds.php [new file with mode: 0644]

diff --git a/funds.js b/funds.js
new file mode 100644 (file)
index 0000000..3afcd35
--- /dev/null
+++ b/funds.js
@@ -0,0 +1,89 @@
+jQuery(function($){
+    function strip_nan(amount){
+        var new_amount = amount.replace(/[^0-9.]/g, '');
+        return new_amount;
+    }
+
+    $(window).on('load', function(){
+        console.log(window);
+        $('.gform_wrapper').find('form').attr('autocomplete', 'off');
+        var tags = all_funds;
+        var page = $('body');
+        var donate_fields = page.find(".donation-input");
+        // var add_remove = page.find('.gfield_list_icons').children('img');
+        var total_input = page.find(".ginput_container_total");
+        var total = 0;
+        var form = $('#gform_3');
+        // var missing_value = false;
+        // var amount = 0;
+
+        // set up autocomplete
+        $('.gfield_list_2_cell2').children().autocomplete({source: tags});
+        
+        $(document).on('keydown.autocomplete','.gfield_list_2_cell2 > input', function(){
+            $(this).autocomplete({source: tags});
+        });
+
+        $(document).on("click", '.delete_list_item', function(e){
+            var amount =  $(this).parent().prev().prev().children('input').val();
+            amount = strip_nan(amount);
+            amount = parseFloat(amount);
+            if(amount && !isNaN(amount)){
+                total -= amount;
+                total_input.children('#input_3_1').val(total.toFixed(2));
+                total_input.children( '.ginput_total' ).text('$' + total.toFixed(2));
+                $('.gfield_hidden_product').last()
+                    .find( $("[id^='ginput_base']") ).val('$' + total.toFixed(2));
+            }
+        });
+
+        $(donate_fields).on('blur', '.gfield_list_2_cell1 > input', function(){
+            var _ = $(this);
+            // var fund_field = _.parent().next().children('input');
+            var amount_input = page.find(".gfield_list_2_cell1").children();
+            // var rows = amount_input.length;
+
+            var stripped = strip_nan( _.val() );
+            stripped = parseFloat(stripped);
+
+            //set amount to 0 if NaN
+            if( isNaN( stripped ) ){
+                $(_).val('');
+            }else{
+                $(_).val(stripped);
+            }
+
+            total = 0;
+            $.each(amount_input, function(index, value){
+                // var fund = $(this).parent().next().children('input').val();
+                var amount = $(this).val();
+
+                amount = strip_nan(amount);
+                amount = parseFloat(amount);
+
+                if( isNaN(amount)){
+                    amount = 0;
+                }
+                
+                if(amount >= 0 && !isNaN(amount)){
+                    total += amount;
+                    total_input.children('#input_3_1').val(total.toFixed(2));
+                    total_input.children( '.ginput_total' ).text('$' + total.toFixed(2));
+                } 
+                
+            });
+
+            $('.gfield_hidden_product').last()
+                .find( $("[id^='ginput_base']") ).val('$' + total.toFixed(2));
+        });
+
+        $("#gform_submit_button_3").on("click", function(e){
+            if(total <= 0){
+                alert("Please enter an amount greater than 0");
+                return false;
+            } else{
+                $(form).on("submit").submit();
+            }
+        })
+    });
+});
\ No newline at end of file
diff --git a/glm-funds.php b/glm-funds.php
new file mode 100644 (file)
index 0000000..bce32ff
--- /dev/null
@@ -0,0 +1,334 @@
+<?php
+
+/**
+ * Plugin Name: GLM WP Funds
+ * Plugin URI: http://www.gaslightmedia.com/
+ * Description: GLM WP Funds 
+ * Version: 1.0.0
+ * Author: Gaslight Media
+ * Author URI: http://www.gaslightmedia.com/
+ * License: GPL2
+ */
+define( 'POST_TYPE', 'fund' );
+define( 'FUND_SINGLE', 'Fund' );
+define( 'FUND_PLURAL', 'Funds' );
+define( 'CATEGORY_NAME', 'fund_group' );
+define( 'CATEGORY_SLUG', 'fund-group' );
+define( 'CATEGORY_SINGLE', 'Fund Group' );
+define( 'CATEGORY_PLURAL', 'Fund Groups' );
+// Register Custom Post Type
+function custom_post_type() {
+
+       $labels = array(
+               'name'                  => _x( FUND_PLURAL, 'Post Type General Name', 'text_domain' ),
+               'singular_name'         => _x( FUND_SINGLE, 'Post Type Singular Name', 'text_domain' ),
+               'menu_name'             => __( FUND_PLURAL, 'text_domain' ),
+               'name_admin_bar'        => __( FUND_PLURAL, 'text_domain' ),
+               'archives'              => __( FUND_PLURAL, 'text_domain' ),
+               'attributes'            => __( 'Fund Attributes', 'text_domain' ),
+               'parent_item_colon'     => __( 'Parent Fund:', 'text_domain' ),
+               'all_items'             => __( 'All Funds', 'text_domain' ),
+               'add_new_item'          => __( 'Add New Fund', 'text_domain' ),
+               'add_new'               => __( 'Add New Fund', 'text_domain' ),
+               'new_item'              => __( 'New Fund', 'text_domain' ),
+               'edit_item'             => __( 'Edit Fund', 'text_domain' ),
+               'update_item'           => __( 'Update Fund', 'text_domain' ),
+               'view_item'             => __( 'View Fund', 'text_domain' ),
+               'view_items'            => __( 'View Funds', 'text_domain' ),
+               'search_items'          => __( 'Search Fund', 'text_domain' ),
+               'not_found'             => __( 'Not found', 'text_domain' ),
+               'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
+               'featured_image'        => __( 'Featured Image', 'text_domain' ),
+               'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
+               'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
+               'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
+               'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
+               'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
+               'items_list'            => __( 'Items list', 'text_domain' ),
+               'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
+               'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
+       );
+       $args = array(
+               'label'                 => __( 'Fund', 'text_domain' ),
+               'description'           => __( 'Custom', 'Funds' ),
+               'labels'                => $labels,
+               'supports'              => array( 'title', 'page-attributes' ),
+               'hierarchical'          => false,
+               'public'                => false,
+               'show_ui'               => true,
+        'show_in_menu'          => true,
+        'menu_icon'             => 'dashicons-clipboard',
+               'menu_position'         => 5,
+               'show_in_admin_bar'     => true,
+               'show_in_nav_menus'     => true,
+               'can_export'            => true,
+               'has_archive'           => true,
+               'exclude_from_search'   => false,
+               'publicly_queryable'    => true,
+               'capability_type'       => 'page',
+       );
+       register_post_type( POST_TYPE, $args );
+    register_taxonomy_for_object_type( CATEGORY_NAME, POST_TYPE );
+
+}
+add_action( 'init', 'custom_post_type', 0 );
+function fund_taxonomies()
+{
+
+    // Categories
+    $labels = array(
+        'name'              => _x( CATEGORY_NAME, 'taxonomy general name' ),
+        'singular_name'     => _x( CATEGORY_NAME, 'taxonomy singular name' ),
+        'search_items'      => __( 'Search ' . CATEGORY_PLURAL),
+        'all_items'         => __( 'All ' . CATEGORY_PLURAL),
+        'parent_item'       => __( 'Parent ' . CATEGORY_SINGLE),
+        'parent_item_colon' => __( 'Parent ' . CATEGORY_SINGLE),
+        'edit_item'         => __( 'Edit ' . CATEGORY_SINGLE),
+        'update_item'       => __( 'Update ' . CATEGORY_SINGLE),
+        'add_new_item'      => __( 'Add New ' . CATEGORY_SINGLE),
+        'new_item_name'     => __( 'New ' . CATEGORY_SINGLE . ' Name' ),
+        'menu_name'         => __(  CATEGORY_SINGLE ),
+    );
+
+    $capabilities = array(
+        'manage_terms' => 'manage_categories',
+        'edit_terms'   => 'manage_categories',
+        'delete_terms' => 'manage_categories',
+        'assign_terms' => 'edit_posts',
+    );
+
+    $args = array(
+        'label'                => __(CATEGORY_PLURAL),
+        'rewrite'              => array( 'slug' => CATEGORY_SLUG ),
+        'capabilities'         => $capabilities,
+        'public '              => false,
+        'show_in_quick_edit'   => true,
+        'show_in_admin_column' => true,
+        'hierarchical'         => true
+    );
+
+     register_taxonomy(
+        CATEGORY_NAME,
+        POST_TYPE,
+        $args
+    );
+}
+function funds_shortcode($atts)
+{
+    extract( shortcode_atts( array( 'limit' => '10' ), $atts ) );
+    ob_start();
+    global $wp;
+    $custom_terms = get_terms('fund_group');
+    echo '<div class="funds-container">';
+    foreach($custom_terms as $custom_term) {
+        wp_reset_query();
+        $args = array(
+            'posts_per_page' => -1,
+            'post_type'     => 'fund',
+            'orderby'       => 'title',
+            'order'         => 'ASC',
+            'tax_query'     => array(
+                array(
+                    'taxonomy' => 'fund_group',
+                    'field' => 'slug',
+                    'terms' => $custom_term->slug,
+                ),
+            ),
+         );
+
+        $loop = new WP_Query($args);
+        if($loop->have_posts()) {
+        echo "<div class='fund-container-$custom_term->term_id'>";
+        echo "<h2 class='$custom_term->term_id'>".$custom_term->name.'</h2>';
+        echo '<ul>';
+        while($loop->have_posts()) : $loop->the_post();
+//            echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
+            echo '<li>'.get_the_title().'</li>';
+        endwhile;
+        echo '</ul>';
+        echo '</div>';
+       }
+        
+    }
+    echo '</div>';
+    $output = ob_get_contents();
+    ob_end_clean();
+    return $output;
+}
+add_action( 'init', 'fund_taxonomies' );
+add_action( 'init', 'custom_post_type' );
+add_shortcode( 'list-funds', 'funds_shortcode' );
+/**
+ * michsci_admin_custom_columns
+ *
+ * This will generate the column data for eaoch record.
+ *
+ * @param mixed $column
+ * @access public
+ * @return void
+ */
+function funds_admin_custom_columns($column)
+{
+    global $post;
+
+    switch ($column) {
+    case 'fund_col_cat':
+        $fund_cats      = get_the_terms( $post->ID, 'fund_group' );
+        $fund_cats_html = array();
+        if ( $fund_cats ) {
+            foreach ( $fund_cats as $fund_cat ) {
+                array_push( $fund_cats_html, $fund_cat->name );
+            }
+            echo implode( $fund_cats_html, ', ' );
+        } else {
+             _e( 'None', 'themeforce' );
+        }
+        break;
+    }
+}
+function funds_admin_edit_columns($columns)
+{
+    $columns = array(
+        'cb'                  => '<input type="checkbox">',
+        'title'               => FUND_SINGLE . ' Title',
+        'fund_col_cat'        => CATEGORY_SINGLE
+    );
+    return $columns;
+}
+function fund_set_admin_columns()
+{
+    add_filter( 'manage_edit-fund_columns', 'funds_admin_edit_columns' );
+    add_action( 'manage_fund_posts_custom_column', 'funds_admin_custom_columns' );
+}
+
+add_action( 'admin_init', 'fund_set_admin_columns' );
+function fund_taxonomy_filter_restrict_manage_posts()
+{
+    global $typenow;
+
+    $post_types = get_post_types( array( '_builtin' => false ) );
+
+    if ( in_array( $typenow, $post_types ) ) {
+        $filters = get_object_taxonomies( $typenow );
+
+        foreach ( $filters as $tax_slug ) {
+
+            $tax_obj = get_taxonomy( $tax_slug );
+            wp_dropdown_categories( array(
+                'show_option_all' => __( 'Show All ' . $tax_obj->label ),
+                'taxonomy'        => $tax_slug,
+                'name'            => $tax_obj->name,
+                'orderby'         => 'name',
+                'selected'        => ( isset( $_GET[$tax_slug] ) ),
+                'hierarchical'    => $tax_obj->hierarchical,
+                'show_count'      => false,
+                'hide_empty'      => true
+            ) );
+        }
+    }
+}
+
+add_action( 'restrict_manage_posts', 'fund_taxonomy_filter_restrict_manage_posts' );
+function fund_taxonomy_filter_post_type_request( $query )
+{
+    global $pagenow, $typenow;
+
+    if ( 'edit.php' == $pagenow ) {
+        $filters = get_object_taxonomies( $typenow );
+        foreach ( $filters as $tax_slug ) {
+            $var = &$query->query_vars[$tax_slug];
+
+            if ( isset( $var ) ) {
+                $term = get_term_by( 'id', $var, $tax_slug );
+
+                $var = $term->slug;
+            }
+        }
+    }
+}
+add_filter( 'parse_query', 'fund_taxonomy_filter_post_type_request' );
+
+/**
+ * Save Meta Data
+ *
+ * Saves the meta fields for the product
+ *
+ * @access public
+ * @return void
+ */
+//function save_meta() {
+//    global $post;
+//    if ( isset( $_POST['title-meta-noncename'] ) && ! wp_verify_nonce( $_POST['title-meta-noncename'], 'title-meta-noncename' ) ) {
+//        return $post->ID;
+//    }
+//    if ( isset( $post ) && ! current_user_can( 'edit_post', $post->ID ) ) {
+//        return $post->ID;
+//    }
+//    $name  = ( isset( $_POST['partner_name'] )  ? filter_var( $_POST['partner_name'] ) : '' );
+//    $title = ( isset( $_POST['partner_title'] ) ? filter_var( $_POST['partner_title'] ) : '' );
+//    $email = ( isset( $_POST['partner_email'] ) ? filter_var( $_POST['partner_email'] )  : '');
+//    $phone = ( isset( $_POST['partner_phone'] ) ? filter_var( $_POST['partner_phone'] )  : '');
+//    $url   = ( isset( $_POST['partner_url'] )   ? filter_var( $_POST['partner_url'] )  : '');
+//
+//    if ( isset( $post ) ) {
+//        update_post_meta( $post->ID, 'partner_name', $name );
+//        update_post_meta( $post->ID, 'partner_title', $title );
+//        update_post_meta( $post->ID, 'partner_email', $email );
+//        update_post_meta( $post->ID, 'partner_phone', $phone );
+//        update_post_meta( $post->ID, 'partner_url', $url );
+//        update_post_meta($post->ID, 'internal_url', $_POST['internal_url']);
+//        update_post_meta($post->ID, 'internal_page', $_POST['internal_page']);
+//    }
+//}
+
+/**
+ * add_metaboxes
+ *
+ * Add the meta fields
+ *
+ * @access public
+ * @return void
+ */
+//function add_metaboxes() {
+//    add_meta_box( 'partner_info', 'Partner Information', 'partner_info', GLM_POST_TYPE, 'normal', 'low' );
+//}
+//add_action( 'save_post', 'save_meta' );
+add_action('init', function(){
+    function get_funds(){
+        
+        $all_funds = [];
+        $custom_terms = get_terms('fund_group');
+        foreach($custom_terms as $custom_term) {
+            wp_reset_query();
+            $args = array(
+                'post_type' => 'fund',
+                'numberposts' => -1,
+                'tax_query' => array(
+                    array(
+                        'taxonomy' => 'fund_group',
+                        'field' => 'slug',
+                        'terms' => $custom_term->slug,
+                        'hide_empty' => false
+                     ),
+                ),
+             );
+
+            $loop = get_posts($args);
+            foreach($loop as $l){
+                $funds_grouped[$custom_term->name][] = $l->post_title;
+                $all_funds[]= $l->post_title;
+            }
+        }
+  
+        $js_funds_grouped = json_encode($funds_grouped);
+        $js_all_funds     = json_encode($all_funds);
+        
+        return $js_all_funds;
+    }
+});
+function glm_funds_enqueue_scripts() {   
+    wp_enqueue_script("jquery");
+    wp_enqueue_script('jquery-ui-autocomplete');
+    wp_enqueue_script( 'form_ui', plugin_dir_url( __FILE__ ) . 'funds.js' );
+}
+add_action('wp_enqueue_scripts', 'glm_funds_enqueue_scripts');
\ No newline at end of file