Changeset 1063182
- Timestamp:
- 01/08/2015 02:49:08 PM (11 years ago)
- Location:
- enzymes/trunk
- Files:
-
- 3 edited
-
src/Enzymes3.php (modified) (6 diffs)
-
src/EnzymesPlugin.php (modified) (2 diffs)
-
tests/test-Enzymes3.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
enzymes/trunk/src/Enzymes3.php
r1063090 r1063182 5 5 class Enzymes3 6 6 { 7 const PREFIX = 'enzymes.'; 8 7 9 static public 8 10 function capabilities() 9 11 { 12 //@Formatter:off 10 13 $result = array( 11 'enzymes.inject' => 'It allows a user to inject enzymes into her posts.',12 'enzymes.use_own_attributes' => 'It allows a user to make her enzymes with her own attributes.',13 'enzymes.use_others_attributes' => 'It allows a user to make her enzymes with others\' attributes.',14 'enzymes.use_own_custom_fields' => 'It allows a user to make her enzymes with her own custom fields.',15 'enzymes.use_others_custom_fields' => 'It allows a user to make her enzymes with others\' custom fields.',16 'enzymes.create_static_custom_fields' => 'It allows a user to create enzymes from non-evaluated custom fields.',17 'enzymes.create_dynamic_custom_fields' => 'It allows a user to create enzymes from evaluated custom fields.',18 'enzymes.share_static_custom_fields' => 'It allows a user to share her enzymes from non-evaluated custom fields.',19 'enzymes.share_dynamic_custom_fields' => 'It allows a user to share her enzymes from evaluated custom fields.',14 self::PREFIX . 'inject' => 'It allows a user to inject enzymes into her posts.', 15 self::PREFIX . 'use_own_attributes' => 'It allows a user to make her enzymes with her own attributes.', 16 self::PREFIX . 'use_others_attributes' => 'It allows a user to make her enzymes with others\' attributes.', 17 self::PREFIX . 'use_own_custom_fields' => 'It allows a user to make her enzymes with her own custom fields.', 18 self::PREFIX . 'use_others_custom_fields' => 'It allows a user to make her enzymes with others\' custom fields.', 19 self::PREFIX . 'create_static_custom_fields' => 'It allows a user to create enzymes from non-evaluated custom fields.', 20 self::PREFIX . 'create_dynamic_custom_fields' => 'It allows a user to create enzymes from evaluated custom fields.', 21 self::PREFIX . 'share_static_custom_fields' => 'It allows a user to share her enzymes from non-evaluated custom fields.', 22 self::PREFIX . 'share_dynamic_custom_fields' => 'It allows a user to share her enzymes from evaluated custom fields.', 20 23 ); 24 //@Formatter:on 21 25 return $result; 22 26 } … … 513 517 function execute_code( $code, $arguments, $post_object ) 514 518 { 515 if ( author_can($post_object, 'enzymes.create_dynamic_custom_fields') &&519 if ( author_can($post_object, self::PREFIX . 'create_dynamic_custom_fields') && 516 520 ($this->belongs_to_current_author($post_object) || 517 author_can($post_object, 'enzymes.share_dynamic_custom_fields') &&518 author_can($this->current_post, 'enzymes.use_others_custom_fields'))521 author_can($post_object, self::PREFIX . 'share_dynamic_custom_fields') && 522 author_can($this->current_post, self::PREFIX . 'use_others_custom_fields')) 519 523 ) { 520 524 list($result,) = $this->safe_eval($code, $arguments); … … 631 635 function transclude_code( $code, $post_object ) 632 636 { 633 if ( author_can($post_object, 'enzymes.create_dynamic_custom_fields') &&637 if ( author_can($post_object, self::PREFIX . 'create_dynamic_custom_fields') && 634 638 ($this->belongs_to_current_author($post_object) || 635 author_can($post_object, 'enzymes.share_dynamic_custom_fields') &&636 author_can($this->current_post, 'enzymes.use_others_custom_fields'))639 author_can($post_object, self::PREFIX . 'share_dynamic_custom_fields') && 640 author_can($this->current_post, self::PREFIX . 'use_others_custom_fields')) 637 641 ) { 638 642 list(, $output) = $this->safe_eval(" ?>$code<?php "); 639 } elseif ( author_can($post_object, 'enzymes.create_static_custom_fields') &&643 } elseif ( author_can($post_object, self::PREFIX . 'create_static_custom_fields') && 640 644 ($this->belongs_to_current_author($post_object) || 641 author_can($post_object, 'enzymes.share_static_custom_fields') &&642 author_can($this->current_post, 'enzymes.use_others_custom_fields'))645 author_can($post_object, self::PREFIX . 'share_static_custom_fields') && 646 author_can($this->current_post, self::PREFIX . 'use_others_custom_fields')) 643 647 ) { 644 648 $output = $code; … … 706 710 $this->debug_print('transcluding post_attr'); 707 711 $same_author = $this->belongs_to_current_author($post_object); 708 if ( $same_author && author_can($post_object, 'enzymes.use_own_attributes') ||709 ! $same_author && author_can($this->current_post, 'enzymes.use_others_attributes')712 if ( $same_author && author_can($post_object, self::PREFIX . 'use_own_attributes') || 713 ! $same_author && author_can($this->current_post, self::PREFIX . 'use_others_attributes') 710 714 ) { 711 715 $expression = $this->grammar['post_attr']->wrapper_set('@@') … … 733 737 $this->debug_print('transcluding author_attr'); 734 738 $same_author = $this->belongs_to_current_author($post_object); 735 if ( $same_author && author_can($post_object, 'enzymes.use_own_attributes') ||736 ! $same_author && author_can($this->current_post, 'enzymes.use_others_attributes')739 if ( $same_author && author_can($post_object, self::PREFIX . 'use_own_attributes') || 740 ! $same_author && author_can($this->current_post, self::PREFIX . 'use_others_attributes') 737 741 ) { 738 742 $expression = $this->grammar['author_attr']->wrapper_set('@@') … … 913 917 return $content; 914 918 } 915 if ( ! author_can($this->current_post, 'enzymes.inject') ) {919 if ( ! author_can($this->current_post, self::PREFIX . 'inject') ) { 916 920 return $content; 917 921 } -
enzymes/trunk/src/EnzymesPlugin.php
r1063085 r1063182 88 88 $no_role_capabilities = array_fill_keys($caps, false); 89 89 //@formatter:off 90 remove_role( 'enzymes.User');90 remove_role(Enzymes3::PREFIX . 'User'); 91 91 $user_role = add_role( 92 'enzymes.User', __('Enzymes User'), array_merge($no_role_capabilities, array(93 'enzymes.inject' => true,94 'enzymes.use_own_attributes' => true,95 'enzymes.use_own_custom_fields' => true,96 'enzymes.create_static_custom_fields' => true,92 Enzymes3::PREFIX . 'User', __('Enzymes User'), array_merge($no_role_capabilities, array( 93 Enzymes3::PREFIX . 'inject' => true, 94 Enzymes3::PREFIX . 'use_own_attributes' => true, 95 Enzymes3::PREFIX . 'use_own_custom_fields' => true, 96 Enzymes3::PREFIX . 'create_static_custom_fields' => true, 97 97 ))); 98 98 99 remove_role( 'enzymes.PrivilegedUser');99 remove_role(Enzymes3::PREFIX . 'PrivilegedUser'); 100 100 $privileged_user_role = add_role( 101 'enzymes.PrivilegedUser', __('Enzymes Privileged User'), array_merge($user_role->capabilities, array(102 'enzymes.use_others_custom_fields' => true,101 Enzymes3::PREFIX . 'PrivilegedUser', __('Enzymes Privileged User'), array_merge($user_role->capabilities, array( 102 Enzymes3::PREFIX . 'use_others_custom_fields' => true, 103 103 ))); 104 104 105 remove_role( 'enzymes.TrustedUser');105 remove_role(Enzymes3::PREFIX . 'TrustedUser'); 106 106 $trusted_user_role = add_role( 107 'enzymes.TrustedUser', __('Enzymes Trusted User'), array_merge($privileged_user_role->capabilities, array(108 'enzymes.share_static_custom_fields' => true,107 Enzymes3::PREFIX . 'TrustedUser', __('Enzymes Trusted User'), array_merge($privileged_user_role->capabilities, array( 108 Enzymes3::PREFIX . 'share_static_custom_fields' => true, 109 109 ))); 110 110 111 remove_role( 'enzymes.Coder');111 remove_role(Enzymes3::PREFIX . 'Coder'); 112 112 $coder_role = add_role( 113 'enzymes.Coder', __('Enzymes Coder'), array_merge($trusted_user_role->capabilities, array(114 'enzymes.create_dynamic_custom_fields' => true,113 Enzymes3::PREFIX . 'Coder', __('Enzymes Coder'), array_merge($trusted_user_role->capabilities, array( 114 Enzymes3::PREFIX . 'create_dynamic_custom_fields' => true, 115 115 ))); 116 116 117 remove_role( 'enzymes.TrustedCoder');117 remove_role(Enzymes3::PREFIX . 'TrustedCoder'); 118 118 $trusted_coder_role = add_role( 119 'enzymes.TrustedCoder', __('Enzymes Trusted Coder'), array_merge($coder_role->capabilities, array(120 'enzymes.share_dynamic_custom_fields' => true,119 Enzymes3::PREFIX . 'TrustedCoder', __('Enzymes Trusted Coder'), array_merge($coder_role->capabilities, array( 120 Enzymes3::PREFIX . 'share_dynamic_custom_fields' => true, 121 121 ))); 122 122 //@formatter:on … … 136 136 137 137 foreach ($wp_roles->roles as $name => $role) { 138 if ( 0 === strpos($name, 'enzymes.') ) {138 if ( 0 === strpos($name, Enzymes3::PREFIX) ) { 139 139 remove_role($name); 140 140 } -
enzymes/trunk/tests/test-Enzymes3.php
r1063085 r1063182 485 485 486 486 // This role is not really needed for attributes, but it makes my test easier to write. 487 $user = $this->factory->user->create_and_get(array('role' => 'enzymes.Coder'));487 $user = $this->factory->user->create_and_get(array('role' => Enzymes3::PREFIX . 'Coder')); 488 488 $data = array(); 489 489 foreach ($attrs as $key) { … … 508 508 function test_transcluded_author_from_current_post() 509 509 { 510 $user_id = $this->factory->user->create(array('role' => 'enzymes.User'));510 $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'User')); 511 511 add_user_meta($user_id, 'sample-name', 'sample-value'); 512 512 add_user_meta($user_id, 'sample name', 'sample value'); … … 523 523 function test_transcluded_author_from_another_post() 524 524 { 525 $user_1_id = $this->factory->user->create(array('role' => 'enzymes.PrivilegedUser'));525 $user_1_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'PrivilegedUser')); 526 526 add_user_meta($user_1_id, 'sample-name', 'sample value 1'); 527 527 $post_1_id = $this->factory->post->create(array('post_author' => $user_1_id)); 528 528 $post_1 = get_post($post_1_id); 529 529 530 $user_2_id = $this->factory->user->create(array('role' => 'enzymes.TrustedUser'));530 $user_2_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'TrustedUser')); 531 531 add_user_meta($user_2_id, 'sample-name', 'sample value 2'); 532 532 $post_2_id = $this->factory->post->create(array('post_author' => $user_2_id)); … … 541 541 function test_transcluded_author_from_another_post_by_slug() 542 542 { 543 $user_1_id = $this->factory->user->create(array('role' => 'enzymes.PrivilegedUser'));543 $user_1_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'PrivilegedUser')); 544 544 add_user_meta($user_1_id, 'sample-name', 'sample value 1'); 545 545 $post_1_id = $this->factory->post->create(array('post_author' => $user_1_id)); 546 546 $post_1 = get_post($post_1_id); 547 547 548 $user_2_id = $this->factory->user->create(array('role' => 'enzymes.TrustedUser'));548 $user_2_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'TrustedUser')); 549 549 add_user_meta($user_2_id, 'sample-name', 'sample value 2'); 550 550 $post_2_id = $this->factory->post->create(array( … … 623 623 function test_executed_author_with_no_arguments() 624 624 { 625 $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));625 $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder')); 626 626 add_user_meta($user_id, 'sample-name', ' 627 627 $a = 100; … … 643 643 function test_executed_author_with_one_argument() 644 644 { 645 $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));645 $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder')); 646 646 add_user_meta($user_id, 'sample-name', ' 647 647 list($a) = $arguments; … … 663 663 function test_executed_author_with_many_arguments() 664 664 { 665 $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));665 $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder')); 666 666 add_user_meta($user_id, 'sample-name', ' 667 667 list($a, $b, $c) = $arguments; … … 681 681 function test_executed_author_with_an_array_argument() 682 682 { 683 $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));683 $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder')); 684 684 add_user_meta($user_id, 'sample-name', ' 685 685 list($a, $bc) = $arguments; … … 699 699 function test_executed_author_with_a_hash_argument() 700 700 { 701 $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));701 $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder')); 702 702 add_user_meta($user_id, 'sample-name', ' 703 703 list($hash) = $arguments;
Note: See TracChangeset
for help on using the changeset viewer.