GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( fc9531...c44ae7 )
by Brad
02:36
created

FooGallery_Admin_CSS_Load_Optimizer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php
2
/**
3
 * FooGallery_Admin_CSS_Load_Optimizer class
4
 * Date: 23/06/2015
5
 */
6
if (!class_exists('FooGallery_Admin_CSS_Load_Optimizer')) {
7
8
    class FooGallery_Admin_CSS_Load_Optimizer {
9
10
        private $_locator;
11
12
        function __construct() {
13
            add_action( 'foogallery_start_attach_gallery_to_post', array( $this, 'start_attach_gallery_to_post' ) );
14
            add_action( 'foogallery_attach_gallery_to_post', array( $this, 'attach_shortcode_to_post' ), 10, 2 );
15
            add_action( 'foogallery_after_save_gallery', array( $this, 'detach_gallery_from_all_posts' ), 10, 1 );
16
        }
17
18
        function start_attach_gallery_to_post( $post_id ) {
19
            //Clear any foogallery css that the post might need to include
20
            delete_post_meta( $post_id, FOOGALLERY_META_POST_USAGE_CSS );
21
22
            //create an instance of the template loader that we will use to find CSS files that the different FooGalleries will require to be loaded
23
            $template_loader = new FooGallery_Template_Loader();
24
            $this->_locator = $template_loader->create_locator_instance();
25
        }
26
27
        function attach_shortcode_to_post( $post_id, $foogallery_id ) {
28
            global $foogallery_templates_css;
29
30
            if ( !is_array( $foogallery_templates_css ) ) {
31
                $foogallery_templates_css = array();
32
            }
33
34
            //load the foogallery, so we can get the template that is used
35
            $foogallery = FooGallery::get_by_id( $foogallery_id );
36
            $template = $foogallery->gallery_template;
37
38
            //check to see if we have already added this template's stylesheet
39
            if ( array_key_exists( $template, $foogallery_templates_css ) ) {
40
41
                //we have already added the template's stylesheets, so do not try again. Possibly 2 galleries on the page
42
43
            } else {
44
                $foogallery_templates_css[] = $template;
45
46
                if ( false !== ( $css_location = $this->_locator->locate_file( "gallery-{$template}.css" ) ) ) {
47
48
                    $style = array(
49
                        'src' => $css_location['url'],
50
                        'deps' => array(),
51
                        'ver' => FOOGALLERY_VERSION,
52
                        'media' => 'all'
53
                    );
54
55
                    add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE_CSS, array( "foogallery-template-{$template}" => $style ), false );
56
                }
57
            }
58
        }
59
60
        function detach_gallery_from_all_posts( $post_id ) {
61
            $gallery = FooGallery::get_by_id( $post_id );
62
            $posts = $gallery->find_usages();
63
64
            foreach ( $posts as $post ) {
65
                delete_post_meta( $post->ID, FOOGALLERY_META_POST_USAGE_CSS );
66
            }
67
        }
68
    }
69
}
70