',
317 | esc_attr( $meta_key ),
318 | esc_html( $meta_args['label'] ),
319 | esc_html( $meta_args['description'] )
320 | );
321 | }
322 | }
323 | }
324 | }
325 |
326 | /**
327 | * Prepare the Type's edit form fields for output.
328 | *
329 | * @since 1.1.0
330 | *
331 | * @param WP_Term $term The WP Term object.
332 | * @param string $taxonomy The name of the taxonomy.
333 | * @return string HTML Output.
334 | */
335 | function bptui_admin_type_edit_form_fields( $term = null, $taxonomy = '' ) {
336 | if ( ! isset( $term->name ) || ! $taxonomy ) {
337 | return;
338 | }
339 |
340 | if ( 'bp_group_type' === $taxonomy ) {
341 | $type = null;
342 | if ( bp_is_active( 'groups') ) {
343 | $type = bp_groups_get_group_type_object( $term->name );
344 | }
345 | } else {
346 | $type = bp_get_member_type_object( $term->name );
347 | }
348 |
349 | return bptui_admin_type_form_fields( $taxonomy, $type );
350 | }
351 |
352 | /**
353 | * Insert the registrered by code types not yet added into the DB.
354 | *
355 | * @since 1.1.0
356 | *
357 | * @param string $taxonomoy The Type taxonomy name.
358 | */
359 | function bptui_admin_type_insert_code_registered_types( $taxonomy = '' ) {
360 | if ( 'bp_group_type' === $taxonomy ) {
361 | $all_types = bp_groups_get_group_types( array(), 'objects' );
362 | } else {
363 | $all_types = bp_get_member_types( array(), 'objects' );
364 | }
365 |
366 | $unsaved_types = wp_filter_object_list( $all_types, array( 'db_id' => 0 ), 'and', 'name' );
367 | if ( $unsaved_types ) {
368 | foreach ( $unsaved_types as $type_name ) {
369 | bp_insert_term(
370 | $type_name,
371 | $taxonomy,
372 | array(
373 | 'slug' => $type_name,
374 | )
375 | );
376 | }
377 | }
378 | }
379 |
380 | /**
381 | * Handle BuddyPress types specific admin actions.
382 | *
383 | * @since 1.1.0
384 | */
385 | function bptui_admin_screen_types_load() {
386 | $taxonomy = '';
387 | $member_type_tax_name = bp_get_member_type_tax_name();
388 | $current_screen = get_current_screen();
389 |
390 | if ( ! isset( $current_screen->taxonomy ) || ! $current_screen->taxonomy ) {
391 | return;
392 | }
393 |
394 | $taxonomy = $current_screen->taxonomy;
395 | $screen_id = $current_screen->id;
396 |
397 | if ( $member_type_tax_name !== $taxonomy && 'bp_group_type' !== $taxonomy ) {
398 | return;
399 | }
400 |
401 | if ( isset( $_POST['action'] ) || isset( $_GET['action'] ) ) {
402 | if ( isset( $_GET['action'] ) ) {
403 | $action = wp_unslash( $_GET['action'] );
404 | } else {
405 | $action = wp_unslash( $_POST['action'] );
406 | }
407 |
408 | // Adding a new type into DB.
409 | if ( 'add-tag' === $action ) {
410 | check_admin_referer( 'add-tag', '_wpnonce_add-tag' );
411 |
412 | $referer = wp_get_referer();
413 | $default_args = array(
414 | 'taxonomy' => '',
415 | 'bp_type_id' => '',
416 | 'bp_type_name' => '',
417 | 'bp_type_singular_name' => '',
418 | 'bp_type_has_directory' => 0,
419 | 'bp_type_directory_slug' => '',
420 | 'bp_type_show_in_create_screen' => 0,
421 | 'bp_type_show_in_list' => 0,
422 | );
423 |
424 | $add_type_arguments = wp_parse_args( array_map( 'wp_unslash', $_POST ), $default_args );
425 |
426 | if ( ! $add_type_arguments['bp_type_id'] || ! $add_type_arguments['taxonomy'] ) {
427 | $referer = add_query_arg(
428 | array(
429 | 'message' => 1,
430 | 'error' => 1,
431 | ),
432 | $referer
433 | );
434 |
435 | wp_safe_redirect( $referer );
436 | exit;
437 | }
438 |
439 | $type_id = sanitize_title( $add_type_arguments['bp_type_id'] );
440 | $taxonomy = sanitize_key( $add_type_arguments['taxonomy'] );
441 | $type_exists = false;
442 |
443 | if ( $member_type_tax_name === $taxonomy ) {
444 | $type_exists = ! is_null( bp_get_member_type_object( $type_id ) );
445 | } elseif ( 'bp_group_type' === $taxonomy && bp_is_active( 'groups' ) ) {
446 | $type_exists = ! is_null( bp_groups_get_group_type_object( $type_id ) );
447 | }
448 |
449 | if ( $type_exists ) {
450 | $referer = add_query_arg(
451 | array(
452 | 'message' => 5,
453 | 'error' => 1,
454 | ),
455 | $referer
456 | );
457 |
458 | wp_safe_redirect( $referer );
459 | exit;
460 | }
461 |
462 | unset( $default_args['bp_type_id'], $default_args['taxonomy'] );
463 | $metas = array_filter( array_intersect_key( $add_type_arguments, $default_args ) );
464 |
465 | $tt_id = bp_insert_term(
466 | $type_id,
467 | $taxonomy,
468 | array(
469 | 'slug' => $type_id,
470 | 'metas' => $metas,
471 | )
472 | );
473 |
474 | $result = array( 'message' => 2 );
475 | if ( is_wp_error( $tt_id ) ) {
476 | $result = array(
477 | 'message' => 3,
478 | 'error' => 1,
479 | );
480 | }
481 |
482 | /**
483 | * Hook here to add code once the type has been inserted.
484 | *
485 | * @since 1.1.0
486 | *
487 | * @param integer $type_id The Type's term_ID.
488 | * @param string $taxonomy The Type's taxonomy name.
489 | */
490 | do_action( 'bp_type_inserted', $type_id, $taxonomy );
491 |
492 | wp_safe_redirect( add_query_arg( $result, $referer ) );
493 | exit;
494 |
495 | // Updating an existing type intot the DB.
496 | } elseif ( 'editedtag' === $action ) {
497 | $type_id = 0;
498 | $taxonomy = '';
499 |
500 | if ( isset( $_POST['tag_ID'] ) ) {
501 | $type_id = (int) wp_unslash( $_POST['tag_ID'] );
502 | }
503 |
504 | if ( isset( $_POST['taxonomy'] ) ) {
505 | $taxonomy = wp_unslash( $_POST['taxonomy'] );
506 | }
507 |
508 | check_admin_referer( 'update-tag_' . $type_id );
509 |
510 | $referer = wp_get_referer();
511 | $default_args = array(
512 | 'bp_type_name' => '',
513 | 'bp_type_singular_name' => '',
514 | 'bp_type_has_directory' => 0,
515 | 'bp_type_directory_slug' => '',
516 | );
517 |
518 | if ( 'bp_group_type' === $taxonomy ) {
519 | $default_args = array_merge(
520 | $default_args,
521 | array(
522 | 'bp_type_show_in_create_screen' => 0,
523 | 'bp_type_show_in_list' => 0,
524 | )
525 | );
526 | }
527 |
528 | $update_meta_arguments = wp_parse_args( array_map( 'wp_unslash', $_POST ), $default_args );
529 | $all_meta_keys = array_fill_keys( array_keys( $default_args ), true );
530 | $update_meta_arguments = array_intersect_key( $update_meta_arguments, $all_meta_keys );
531 |
532 | foreach ( $update_meta_arguments as $meta_key => $meta_value ) {
533 | if ( '' === $meta_value ) {
534 | delete_term_meta( $type_id, $meta_key );
535 | } else {
536 | update_term_meta( $type_id, $meta_key, $meta_value );
537 | }
538 | }
539 |
540 | /**
541 | * Hook here to add code once the type has been updated.
542 | *
543 | * @since 1.1.0
544 | *
545 | * @param integer $type_id The Type's term_ID.
546 | * @param string $taxonomy The Type's taxonomy name.
547 | */
548 | do_action( 'bp_type_updated', $type_id, $taxonomy );
549 |
550 | wp_safe_redirect( add_query_arg( 'message', 4, $referer ) );
551 | exit;
552 |
553 | // Deletes a type.
554 | } elseif ( 'delete' === $action ) {
555 | $type_id = 0;
556 | $taxonomy = '';
557 |
558 | if ( isset( $_GET['tag_ID'] ) ) {
559 | $type_id = (int) wp_unslash( $_GET['tag_ID'] );
560 | }
561 |
562 | if ( isset( $_GET['taxonomy'] ) ) {
563 | $taxonomy = wp_unslash( $_GET['taxonomy'] );
564 | }
565 |
566 | check_admin_referer( 'delete-tag_' . $type_id );
567 |
568 | $type = bp_get_term_by( 'id', $type_id, $taxonomy );
569 | $referer = wp_get_referer();
570 |
571 | if ( ! $type ) {
572 | $referer = add_query_arg(
573 | array(
574 | 'message' => 6,
575 | 'error' => 1,
576 | ),
577 | $referer
578 | );
579 |
580 | wp_safe_redirect( $referer );
581 | exit;
582 | }
583 |
584 | // Get the "registered by code" types.
585 | $registered_by_code_types = bptui_get_types_registered_by_code( $taxonomy );
586 | if ( isset( $registered_by_code_types[ $type->name ] ) ) {
587 | $referer = add_query_arg(
588 | array(
589 | 'message' => 7,
590 | 'error' => 1,
591 | ),
592 | $referer
593 | );
594 |
595 | wp_safe_redirect( $referer );
596 | exit;
597 | }
598 |
599 | $deleted = bp_delete_term( $type->term_id, $taxonomy );
600 |
601 | if ( true !== $deleted ) {
602 | $referer = add_query_arg(
603 | array(
604 | 'message' => 8,
605 | 'error' => 1,
606 | ),
607 | $referer
608 | );
609 |
610 | wp_safe_redirect( $referer );
611 | exit;
612 | }
613 |
614 | /**
615 | * Hook here to add code once the type has been deleted.
616 | *
617 | * @since 1.1.0
618 | *
619 | * @param integer $type_id The Type's term_ID.
620 | * @param string $taxonomy The Type's taxonomy name.
621 | */
622 | do_action( 'bp_type_deleted', $type_id, $taxonomy );
623 |
624 | wp_safe_redirect( add_query_arg( 'message', 9, $referer ) );
625 | exit;
626 | }
627 | }
628 |
629 | // Customize the WP Terms UI.
630 | add_action( 'admin_enqueue_scripts', 'bptui_admin_screen_types_enqueue_scripts' );
631 | add_action( 'admin_head-edit-tags.php', 'bptui_admin_screen_types_head' );
632 | add_action( 'admin_head-term.php', 'bptui_admin_screen_types_head' );
633 | add_action( "{$taxonomy}_add_form_fields", 'bptui_admin_type_form_fields', 10, 1 );
634 | add_action( "{$taxonomy}_edit_form_fields", 'bptui_admin_type_edit_form_fields', 10, 2 );
635 | add_action( "{$current_screen->taxonomy}_add_form", 'bptui_admin_type_insert_code_registered_types', 10, 1 );
636 | add_filter( "manage_{$screen_id}_columns", 'bptui_admin_list_table_column_headers', 10, 1 );
637 | add_filter( "manage_{$taxonomy}_custom_column", 'bptui_admin_list_table_column_content', 10, 3 );
638 | add_filter( "{$taxonomy}_row_actions", 'bptui_admin_list_table_row_actions', 10, 2 );
639 | add_filter( "bulk_actions-{$screen_id}", '__return_empty_array', 10, 1 );
640 | }
641 | add_action( 'load-edit-tags.php', 'bptui_admin_screen_types_load' );
642 |
643 | /**
644 | * Redirects the user ot the Goups network admin screen when BuddyPress is network activated.
645 | *
646 | * @since 1.1.0
647 | */
648 | function bptui_group_admin_menu_callback_load() {
649 | wp_safe_redirect( add_query_arg( 'page', 'bp-groups', network_admin_url( 'admin.php' ) ) );
650 | exit();
651 | }
652 |
653 | /**
654 | * Root blog's Groups Admin Screen callback function used when BuddyPress is network activated.
655 | *
656 | * @since 1.1.0
657 | */
658 | function bptui_group_admin_menu_callback() {
659 | return;
660 | }
661 |
662 | /**
663 | * Create Admin submenus for BuddyPress types.
664 | *
665 | * @since 1.1.0
666 | */
667 | function bptui_admin_menu() {
668 | if ( ! bp_is_root_blog() ) {
669 | return;
670 | }
671 |
672 | if ( bp_is_network_activated() ) {
673 | if ( is_network_admin() ) {
674 | // Adds a users.php submenu to go to the root blog Member types screen.
675 | $member_type_admin_url = add_query_arg( 'taxonomy', bp_get_member_type_tax_name(), get_admin_url( bp_get_root_blog_id(), 'edit-tags.php' ) );
676 |
677 | add_submenu_page(
678 | 'users.php',
679 | __( 'Member types', 'bp-types-ui' ),
680 | __( 'Member types', 'bp-types-ui' ),
681 | 'bp_moderate',
682 | esc_url( $member_type_admin_url )
683 | );
684 |
685 | // Adds a 'bp-groups' submenu to go to the root blog Group types screen.
686 | $group_type_admin_url = add_query_arg( 'taxonomy', 'bp_group_type', get_admin_url( bp_get_root_blog_id(), 'edit-tags.php' ) );
687 | add_submenu_page(
688 | 'bp-groups',
689 | __( 'Group types', 'bp-types-ui' ),
690 | __( 'Group types', 'bp-types-ui' ),
691 | 'bp_moderate',
692 | esc_url( $group_type_admin_url )
693 | );
694 | } elseif ( bp_is_active( 'groups' ) ) {
695 | // Adds a 'bp-groups' menu to the root blog menu.
696 | $redirect_hook = add_menu_page(
697 | _x( 'Groups', 'Admin Groups page title', 'buddypress' ),
698 | _x( 'Groups', 'Admin Groups menu', 'buddypress' ),
699 | 'bp_moderate',
700 | 'bp-groups',
701 | 'bptui_group_admin_menu_callback',
702 | 'div'
703 | );
704 |
705 | add_action( "load-{$redirect_hook}", 'bptui_group_admin_menu_callback_load' );
706 | }
707 | }
708 |
709 | if ( ! is_network_admin() ) {
710 | add_submenu_page(
711 | 'users.php',
712 | __( 'Member types', 'bp-types-ui' ),
713 | __( 'Member types', 'bp-types-ui' ),
714 | 'bp_moderate',
715 | basename( add_query_arg( 'taxonomy', bp_get_member_type_tax_name(), bp_get_admin_url( 'edit-tags.php' ) ) )
716 | );
717 |
718 | if ( bp_is_active( 'groups' ) ) {
719 | add_submenu_page(
720 | 'bp-groups',
721 | __( 'Group types', 'bp-types-ui' ),
722 | __( 'Group types', 'bp-types-ui' ),
723 | 'bp_moderate',
724 | basename( add_query_arg( 'taxonomy', 'bp_group_type', bp_get_admin_url( 'edit-tags.php' ) ) )
725 | );
726 | }
727 | }
728 | }
729 | add_action( 'bp_admin_menu', 'bptui_admin_menu' );
730 |
--------------------------------------------------------------------------------
/includes/bp-core-taxonomy.php:
--------------------------------------------------------------------------------
1 | 'members',
33 | 'bp_group_type' => 'groups',
34 | );
35 |
36 | if ( ! isset( $taxonomies[ $type_tax ] ) ) {
37 | return false;
38 | }
39 |
40 | if ( isset( $args['label'] ) ) {
41 | unset( $args['label'] );
42 | }
43 |
44 | // register_term_meta() was introduced in WP 4.9.8.
45 | if ( ! function_exists( 'register_term_meta' ) ) {
46 | $args['object_subtype'] = $type_tax;
47 |
48 | return register_meta( 'term', $meta_key, $args );
49 | }
50 |
51 | return register_term_meta( $type_tax, $meta_key, $args );
52 | }
53 |
54 | /**
55 | * Add a new taxonomy term to the database.
56 | *
57 | * @since 7.0.0
58 | *
59 | * @param string $term The term name to add or update.
60 | * @param string $taxonomy The taxonomy to which to add the term.
61 | * @param array|string $args {
62 | * Optional. Array or string of arguments for inserting a term.
63 | * @type string $description The term description. Default empty string.
64 | * @type string $slug The term slug to use. Default empty string.
65 | * @type array $metas The term metas to add. Default empty array.
66 | * }
67 | * @return array|WP_Error An array containing the `term_id` and `term_taxonomy_id`,
68 | * WP_Error otherwise.
69 | */
70 | function bp_insert_term( $term, $taxonomy = '', $args = array() ) {
71 | if ( ! taxonomy_exists( $taxonomy ) ) {
72 | return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.', 'buddypress' ) );
73 | }
74 |
75 | $site_id = bp_get_taxonomy_term_site_id( $taxonomy );
76 |
77 | $switched = false;
78 | if ( $site_id !== get_current_blog_id() ) {
79 | switch_to_blog( $site_id );
80 | bp_register_taxonomies();
81 | $switched = true;
82 | }
83 |
84 | $term_metas = array();
85 | if ( isset( $args['metas'] ) ) {
86 | $term_metas = (array) $args['metas'];
87 | unset( $args['metas'] );
88 | }
89 |
90 | $tt_id = wp_insert_term( $term, $taxonomy, $args );
91 |
92 | if ( is_wp_error( $tt_id ) ) {
93 | return $tt_id;
94 | }
95 |
96 | $term_id = reset( $tt_id );
97 |
98 | if ( $term_metas ) {
99 | foreach ( $term_metas as $meta_key => $meta_value ) {
100 | if ( ! registered_meta_key_exists( 'term', $meta_key, $taxonomy ) ) {
101 | continue;
102 | }
103 |
104 | update_term_meta( $term_id, $meta_key, $meta_value );
105 | }
106 | }
107 |
108 | if ( $switched ) {
109 | restore_current_blog();
110 | }
111 |
112 | /**
113 | * Fires when taxonomy terms have been set on BuddyPress objects.
114 | *
115 | * @since 7.0.0
116 | *
117 | * @param array $tt_ids An array containing the `term_id` and `term_taxonomy_id`.
118 | * @param string $taxonomy Taxonomy name.
119 | * @param array $term_metas The term metadata.
120 | */
121 | do_action( 'bp_insert_term', $tt_id, $taxonomy, $term_metas );
122 |
123 | return $tt_id;
124 | }
125 |
126 | /**
127 | * Get taxonomy terms from the database.
128 | *
129 | * @since 7.0.0
130 | *
131 | * @param array $args {
132 | * Array of arguments to query terms.
133 | * @see `get_terms()` for full description of arguments in case of a member type.
134 | * }
135 | * @return array The list of terms matching arguments.
136 | */
137 | function bp_get_terms( $args = array() ) {
138 | $args = wp_parse_args(
139 | $args,
140 | array(
141 | 'taxonomy' => '',
142 | 'number' => '',
143 | 'hide_empty' => false,
144 | )
145 | );
146 |
147 | if ( ! $args['taxonomy'] ) {
148 | return array();
149 | }
150 |
151 | $site_id = bp_get_taxonomy_term_site_id( $args['taxonomy'] );
152 |
153 | $switched = false;
154 | if ( $site_id !== get_current_blog_id() ) {
155 | switch_to_blog( $site_id );
156 | bp_register_taxonomies();
157 | $switched = true;
158 | }
159 |
160 | $terms = get_terms( $args );
161 |
162 | if ( $switched ) {
163 | restore_current_blog();
164 | }
165 |
166 | return $terms;
167 | }
168 |
169 | /**
170 | * Deletes a term.
171 | *
172 | * @since 7.0.0
173 | *
174 | * @param int $term Term ID. Required.
175 | * @param string $taxonomy Taxonomy Name. Required.
176 | * @return bool|WP_Error True on success, WP_Error on failure.
177 | */
178 | function bp_delete_term( $term_id = 0, $taxonomy = '' ) {
179 | if ( ! $term_id || ! $taxonomy ) {
180 | return new WP_Error( 'missing_arguments', __( 'Sorry, the term ID and the taxonomy are required arguments.', 'buddypress' ) );
181 | }
182 |
183 | $site_id = bp_get_taxonomy_term_site_id( $taxonomy );
184 |
185 | $switched = false;
186 | if ( $site_id !== get_current_blog_id() ) {
187 | switch_to_blog( $site_id );
188 | bp_register_taxonomies();
189 | $switched = true;
190 | }
191 |
192 | $deleted = wp_delete_term( $term_id, $taxonomy );
193 |
194 | if ( $switched ) {
195 | restore_current_blog();
196 | }
197 |
198 | if ( is_wp_error( $deleted ) ) {
199 | return $deleted;
200 | }
201 |
202 | if ( false === $deleted ) {
203 | return new WP_Error( 'inexistant_term', __( 'Sorry, the term does not exist.', 'buddypress' ) );
204 | }
205 |
206 | if ( 0 === $deleted ) {
207 | return new WP_Error( 'default_term', __( 'Sorry, the default term cannot be deleted.', 'buddypress' ) );
208 | }
209 |
210 | return $deleted;
211 | }
212 |
--------------------------------------------------------------------------------
/includes/css/bp-types-admin.css:
--------------------------------------------------------------------------------
1 | // Add header-like spacing and emphasis to feidlsets.
2 | .inside fieldset {
3 | margin: 1.33em 0;
4 | }
5 | .inside fieldset legend {
6 | font-weight: 600;
7 | }
8 | .wp-editor-area {
9 | height: 150px;
10 | width: 100%;
11 | }
12 |
--------------------------------------------------------------------------------
/includes/functions.php:
--------------------------------------------------------------------------------
1 | false,
26 | 'show_in_rest' => false,
27 | 'query_var' => false,
28 | 'rewrite' => false,
29 | 'show_in_menu' => false,
30 | 'show_tagcloud' => false,
31 | 'show_ui' => bp_is_root_blog() && bp_current_user_can( 'bp_moderate' ),
32 | );
33 |
34 | $member_type_tax_name = bp_get_member_type_tax_name();
35 | $taxonomy_args[ $member_type_tax_name ] = array_merge(
36 | $common_args,
37 | array(
38 | 'description' => _x( 'BuddyPress Member types', 'Member type taxonomy description', 'bp-types-ui' ),
39 | 'labels' => array(
40 | 'name' => _x( 'Member types', 'Member type taxonomy name', 'bp-types-ui' ),
41 | 'singular_name' => _x( 'Member type', 'Member type taxonomy singular name', 'bp-types-ui' ),
42 | 'search_items' => _x( 'Search Member types', 'Member type taxonomy search items label', 'bp-types-ui' ),
43 | 'popular_items' => _x( 'Most used Member types', 'Member type taxonomy popular items label', 'bp-types-ui' ),
44 | 'all_items' => _x( 'All Member types', 'Member type taxonomy all items label', 'bp-types-ui' ),
45 | 'edit_item' => _x( 'Edit Member type', 'Member type taxonomy edit item label', 'bp-types-ui' ),
46 | 'view_item' => _x( 'View Member type', 'Member type taxonomy view item label', 'bp-types-ui' ),
47 | 'update_item' => _x( 'Update Member type', 'Member type taxonomy update item label', 'bp-types-ui' ),
48 | 'add_new_item' => _x( 'Add new Member type', 'Member type taxonomy add new item label', 'bp-types-ui' ),
49 | 'new_item_name' => _x( 'New Member type name', 'Member type taxonomy new item name label', 'bp-types-ui' ),
50 | 'separate_items_with_commas' => _x( 'Separate Member types with commas', 'Member type taxonomy separate items with commas label', 'bp-types-ui' ),
51 | 'add_or_remove_items' => _x( 'Add or remove Member types', 'Member type taxonomy add or remove items label', 'bp-types-ui' ),
52 | 'choose_from_most_used' => _x( 'Choose from the most used Member types', 'Member type taxonomy choose from most used label', 'bp-types-ui' ),
53 | 'not_found' => _x( 'No Member types found', 'Member type taxonomy not found label', 'bp-types-ui' ),
54 | 'no_terms' => _x( 'No Member types', 'Member type taxonomy no terms label', 'bp-types-ui' ),
55 | 'items_list_navigation' => _x( 'Member types list navigation', 'Member type taxonomy items list navigation label', 'bp-types-ui' ),
56 | 'items_list' => _x( 'Member types list', 'Member type taxonomy items list label', 'bp-types-ui' ),
57 | 'back_to_items' => _x( 'Back to all Member types', 'Member type taxonomy back to items label', 'bp-types-ui' ),
58 | ),
59 | /**
60 | * 'show_in_rest' should be true.
61 | * 'rest_base' should be set.
62 | * 'rest_controller_class' should be handle into the BP REST API.
63 | */
64 | )
65 | );
66 |
67 | $taxonomy_args['bp_group_type'] = array_merge(
68 | $common_args,
69 | array(
70 | 'description' => _x( 'BuddyPress Groyp types', 'Group type taxonomy description', 'bp-types-ui' ),
71 | 'labels' => array(
72 | 'name' => _x( 'Group types', 'Group type taxonomy name', 'bp-types-ui' ),
73 | 'singular_name' => _x( 'Group type', 'Group type taxonomy singular name', 'bp-types-ui' ),
74 | 'search_items' => _x( 'Search Group types', 'Group type taxonomy search items label', 'bp-types-ui' ),
75 | 'popular_items' => _x( 'Most used Group types', 'Group type taxonomy popular items label', 'bp-types-ui' ),
76 | 'all_items' => _x( 'All Group types', 'Group type taxonomy all items label', 'bp-types-ui' ),
77 | 'edit_item' => _x( 'Edit Group type', 'Group type taxonomy edit item label', 'bp-types-ui' ),
78 | 'view_item' => _x( 'View Group type', 'Group type taxonomy view item label', 'bp-types-ui' ),
79 | 'update_item' => _x( 'Update Group type', 'Group type taxonomy update item label', 'bp-types-ui' ),
80 | 'add_new_item' => _x( 'Add new Group type', 'Group type taxonomy add new item label', 'bp-types-ui' ),
81 | 'new_item_name' => _x( 'New Group type name', 'Group type taxonomy new item name label', 'bp-types-ui' ),
82 | 'separate_items_with_commas' => _x( 'Separate Group types with commas', 'Group type taxonomy separate items with commas label', 'bp-types-ui' ),
83 | 'add_or_remove_items' => _x( 'Add or remove Group types', 'Group type taxonomy add or remove items label', 'bp-types-ui' ),
84 | 'choose_from_most_used' => _x( 'Choose from the most used Group types', 'Group type taxonomy choose from most used label', 'bp-types-ui' ),
85 | 'not_found' => _x( 'No Group types found', 'Group type taxonomy not found label', 'bp-types-ui' ),
86 | 'no_terms' => _x( 'No Group types', 'Group type taxonomy no terms label', 'bp-types-ui' ),
87 | 'items_list_navigation' => _x( 'Group types list navigation', 'Group type taxonomy items list navigation label', 'bp-types-ui' ),
88 | 'items_list' => _x( 'Group types list', 'Group type taxonomy items list label', 'bp-types-ui' ),
89 | 'back_to_items' => _x( 'Back to all Group types', 'Group type taxonomy back to items label', 'bp-types-ui' ),
90 | )
91 | /**
92 | * 'show_in_rest' should be true.
93 | * 'rest_base' should be set.
94 | * 'rest_controller_class' should be handle into the BP REST API.
95 | */
96 | )
97 | );
98 |
99 | if ( ! isset( $taxonomy_args[ $taxonomy_name ] ) ) {
100 | return array();
101 | }
102 |
103 | return $taxonomy_args[ $taxonomy_name ];
104 | }
105 |
106 | /**
107 | * Get the BuddyPress type meta arguments.
108 | *
109 | * @since 1.1.0
110 | *
111 | * @param string $type The type name.
112 | * @return array The BuddyPress type meta arguments.
113 | */
114 | function bptui_get_bp_type_meta_args( $type = '' ) {
115 | $meta_args = array(
116 | 'bp_type_name' => array(
117 | 'label' => __( 'Name', 'bp-types-ui' ),
118 | 'description' => __( 'The name of your type, at the plural form.', 'bp-types-ui' ),
119 | 'type' => 'string',
120 | 'single' => true,
121 | 'sanitize_callback' => 'sanitize_text_field',
122 | ),
123 | 'bp_type_singular_name' => array(
124 | 'label' => __( 'Singular name', 'bp-types-ui' ),
125 | 'description' => __( 'The name of your type, at the singular form.', 'bp-types-ui' ),
126 | 'type' => 'string',
127 | 'single' => true,
128 | 'sanitize_callback' => 'sanitize_text_field',
129 | ),
130 | 'bp_type_has_directory' => array(
131 | 'label' => __( 'Add Type-Filtered Directory View', 'bp-types-ui' ),
132 | 'description' => __( 'Add a list of members matching the member type available on the Members Directory page (e.g. site.url/members/type/teacher/).', 'bp-types-ui' ),
133 | 'type' => 'boolean',
134 | 'single' => true,
135 | 'sanitize_callback' => 'absint',
136 | ),
137 | 'bp_type_directory_slug' => array(
138 | 'label' => __( 'Custom type directory slug', 'bp-types-ui' ),
139 | 'description' => __( 'If you want to use a slug that is different from the Member Type ID above, enter it here.', 'bp-types-ui' ),
140 | 'type' => 'string',
141 | 'single' => true,
142 | 'sanitize_callback' => 'sanitize_title',
143 | ),
144 | );
145 |
146 | if ( 'bp_group_type' === $type ) {
147 | $meta_args['bp_type_has_directory']['description'] = __( 'Add a list of groups matching the member type available on the Groups Directory page (e.g. site.url/groups/type/ninja/).', 'bp-types-ui' );
148 | $meta_args['bp_type_directory_slug']['description'] = __( 'If you want to use a slug that is different from the Group Type ID above, enter it here.', 'bp-types-ui' );
149 |
150 | $meta_args = array_merge(
151 | $meta_args,
152 | array(
153 | 'bp_type_show_in_create_screen' => array(
154 | 'label' => __( 'Add to Available Types on Create Screen', 'bp-types-ui' ),
155 | 'description' => __( 'Include this group type during group creation and when a group administrator is on the group’s “Manage > Settings” page.', 'bp-types-ui' ),
156 | 'type' => 'boolean',
157 | 'single' => true,
158 | 'sanitize_callback' => 'absint',
159 | ),
160 | 'bp_type_show_in_list' => array(
161 | 'label' => __( 'Include when Group Types are Listed for a Group', 'bp-types-ui' ),
162 | 'description' => __( 'Include this group type when group types are listed, like in the group header.', 'bp-types-ui' ),
163 | 'type' => 'boolean',
164 | 'single' => true,
165 | 'sanitize_callback' => 'absint',
166 | ),
167 | )
168 | );
169 | }
170 |
171 | return $meta_args;
172 | }
173 |
174 | /**
175 | * Set BuddyPress type taxonomies arguments.
176 | *
177 | * @since 1.1.0
178 | */
179 | function bptui_set_bp_type_taxonomy_args( $args = array(), $taxonomy_name = '' ) {
180 | if ( bp_get_member_type_tax_name() !== $taxonomy_name && 'bp_group_type' !== $taxonomy_name ) {
181 | return $args;
182 | }
183 |
184 | return bptui_get_bp_type_taxonomy_args( $taxonomy_name );
185 | }
186 | add_filter( 'register_taxonomy_args', 'bptui_set_bp_type_taxonomy_args', 10, 2 );
187 |
188 | /**
189 | * Registers BuddyPress type taxonomies metadata.
190 | *
191 | * @since 1.1.0
192 | */
193 | function bptui_register_type_taxonomies_metadata() {
194 | $type_taxonomies = array( bp_get_member_type_tax_name() );
195 |
196 | if ( bp_is_active( 'groups') ) {
197 | $type_taxonomies[] = 'bp_group_type';
198 | }
199 |
200 | foreach ( $type_taxonomies as $type_taxonomy ) {
201 | foreach ( bptui_get_bp_type_meta_args( $type_taxonomy ) as $meta_key => $meta_args ) {
202 | bp_register_type_meta( $type_taxonomy, $meta_key, $meta_args );
203 | }
204 | }
205 | }
206 | add_action( 'bp_register_taxonomies', 'bptui_register_type_taxonomies_metadata', 11 );
207 |
208 | /**
209 | * Adds a `code` property set to true for object type registered using code.
210 | *
211 | * @since 1.0.0
212 | *
213 | * @param array $args {
214 | * Array of arguments describing the object type.
215 | * @see `bp_register_member_type()` for full description of arguments in case of a member type.
216 | * @see `bp_groups_register_group_type()` for full description of arguments in case of a group type.
217 | * }
218 | * @return array Arguments describing the object type.
219 | */
220 | function bptui_set_registered_by_code_property( $args = array() ) {
221 | $args['code'] = true;
222 | $args['db_id'] = 0;
223 | return $args;
224 | }
225 | add_filter( 'bp_after_register_member_type_parse_args', 'bptui_set_registered_by_code_property', 0, 1 );
226 | add_filter( 'bp_after_register_group_type_parse_args', 'bptui_set_registered_by_code_property', 0, 1 );
227 |
228 | /**
229 | * Gets the registered by code types only.
230 | *
231 | * @since 1.1.0
232 | *
233 | * @param string $taxonomy The taxonomy to get types from.
234 | * @return array The registered by code types.
235 | */
236 | function bptui_get_types_registered_by_code( $taxonomy = '' ) {
237 | $callbacks = array(
238 | bp_get_member_type_tax_name() => 'bp_get_member_types',
239 | 'bp_group_type' => 'bp_groups_get_group_types',
240 | );
241 |
242 | if ( ! isset( $callbacks[ $taxonomy ] ) ) {
243 | return array();
244 | }
245 |
246 | return call_user_func_array(
247 | $callbacks[ $taxonomy ],
248 | array(
249 | 'args' => array(
250 | 'code' => true
251 | ),
252 | 'output' => 'objects',
253 | )
254 | );
255 | }
256 |
257 | /**
258 | * Add a cache group for Database object types.
259 | *
260 | * @since 1.1.0
261 | */
262 | function bptui_set_object_type_terms_cache_group() {
263 | wp_cache_add_global_groups( 'bp_object_terms' );
264 | }
265 | add_action( 'bp_setup_cache_groups', 'bptui_set_object_type_terms_cache_group' );
266 |
267 | /**
268 | * Clear the Database object types cache.
269 | *
270 | * @since 2.2.0
271 | *
272 | * @param int $type_id The Type's term ID.
273 | * @param string $taxonomy The Type's taxonomy name.
274 | */
275 | function bptui_clear_object_type_terms_cache( $type_id = 0, $taxonomy = '' ) {
276 | wp_cache_delete( $taxonomy, 'bp_object_terms' );
277 | }
278 | add_action( 'bp_type_inserted', 'bptui_clear_object_type_terms_cache' );
279 | add_action( 'bp_type_updated', 'bptui_clear_object_type_terms_cache' );
280 | add_action( 'bp_type_deleted', 'bptui_clear_object_type_terms_cache' );
281 |
282 | /**
283 | * Transform saved terms for the taxonomy in corresponding types.
284 | *
285 | * @since 1.1.0
286 | *
287 | * @param string $taxonomy The taxonomy to transform terms in types for.
288 | * @param array $types The registered by code types.
289 | * @return array DB/code Merged types.
290 | */
291 | function bptui_set_types_from_terms( $taxonomy = '', $types = array() ) {
292 | if ( ! $taxonomy ) {
293 | return $types;
294 | }
295 |
296 | $db_types = wp_cache_get( $taxonomy, 'bp_object_terms' );
297 |
298 | if ( ! $db_types ) {
299 | $terms = bp_get_terms(
300 | array(
301 | 'taxonomy' => $taxonomy,
302 | )
303 | );
304 |
305 | if ( ! is_array( $terms ) ) {
306 | return $types;
307 | }
308 |
309 | $metas = array_keys( bptui_get_bp_type_meta_args( $taxonomy ) );
310 |
311 | foreach ( $terms as $term ) {
312 | $type_name = $term->name;
313 | $db_types[ $type_name ] = new stdClass();
314 | $db_types[ $type_name ]->db_id = $term->term_id;
315 | $db_types[ $type_name ]->labels = array();
316 | $db_types[ $type_name ]->name = $type_name;
317 |
318 |
319 | foreach ( $metas as $meta_key ) {
320 | $type_key = str_replace( 'bp_type_', '', $meta_key );
321 | if ( in_array( $type_key, array( 'name', 'singular_name' ), true ) ) {
322 | $db_types[ $type_name ]->labels[ $type_key ] = get_term_meta( $term->term_id, $meta_key, true );
323 | } else {
324 | $db_types[ $type_name ]->{$type_key} = get_term_meta( $term->term_id, $meta_key, true );
325 | }
326 | }
327 | }
328 |
329 | wp_cache_set( $taxonomy, $db_types, 'bp_object_terms' );
330 | }
331 |
332 |
333 | if ( is_array( $db_types ) ) {
334 | foreach ( $db_types as $db_type_name => $db_type ) {
335 | // Override props of registered by code types if customized by the admun user.
336 | if ( isset( $types[ $db_type_name ] ) && isset( $types[ $db_type_name ]->code ) && $types[ $db_type_name ]->code ) {
337 | // Merge Labels.
338 | if ( $db_type->labels ) {
339 | foreach ( $db_type->labels as $key_label => $value_label ) {
340 | if ( '' !== $value_label ) {
341 | $types[ $db_type_name ]->labels[ $key_label ] = $value_label;
342 | }
343 | }
344 | }
345 |
346 | // Merge other properties.
347 | foreach ( get_object_vars( $types[ $db_type_name ] ) as $key_prop => $value_prop ) {
348 | if ( 'labels' === $key_prop || 'name' === $key_prop ) {
349 | continue;
350 | }
351 |
352 | if ( isset( $db_type->{$key_prop} ) && '' !== $db_type->{$key_prop} ) {
353 | $types[ $db_type_name ]->{$key_prop} = $db_type->{$key_prop};
354 | }
355 | }
356 |
357 | unset( $db_types[ $db_type_name ] );
358 | }
359 | }
360 | }
361 |
362 | return array_merge( $types, (array) $db_types );
363 | }
364 |
365 | /**
366 | * Filters the `bp_get_member_types()` function to include member types added via DB insertion.
367 | *
368 | * @since 1.1.0
369 | *
370 | * @param array $types List of Member type objects, keyed by name.
371 | * @param array $args Array of key=>value arguments for filtering.
372 | * @param string $operator 'or' to match any of $args, 'and' to require all.
373 | * @return array The complete list of Member type objects, keyed by name.
374 | */
375 | function bptui_get_all_member_types( $types = array(), $args = array(), $operator = 'and' ) {
376 | if ( isset( $args['code'] ) && true === $args['code'] ) {
377 | return $types;
378 | }
379 |
380 | $types = bptui_set_types_from_terms( bp_get_member_type_tax_name(), $types );
381 |
382 | // Filter the list if needed.
383 | if ( array_filter( $args ) ) {
384 | $types = wp_filter_object_list( $types, $args, $operator );
385 | }
386 |
387 | return $types;
388 | }
389 | add_filter( 'bp_get_member_types', 'bptui_get_all_member_types', 10, 3 );
390 |
391 | /**
392 | * Filters the `bp_groups_get_group_types()` function to include group types added via DB insertion.
393 | *
394 | * @since 1.1.0
395 | *
396 | * @param array $types List of Group type objects, keyed by name.
397 | * @param array $args Array of key=>value arguments for filtering.
398 | * @param string $operator 'or' to match any of $args, 'and' to require all.
399 | * @return array The complete list of Group type objects, keyed by name.
400 | */
401 | function bptui_get_all_group_types( $types = array(), $args = array(), $operator = 'and' ) {
402 | if ( isset( $args['code'] ) && true === $args['code'] ) {
403 | return $types;
404 | }
405 |
406 | $types = bptui_set_types_from_terms( 'bp_group_type', $types );
407 |
408 | // Filter the list if needed.
409 | if ( array_filter( $args ) ) {
410 | $types = wp_filter_object_list( $types, $args, $operator );
411 | }
412 |
413 | return $types;
414 | }
415 | add_filter( 'bp_groups_get_group_types', 'bptui_get_all_group_types', 10, 3 );
416 |
--------------------------------------------------------------------------------
/includes/js/bp-types-admin.js:
--------------------------------------------------------------------------------
1 | ( function() {
2 | var bpTypesCustomizeForm = function() {
3 | if ( document.querySelector( '#addtag input[name="post_type"]' ) ) {
4 | document.querySelector( '#addtag input[name="post_type"]' ).remove();
5 | }
6 |
7 | if ( document.querySelectorAll( '.form-field' ) ) {
8 | document.querySelectorAll( '.form-field' ).forEach( function( element ) {
9 | if ( -1 === element.classList.value.indexOf( 'bp-types-form' ) ) {
10 | element.remove();
11 | }
12 | } );
13 | }
14 |
15 | if ( document.querySelector( '#bp_type_has_directory' ) ) {
16 | if ( true === document.querySelector( '#bp_type_has_directory' ).checked ) {
17 | document.querySelector( '.term-bp_type_directory_slug-wrap' ).classList.add( 'bp-set-directory-slug' );
18 | }
19 |
20 | document.querySelector( '#bp_type_has_directory' ).addEventListener( 'change', function( event ) {
21 | if ( true === event.target.checked ) {
22 | document.querySelector( '.term-bp_type_directory_slug-wrap' ).classList.add( 'bp-set-directory-slug' );
23 | document.querySelector( '#bp_type_directory_slug' ).removeAttribute( 'disabled' );
24 | } else {
25 | document.querySelector( '.term-bp_type_directory_slug-wrap' ).classList.remove( 'bp-set-directory-slug' );
26 | document.querySelector( '#bp_type_directory_slug' ).setAttribute( 'disabled', 'disabled' );
27 | }
28 | } );
29 | }
30 |
31 | if ( document.querySelector( '#delete-link' ) ) {
32 | document.querySelector( '#delete-link' ).remove();
33 | }
34 | };
35 |
36 | if ( 'loading' === document.readyState ) {
37 | document.addEventListener( 'DOMContentLoaded', bpTypesCustomizeForm );
38 | } else {
39 | bpTypesCustomizeForm;
40 | }
41 | } )();
42 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/loader.php:
--------------------------------------------------------------------------------
1 |