46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/fundraising-templates.txt:
--------------------------------------------------------------------------------
1 | You can create new files inside your active theme's root folder to be used when displaying a fundraiser.
2 |
3 | There are 3 types of templates you can create.
4 |
5 | Template Hierarchy
6 |
7 | Single Fundraiser
8 | wdf_funder-{ID}.php
9 | wdf_funder-{slug}.php
10 | wdf_funder.php
11 |
12 | Fundraiser Checkout
13 | wdf_checkout-{ID}.php
14 | wdf_checkout-{slug}.php
15 | wdf_checkout.php
16 |
17 | Fundraiser Confirmation Page
18 | wdf_confirm-{ID}.php
19 | wdf_confirm-{slug}.php
20 | wdf_confirm.php
21 |
22 |
23 | == Custom Template Functions ==
24 | You can change the location of the template-functions that are loaded in fundraising to an external location.
25 | This will insure that any custom changes you make to your template functions are not broken when updating the plugin in the future.
26 |
27 | Add a new define statement in your wp-config.php file containing a string pointing to the location.
28 | define('WDF_CUSTOM_TEMPLATE_FUNCTIONS','/full-server-path/and/filename.php');
29 |
30 |
31 | == Custom Styles ==
32 | Add any CSS file to your fundraising /styles/ folder for it to be available in your settings.
33 |
34 | You can also create a folder named "wdf-styles" in your wp-content folder
35 | OR
36 | you can set an external location using the following code in your wp-config.php file.
37 |
38 | define('WDF_EXTERNAL_STYLE_DIRECTORY','/full/server/path/to/styles/')
39 |
40 | By default the name of the style is the name of the file. You can manually adjust this using the "wdf_custom_style_name" filter
41 |
42 | Exmaple:
43 | add_filter('wdf_custom_style_name', 'my_custom_filter_style_name', 10, 2);
44 |
45 | function my_custom_filter_style_name($name, $file_name) {
46 | if($file_name == 'my-file.css') {
47 | $name = "My Custom Style";
48 | }
49 | return $name;
50 | }
--------------------------------------------------------------------------------
/lib/bp/templates/wdf/index.php:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
' . esc_js( __('Simple payments act like regular donations. Advanced payments allow for the creation of Goals and Rewards. Advanced payments will only be approved initially. Approved payments will not process until the goal has been reached.', 'wdf') ) . '
' . esc_js( __('Now that you have setup your presentation and payment settings you can create your first fundraiser. Start by adding a title.', 'wdf') ) . '
' . esc_js( __('This step is crucial to how your fundraiser will operate. Remember: Simple Donations process automatically but can not set goals or rewards. Advanced Crowdfunding allows for goals and rewards but will only be approved until the goal has been reached. After you save your fundraising type you will have additional options depending on your choice. Enjoy!', 'wdf') ) . '
' . esc_js( __('You can recommend donation levels to your visitors, provide a title, short description, and dollar amount for each level you create.', 'wdf') ) . '
' . esc_js( __('Send the user back to a specific url, any post or page ID, or enter a custom thank you message customizable with shortcodes.', 'wdf') ) . '
' . esc_js( __('Publish your fundraiser, or save it as a draft. Now start fundraising! You can use the fundraiser url or insert the fundraising shortcodes directly into any page or post.', 'wdf')) . '
122 |
--------------------------------------------------------------------------------
/lib/bp/bp-wdf-notifications.php:
--------------------------------------------------------------------------------
1 | Notifications within a users profile page they will see
24 | * settings to turn off notifications for each component.
25 | *
26 | * You can plug your custom notification settings into this page, so that when your
27 | * component is active, the user will see options to turn off notifications that are
28 | * specific to your component.
29 | */
30 |
31 | /**
32 | * Each option is stored in a posted array notifications[SETTING_NAME]
33 | * When saved, the SETTING_NAME is stored as usermeta for that user.
34 | *
35 | * For example, notifications[notification_friends_friendship_accepted] could be
36 | * used like this:
37 | *
38 | * if ( 'no' == get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_accepted', true ) )
39 | * // don't send the email notification
40 | * else
41 | * // send the email notification.
42 | */
43 |
44 | ?>
45 |
180 |
202 |
--------------------------------------------------------------------------------
/changelog.txt:
--------------------------------------------------------------------------------
1 | Plugin Name: Fundraising
2 | Author: WPMUDEV
3 | Lead developer: Maniu
4 | Contributors: Cole Stevenson, Jose Jaureguiberry
5 |
6 | == Changelog ==
7 |
8 | = 2.6.4.9 =
9 | Fixed remaining deprecated constructors
10 | Fixed rewards count on pledge status change
11 | Improved UX for configuring simple donations with goals
12 |
13 | = 2.6.4.8 =
14 | Fixed issue causing redirects to a blank page when pledge is submitted
15 | Fixed issue forcing no funding goal for advanced crowd funding
16 | Fixed deprecated constructor for one of the classes
17 |
18 | = 2.6.4.7 =
19 | Fixed BuddyPress compatibility issues
20 | Fixed manual payment country field issues
21 |
22 | = 2.6.4.6 =
23 | Removed PHP 4 constructor
24 |
25 | = 2.6.4.5 =
26 | Fixed issues with counting reward limits
27 |
28 | = 2.6.4.4 =
29 | Fixed issues with address colection for manual gateway
30 | WPMUDEV dashboard notice update
31 |
32 | = 2.6.4.3 =
33 | Fixed "Times Up!" issues with simple donation fundraising
34 |
35 | = 2.6.4.2 =
36 | Improved FE styling (please check compatibility with active theme)
37 | Improved UX for jumping between Simple and Advanced fundraising type
38 | Improved fundraising start/end date handling
39 | Improved PP error handling
40 | Added ajax check for delayed pledges
41 | Enabled address collecting without rewards
42 | Fixed typo
43 |
44 | = 2.6.4.1 =
45 | Improved Upfront compatibility
46 | Added ability to hide standard Fundraising Panel (may be useful in some scenarios)
47 | Fixed widgets related PHP notices
48 | Fixed BP related PHP strick notices
49 |
50 | = 2.6.4 =
51 | Fixed compatibility with PayPal changes
52 | Fixed widget's edit screen markup
53 |
54 | = 2.6.3 =
55 | Fixed issues with tutorial
56 |
57 | = 2.6.2 =
58 | Added support for refunds in recurring payments
59 | Fixed recurring payments amount problem for currencies different than US Dollars
60 |
61 | = 2.6.1.9 =
62 | Improved UX when switching to advanced payments
63 | Fixed problems with address storing when using advanced payments
64 |
65 | = 2.6.1.8 =
66 | Fixed is_subdomain_install error
67 |
68 | = 2.6.1.7 =
69 | Added possibility to collect address even when rewards are disabled
70 | Fixed some permalink issues
71 | Fixed storing of custom data for PayPal
72 |
73 | = 2.6.1.6 =
74 | Added default WP filter for titles in widgets
75 |
76 | = 2.6.1.5 =
77 | Added missing jquery ui images
78 |
79 | = 2.6.1.4 =
80 | Fixed SSL loading issues
81 |
82 | = 2.6.1.3 =
83 | Changed IPN url for better server compatibility
84 | Fixed pledge button for touch devices
85 | Fixed recurring payments
86 | Fixed rewards counting after donation removal
87 |
88 | = 2.6.1.2 =
89 | Fixed top pledges sorting
90 |
91 | = 2.6.1.1 =
92 | Fixed counting of rewards left
93 |
94 | = 2.6.1 =
95 | Added pledges panel widget and shortcode to list recent or top pledges
96 | Added ability to set custom message for situation when pledge was not found
97 | Improved UX for creating new Fundraisers
98 | Improved respect for label settings inside admin panel
99 | Fixed PHP warnings
100 | Fixed time left counting for Fundraisers
101 | Fixed session cleaning
102 |
103 | = 2.6.0.5 =
104 | Added back front permalink option on main site in multisite
105 | Fixed buddypress activity item being added for unlogged users
106 | Other small improvements
107 |
108 | = 2.6.0.4 =
109 | Fixed missing translation strings
110 |
111 | = 2.6.0.3 =
112 | Fixed missing ")" causing php error
113 |
114 | = 2.6.0.2 =
115 | Fixed rounding of raised amount
116 | Fixed problems with older Internet explorers
117 | Fixed notifications about minimal amount
118 | Fixed limit of listed fundraisers in widget
119 | Small visual improvements
120 |
121 | = 2.6.0.1 =
122 | Update plugins for WP 3.8. UI changes.
123 |
124 | = 2.6 =
125 | Added ability to collect address
126 | Added ability to limit number of rewards
127 | Small improvements to UI
128 | Fixed problem with fundraisers list widget
129 |
130 | = 2.5.3 =
131 | Fixed forms not being closed for custom buttons in some configurations
132 |
133 | = 2.5.2 =
134 | Added missing translation
135 | Unnecessary string removal
136 |
137 | = 2.5.1 =
138 | Removed "front" permalink option for multisite
139 | Fixed permalink problem with /%category%/ inside
140 | Other small improvements
141 |
142 | = 2.5 =
143 | Added ability to control access to fundraisings features for all available user types
144 | Fixed email subject in fundraising not saving correctly
145 |
146 | = 2.4.2 =
147 | Allows shortcodes inside fundraising if ID is not the same as current fundraising
148 |
149 | = 2.4.1 =
150 | Fixed problem with fundraising content not being displayed
151 |
152 | = 2.4 =
153 | Disables fundraising shortcodes inside fundraising
154 | PayPal Support for all UTF-8 characters
155 |
156 | = 2.3.9 =
157 | Fixed styles on older browsers
158 |
159 | = 2.3.8 =
160 | Fixed bug with fundraising panel not being displayed when only specific fundraising widget is configured in sidebar
161 | Fixed mistype in manual payment getaway
162 |
163 | = 2.3.7 =
164 | Allowed HTML tags in reward description
165 | Added information about choosen reward(id) in admin panel
166 | Changed paypal url for possible ipn problem fixes
167 | Fixed security issue
168 |
169 | = 2.3.6 =
170 | Replaced .live jQuery functions with .on
171 | Fixed small UI issue in chrome for fundraising type chooser
172 | Fixed "Add reward" button not working after deleting all rewards before last
173 |
174 | = 2.3.5 =
175 | Fixed manual payment status not saving
176 | Changed/fixed behavior of permalinks and rewrite flushing
177 | Added ability to disable "front" in permalinks from main MU site ("blog/" by default)
178 | Added option to select default getaway
179 | Added workaround for EURO sign in email
180 |
181 | = 2.3.1 =
182 | Added manual payment getaway
183 |
184 | = 2.2.5 =
185 | Fixed php notices about undefined indexes
186 | Fixed notifications from paypal to wordpress about payments with special characters in payment details ( ', " ...)
187 |
188 | = 2.2.4 =
189 | Added new external style locations. Check fundraising-templates.txt for more info
190 | Added new filter and reference label option for standard payments and simple donation buttons
191 |
192 | = 2.2.3 =
193 | Rewrite Flush Issue Fixed
194 | Fixed issue with subscriber error in admin panel
195 | Currency characters are properly decoded for thank you emails
196 | New "wdf_paypal_gateway_standard_item_number" filter for changing the "Reference" on checkout
197 |
198 | = 2.2 =
199 | Fundraising slug now functional with multisite subdirectory.
200 | Fundraiser menu ancestry now works properly when using menus in your theme.
201 | Fixed problem concerning per checkout types breaking panel display.
202 | Adjusted all concatenated translation strings to sprintf() strings.
203 | Fixed action name not displaying in fundraising widget
204 |
205 |
206 | = 2.1.8 =
207 | Fixed issue with fundraisers with goals not showing in shortcode generator
208 | Fixed problem with styles not loading in particular situations
209 | Custom css styling available, but simply adding a css file to /styles folder, see fundraising-templates.txt for more info
210 |
211 | = 2.1.7 =
212 | Shortcode generator now inserts properly into both the HTML and Visual editor
213 | Fixed problem with above/below content option not displaying the current setting
214 | Backer Label now displays a singular label when only one pledge has been taken
215 | Fixed issue with displaying email settings correctly
216 |
217 | = 2.1.6 =
218 | Fixed bug with not allowing more than 10 rewards
219 |
220 | = 2.1.5 =
221 | Fundraising now has it's own metabox in your Theme's Appearance Menus
222 | Multiple php warning fixes
223 | Corrected x.com links for creating an application
224 | Added the ability to set checkout type per fundraiser
225 | Fixed currency display issues
226 | Better display of options on the shortcode generator pop-up
227 | Small change to menu order due to compatibility errors with other plugins and hosting services
228 | New fundraising-templates.txt file in root folder that explains the template hierarchy
229 |
230 |
231 | = 2.1.1 =
232 | Fixed Manual Pledge Payments
233 | Rewards and Goals can now be set independently of each other
234 |
235 |
236 | = 2.1 =
237 | Fixed Canadian Currency Issue
238 | New plugin labeling system
239 | Fixed HTML structure error on checkout pages
240 | Added global custom CSS box in presentation settings (better styles in next release)
241 | Added Minutes to wdf_time_left()
242 | Changed Featured Fundraisers widget to Fundraiser List
243 |
244 |
245 | = 2.0-RC-3 =
246 | Paypal error codes now correctly display if redirection fails.
247 |
248 | Fixed headers already sent error with certain themes.
249 |
250 | Simple Fundraisers can now use rewards and goals again
251 | - Advanced Payments still may not change goals and rewards if the fundraiser has been published and pledges have already been taken.
252 |
253 | New wdf_has_date_range() template function.
254 |
255 | Added new option in presentation settings for checking out directly from the fundraising panel.
256 |
257 |
258 | = 2.0-RC-2 =
259 | Fixed issues with PayPal App ID not saving.
260 |
261 | Fixed problem with PayPal redirect on certain server setups
262 |
263 |
264 | = 2.0-RC-1 =
265 | New Payment Gateway API
266 | - Fundraisers are now split into two types: Simple and Advanced
267 | - Simple payments are donations that are accepted immediately. ( No Goals or Rewards )
268 | - Advanced Payments are pre-approved and only processed after the completion of the fundraiser's goal. ( Goals and Rewards allowed )
269 |
270 | Donations are now refered to as pledges.
271 | - 4 new pledge statuses are available. ( Complete, Approved, Canceled, Refunded )
272 |
273 | New Fundraising Panel
274 | - Use either a shortcode or widget to display relevant fundraiser information
275 |
276 | New Reset option for clearing all fundraising data
277 | - add define('WDF_ALLOW_RESET',true); in your wp-config file to add an extra reset tab to your settings page.
278 |
279 | Limited BuddyPress Integration
280 | - Users are allow to publicly display their plegde as an activity item if they choose to do so. This option display requires that BuddyPress be activated on your site.
281 |
282 | CSS style containers are now all
elements to allow for easier customization.
283 |
284 | New permalink structure
285 | - Each fundraiser now contains a checkout and confirmation page.
286 |
287 | Template functions can now be overridden using the action 'wdf_custom_template_functions'
288 | - fundraiser.php line: 1521
289 |
290 | Fixed shortcode media button errors
291 |
292 | New custom template structure for your theme
293 | - wdf_funder-{$name/$id}.php
294 | - wdf_checkout-{$name/$id}.php
295 | - wdf_confirm-{$name/$id}.php
296 |
297 | Addition of several action and filter hooks for external plugins or theme function files.
--------------------------------------------------------------------------------
/lib/bp/bp-wdf-template.php:
--------------------------------------------------------------------------------
1 |
21 | *
22 | *
23 | *
24 | *
25 | *
26 | *
27 | *
28 | *
29 | *
30 | *
No items!
31 | *
32 | *
33 | *
34 | * Obviously, you'd want to be more specific than the word 'item'.
35 | *
36 | * In our example here, we've used a custom post type for storing and fetching our content. Though
37 | * the custom post type method is recommended, you can also create custom database tables for this
38 | * purpose. See bp-example-classes.php for more details.
39 | *
40 | */
41 |
42 | function bp_wdf_has_items( $args = '' ) {
43 | global $bp, $items_template;
44 |
45 | // This keeps us from firing the query more than once
46 | if ( empty( $items_template ) ) {
47 | /***
48 | * This function should accept arguments passes as a string, just the same
49 | * way a 'query_posts()' call accepts parameters.
50 | * At a minimum you should accept 'per_page' and 'max' parameters to determine
51 | * the number of items to show per page, and the total number to return.
52 | *
53 | * e.g. bp_get_wdf_has_items( 'per_page=10&max=50' );
54 | */
55 |
56 | /***
57 | * Set the defaults for the parameters you are accepting via the "bp_get_wdf_has_items()"
58 | * function call
59 | */
60 | $defaults = array(
61 | 'donation_id' => 0,
62 | 'recipient_id' => 0,
63 | 'per_page' => 10,
64 | 'paged' => 1
65 | );
66 |
67 | /***
68 | * This function will extract all the parameters passed in the string, and turn them into
69 | * proper variables you can use in the code - $per_page, $max
70 | */
71 | $r = wp_parse_args( $args, $defaults );
72 | extract( $r, EXTR_SKIP );
73 |
74 | $items_template = new BP_WDF_Donation();
75 | $items_template->get( $r );
76 | }
77 |
78 | return $items_template->have_posts();
79 | }
80 |
81 | function bp_wdf_the_item() {
82 | global $items_template;
83 | return $items_template->query->the_post();
84 | }
85 |
86 | function bp_wdf_item_name() {
87 | echo bp_wdf_get_item_name();
88 | }
89 | /* Always provide a "get" function for each template tag, that will return, not echo. */
90 | function bp_wdf_get_item_name() {
91 | global $items_template;
92 | echo apply_filters( 'bp_wdf_get_item_name', $items_template->item->name ); // Example: $items_template->item->name;
93 | }
94 |
95 | /**
96 | * Echo "Viewing x of y pages"
97 | *
98 | * @package BuddyPress_Skeleton_Component
99 | * @since 1.6
100 | */
101 | function bp_wdf_pagination_count() {
102 | echo bp_wdf_get_pagination_count();
103 | }
104 | /**
105 | * Return "Viewing x of y pages"
106 | *
107 | * @package BuddyPress_Skeleton_Component
108 | * @since 1.6
109 | */
110 | function bp_wdf_get_pagination_count() {
111 | global $items_template;
112 |
113 | $pagination_count = sprintf( __( 'Viewing page %1$s of %2$s', 'wdf' ), $items_template->query->query_vars['paged'], $items_template->query->max_num_pages );
114 |
115 | return apply_filters( 'bp_wdf_get_pagination_count', $pagination_count );
116 | }
117 |
118 | /**
119 | * Echo pagination links
120 | *
121 | * @package BuddyPress_Skeleton_Component
122 | * @since 1.6
123 | */
124 | function bp_wdf_item_pagination() {
125 | echo bp_wdf_get_item_pagination();
126 | }
127 | /**
128 | * return pagination links
129 | *
130 | * @package BuddyPress_Skeleton_Component
131 | * @since 1.6
132 | */
133 | function bp_wdf_get_item_pagination() {
134 | global $items_template;
135 | return apply_filters( 'bp_wdf_get_item_pagination', $items_template->pag_links );
136 | }
137 |
138 | /**
139 | * Echo the high-fiver avatar (post author)
140 | *
141 | * @package BuddyPress_Skeleton_Component
142 | * @since 1.6
143 | */
144 | function bp_wdf_funder_avatar( $args = array() ) {
145 | echo bp_wdf_get_funder_avatar( $args );
146 | }
147 | /**
148 | * Return the high-fiver avatar (the post author)
149 | *
150 | * @package BuddyPress_Skeleton_Component
151 | * @since 1.6
152 | *
153 | * @param mixed $args Accepts WP style arguments - either a string of URL params, or an array
154 | * @return str The HTML for a user avatar
155 | */
156 | function bp_wdf_get_funder_avatar( $args = array() ) {
157 | $defaults = array(
158 | 'item_id' => get_the_author_meta( 'ID' ),
159 | 'object' => 'user'
160 | );
161 |
162 | $r = wp_parse_args( $args, $defaults );
163 |
164 | return bp_core_fetch_avatar( $r );
165 | }
166 |
167 | /**
168 | * Echo the "title" of the high-five
169 | *
170 | * @package BuddyPress_Skeleton_Component
171 | * @since 1.6
172 | */
173 | function bp_wdf_donation_title() {
174 | echo bp_wdf_get_donation_title();
175 | }
176 | /**
177 | * Return the "title" of the high-five
178 | *
179 | * We'll assemble the title out of the available information. This way, we can insert
180 | * fancy stuff link links, and secondary avatars.
181 | *
182 | * @package BuddyPress_Skeleton_Component
183 | * @since 1.6
184 | */
185 | function bp_wdf_get_donation_title() {
186 | // First, set up the high fiver's information
187 | $funder_link = bp_core_get_userlink( get_the_author_meta( 'ID' ) );
188 |
189 | // Next, get the information for the high five recipient
190 | $recipient_id = get_post_meta( get_the_ID(), 'bp_wdf_recipient_id', true );
191 | $recipient_link = bp_core_get_userlink( $recipient_id );
192 |
193 | // Use sprintf() to make a translatable message
194 | $title = sprintf( __( '%1$s gave %2$s a high-five!', 'wdf' ), $funder_link, $recipient_link );
195 |
196 | return apply_filters( 'bp_wdf_get_donation_title', $title, $funder_link, $recipient_link );
197 | }
198 |
199 | /**
200 | * Is this page part of the Example component?
201 | *
202 | * Having a special function just for this purpose makes our code more readable elsewhere, and also
203 | * allows us to place filter 'bp_is_wdf_component' for other components to interact with.
204 | *
205 | * @package BuddyPress_Skeleton_Component
206 | * @since 1.6
207 | *
208 | * @uses bp_is_current_component()
209 | * @uses apply_filters() to allow this value to be filtered
210 | * @return bool True if it's the example component, false otherwise
211 | */
212 | function bp_is_wdf_component() {
213 | $is_wdf_component = bp_is_current_component( 'wdf_bp' );
214 |
215 | return apply_filters( 'bp_is_wdf_component', $is_wdf_component );
216 | }
217 |
218 | /**
219 | * Echo the component's slug
220 | *
221 | * @package BuddyPress_Skeleton_Component
222 | * @since 1.6
223 | */
224 | function bp_wdf_slug() {
225 | echo bp_get_wdf_slug();
226 | }
227 | /**
228 | * Return the component's slug
229 | *
230 | * Having a template function for this purpose is not absolutely necessary, but it helps to
231 | * avoid too-frequent direct calls to the $bp global.
232 | *
233 | * @package BuddyPress_Skeleton_Component
234 | * @since 1.6
235 | *
236 | * @uses apply_filters() Filter 'bp_get_wdf_slug' to change the output
237 | * @return str $example_slug The slug from $bp->wdf->slug, if it exists
238 | */
239 | function bp_get_wdf_slug() {
240 | global $bp;
241 |
242 | // Avoid PHP warnings, in case the value is not set for some reason
243 | $wdf_slug = isset( $bp->wdf->slug ) ? $bp->wdf->slug : '';
244 |
245 | return apply_filters( 'bp_get_wdf_slug', $wdf_slug );
246 | }
247 |
248 | /**
249 | * Echo the component's root slug
250 | *
251 | * @package BuddyPress_Skeleton_Component
252 | * @since 1.6
253 | */
254 | function bp_wdf_root_slug() {
255 | echo bp_get_wdf_root_slug();
256 | }
257 | /**
258 | * Return the component's root slug
259 | *
260 | * Having a template function for this purpose is not absolutely necessary, but it helps to
261 | * avoid too-frequent direct calls to the $bp global.
262 | *
263 | * @package BuddyPress_Skeleton_Component
264 | * @since 1.6
265 | *
266 | * @uses apply_filters() Filter 'bp_get_wdf_root_slug' to change the output
267 | * @return str $wdf_root_slug The slug from $bp->wdf->root_slug, if it exists
268 | */
269 | function bp_get_wdf_root_slug() {
270 | global $bp;
271 |
272 | // Avoid PHP warnings, in case the value is not set for some reason
273 | $wdf_root_slug = isset( $bp->wdf->root_slug ) ? $bp->wdf->root_slug : '';
274 |
275 | return apply_filters( 'bp_get_wdf_root_slug', $wdf_root_slug );
276 | }
277 |
278 | /**
279 | * Echo the total of all donations across the site
280 | *
281 | * @package BuddyPress_Skeleton_Component
282 | * @since 1.6
283 | */
284 | function bp_wdf_total_donation_count() {
285 | echo bp_wdf_get_total_donation_count();
286 | }
287 | /**
288 | * Return the total of all donations across the site
289 | *
290 | * The most straightforward way to get a post count is to run a WP_Query. In your own plugin
291 | * you might consider storing data like this with update_option(), incrementing each time
292 | * a new item is published.
293 | *
294 | * @package BuddyPress_Skeleton_Component
295 | * @since 1.6
296 | *
297 | * @return int
298 | */
299 | function bp_wdf_get_total_donation_count() {
300 | $donations = new BP_WDF_Donation();
301 | $donations->get();
302 |
303 | return apply_filters( 'bp_wdf_get_total_donation_count', $donations->query->found_posts, $donations );
304 | }
305 |
306 | /**
307 | * Echo the total of all donations given to a particular user
308 | *
309 | * @package BuddyPress_Skeleton_Component
310 | * @since 1.6
311 | */
312 | function bp_wdf_total_donation_count_for_user( $user_id = false ) {
313 | echo bp_wdf_get_total_donation_count_for_user( $user_id = false );
314 | }
315 | /**
316 | * Return the total of all donations given to a particular user
317 | *
318 | * The most straightforward way to get a post count is to run a WP_Query. In your own plugin
319 | * you might consider storing data like this with update_option(), incrementing each time
320 | * a new item is published.
321 | *
322 | * @package BuddyPress_Skeleton_Component
323 | * @since 1.6
324 | *
325 | * @return int
326 | */
327 | function bp_wdf_get_total_donation_count_for_user( $user_id = false ) {
328 | // If no explicit user id is passed, fall back on the loggedin user
329 | if ( !$user_id ) {
330 | $user_id = bp_loggedin_user_id();
331 | }
332 |
333 | if ( !$user_id ) {
334 | return 0;
335 | }
336 |
337 | $donations = new BP_WDF_Donation();
338 | $donations->get( array( 'recipient_id' => $user_id ) );
339 |
340 | return apply_filters( 'bp_wdf_get_total_donation_count', $donations->query->found_posts, $donations );
341 | }
342 |
343 | ?>
--------------------------------------------------------------------------------
/lib/bp/bp-wdf-functions.php:
--------------------------------------------------------------------------------
1 | current_component != $bp->wdf->slug )
31 | return $found_template;
32 |
33 | foreach ( (array) $templates as $template ) {
34 | if ( file_exists( STYLESHEETPATH . '/' . $template ) )
35 | $filtered_templates[] = STYLESHEETPATH . '/' . $template;
36 | else
37 | $filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
38 | }
39 |
40 | $found_template = $filtered_templates[0];
41 |
42 | return apply_filters( 'bp_wdf_load_template_filter', $found_template );
43 | }
44 | add_filter( 'bp_located_template', 'bp_wdf_load_template_filter', 10, 2 );
45 |
46 | /***
47 | * From now on you will want to add your own functions that are specific to the component you are developing.
48 | * For example, in this section in the friends component, there would be functions like:
49 | * friends_add_friend()
50 | * friends_remove_friend()
51 | * friends_check_friendship()
52 | *
53 | * Some guidelines:
54 | * - Don't set up error messages in these functions, just return false if you hit a problem and
55 | * deal with error messages in screen or action functions.
56 | *
57 | * - Don't directly query the database in any of these functions. Use database access classes
58 | * or functions in your bp-example-classes.php file to fetch what you need. Spraying database
59 | * access all over your plugin turns into a maintenance nightmare, trust me.
60 | *
61 | * - Try to include add_action() functions within all of these functions. That way others will
62 | * find it easy to extend your component without hacking it to pieces.
63 | */
64 |
65 | /**
66 | * bp_wdf_accept_terms()
67 | *
68 | * Accepts the terms and conditions screen for the logged in user.
69 | * Records an activity stream item for the user.
70 | */
71 | function bp_wdf_accept_terms() {
72 | global $bp;
73 |
74 | /**
75 | * First check the nonce to make sure that the user has initiated this
76 | * action. Remember the wp_nonce_url() call? The second parameter is what
77 | * you need to check for.
78 | */
79 | check_admin_referer( 'bp_wdf_accept_terms' );
80 |
81 | /***
82 | * Here is a good example of where we can post something to a users activity stream.
83 | * The user has excepted the terms on screen two, and now we want to post
84 | * "Andy accepted the really exciting terms and conditions!" to the stream.
85 | */
86 | $user_link = bp_core_get_userlink( $bp->loggedin_user->id );
87 |
88 | bp_wdf_record_activity( array(
89 | 'type' => 'accepted_terms',
90 | 'action' => apply_filters( 'bp_wdf_accepted_terms_activity_action', sprintf( __( '%s accepted the really exciting terms and conditions!', 'wdf' ), $user_link ), $user_link ),
91 | ) );
92 |
93 | /* See bp_wdf_reject_terms() for an explanation of deleting activity items */
94 | if ( function_exists( 'bp_activity_delete') )
95 | bp_activity_delete( array( 'type' => 'rejected_terms', 'user_id' => $bp->loggedin_user->id ) );
96 |
97 | /* Add a do_action here so other plugins can hook in */
98 | do_action( 'bp_wdf_accept_terms', $bp->loggedin_user->id );
99 |
100 | /***
101 | * You'd want to do something here, like set a flag in the database, or set usermeta.
102 | * just for the sake of the demo we're going to return true.
103 | */
104 |
105 | return true;
106 | }
107 |
108 | /**
109 | * bp_wdf_reject_terms()
110 | *
111 | * Rejects the terms and conditions screen for the logged in user.
112 | * Records an activity stream item for the user.
113 | */
114 | function bp_wdf_reject_terms() {
115 | global $bp;
116 |
117 | check_admin_referer( 'bp_wdf_reject_terms' );
118 |
119 | /***
120 | * In this example component, the user can reject the terms even after they have
121 | * previously accepted them.
122 | *
123 | * If a user has accepted the terms previously, then this will be in their activity
124 | * stream. We don't want both 'accepted' and 'rejected' in the activity stream, so
125 | * we should remove references to the user accepting from all activity streams.
126 | * A real world example of this would be a user deleting a published blog post.
127 | */
128 |
129 | $user_link = bp_core_get_userlink( $bp->loggedin_user->id );
130 |
131 | /* Now record the new 'rejected' activity item */
132 | bp_wdf_record_activity( array(
133 | 'type' => 'rejected_terms',
134 | 'action' => apply_filters( 'bp_wdf_rejected_terms_activity_action', sprintf( __( '%s rejected the really exciting terms and conditions.', 'wdf' ), $user_link ), $user_link ),
135 | ) );
136 |
137 | /* Delete any accepted_terms activity items for the user */
138 | if ( function_exists( 'bp_activity_delete') )
139 | bp_activity_delete( array( 'type' => 'accepted_terms', 'user_id' => $bp->loggedin_user->id ) );
140 |
141 | do_action( 'bp_wdf_reject_terms', $bp->loggedin_user->id );
142 |
143 | return true;
144 | }
145 |
146 | /**
147 | * bp_wdf_send_donation()
148 | *
149 | * Sends a high five message to a user. Registers an notification to the user
150 | * via their notifications menu, as well as sends an email to the user.
151 | *
152 | * Also records an activity stream item saying "User 1 high-fived User 2".
153 | */
154 | function bp_wdf_send_donation( $to_user_id, $from_user_id ) {
155 | global $bp;
156 |
157 | check_admin_referer( 'bp_wdf_send_donation' );
158 |
159 | /**
160 | * We'll store donations as usermeta, so we don't actually need
161 | * to do any database querying. If we did, and we were storing them
162 | * in a custom DB table, we'd want to reference a function in
163 | * bp-wdf-classes.php that would run the SQL query.
164 | */
165 | delete_user_meta( $to_user_id, 'donations' );
166 | /* Get existing fives */
167 | $existing_fives = maybe_unserialize( get_user_meta( $to_user_id, 'donations', true ) );
168 |
169 | /* Check to see if the user has already high-fived. That's okay, but lets not
170 | * store duplicate donations in the database. What's the point, right?
171 | */
172 | if ( !in_array( $from_user_id, (array)$existing_fives ) ) {
173 | $existing_fives[] = (int)$from_user_id;
174 |
175 | /* Now wrap it up and fire it back to the database overlords. */
176 | update_user_meta( $to_user_id, 'donations', serialize( $existing_fives ) );
177 |
178 | // Let's also record it in our custom database tables
179 | $db_args = array(
180 | 'recipient_id' => (int)$to_user_id,
181 | 'funder_id' => (int)$from_user_id
182 | );
183 |
184 | $donation = new BP_WDF_Donation( $db_args );
185 | $donation->save();
186 | }
187 |
188 | /***
189 | * Now we've registered the new high-five, lets work on some notification and activity
190 | * stream magic.
191 | */
192 |
193 | /***
194 | * Post a screen notification to the user's notifications menu.
195 | * Remember, like activity streams we need to tell the activity stream component how to format
196 | * this notification in bp_wdf_format_notifications() using the 'new_donation' action.
197 | */
198 | bp_core_add_notification( $from_user_id, $to_user_id, $bp->wdf->slug, 'new_donation' );
199 |
200 | /* Now record the new 'new_donation' activity item */
201 | $to_user_link = bp_core_get_userlink( $to_user_id );
202 | $from_user_link = bp_core_get_userlink( $from_user_id );
203 |
204 | bp_wdf_record_activity( array(
205 | 'type' => 'rejected_terms',
206 | 'action' => apply_filters( 'bp_wdf_new_donation_activity_action', sprintf( __( '%s supported %s!', 'wdf' ), $from_user_link, $to_user_link ), $from_user_link, $to_user_link ),
207 | 'item_id' => $to_user_id,
208 | ) );
209 |
210 | /* We'll use this do_action call to send the email notification. See bp-wdf-notifications.php */
211 | do_action( 'bp_wdf_send_donation', $to_user_id, $from_user_id );
212 |
213 | return true;
214 | }
215 |
216 | /**
217 | * bp_wdf_get_donations_for_user()
218 | *
219 | * Returns an array of user ID's for users who have high fived the user passed to the function.
220 | */
221 | function bp_wdf_get_donations_for_user( $user_id ) {
222 | global $bp;
223 |
224 | if ( !$user_id )
225 | return false;
226 |
227 | return maybe_unserialize( get_user_meta( $user_id, 'donations', true ) );
228 | }
229 |
230 |
231 | /**
232 | * bp_wdf_remove_data()
233 | *
234 | * It's always wise to clean up after a user is deleted. This stops the database from filling up with
235 | * redundant information.
236 | */
237 | function bp_wdf_remove_data( $user_id ) {
238 | /* You'll want to run a function here that will delete all information from any component tables
239 | for this $user_id */
240 |
241 | /* Remember to remove usermeta for this component for the user being deleted */
242 | delete_user_meta( $user_id, 'bp_wdf_some_setting' );
243 |
244 | do_action( 'bp_wdf_remove_data', $user_id );
245 | }
246 | add_action( 'wpmu_delete_user', 'bp_wdf_remove_data', 1 );
247 | add_action( 'delete_user', 'bp_wdf_remove_data', 1 );
248 |
249 | /***
250 | * Object Caching Support ----
251 | *
252 | * It's a good idea to implement object caching support in your component if it is fairly database
253 | * intensive. This is not a requirement, but it will help ensure your component works better under
254 | * high load environments.
255 | *
256 | * In parts of this wdf component you will see calls to wp_cache_get() often in template tags
257 | * or custom loops where database access is common. This is where cached data is being fetched instead
258 | * of querying the database.
259 | *
260 | * However, you will need to make sure the cache is cleared and updated when something changes. For example,
261 | * the groups component caches groups details (such as description, name, news, number of members etc).
262 | * But when those details are updated by a group admin, we need to clear the group's cache so the new
263 | * details are shown when users view the group or find it in search results.
264 | *
265 | * We know that there is a do_action() call when the group details are updated called 'groups_settings_updated'
266 | * and the group_id is passed in that action. We need to create a function that will clear the cache for the
267 | * group, and then add an action that calls that function when the 'groups_settings_updated' is fired.
268 | *
269 | * Example:
270 | *
271 | * function groups_clear_group_object_cache( $group_id ) {
272 | * wp_cache_delete( 'groups_group_' . $group_id );
273 | * }
274 | * add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' );
275 | *
276 | * The "'groups_group_' . $group_id" part refers to the unique identifier you gave the cached object in the
277 | * wp_cache_set() call in your code.
278 | *
279 | * If this has completely confused you, check the function documentation here:
280 | * http://codex.wordpress.org/Function_Reference/WP_Cache
281 | *
282 | * If you're still confused, check how it works in other BuddyPress components, or just don't use it,
283 | * but you should try to if you can (it makes a big difference). :)
284 | */
285 |
286 | ?>
--------------------------------------------------------------------------------
/lib/bp/bp-wdf-screens.php:
--------------------------------------------------------------------------------
1 | is_directory flag to true, which help other
21 | // content to display content properly on your directory.
22 | bp_update_is_directory( true, 'wdf' );
23 |
24 | // Add an action so that plugins can add content or modify behavior
25 | do_action( 'bp_wdf_directory_setup' );
26 |
27 | bp_core_load_template( apply_filters( 'wdf_directory_template', 'wdf/index' ) );
28 | }
29 | }
30 | add_action( 'bp_screens', 'bp_wdf_directory_setup' );
31 |
32 |
33 | /**
34 | * bp_wdf_screen_one()
35 | *
36 | * Sets up and displays the screen output for the sub nav item "wdf/screen-one"
37 | */
38 | function bp_wdf_screen_one() {
39 | global $bp;
40 |
41 | /**
42 | * There are three global variables that you should know about and you will
43 | * find yourself using often.
44 | *
45 | * $bp->current_component (string)
46 | * This will tell you the current component the user is viewing.
47 | *
48 | * Example: If the user was on the page http://example.org/members/andy/groups/my-groups
49 | * $bp->current_component would equal 'groups'.
50 | *
51 | * $bp->current_action (string)
52 | * This will tell you the current action the user is carrying out within a component.
53 | *
54 | * Example: If the user was on the page: http://example.org/members/andy/groups/leave/34
55 | * $bp->current_action would equal 'leave'.
56 | *
57 | * $bp->action_variables (array)
58 | * This will tell you which action variables are set for a specific action
59 | *
60 | * Example: If the user was on the page: http://example.org/members/andy/groups/join/34
61 | * $bp->action_variables would equal array( '34' );
62 | *
63 | * There are three handy functions you can use for these purposes:
64 | * bp_is_current_component()
65 | * bp_is_current_action()
66 | * bp_is_action_variable()
67 | */
68 |
69 | /* Add a do action here, so your component can be extended by others. */
70 | do_action( 'bp_wdf_screen_one' );
71 |
72 | /****
73 | * Displaying Content
74 | */
75 |
76 | /****
77 | * OPTION 1:
78 | * You've got a few options for displaying content. Your first option is to bundle template files
79 | * with your plugin that will be used to output content.
80 | *
81 | * In an earlier function bp_wdf_load_template_filter() we set up a filter on the core BP template
82 | * loading function that will make it first look in the plugin directory for template files.
83 | * If it doesn't find any matching templates it will look in the active theme directory.
84 | *
85 | * This example component comes bundled with a template for screen one, so we can load that
86 | * template to display what we need. If you copied this template from the plugin into your theme
87 | * then it would load that one instead. This allows users to override templates in their theme.
88 | */
89 |
90 | /* This is going to look in wp-content/plugins/[plugin-name]/includes/templates/ first */
91 | bp_core_load_template( apply_filters( 'bp_wdf_template_screen_one', 'wdf/screen-one' ) );
92 |
93 | /****
94 | * OPTION 2 (NOT USED FOR THIS SCREEN):
95 | * If your component is simple, and you just want to insert some HTML into the user's active theme
96 | * then you can use the bundle plugin template.
97 | *
98 | * There are two actions you need to hook into. One for the title, and one for the content.
99 | * The functions you hook these into should simply output the content you want to display on the
100 | * page.
101 | *
102 | * The follow lines are commented out because we are not using this method for this screen.
103 | * You'd want to remove the OPTION 1 parts above and uncomment these lines if you want to use
104 | * this option instead.
105 | *
106 | * Generally, this method of adding content is preferred, as it makes your plugin
107 | * work better with a wider variety of themes.
108 | */
109 |
110 | // add_action( 'bp_template_title', 'bp_wdf_screen_one_title' );
111 | // add_action( 'bp_template_content', 'bp_wdf_screen_one_content' );
112 |
113 | // bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
114 | }
115 | /***
116 | * The second argument of each of the above add_action() calls is a function that will
117 | * display the corresponding information. The functions are presented below:
118 | */
119 | function bp_wdf_screen_one_title() {
120 | _e( 'Fundraiser Projects', 'wdf' );
121 | }
122 |
123 | function bp_wdf_screen_one_content() {
124 | global $bp;
125 |
126 | $donations = bp_wdf_get_donations_for_user( $bp->displayed_user->id );
127 |
128 | /**
129 | * For security reasons, we MUST use the wp_nonce_url() function on any actions.
130 | * This will stop naughty people from tricking users into performing actions without their
131 | * knowledge or intent.
132 | */
133 | $send_link = wp_nonce_url( $bp->displayed_user->domain . $bp->current_component . '/screen-one/send-donation', 'bp_wdf_send_donation' );
134 | ?>
135 |
136 |