Plugin Directory

Changeset 2920206


Ignore:
Timestamp:
06/01/2023 03:18:44 PM (3 years ago)
Author:
arstudios
Message:

Release 1.5.8.

Location:
constellation-client-portal
Files:
108 added
11 edited

Legend:

Unmodified
Added
Removed
  • constellation-client-portal/trunk/README.txt

    r2906601 r2920206  
    55Requires at least: 5.0.0
    66Tested up to: 6.2
    7 Stable tag: 1.5.7
     7Stable tag: 1.5.8
    88Requires PHP: 7.4
    99License: GPLv3 or later
     
    203203
    204204== Changelog ==
     205= 1.5.8 (Pro) - 2023-6-1 =
     206* Fix: Updated the pro public facing functions to check for WooCommerce to prevent errors if WooCommerce is not installed/active.
     207* Feature: Added global page functionality that allows client pages to be accessed by multiple companies.
     208* Update: Updated add functionality to allow global pages to be created in the client page quick-create section with company edit pages.
     209* Update: Updated the client page post meta save functionality to exit early on new, unsaved posts to clear notices related to the post object not yet existing.
     210
     211= 1.5.8 (Core) - 2023-6-1 =
     212* Update: Relocated select2 script related to the company select field within client pages from the pro admin js file to the core admin js file for UI consistency.
     213* Improvement: Improved the client page quick-create functionality within company edit pages.
     214* Improvement: Added functionality to remove assigned companies from user profiles when the company posts are permanently deleted in WP.
     215* Fix: Fixed issue preventing client company posts from being permanently deleted via the WP list table bulk actions.
     216* Improvement: Updated the company and additional company select fields/functionality in user profile edit pages to include all post statuses in the select fields (not just published companies) to accommodate more customer workflows.
     217* Improvement: Added a new Assigned Companies column to the WP user list table to allow users to quickly see company assignments at a glance.
     218* Improvement: Updated the client information section within WP Admin user profile edit pages. Also added tooltips to provide better contextual information.
     219* Update: Made minor update to improve the new user creation process when creating a new company.
     220
    205221= 1.5.7 (Pro) - 2023-5-1 =
    206222* Update: Fixed visibility issue with the due date datepicker month navigation elements.
  • constellation-client-portal/trunk/admin/class-ars-constellation-client-portal-admin.php

    r2906601 r2920206  
    281281        $home    = set_url_scheme( get_option( 'home' ), 'http' );
    282282        $siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
     283
    283284        if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
     285
    284286            $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
    285287            $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
    286288            $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
    287289            $home_path = trailingslashit( $home_path );
     290
    288291        } else {
     292
    289293            $home_path = ABSPATH;
     294
    290295        }
    291296
     
    467472
    468473    /**
    469      * Add the main TCP admin menu item
     474     * Add the main ACCP admin menu item
    470475     */
    471476    function register_accp_custom_menu_page(){
     
    22112216        $screen = 'accp_client_pages';
    22122217       
    2213         add_meta_box("client-meta-2", "Assign Company", array($this, "display_meta_company_select_options"), $screen, "normal", "high");
     2218        add_meta_box("client-meta-2", "Assign Company*", array($this, "display_meta_company_select_options"), $screen, "normal", "high");
    22142219
    22152220    }
     
    22212226    function display_meta_company_select_options() {       
    22222227       
    2223         global $post;
    2224 
    2225         $accp_user = get_post_meta($post->ID, 'accp_user', true);
    2226 
    2227         if(get_post_meta($post->ID, 'accp_user', true)){
    2228 
    2229             echo 'Assigned Company: ' . esc_html(get_the_title($accp_user));
    2230         }
    2231         ?>         
    2232            
    2233         <p class="label"><label for="accp_user">*Assign Company</label></p>
    2234 
    2235         <?php 
    2236 
    2237         // Assign Company select
    2238         wp_dropdown_pages(array('post_type'=>'accp_clientcompany', 'id' => 'company-select', 'value_field' => 'ID', 'echo' => TRUE, 'show_option_none' => 'Select a company...', 'name' => 'accp_user', 'selected' => $accp_user, 'class' => 'select2-container' ));     
     2228        $post_id = get_the_ID();
     2229
     2230        if(!$post_id)
     2231            return;
     2232
     2233        $accp_user = get_post_meta($post_id, 'accp_user', true);
     2234        $global_page_enabled = get_post_meta($post_id, 'accp_make_page_global', true);     
     2235
     2236        if( $accp_user || ( $global_page_enabled && $global_page_enabled === 'global' )  ){
     2237
     2238            if( $global_page_enabled && $global_page_enabled === 'global' ){
     2239
     2240                $assigned_company_name = 'Global Page';
     2241           
     2242            }else{
     2243
     2244                $assigned_company_name = $accp_user ? get_the_title($accp_user) : '';
     2245
     2246            }
     2247
     2248            ?>
     2249            <div class="accp-boxed-container current-assigned-company-container">
     2250
     2251                <p><strong>Current Assigned Company:</strong> <?php echo esc_html( $assigned_company_name ); ?></p>
     2252
     2253            </div>
     2254            <?php
     2255
     2256        }else{
     2257
     2258            ?>
     2259            <div class="accp-boxed-container current-assigned-company-container">
     2260
     2261                <p>Unassigned: Please select an option below to assign this page to a company or set this as a global page.</p>
     2262
     2263            </div>
     2264            <?php
     2265
     2266        }
     2267        ?>
     2268
     2269        <?php
     2270        /**
     2271         * Specify unique company section.
     2272         */
     2273        ?>
     2274        <div class="accp-boxed-container accp-specify-company-field-container">
     2275
     2276            <p class="label"><label for="accp_user">Assign Company</label></p>
     2277           
     2278            <p class="accp-field-note">This field is required if this is not a global page.</p>
     2279            <?php
     2280
     2281            /**
     2282             * Assign Company select field.
     2283             */
     2284            wp_dropdown_pages(array('post_type'=>'accp_clientcompany', 'id' => 'company-select', 'value_field' => 'ID', 'echo' => TRUE, 'show_option_none' => 'Select a company...', 'name' => 'accp_user', 'selected' => $accp_user, 'class' => 'select2-container' ));
     2285
     2286        ?>
     2287        </div> <?php // END .accp-specify-company-field-container ?>
     2288
     2289        <?php
     2290        if( is_user_logged_in() && is_admin() && current_user_can('manage_options') ){
     2291
     2292            do_action('accp_after_client_page_company_select_section', $post_id);           
     2293
     2294        }
     2295
    22392296    }
    22402297
     
    22512308            if( $current_screen->id === "accp_client_pages" ) {
    22522309
    2253             global $post;
    2254             global $post_id;       
    2255            
    2256             //  Assign Company select field on the Client Pages
    2257             if($post && !empty($_POST['accp_user']) ){
    2258 
    2259                 $company_id = (int)$_POST['accp_user'];             
    2260                 update_post_meta($post->ID, 'accp_user', $company_id );
     2310                global $post;
     2311                global $post_id;
     2312
     2313                if( !$post )
     2314                    return;
     2315               
     2316                if( !$post_id )
     2317                    return;
     2318               
     2319                /**
     2320                 * Save the Assign Company select field on the Client Pages.
     2321                 */
     2322                if( $post && !empty($_POST['accp_user']) ){
     2323
     2324                    $company_id = (int)$_POST['accp_user'];             
     2325                    update_post_meta($post->ID, 'accp_user', $company_id );
     2326
     2327                }
     2328
     2329                if( $post && empty($_POST['accp_user']) ){
     2330                    delete_post_meta($post->ID, 'accp_user');
     2331                }
     2332
     2333
     2334                /**
     2335                 * Save the Enable Global Comany Access check box
     2336                 * on Company Pages.
     2337                 */
     2338                if( $post && !empty($_POST['accp_make_page_global']) ){
     2339
     2340                    $company_id = sanitize_text_field( $_POST['accp_make_page_global'] );               
     2341                    update_post_meta($post->ID, 'accp_make_page_global', $company_id );
     2342
     2343                    /**
     2344                     * Delete the assigned company if it exists,
     2345                     * since this is now a global page.
     2346                     */
     2347                    delete_post_meta($post->ID, 'accp_user');
     2348
     2349                }
     2350
     2351                if( $post && empty($_POST['accp_make_page_global']) ){
     2352                    delete_post_meta($post->ID, 'accp_make_page_global');
     2353                }               
    22612354
    22622355            }
    22632356
    2264             if($post && empty($_POST['accp_user']) ){
    2265                 delete_post_meta($post->ID, 'accp_user');
    2266             }
    2267 
    2268             }
    2269 
    2270         }
    2271 
    2272     }
    2273 
    2274 
    2275     /**
    2276      * Add user profile fields
    2277      */
    2278     function extra_user_profile_fields( $user ) {
     2357        }
     2358
     2359    }
     2360
     2361
     2362    /**
     2363     * Add user profile fields.
     2364     */
     2365    function extra_user_profile_fields($user){
     2366
     2367        if(!$user)
     2368            return;
     2369
     2370        $user_id = $user->ID;
     2371
     2372        if(!$user_id)
     2373            return;
     2374
     2375        $wp_post_statuses = get_post_statuses() ? array_keys( (array)get_post_statuses() ) : array();
    22792376       
    22802377        ?>
    2281         <h2>Client information</h2>
     2378        <h2>Constellation Client Information</h2>
    22822379
    22832380        <table class="form-table">
    22842381
     2382            <?php
     2383            /**
     2384             * Primary Company section.
     2385             */
     2386            ?>
    22852387            <tr>
    22862388                <th><label for="client_company">Company</label></th>
     
    22882390                <td>               
    22892391                    <?php
    2290                     $saved_company = is_object($user) ? get_user_meta($user->ID, 'client_company', true) : '';
     2392                    $saved_company = is_object($user) ? get_user_meta($user_id, 'client_company', true) : '';
    22912393                   
    22922394                    if ( current_user_can('manage_options') ){
    22932395
    2294                         wp_dropdown_pages(array('post_type'=>'accp_clientcompany', 'value_field' => 'ID', 'echo' => TRUE, 'show_option_none' => 'Select a company...', 'name' => 'client_company', 'selected' => $saved_company ));
     2396                        $args = array(
     2397                            'post_type' => 'accp_clientcompany',                                                       
     2398                        );
     2399
     2400                        /**
     2401                         * Include all defined WP post statuses,
     2402                         * not just "publish."
     2403                         */
     2404                        if(!empty($wp_post_statuses)){
     2405
     2406                            $args['post_status'] = $wp_post_statuses;
     2407
     2408                        }
     2409
     2410                       
     2411                        $company_list = get_pages($args);
     2412
     2413                        ?>
     2414                        <select name="client_company" id="client_company">
     2415
     2416                            <option value="">Select a company...</option>
     2417                        <?php
     2418
     2419                            foreach( $company_list as $key => $company ){
     2420
     2421                                $company_id = $company->ID;
     2422                                $company_name = $company->post_title;
     2423                                $selected = $saved_company && (int)$saved_company === (int)$company_id ? "selected" : "";
     2424                                $post_status_class = '';
     2425
     2426                                if( $company->post_status != 'publish' ){
     2427
     2428                                    $company_name = $company_name . ' (' . $company->post_status . ')';
     2429                                    $post_status_class = "accp-non-published-post-option";
     2430
     2431                                }
     2432                               
     2433                                ?>
     2434                                <option class="level-0 <?php echo esc_attr($post_status_class); ?>" value="<?php echo esc_attr($company_id); ?>" <?php echo esc_attr($selected); ?> ><?php echo esc_html($company_name); ?></option>
     2435                                <?php
     2436
     2437
     2438                            }
     2439
     2440                        ?>
     2441                        </select>
     2442                        <?php
    22952443
    22962444                    }else{
    22972445
    2298                         if(!empty($saved_company)){
     2446                        if( !empty($saved_company) ){
    22992447
    23002448                            echo esc_html(get_the_title($saved_company));
    23012449
    23022450                        }
     2451
    23032452                    }
    23042453                    ?>
     
    23072456                </td>
    23082457            </tr>
    2309 
     2458           
     2459
     2460            <?php
     2461            /**
     2462             * Client Status section.
     2463             */
     2464            ?>
    23102465            <tr>
    2311                 <th><label for="client_status"><?php _e("Client Status"); ?></label></th>
     2466                <th>
     2467                    <label for="client_status">
     2468                        <?php _e("Client Status"); ?>
     2469                        <span class="accp-admin-tooltip-icon">i</span>
     2470                        <span class="accp-wp-admin-tooltip accp-wp-admin-tooltip-dark accp-wp-admin-has-tooltip-center accp-user-status-tooltip">A status of <strong>Inactive</strong> or <strong>Pending</strong> will prevent the user from accessing client pages, invoices, and files.</span>
     2471                    </label>
     2472                </th>
     2473
    23122474                <td>
    23132475                    <?php $saved_status = is_object($user) ? get_user_meta($user->ID, 'client_status', true) : '';
     
    23162478                    ?>
    23172479
    2318                         <select name="client_status" id="client-status" value="<?php echo esc_attr( get_the_author_meta( 'client_status', $user->ID ) ); ?>">
    2319                             <option value="active" <?php if ($saved_status == 'active' ) echo 'selected' ; ?>>Active</option>
    2320                             <option value="inactive" <?php if ($saved_status == 'inactive' ) echo 'selected' ; ?>>Inactive</option>
    2321                             <option value="pending" <?php if ($saved_status == 'pending' ) echo 'selected' ; ?>>Pending</option>           
     2480                        <select name="client_status" id="client-status" value="<?php echo esc_attr( get_the_author_meta( 'client_status', $user_id ) ); ?>">
     2481                            <option value="active" <?php echo $saved_status == 'active' ? esc_attr("selected") : ""; ?>>Active</option>
     2482                            <option value="inactive" <?php echo $saved_status == 'inactive' ? esc_attr("selected") : ""; ?>>Inactive</option>
     2483                            <option value="pending" <?php echo $saved_status == 'pending' ? esc_attr("selected") : ""; ?>>Pending</option>           
    23222484                        </select>
    23232485
     
    23342496                   
    23352497                </td>
    2336             </tr>
     2498            </tr>
     2499
     2500           
     2501            <?php
     2502            /**
     2503             * Additional Assigned Companies section.
     2504             */
     2505            ?>
    23372506            <tr>
    23382507                <th>
     
    23482517                    if(is_object($user)){
    23492518
    2350                         if ( get_user_meta($user->ID, 'client_additional_company', true) && !empty(get_user_meta($user->ID, 'client_additional_company', true)) ){
     2519                        if ( get_user_meta($user_id, 'client_additional_company', true) && !empty(get_user_meta($user_id, 'client_additional_company', true)) ){
    23512520                       
    2352                             $saved_companies = get_user_meta($user->ID, 'client_additional_company', true);
     2521                            $saved_companies = (array)get_user_meta( $user_id, 'client_additional_company', true );
    23532522
    23542523                        }
    23552524
    2356                     }                   
    2357                    
    2358                     $args = array(
    2359                         'numberposts'      => -1,             
    2360                         'post_type'   => 'accp_clientcompany'
    2361                     );
    2362 
    2363                     $company_items = get_posts($args);         
     2525                    }                           
    23642526
    23652527                    if ( current_user_can('manage_options') ){
    2366 
     2528                       
    23672529                        ?>
    23682530                        <select class="client-add-company-select" name="client_additional_company[]"  value="" multiple="multiple" >
    23692531                        <?php                       
    23702532                       
    2371                         foreach( $company_items as $company_item ){
    2372                            
    2373                             $selected = (  is_array( $company_items ) &&  in_array( $company_item->ID, $saved_companies ) ) ? ' selected=selected' : '';   
    2374 
    2375                             echo '<option value="' . esc_attr($company_item->ID)  . '"' . esc_attr($selected) . '>' . esc_html($company_item->post_title)  . '</option>';       
    2376 
    2377                         }
     2533                            foreach( $company_list as $company ){
     2534
     2535                                $company_id = $company->ID;
     2536                                $company_name = $company->post_title;
     2537                                $selected = in_array( $company_id , $saved_companies ) ? "selected" : "";
     2538                                $post_status_class = '';
     2539
     2540                                if( $company->post_status != 'publish' ){
     2541
     2542                                    $company_name = $company_name . ' (' . $company->post_status . ')';
     2543                                    $post_status_class = "accp-non-published-post-option";
     2544
     2545                                }
     2546                               
     2547                                ?>
     2548                                <option class="level-0 <?php echo esc_attr($post_status_class); ?>" value="<?php echo esc_attr($company_id); ?>" <?php echo esc_attr($selected); ?> ><?php echo esc_html($company_name); ?></option>
     2549                                <?php
     2550
     2551                            }
    23782552
    23792553                        ?>
     
    24022576                    ?>
    24032577                   
    2404                 </td>
    2405             </tr>   
     2578                </td>               
     2579
     2580            </tr>
     2581           
     2582            <?php
     2583            if( is_admin() && is_user_logged_in() && current_user_can('manage_options') ){
     2584                do_action('accp_after_user_profile_settings', $user_id);
     2585            }
     2586            ?>     
    24062587       
    24072588        </table>
    24082589    <?php
     2590    }
     2591
     2592
     2593    /**
     2594     * Check user global page suitability.  If a user
     2595     * is assigned to only 1 company, they are suitable
     2596     * for global pages, otherwise they are not.
     2597     *
     2598     * @param int $user_id - The ID of the user to check.
     2599     *
     2600     * @return bool $is_eligible - true|false.
     2601     */
     2602    function check_if_user_is_eligible_for_global_pages($user_id){
     2603
     2604        $primary_company_id = get_user_meta($user_id, 'client_company', true);
     2605        $additional_company_ids = get_user_meta($user_id, 'client_additional_company', true);
     2606
     2607        /**
     2608         * Return true if a primary company is assigned and no
     2609         * additional companies are assigned.
     2610         */
     2611        if( $primary_company_id && ( !$additional_company_ids || empty($additional_company_ids) ) )
     2612            return true;
     2613
     2614       
     2615        /**
     2616         * Return true if a primary company is not assigned and only
     2617         * one additional company is assigned.
     2618         */
     2619        if( !$primary_company_id && $additional_company_ids && is_array($additional_company_ids) ){
     2620
     2621            if( count($additional_company_ids) === 1)
     2622                return true;
     2623
     2624        }
     2625
     2626
     2627        /**
     2628         * Return true if a primary company is not assigned and
     2629         * no additional companies are assigned.
     2630         */
     2631        if( !$primary_company_id && ( !$additional_company_ids || empty($additional_company_ids) ) ){
     2632           
     2633                return true;
     2634
     2635        }
     2636
     2637        return false;
     2638
    24092639    }
    24102640
     
    28143044
    28153045    }
     3046
     3047
     3048    /**
     3049     * Add columns to the WP user list table.
     3050     */
     3051    function add_wp_user_list_columns($columns){
     3052
     3053        $columns['accp_assigned_companies'] = 'Assigned Companies';
     3054
     3055        return $columns;
     3056
     3057    }
     3058
     3059
     3060    /**
     3061     * Add WP user list table column content.
     3062     */
     3063    function add_wp_user_list_column_content($output, $column_name, $user_id){
     3064
     3065        if( $column_name === 'accp_assigned_companies'){
     3066
     3067            if(!$user_id)
     3068                return;
     3069
     3070            $company_list = array();
     3071
     3072            $user_primary_company = get_user_meta($user_id, 'client_company', true);
     3073
     3074            if($user_primary_company){
     3075               
     3076                $post_status = get_post_status($user_primary_company) ? get_post_status($user_primary_company) : '';
     3077                $post_status_text = '';
     3078               
     3079                if( $post_status && !empty($post_status) ){
     3080                   
     3081                    if( $post_status != 'publish' ){
     3082                   
     3083                        $post_status_text = ' (' . $post_status . ')';
     3084
     3085                    }
     3086
     3087                }
     3088               
     3089                $company_name = get_the_title($user_primary_company) ? esc_html( get_the_title($user_primary_company) ) : (int)$user_primary_company;
     3090                $company_list[] = $company_name . $post_status_text;
     3091
     3092            }
     3093
     3094            $additional_assigned_companies = get_user_meta($user_id, 'client_additional_company', true);
     3095
     3096            if( $additional_assigned_companies && is_array($additional_assigned_companies) && !empty($additional_assigned_companies) ){
     3097
     3098                foreach($additional_assigned_companies as $company_id){
     3099                   
     3100                    $post_status = get_post_status($company_id) ? get_post_status($company_id) : '';
     3101                    $post_status_text = '';
     3102                   
     3103                    if( $post_status && !empty($post_status) ){                     
     3104                       
     3105                        if( $post_status != 'publish' ){
     3106                       
     3107                            $post_status_text = ' (' . $post_status . ')';
     3108
     3109                        }
     3110
     3111                    }
     3112
     3113                    $company_name = get_the_title($company_id) ? esc_html( get_the_title($company_id) ) : (int)$company_id;
     3114                    $company_list[] = $company_name . $post_status_text;
     3115
     3116                }
     3117
     3118            }
     3119
     3120            if( !empty($company_list) ) {
     3121
     3122                $company_str = esc_html( implode(', ', $company_list) );
     3123
     3124                return $company_str;
     3125
     3126            }
     3127
     3128        }       
     3129
     3130    }
     3131
     3132
     3133    /**
     3134     * Get all assigned companies for a user.
     3135     *
     3136     * @param int $user_id - The ID of the respective user.
     3137     * @param string $include_statuses - The WP post statuses to include, or empty for all
     3138     * (example: array('publish', 'draft')).
     3139     *
     3140     * @return array $assigned_companies - Array of companies that the user is assigned to.
     3141     */
     3142    function get_all_assigned_companies_for_user( $user_id, $include_statuses = array() ){
     3143
     3144        if(!$user_id)
     3145            return array();
     3146
     3147        $company_list = array();
     3148
     3149        $user_primary_company = get_user_meta($user_id, 'client_company', true);       
     3150
     3151        if($user_primary_company){
     3152           
     3153            $post_status = get_post_status($user_primary_company) ? get_post_status($user_primary_company) : '';           
     3154           
     3155            if( ( $post_status && !empty($post_status) ) && ( empty($include_statuses) || in_array($post_status, $include_statuses) )  ){
     3156               
     3157                $company_name = get_the_title($user_primary_company) ? esc_html( get_the_title($user_primary_company) ) : (int)$user_primary_company;
     3158
     3159                $company_list[$user_primary_company]['id'] = $user_primary_company;
     3160                $company_list[$user_primary_company]['name'] = $company_name;
     3161                $company_list[$user_primary_company]['post_status'] = $post_status;         
     3162
     3163            }           
     3164
     3165        }
     3166
     3167        $additional_assigned_companies = get_user_meta($user_id, 'client_additional_company', true);
     3168
     3169        if( $additional_assigned_companies && is_array($additional_assigned_companies) && !empty($additional_assigned_companies) ){
     3170
     3171            foreach($additional_assigned_companies as $company_id){
     3172               
     3173                $post_status = get_post_status($company_id) ? get_post_status($company_id) : '';
     3174
     3175                if( ( $post_status && !empty($post_status) ) && ( empty($include_statuses) || in_array($post_status, $include_statuses) )  ){
     3176               
     3177                    $company_name = get_the_title($company_id) ? esc_html( get_the_title($company_id) ) : (int)$company_id;
    28163178   
     3179                    $company_list[$company_id]['id'] = $company_id;
     3180                    $company_list[$company_id]['name'] = $company_name;
     3181                    $company_list[$company_id]['post_status'] = $post_status;           
     3182   
     3183                }   
     3184
     3185            }
     3186
     3187        }
     3188
     3189        return $company_list;
     3190
     3191    }
     3192   
    28173193
    28183194} //End ARS_Constellation_Client_Portal_Admin Class
  • constellation-client-portal/trunk/admin/class-ars-constellation-client-portal-client-pages.php

    r2906601 r2920206  
    9494            'query_var' => true,
    9595            'can_export' => true,
    96             'rewrite' => array('slug' => 'accp-client-page'),
     96            'rewrite' => array('slug' => 'accp-client-page'),       
    9797            'capabilities' => array(
    9898                'edit_post' => 'update_core',
     
    230230    /**
    231231     * Display the Company column content in the Client Page WP List Table.
     232     *
     233     * @param string $column_name - The slug name of the column.
     234     * @param int $post_id - The post ID of the Client Page.
    232235     */
    233236    public function accp_client_pages_column_display_company_name( $column_name, $post_id ) {   
    234237       
    235         //Client Company
     238        /**
     239         * Client Company
     240         */
    236241        if ( 'company' != $column_name )
    237242            return;
    238243
    239         $accp_user = get_post_meta($post_id, 'accp_user', true);
    240 
    241         if(get_post_meta($post_id, 'accp_user', true)){
    242 
    243             echo '<a href="' . esc_url(get_edit_post_link($accp_user)) . '">' . esc_html(get_the_title($accp_user)) . '</a>';
     244        $company_id = (int)get_post_meta($post_id, 'accp_user', true);
     245
     246        /**
     247         * Check if this is a Client page set to global
     248         * access before checking for a saved company.
     249         *
     250         * Only valid for Client Page post types,
     251         * and not Client Files, Client Invoices, or
     252         * direct file access.
     253         */
     254        $core_authorization = new ARS_Constellation_Client_Portal_Core_Authorization( $this->plugin_name, $this->version );
     255        $is_global_page = $core_authorization->is_global_company_page($post_id);
     256
     257        /**
     258         * Display the company name if one is assigned,
     259         * and this is not a global page.
     260         */
     261        if( $company_id && $is_global_page != true ){
     262
     263            $html = '<a href="' . esc_url(get_edit_post_link($company_id)) . '">' . esc_html(get_the_title($company_id)) . '</a>';
     264
     265            echo wp_kses_post($html);
    244266           
    245267        }
    246268
     269
     270        /**
     271         * Display Global Page text if
     272         * this is a global page.
     273         */
     274        if( true === $is_global_page ){
     275
     276            $hover_message = 'Global Pages are only suitable for companies comprised of users that are only assigned to one company, unless the page content is static.';
     277
     278            $html = '<span class="accp-column-pointer-item" title="' . esc_attr($hover_message) . '" alt="' . esc_attr($hover_message) . '">Global Page</span>';
     279
     280            echo wp_kses_post($html);
     281
     282        }
     283
    247284    }   
    248285
  • constellation-client-portal/trunk/admin/class-ars-constellation-client-portal-company.php

    r2906601 r2920206  
    373373        <?php
    374374
    375         wp_dropdown_pages(array('post_type'=>'accp_client_pages', 'value_field' => 'ID', 'echo' => TRUE, 'show_option_none' => 'Select a page...', 'name' => 'accp_home_page', 'selected' => $accp_home_page ));
     375        $wp_post_statuses = get_post_statuses() ? array_keys( (array)get_post_statuses() ) : array();
     376
     377        $args = array(
     378            'post_type' => 'accp_client_pages',                                                     
     379        );
     380
     381        /**
     382         * Include all defined WP post statuses,
     383         * not just "publish."
     384         */
     385        if(!empty($wp_post_statuses)){
     386
     387            $args['post_status'] = $wp_post_statuses;
     388
     389        }
     390
     391        $client_page_list = get_pages($args);       
     392        ?>
     393        <select name="accp_home_page" id="accp_home_page">
     394
     395            <option value="">Select a page...</option>
     396            <?php
     397
     398            foreach( $client_page_list as $key => $post ){
     399
     400                $post_id = $post->ID;
     401                $post_name = $post->post_title;
     402                $selected = $accp_home_page && (int)$accp_home_page === (int)$post_id ? "selected" : "";
     403                $post_status_class = '';
     404
     405                if( $post->post_status != 'publish' ){
     406
     407                    $post_name = $post_name . ' (' . $post->post_status . ')';
     408                    $post_status_class = "accp-non-published-post-option";
     409
     410                }
     411               
     412                ?>
     413                <option class="level-0 <?php echo esc_attr($post_status_class); ?>" value="<?php echo esc_attr($post_id); ?>" <?php echo esc_attr($selected); ?> ><?php echo esc_html($post_name); ?></option>
     414                <?php
     415
     416            }
     417
     418        ?>
     419        </select>
     420        <?php
    376421       
    377422        $create_page_nonce = wp_create_nonce('create_home_page');
     
    390435                </p>
    391436
    392                 <label for="accp_new_page_title">Client Page Title</label>
    393                 <input type="text" class="accp-new-page-title" name="accp_new_page_title">             
     437                <span class="accp-generate-new-page-field-container">
     438
     439                    <label for="accp_new_page_title">Client Page Title</label>
     440                    <input type="text" class="accp-new-page-title" name="accp_new_page_title">
     441
     442                </span>
     443               
     444                <?php
     445                if( is_user_logged_in() && current_user_can('manage_options') && is_admin() ){
     446                    do_action('accp_after_generate_client_page_title_field');
     447                }
     448                ?>
    394449
    395450                <span class="button button-primary accp-generate-new-page" data-nonce="<?php echo $create_page_nonce; ?>" data-post-id="<?php echo $post->ID; ?>">Generate Page</span>
     
    423478        $post_title = filter_var($_POST['post_title'], FILTER_SANITIZE_STRING);
    424479        $company_post_id = (int)$_POST['company_post_id'];
     480        $is_global = filter_var($_POST['is_global'], FILTER_SANITIZE_STRING) === 'true' ? true : false;
    425481       
    426482        /**
    427483         * Exit if this is a new post that has not yet been saved.
    428484         */
    429         if(!get_post($company_post_id)){
     485        if( !get_post($company_post_id) ){
    430486
    431487            echo 'Please save the post before attempting to assign a home page';
     
    446502
    447503            /**
    448              * Assign the Company to the new Client Page.
     504             * Assign the Company to the new Client Page if this
     505             * is not a global page.
    449506             */
    450             update_post_meta($post_id, 'accp_user', $company_post_id);
     507            if( $is_global != true ){
     508                update_post_meta($post_id, 'accp_user', $company_post_id);
     509            }
     510
     511            /**
     512             * Make the page global if the global option was checked.
     513             */
     514            if( $is_global === true ){
     515                update_post_meta($post_id, 'accp_make_page_global', 'global');
     516            }
    451517
    452518
     
    619685                    $user_name = $user->user_login;
    620686                    $user_first_name = $user->first_name;
    621                     $user_last_name = $user->last_name;         
     687                    $user_last_name = $user->last_name;
     688                    $selected = $saved_primary_user && $saved_primary_user === $user_id ? "selected" : "";                 
    622689                   
    623690                    ?>
    624                     <option value="<?php echo esc_attr($user_id); ?>" <?php echo ($saved_primary_user && $saved_primary_user === $user_id) ? "selected" : ""; ?>><?php echo esc_html($user_name); ?> <?php echo $user_first_name ? ' - ' . esc_html($user_first_name) : ''; ?> <?php echo $user_last_name ? ' ' . esc_html($user_last_name) : ''; ?></option>
     691                    <option value="<?php echo esc_attr($user_id); ?>" <?php echo esc_attr($selected); ?>><?php echo esc_html($user_name); ?> <?php echo $user_first_name ? ' - ' . esc_html($user_first_name) : ''; ?> <?php echo esc_html($user_last_name) ? ' ' . esc_html($user_last_name) : ''; ?></option>
    625692                    <?php
    626693
  • constellation-client-portal/trunk/admin/class-ars-constellation-client-portal-core-authorization.php

    r2906601 r2920206  
    9696
    9797
     98        /**
     99         * Check if this is a Global Access page.
     100         *
     101         * Only valid for Client Page post types,
     102         * and not Client Files, Client Invoices, or
     103         * direct file access.
     104         */
     105        $is_global_page = $this->is_global_company_page($post_id);       
     106
     107        if( $is_global_page === true ){
     108
     109            $authorized = true;
     110
     111            return $authorized;
     112
     113        }
     114
     115
     116        /**
     117         * Check the companies assigned to the user against
     118         * the company assigned to the post.
     119         */
    98120        if( get_post_meta($post_id, 'accp_user', true ) ){
    99121
     
    357379
    358380
     381    /**
     382     * Check if this is a Global Access page
     383     * (Client Pages only), and return authorization.
     384     *
     385     * @param int $post_id - the ID of the Client Page.
     386     *
     387     * @return bool $is_global_page - true if this is a global page.
     388     */
     389    function is_global_company_page($post_id){
     390
     391        if(!$post_id)
     392            return false;
     393           
     394        $post = get_post($post_id);
     395
     396        if(!$post)
     397            return false;
     398
     399        $post_type = $post->post_type;
     400
     401        /**
     402         * Return false if the post type is not "accp_client_pages."
     403         */
     404        if( !$post_type || $post_type != 'accp_client_pages' )
     405            return false;
     406       
     407        $is_global_page = get_post_meta($post_id, 'accp_make_page_global', true);
     408
     409        if( $is_global_page && $is_global_page === 'global' ){
     410
     411            /**
     412             * This is a global page, so return true.
     413             */
     414            return true;
     415
     416        }
     417
     418        return false;
     419   
     420    }
     421
     422
    359423} // END ARS_Constellation_Client_Portal_Core_Authorization
  • constellation-client-portal/trunk/admin/class-ars-constellation-client-portal-invoice.php

    r2906601 r2920206  
    8787            'query_var' => true,
    8888            'can_export' => true,
    89             'rewrite' => false,
     89            'rewrite' => false,         
    9090            'capabilities' => array(
    9191                'edit_post' => 'update_core',
  • constellation-client-portal/trunk/admin/css/ars-constellation-client-portal-admin.css

    r2845715 r2920206  
    494494}
    495495
     496.accp-boxed-container {
     497    background-color: #f6f7f7;
     498    border: 1px solid #eeefef;
     499    padding-left: 15px;
     500    padding-right: 15px;
     501}
     502
     503.accp-boxed-container.current-assigned-company-container {
     504    margin-bottom: 20px;
     505}
     506
     507.accp-boxed-container label {
     508    font-weight: 600;
     509    padding-top: 15px;
     510}
     511
     512.accp-or-sparator {
     513    font-weight: 600;
     514}
     515
     516.accp-admin-tooltip-icon{
     517    content: 'i';
     518    color: #fff;
     519    background-color: #5A5A5A;
     520    border-radius: 50%;
     521    width: 12px;
     522    height: 12px;
     523    font-family: Georgia, 'Times New Roman', Times, serif;
     524    display: inline-block;
     525    text-align: center;
     526    font-size: 9px;
     527    padding-top: 1px;
     528    position: relative;
     529    top: -10px;
     530    cursor: pointer;
     531}
     532
     533.accp-admin-tooltip-icon:hover + .accp-wp-admin-tooltip{
     534    visibility: visible;
     535}
     536
     537.accp-wp-admin-tooltip {
     538    position: absolute;
     539    z-index: 1;
     540    width: 150px;
     541    background-color: #fff;
     542    padding: 10px;
     543    border-radius: 5px;
     544    visibility: hidden;
     545    margin-top: -100px;
     546    font-weight: normal;
     547    font-size: 12px;
     548    color: #3c434a;
     549    line-height: 18px;
     550    pointer-events: none;
     551}
     552
     553.accp-wp-admin-tooltip-dark {
     554    position: absolute;
     555    z-index: 1;
     556    width: 150px;
     557    background-color: #3c434a;
     558    padding: 10px;
     559    border-radius: 5px;
     560    visibility: hidden;
     561    margin-top: -100px;
     562    font-weight: normal;
     563    font-size: 12px;
     564    color: #fff;
     565    line-height: 18px;
     566    pointer-events: none;
     567}
     568
     569.accp-wp-admin-tooltip.accp-user-status-tooltip {
     570    left: 0;
     571}
     572
     573.accp-wp-admin-tooltip::after {
     574    content:'';
     575    position: absolute;
     576    top: 100%;
     577    left: 50%;   
     578    border-top: solid 10px #ffffff;
     579    border-left: solid 10px transparent;
     580    border-right: solid 10px transparent;
     581    margin-left: -60px;
     582    width: 0;
     583    height: 0;
     584}
     585
     586.accp-wp-admin-tooltip-dark::after {
     587    border-top: solid 10px #3c434a;
     588}
     589
     590.accp-wp-admin-has-tooltip-center {
     591    left: 12%;
     592    margin-top: -115px;
     593}
     594
     595.accp-company-global-page-tooltip {
     596    margin-top: -143px;
     597}
     598
     599.accp-generate-page-form p.accp-create-new-page-instructions {
     600    margin-top: 20px;
     601}
     602
     603.accp-generate-new-page-field-container {
     604    display: block;
     605    margin-bottom: 10px;
     606}
     607
     608.button.button-primary.accp-generate-new-page {
     609    margin-top: 15px;
     610}
     611
     612.accp-unpublished-company-item {
     613    padding: 10px;
     614    background-color: #fff;
     615    margin-right: 7px;
     616    border-radius: 3px;
     617}
     618
     619.accp-delete-unpublished-company-item {
     620    display: inline-block;
     621    background-color: #C3C3C3;
     622    width: 15px;
     623    text-align: center;
     624    padding-right: 1px;
     625    cursor: pointer;
     626}
     627
     628.accp-column-pointer-item{
     629    cursor: pointer;
     630}
     631
     632.accp-spinner.spinner {
     633    margin-top: 20px;
     634}
     635
     636option.accp-non-published-post-option {
     637    color: #717171;
     638}
     639
     640.accp-boxed-container label[for="accp_make_page_global"] {
     641    display: block;
     642    padding-bottom: 15px;
     643}
     644
     645.accp-boxed-container.accp-specify-company-field-container .select2-container {
     646    padding-bottom: 15px;
     647}
     648
     649.accp-boxed-container.current-assigned-company-container p {
     650    padding-top: 15px;
     651    padding-bottom: 15px;
     652}
     653
    496654.accp-directory-assigned{
    497655    display: none;
  • constellation-client-portal/trunk/admin/js/ars-constellation-client-portal-admin.js

    r2906601 r2920206  
    88
    99        accp_admin_make_company_select_field_required();
    10 
    11         if($('select.accp_admin_list_filter').length){
    12            
    13             $('select.accp_admin_list_filter').select2({
    14                
    15             });
    16 
    17         }
    18 
    19         $('.client-add-company-select').select2({
    20             placeholder: 'Select a company...',
    21             multiple: true,
    22             allowClear: true,
    23             tags: true,
    24             tokenSeparators: [',', ' ']   
    25         });
     10       
     11        accp_initiate_core_select2_fields();               
    2612       
    2713        // Delete file associated with accp_clientfile post
     
    2915        $('table a.submitdelete').click(function (e) {
    3016           
    31             if (window.location.href.indexOf("post_status=trash&post_type=accp_clientfile") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientinvoice") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientcompany") > -1) {           
     17            if (window.location.href.indexOf("post_status=trash&post_type=accp_clientfile") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientinvoice") > -1 ) {         
    3218               
    3319                var file_del_nonce = $('#clientfile-admin-nonce').attr('data-nonce');   
     
    7864        $('#doaction').click(function (e) {
    7965       
    80             // Only do this on accp_clientfile delete pages
    81             if ( (window.location.href.indexOf("post_status=trash&post_type=accp_clientfile") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientinvoice") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientcompany") > -1) && $('#bulk-action-selector-top').val() == 'delete' ) {   
     66            // Only do this on accp_clientfile or accp_clientinvoice delete pages
     67            if (
     68                (
     69                window.location.href.indexOf("post_status=trash&post_type=accp_clientfile") > -1 ||
     70                window.location.href.indexOf("post_status=trash&post_type=accp_clientinvoice") > -1
     71                ) &&
     72                $('#bulk-action-selector-top').val() == 'delete'
     73            ){ 
    8274
    8375                e.preventDefault();             
     
    128120         $('#delete_all').click(function (e) {     
    129121           
    130             if (window.location.href.indexOf("post_status=trash&post_type=accp_clientfile") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientinvoice") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientcompany") > -1) {   
     122            if (window.location.href.indexOf("post_status=trash&post_type=accp_clientfile") > -1 || window.location.href.indexOf("post_status=trash&post_type=accp_clientinvoice") > -1 ) {
    131123
    132124                e.preventDefault();
     
    173165        });
    174166
    175         accp_admin_toggle_file_reassigne_form();
     167        accp_admin_toggle_file_reassign_form();
    176168
    177169        accp_admin_toggle_file_replace_form();
     
    533525
    534526                                $('.accp-primary-user-section-message').html('Primary User: ' + response_obj.username);
    535                                 $('input[name="accp_company_primary_user"').val(response_obj.user_id);
     527                                $('input[name="accp_company_primary_user"').val(response_obj.user_id); // Save to hidden field for Gutenberg.
    536528                                $('.accp-create-user-text-field').val('');
    537529                                $('#accp-send-user-notification').prop('checked', false);
     
    602594        $('.accp-generate-new-page').click(function (e) {
    603595           
    604             e.preventDefault();         
     596            e.preventDefault();     
     597           
     598            accp_add_and_show_status_spinner(e);
     599           
     600            $(this).css('pointer-events', 'none');
     601            $(this).prop('disabled', true);
     602            $(this).attr('disabled', true);
    605603
    606604            var nonce = $(this).attr('data-nonce');
    607605            var post_title = $('.accp-new-page-title').val();
    608             var company_post_id = $(this).attr('data-post-id');     
     606            var company_post_id = $(this).attr('data-post-id');
     607            var is_global = 'false';
     608           
     609            if( $('#accp-make-page-global-input').length ){
     610
     611                if( $('#accp-make-page-global-input').is(':checked') ){
     612
     613                    var is_global = 'true';
     614
     615                }
     616
     617            }
    609618
    610619            $.ajax({
     
    616625                    post_title: post_title,
    617626                    company_post_id: company_post_id,
     627                    is_global: is_global,
    618628                    nonce: nonce                                                   
    619629                },
     
    632642                        $('.accp-generate-page-form').toggle('slow');
    633643                        $('.accp-generate-new-page').text('Create New Page');
     644                        $('.accp-spinner.spinner').remove();
     645                        $('.accp-generate-new-page').css('pointer-events', 'all');
     646                        $('.accp-generate-new-page').prop('disabled', false);
     647                        $('.accp-generate-new-page').attr('disabled', false);
     648                        $('#accp-make-page-global-input').prop('checked', false);
     649                        $('#accp-make-page-global-input').attr('checked', false);
    634650
    635651                    }else{
     
    638654
    639655                        $('.accp-generate-page-message').text(message);
     656                        $('.accp-spinner.spinner').remove();
     657                        $('.accp-generate-new-page').css('pointer-events', 'all');
     658                        $('.accp-generate-new-page').prop('disabled', false);
     659                        $('.accp-generate-new-page').attr('disabled', false);
     660                        $('#accp-make-page-global-input').prop('checked', false);
     661                        $('#accp-make-page-global-input').attr('checked', false);
    640662
    641663                    }                   
     
    643665                },
    644666                error: function(jqXHR, textStatus, errorThrown){
     667
     668                    $('.accp-spinner.spinner').remove();
     669                    $('.accp-generate-new-page').css('pointer-events', 'all');
     670                    $('.accp-generate-new-page').prop('disabled', false);
     671                    $('.accp-generate-new-page').attr('disabled', false);
     672                    $('#accp-make-page-global-input').prop('checked', false);
     673                    $('#accp-make-page-global-input').attr('checked', false);
     674
    645675                    console.log(textStatus, errorThrown);
    646676                    console.log(jqXHR);
     677                   
    647678                },         
    648679                               
     
    786817
    787818
    788     function accp_admin_toggle_file_reassigne_form(){
     819    function accp_admin_toggle_file_reassign_form(){
    789820
    790821        $('#reassign-toggle').click(function () {
     
    881912    }
    882913
     914    function accp_add_and_show_status_spinner(e){
     915
     916        var target_elem = e.target;
     917        var unique_class = 'accp-' + Math.random().toString(36).slice(2) + '-spinner';
     918        var spinner_elem = '<span class="'+unique_class+' accp-spinner spinner" style="float: none;"></span>';
     919        var new_spinner_class = '.' + unique_class + '.accp-spinner.spinner';
     920
     921        $(spinner_elem).insertAfter(target_elem);
     922        $(new_spinner_class).css('visibility', 'visible');
     923       
     924        return new_spinner_class;
     925
     926    }
     927
     928
     929    function accp_initiate_core_select2_fields(){
     930
     931        $('.client-add-company-select').select2({
     932            placeholder: 'Select a company...',
     933            multiple: true,
     934            allowClear: true,
     935            tags: true,
     936            tokenSeparators: [',', ' ']   
     937        });
     938
     939        $('#company-select').select2({
     940            placeholder: 'Select a company...',
     941            multiple: false,
     942            allowClear: true,
     943            tags: true,
     944            tokenSeparators: [',', ' ']   
     945        });
     946
     947        if($('select.accp_admin_list_filter').length){
     948           
     949            $('select.accp_admin_list_filter').select2({
     950                multiple: false                         
     951            });
     952
     953        }
     954
     955    }
    883956
    884957})( jQuery );
  • constellation-client-portal/trunk/ars-constellation-client-portal.php

    r2906601 r2920206  
    55 * Plugin URI:        https://adrianrodriguezstudios.com/constellation-client-portal/
    66 * Description:       Create private pages for each of your clients, post private files, and protect your client files from unauthorized users and search engines.  <strong>Important:</strong> All Site-level File Protection features will cease to function if the plugin is disabled or uninstalled.
    7  * Version:           1.5.7
     7 * Version:           1.5.8
    88 * Author:            ARS
    99 * Author URI:        https://adrianrodriguezstudios.com
     
    5555     */
    5656    define('ACCP_PLUGIN_NAME', 'ARS_CONSTELLATION_CLIENT_PORTAL');
    57     define('ACCP_PLUGIN_VERSION', '1.5.7'); // Change the version in the header as well.
     57    define('ACCP_PLUGIN_VERSION', '1.5.8'); // Change the version in the header as well.
    5858    define( ACCP_PLUGIN_NAME, ACCP_PLUGIN_VERSION );
    5959    define('ACCP_PLUGIN_FILE_NAME', __FILE__);
  • constellation-client-portal/trunk/includes/class-ars-constellation-client-portal.php

    r2906601 r2920206  
    124124        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ars-constellation-client-portal-core-authorization.php';
    125125        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ars-constellation-client-portal-core-file-checks.php';
     126        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ars-constellation-client-portal-users.php';
    126127        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ars-constellation-client-portal-utility-functions.php';
    127128
     
    198199        $plugin_client_invoice = new ARS_Constellation_Client_Portal_Client_Invoice( $this->get_plugin_name(), $this->get_version() );
    199200        $plugin_authorization = new ARS_Constellation_Client_Portal_Core_Authorization( $this->get_plugin_name(), $this->get_version() );
     201        $plugin_users = new ARS_Constellation_Client_Portal_Users( $this->get_plugin_name(), $this->get_version() );
    200202
    201203        /* Core (Basic tier) hooks */
    202204        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    203         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );     
     205        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
     206       
     207       
     208        /**
     209         * WP user list.
     210         */
     211        $this->loader->add_filter('manage_users_columns', $plugin_admin, 'add_wp_user_list_columns');
     212        $this->loader->add_filter('manage_users_custom_column', $plugin_admin, 'add_wp_user_list_column_content', 10, 3);
     213
     214
     215        /**
     216         * Remove company from user profile when company is permanently deleted in WP.
     217         */
     218        $this->loader->add_action( 'after_delete_post', $plugin_users, 'remove_company_from_user_on_company_permanent_delete', 10, 2 );
    204219
    205220
     
    408423        $this->loader->add_action( 'init', $plugin_client_pages, 'accp_register_taxonomy_client_page_tags' );
    409424
    410         //Client Pages - WP list table columns
     425        // Client Pages - WP list table columns
    411426        $this->loader->add_filter( 'manage_accp_client_pages_posts_columns', $plugin_client_pages, 'accp_client_pages_column_register');
    412427        $this->loader->add_action( 'manage_accp_client_pages_posts_custom_column', $plugin_client_pages, 'accp_client_pages_column_display_company_name', 10, 2 );
     
    425440
    426441        // Generate User Password ajax function
    427         $this->loader->add_action( 'wp_ajax_accp_generate_user_password', $plugin_admin, 'accp_generate_user_password');   
    428        
     442        $this->loader->add_action( 'wp_ajax_accp_generate_user_password', $plugin_admin, 'accp_generate_user_password');       
    429443
    430444        //Add content above the clienfile list table
     
    460474            require_once ( dirname(__DIR__)  . '/pro/admin/ars-constellation-client-portal-pro-admin-hooks.php'  );         
    461475           
    462         }
    463 
    464         /* Premium tier hooks */
    465         if ( $this->plugin_name == 'ars-constellation-client-portal-premium' ){     
    466            
    467             // Include the Pro hooks
    468             $plugin_pro_admin = new ARS_Constellation_Client_Portal_Pro_Admin( $this->get_plugin_name(), $this->get_version() );
    469             $plugin_pro_email = new ARS_Constellation_Client_Portal_Pro_Email( $this->get_plugin_name(), $this->get_version() );
    470 
    471             require_once ( dirname(__DIR__)  . '/pro/admin/ars-constellation-client-portal-pro-admin-hooks.php'  );
    472 
    473             // Include the Premium hooks
    474             $plugin_premium_admin = new ARS_Constellation_Client_Portal_Premium_Admin( $this->get_plugin_name(), $this->get_version() );
    475             require_once ( dirname(__DIR__)  . '/premium/admin/ars-constellation-client-portal-prem-admin-hooks.php'  );
    476            
    477         }
     476        }       
    478477       
    479478    }
  • constellation-client-portal/trunk/public/class-ars-constellation-client-portal-public.php

    r2906601 r2920206  
    101101        $list_instance = filter_var( $this->accp_generate_list_instance_id(), FILTER_SANITIZE_NUMBER_INT);
    102102        $paged_param = 'paged' . $list_instance;
    103         $paged = isset( $_GET[$paged_param] ) ? (int)$_GET[$paged_param] : 1;
    104        
    105         // Get the Company ID associated with the current user
    106         $curr_user_company_id = get_user_meta( $user_id, 'client_company', true );
    107 
    108         // Get the Company id of the current page
    109         $page_company = get_post_meta($post_id, 'accp_user', true);
    110 
    111         // Get additonal assigned companies
    112         $additional_assigned_companies = get_user_meta($user_id, 'client_additional_company', true);
    113 
    114         if ( $additional_assigned_companies != null && in_array($page_company, $additional_assigned_companies) ){
    115 
    116             $additional_company_id = $page_company;
    117 
    118         }else{
    119 
    120             $additional_company_id = null;
    121             $additional_assigned_companies = array();
    122         }
    123 
    124         if ( $additional_company_id != null){
    125            
    126             $authorized_company_id = $additional_company_id;
    127 
    128         }else{
    129            
    130             $authorized_company_id = $curr_user_company_id;
    131         }
    132 
    133         // Admins have access to all companies
    134         if( current_user_can('manage_options') ){
    135 
    136             $authorized_company_id = $page_company;
    137             $additional_assigned_companies = array();
    138 
    139         }
     103        $paged = isset( $_GET[$paged_param] ) ? (int)$_GET[$paged_param] : 1;       
     104        $authorized_company_id = $this->get_client_page_authorized_company_id_by_user_id($user_id, $post_id);
     105
     106        /**
     107         * Exit if the $authorized_company_id is false.
     108         */
     109        if( false === $authorized_company_id || !$authorized_company_id )
     110            return;
    140111
    141112        $current_date = date('Y-m-d');
     
    658629        $paged = isset( $_GET[$paged_param] ) ? (int)$_GET[$paged_param] : 1;
    659630
    660         // Get the Company ID associated with the current user
    661         $curr_user_company_id = get_user_meta( $user_id, 'client_company', true );
    662 
    663         // Get the Company id of the current page
    664         $page_company = get_post_meta($post_id, 'accp_user', true);
    665 
    666         // Get additonal assigned companies
    667         $additional_assigned_companies = get_user_meta($user_id, 'client_additional_company', true);
    668 
    669         if ( $additional_assigned_companies != null && in_array($page_company, $additional_assigned_companies) ){
    670 
    671             $additional_company_id = $page_company;
    672 
    673         }else{
    674 
    675             $additional_company_id = null;
    676             $additional_assigned_companies = array();
    677         }
    678 
    679         if ( $additional_company_id != null){
    680            
    681             $authorized_company_id = $additional_company_id;
    682 
    683         }else{
    684            
    685             $authorized_company_id = $curr_user_company_id;
    686         }
    687 
    688         // Admins have access to all companies
    689         if( current_user_can('manage_options') ){
    690 
    691             $authorized_company_id = $page_company;
    692             $additional_assigned_companies = array();
    693 
    694         }
     631        $authorized_company_id = $this->get_client_page_authorized_company_id_by_user_id($user_id, $post_id);
     632
     633        /**
     634         * Exit if the $authorized_company_id is false.
     635         */
     636        if( false === $authorized_company_id || !$authorized_company_id )
     637            return;
    695638
    696639        $current_date = date('Y-m-d');
     
    706649         * Conditionally add Pro Tier shortcode attributes.
    707650         */
    708         if ( $this->plugin_name == 'ars-constellation-client-portal-pro' || $this->plugin_name == 'ars-constellation-client-portal-premium' ){
     651        if ( $this->plugin_name == 'ars-constellation-client-portal-pro' ){
    709652            include dirname(__DIR__) . '/pro/public/accp-invoice-list-shortcode-atts.php';
    710653        }
     
    11321075
    11331076        return $html;
     1077    }
     1078
     1079
     1080    /**
     1081     * Get the authorized company ID for a given user.
     1082     *
     1083     * This ID is used for generating file and invoice
     1084     * post loops for the specified company(ID).
     1085     *
     1086     * @param int $user_id - The user ID of the respective user.
     1087     * @param int $post_id - The ID of the current Client Page.
     1088     *
     1089     * @return int|bool $authorized_company_id|false - The post ID of the company that the user has
     1090     * access to.
     1091     */
     1092    function get_client_page_authorized_company_id_by_user_id($user_id, $post_id){
     1093
     1094        if( !$user_id || !$post_id)
     1095            return false;
     1096
     1097        /**
     1098         * Get the primary Company ID associated with the current user.
     1099         */
     1100        $user_primary_company_id = get_user_meta( $user_id, 'client_company', true );       
     1101
     1102        /**
     1103         * Get additonal companies assigned to the user (if any).
     1104         */
     1105        $additional_assigned_companies = get_user_meta($user_id, 'client_additional_company', true);
     1106
     1107        /**
     1108         * Check if this is a Client page set to global
     1109         * access before checking for a saved company.
     1110         *
     1111         * Only valid for Client Page post types,
     1112         * and not Client Files, Client Invoices, or
     1113         * direct file access.
     1114         */
     1115        $core_authorization = new ARS_Constellation_Client_Portal_Core_Authorization( $this->plugin_name, $this->version );
     1116        $is_global_page = $core_authorization->is_global_company_page($post_id);
     1117
     1118        if( true === $is_global_page ){
     1119
     1120            /**
     1121             * If this is a global page, verify that the current user
     1122             * only has a single company assigned, otherwise return false.
     1123             *
     1124             * Global pages are only suitable for users that have a single
     1125             * company assigned.
     1126             */
     1127            if( $user_primary_company_id && $additional_assigned_companies && !empty($additional_assigned_companies) )
     1128                return false;
     1129
     1130            if( !$user_primary_company_id && $additional_assigned_companies && count($additional_assigned_companies) > 1 )
     1131                return false;
     1132
     1133            /**
     1134             * Otherwise set the $authorized_company_id to the
     1135             * user primary company ID, or a single additonal company
     1136             * if the primary company is not set, and only a single
     1137             * additional company is set.
     1138             */
     1139            if($user_primary_company_id){
     1140
     1141                $authorized_company_id = (int)$user_primary_company_id;
     1142
     1143                return $authorized_company_id;
     1144
     1145            }
     1146
     1147            if( !empty($additional_assigned_companies) && is_array($additional_assigned_companies) && count($additional_assigned_companies) === 1 ){
     1148
     1149                $authorized_company_id = (int)$additional_assigned_companies[0];
     1150
     1151                return $authorized_company_id;
     1152
     1153            }
     1154
     1155        }
     1156
     1157
     1158        /**
     1159         * Get the Company id of the current page if
     1160         * this is not a global page.
     1161         */
     1162        $page_company_id = get_post_meta($post_id, 'accp_user', true);
     1163
     1164        if(!$page_company_id)
     1165            return false;
     1166
     1167        if ( $additional_assigned_companies && !empty($additional_assigned_companies) && in_array($page_company_id, $additional_assigned_companies) ){
     1168           
     1169            $additional_company_id = $page_company_id;
     1170
     1171        }else{
     1172
     1173            $additional_company_id = '';
     1174            $additional_assigned_companies = array();
     1175
     1176        }
     1177
     1178        if ( $additional_company_id && !empty($additional_company_id) ){
     1179           
     1180            $authorized_company_id = (int)$additional_company_id;
     1181
     1182        }else{
     1183           
     1184            $authorized_company_id = $user_primary_company_id ? (int)$user_primary_company_id : false;
     1185
     1186        }
     1187
     1188        /**
     1189         * Admins have access to all companies, so just
     1190         * return the current Client Page ID as the authorized
     1191         * company ID if the current user is an admin.
     1192         */
     1193        if( current_user_can('manage_options') ){
     1194
     1195            $authorized_company_id = $page_company_id;
     1196            $additional_assigned_companies = array();
     1197
     1198            return $authorized_company_id;
     1199
     1200        }
     1201
     1202        return $authorized_company_id;
     1203
    11341204    }
    11351205
     
    12231293    /**
    12241294     * Set up Client Home Page Link shortcode.
     1295     * This will only check the user's primary
     1296     * assigned company, and base the home page
     1297     * on that.
    12251298     *
    12261299     * Shortcode: [accp_my_company_page]
     
    12551328        $html = '';
    12561329
    1257         // Link Text att
    1258         if($atts['link_text'] != null){
     1330        /**
     1331         * Link Text att.
     1332         */
     1333        $link_text = 'My Home';
     1334
     1335        if( $atts['link_text'] != null ){
    12591336
    12601337            $link_text = $atts['link_text'];
    12611338
    1262         }else{
    1263 
    1264             $link_text = 'My Home';
    1265 
    12661339        }
    12671340
    1268         // Link Class att
    1269         if($atts['link_class'] != null){
     1341        /**
     1342         * Link Class att.
     1343         */
     1344        $link_class = null;
     1345
     1346        if( $atts['link_class'] != null ){
    12701347
    12711348            $link_class = $atts['link_class'];
    12721349
    1273         }else{
    1274 
    1275             $link_class = null;
    1276 
    12771350        }
    12781351
    1279         // Hide if Logged Out att
     1352        /**
     1353         * Hide if Logged Out att.
     1354         */
     1355        $hide_logged_out = true;
     1356
    12801357        if($atts['hide_logged_out'] != null){
    12811358
    12821359            $hide_logged_out = strtolower($atts['hide_logged_out']);
    12831360
    1284         }else{
    1285 
    1286             $hide_logged_out = true;
    1287 
    12881361        }       
    12891362
    1290         // Get the Company ID associated with the current user
     1363        /**
     1364         * Get the primary Company ID associated with the current user.
     1365         */
    12911366        $curr_user_company_id = get_user_meta( $user_id, 'client_company', true );
    12921367
    1293         // Get the home page of the current user's company
    1294         if( !empty($curr_user_company_id) ){
     1368        if(!$curr_user_company_id)
     1369            return;
     1370
     1371
     1372        /**
     1373         * Get the home page of the current user's company.
     1374         */
     1375        $company_home_page = null;
     1376
     1377        if( $curr_user_company_id && !empty($curr_user_company_id) ){
    12951378
    12961379            $company_home_page = get_post_meta($curr_user_company_id, 'accp_home_page', true);
    12971380
    1298         }else{
    1299 
    1300             $company_home_page = null;
    1301 
    1302         }
    1303 
    1304         if( is_user_logged_in() && $hide_logged_out != false ){
    1305        
    1306             if( $company_home_page != null && !empty($company_home_page) && $curr_user_company_id != null && !empty($curr_user_company_id) ){
    1307                 $home_page_link = get_the_permalink($company_home_page);
    1308                
    1309                 ?>             
    1310                 <a class="accp-home-link <?php echo $link_class != null ? esc_attr($link_class) : ''; ?>" href="<?php echo esc_url($home_page_link); ?>"><?php echo esc_html($link_text); ?></a>
    1311                 <?php       
    1312 
    1313             }
    1314 
    1315         }else if( !is_user_logged_in() && $hide_logged_out === 'false' && $hide_logged_out !== true){
     1381        }
     1382
     1383        if( $company_home_page === null || !$company_home_page || empty($company_home_page) )
     1384            return;
     1385
     1386        if( is_user_logged_in() ){     
     1387           
     1388            $home_page_link = get_the_permalink($company_home_page);
     1389           
     1390            ?>             
     1391            <a class="accp-home-link <?php echo $link_class != null ? esc_attr($link_class) : ''; ?>" href="<?php echo esc_url($home_page_link); ?>"><?php echo esc_html($link_text); ?></a>
     1392            <?php           
     1393
     1394        }elseif( !is_user_logged_in() && $hide_logged_out === 'false' ){
    13161395
    13171396            ?>             
Note: See TracChangeset for help on using the changeset viewer.