Plugin Directory

Changeset 1063182


Ignore:
Timestamp:
01/08/2015 02:49:08 PM (11 years ago)
Author:
aercolino
Message:

Extracted the 'enzymes.' prefix in its own Enzymes3::PREFIX constant.

Location:
enzymes/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • enzymes/trunk/src/Enzymes3.php

    r1063090 r1063182  
    55class Enzymes3
    66{
     7    const PREFIX = 'enzymes.';
     8
    79    static public
    810    function capabilities()
    911    {
     12//@Formatter:off
    1013        $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.',
    2023        );
     24//@Formatter:on
    2125        return $result;
    2226    }
     
    513517    function execute_code( $code, $arguments, $post_object )
    514518    {
    515         if ( author_can($post_object, 'enzymes.create_dynamic_custom_fields') &&
     519        if ( author_can($post_object, self::PREFIX . 'create_dynamic_custom_fields') &&
    516520             ($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'))
    519523        ) {
    520524            list($result,) = $this->safe_eval($code, $arguments);
     
    631635    function transclude_code( $code, $post_object )
    632636    {
    633         if ( author_can($post_object, 'enzymes.create_dynamic_custom_fields') &&
     637        if ( author_can($post_object, self::PREFIX . 'create_dynamic_custom_fields') &&
    634638             ($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'))
    637641        ) {
    638642            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') &&
    640644                   ($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'))
    643647        ) {
    644648            $output = $code;
     
    706710        $this->debug_print('transcluding post_attr');
    707711        $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')
    710714        ) {
    711715            $expression = $this->grammar['post_attr']->wrapper_set('@@')
     
    733737        $this->debug_print('transcluding author_attr');
    734738        $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')
    737741        ) {
    738742            $expression = $this->grammar['author_attr']->wrapper_set('@@')
     
    913917            return $content;
    914918        }
    915         if ( ! author_can($this->current_post, 'enzymes.inject') ) {
     919        if ( ! author_can($this->current_post, self::PREFIX . 'inject') ) {
    916920            return $content;
    917921        }
  • enzymes/trunk/src/EnzymesPlugin.php

    r1063085 r1063182  
    8888        $no_role_capabilities = array_fill_keys($caps, false);
    8989//@formatter:off
    90         remove_role('enzymes.User');
     90        remove_role(Enzymes3::PREFIX . 'User');
    9191        $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,
    9797        )));
    9898
    99         remove_role('enzymes.PrivilegedUser');
     99        remove_role(Enzymes3::PREFIX . 'PrivilegedUser');
    100100        $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,
    103103        )));
    104104
    105         remove_role('enzymes.TrustedUser');
     105        remove_role(Enzymes3::PREFIX . 'TrustedUser');
    106106        $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,
    109109        )));
    110110
    111         remove_role('enzymes.Coder');
     111        remove_role(Enzymes3::PREFIX . 'Coder');
    112112        $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,
    115115        )));
    116116
    117         remove_role('enzymes.TrustedCoder');
     117        remove_role(Enzymes3::PREFIX . 'TrustedCoder');
    118118        $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,
    121121        )));
    122122//@formatter:on
     
    136136
    137137        foreach ($wp_roles->roles as $name => $role) {
    138             if ( 0 === strpos($name, 'enzymes.') ) {
     138            if ( 0 === strpos($name, Enzymes3::PREFIX) ) {
    139139                remove_role($name);
    140140            }
  • enzymes/trunk/tests/test-Enzymes3.php

    r1063085 r1063182  
    485485
    486486        // 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'));
    488488        $data = array();
    489489        foreach ($attrs as $key) {
     
    508508    function test_transcluded_author_from_current_post()
    509509    {
    510         $user_id = $this->factory->user->create(array('role' => 'enzymes.User'));
     510        $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'User'));
    511511        add_user_meta($user_id, 'sample-name', 'sample-value');
    512512        add_user_meta($user_id, 'sample name', 'sample value');
     
    523523    function test_transcluded_author_from_another_post()
    524524    {
    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'));
    526526        add_user_meta($user_1_id, 'sample-name', 'sample value 1');
    527527        $post_1_id = $this->factory->post->create(array('post_author' => $user_1_id));
    528528        $post_1 = get_post($post_1_id);
    529529
    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'));
    531531        add_user_meta($user_2_id, 'sample-name', 'sample value 2');
    532532        $post_2_id = $this->factory->post->create(array('post_author' => $user_2_id));
     
    541541    function test_transcluded_author_from_another_post_by_slug()
    542542    {
    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'));
    544544        add_user_meta($user_1_id, 'sample-name', 'sample value 1');
    545545        $post_1_id = $this->factory->post->create(array('post_author' => $user_1_id));
    546546        $post_1 = get_post($post_1_id);
    547547
    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'));
    549549        add_user_meta($user_2_id, 'sample-name', 'sample value 2');
    550550        $post_2_id = $this->factory->post->create(array(
     
    623623    function test_executed_author_with_no_arguments()
    624624    {
    625         $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));
     625        $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder'));
    626626        add_user_meta($user_id, 'sample-name', '
    627627        $a = 100;
     
    643643    function test_executed_author_with_one_argument()
    644644    {
    645         $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));
     645        $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder'));
    646646        add_user_meta($user_id, 'sample-name', '
    647647        list($a) = $arguments;
     
    663663    function test_executed_author_with_many_arguments()
    664664    {
    665         $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));
     665        $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder'));
    666666        add_user_meta($user_id, 'sample-name', '
    667667        list($a, $b, $c) = $arguments;
     
    681681    function test_executed_author_with_an_array_argument()
    682682    {
    683         $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));
     683        $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder'));
    684684        add_user_meta($user_id, 'sample-name', '
    685685        list($a, $bc) = $arguments;
     
    699699    function test_executed_author_with_a_hash_argument()
    700700    {
    701         $user_id = $this->factory->user->create(array('role' => 'enzymes.Coder'));
     701        $user_id = $this->factory->user->create(array('role' => Enzymes3::PREFIX . 'Coder'));
    702702        add_user_meta($user_id, 'sample-name', '
    703703        list($hash) = $arguments;
Note: See TracChangeset for help on using the changeset viewer.