function decode_object()

in web/wp-content/plugins/acf-extended/includes/hooks.php [241:385]


    function decode_object($post_id){
    
        //data
        $data = array(
            'id'     => false,
            'type'   => false,
            'object' => false,
            'hooks'  => array(),
        );
    
        /**
         * @string  $post_id  12   | term_46 | user_22 | my-option | comment_89 | widget_56 | menu_74 | menu_item_96 | block_my-block | blog_55 | site_36 | attachment_24
         * @string  $id       12   | 46      | 22      | my-option | 89         | widget_56 | 74      | 96           | block_my-block | 55      | 36      | 24
         * @string  $type     post | term    | user    | option    | comment    | option    | term    | post         | block          | blog    | blog    | post
         */
    
        /**
         * @var $type
         * @var $id
         */
        extract(acf_decode_post_id($post_id));
        
        // validate id
        if(!$id){
            return false;
        }
        
        // assign default
        $data['id'] = $id;
        $data['type'] = $type;
        
        switch($type){
            
            // post
            case 'post': {
    
                $post = get_post($id);
                if($post && !is_wp_error($post)){
        
                    $data['object'] = $post;
        
                    if(isset($post->post_type) && post_type_exists($post->post_type)){
                        $data['hooks'][] = "post_type={$post->post_type}";
                    }
        
                }
                
                break;
            }
            
            // term
            case 'term': {
    
                $term = get_term($id);
                if($term && !is_wp_error($term)){
        
                    $data['object'] = $term;
        
                    if(isset($term->taxonomy) && taxonomy_exists($term->taxonomy)){
                        $data['hooks'][] = "taxonomy={$term->taxonomy}";
                    }
        
                }
        
                break;
            }
            
            // user
            case 'user': {
    
                $user = get_user_by('id', $id);
                if($user && !is_wp_error($user)){
        
                    $data['object'] = $user;
        
                    if(isset($user->roles) && !empty($user->roles)){
                        foreach($user->roles as $role){
                            $data['hooks'][] = "role={$role}";
                        }
                    }
        
                }
        
                break;
            }
            
            // option
            case 'option': {
    
                $location = acf_get_form_data('location');
                $options_page = acf_maybe_get($location, 'options_page');
    
                if($options_page){
        
                    $data['object'] = acf_get_options_page($options_page);
                    $data['hooks'][] = "slug={$options_page}";
        
                }
        
                break;
            }
            
            // comment
            case 'comment': {
    
                $comment = get_comment($id);
                if($comment && !is_wp_error($comment)){
                    $data['object'] = $comment;
                }
        
                break;
            }
            
            // block
            case 'block': {
    
                $block = acf_get_block_type("acf/$id");
                if($block){
                    $data['object'] = $block;
                }
        
                break;
            }
            
            // blog
            case 'blog': {
    
                if(function_exists('get_blog_details')){
        
                    $blog = get_blog_details($id);
                    if($blog){
                        $data['object'] = $blog;
                    }
        
                }
        
                break;
            }
            
        }
        
        // return
        return $data;
        
    }