admin
3 years ago
compatibility
3 years ago
extensions
3 years ago
foopluginbase
3 years ago
public
3 years ago
thumbs
3 years ago
class-attachment-filters.php
3 years ago
class-foogallery-animated-gif-support.php
3 years ago
class-foogallery-attachment-custom-class.php
3 years ago
class-foogallery-attachment.php
3 years ago
class-foogallery-cache.php
3 years ago
class-foogallery-common-fields.php
3 years ago
class-foogallery-crop-position.php
3 years ago
class-foogallery-datasource-media_library.php
3 years ago
class-foogallery-debug.php
3 years ago
class-foogallery-extensions-compatibility.php
3 years ago
class-foogallery-force-https.php
3 years ago
class-foogallery-lazyload.php
3 years ago
class-foogallery-paging.php
3 years ago
class-foogallery-sitemaps.php
3 years ago
class-foogallery-widget.php
3 years ago
class-foogallery.php
3 years ago
class-gallery-advanced-settings.php
3 years ago
class-il8n.php
3 years ago
class-override-thumbnail.php
3 years ago
class-posttypes.php
3 years ago
class-retina.php
3 years ago
class-thumbnail-dimensions.php
3 years ago
class-thumbnails.php
3 years ago
class-version-check.php
3 years ago
constants.php
3 years ago
functions.php
3 years ago
includes.php
3 years ago
index.php
3 years ago
render-functions.php
3 years ago
class-foogallery-debug.php
161 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class used to help with debugging issues in FooGallery |
| 4 | * |
| 5 | * @package foogallery |
| 6 | * |
| 7 | * Date: 03/05/2021 |
| 8 | */ |
| 9 | |
| 10 | if ( ! class_exists( 'FooGallery_Debug' ) ) { |
| 11 | |
| 12 | /** |
| 13 | * Class FooGallery_Debug |
| 14 | */ |
| 15 | class FooGallery_Debug { |
| 16 | |
| 17 | /** |
| 18 | * FooGallery_Debug constructor. |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | if ( is_admin() ) { |
| 22 | add_action( 'add_meta_boxes_' . FOOGALLERY_CPT_GALLERY, array( $this, 'add_meta_boxes_to_gallery' ) ); |
| 23 | } |
| 24 | |
| 25 | add_action( 'foogallery_loaded_template_after', array( $this, 'output_gallery_debug_info' ), 10, 1 ); |
| 26 | |
| 27 | add_filter( 'foogallery_build_class_attribute', array( $this, 'add_debug_class' ), 10, 2 ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Add a debug class onto the container if in debug |
| 32 | * |
| 33 | * @param array $classes The list of classes. |
| 34 | * @param FooGallery $gallery The gallery we are working with. |
| 35 | * |
| 36 | * @return array |
| 37 | */ |
| 38 | public function add_debug_class( $classes, $gallery ) { |
| 39 | if ( foogallery_is_debug() ) { |
| 40 | $classes[] = 'fg-debug'; |
| 41 | } |
| 42 | |
| 43 | return $classes; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Output an HTML comment containing some debug info for the gallery |
| 48 | * |
| 49 | * @param FooGallery $gallery the current gallery being output. |
| 50 | */ |
| 51 | public function output_gallery_debug_info( $gallery ) { |
| 52 | if ( ! foogallery_is_debug() ) { |
| 53 | return; // Get out early if we are not in debug mode! |
| 54 | } |
| 55 | echo '<!-- FooGallery Debug Info : Start'; |
| 56 | echo "\r\n"; |
| 57 | echo "\r\n"; |
| 58 | $main = array( |
| 59 | 'ID' => $gallery->ID, |
| 60 | 'Template' => $gallery->gallery_template, |
| 61 | 'Datasource' => $gallery->datasource_name, |
| 62 | ); |
| 63 | if ( isset( $gallery->datasource_value ) ) { |
| 64 | $main['Datasource Value'] = $gallery->datasource_value; |
| 65 | } |
| 66 | foogallery_render_debug_array( $main ); |
| 67 | echo "\r\n"; |
| 68 | echo 'FooGallery Settings'; |
| 69 | echo "\r\n"; |
| 70 | echo '==================='; |
| 71 | echo "\r\n"; |
| 72 | $settings = $gallery->settings; |
| 73 | if ( is_array( $settings ) ) { |
| 74 | ksort( $settings ); |
| 75 | } |
| 76 | foogallery_render_debug_array( $settings ); |
| 77 | echo "\r\n"; |
| 78 | |
| 79 | echo 'Attachment Info'; |
| 80 | echo "\r\n"; |
| 81 | echo '==============='; |
| 82 | echo "\r\n"; |
| 83 | $dimensions = array(); |
| 84 | foreach ( $gallery->attachments() as $attachment ) { |
| 85 | $dimension = array( |
| 86 | 'url' => $attachment->url, |
| 87 | 'type' => $attachment->type, |
| 88 | ); |
| 89 | if ( isset( $attachment->has_thumbnail_dimensions ) && $attachment->has_thumbnail_dimensions ) { |
| 90 | $dimension['width'] = $attachment->thumb_width; |
| 91 | $dimension['height'] = $attachment->thumb_height; |
| 92 | } |
| 93 | if ( $attachment->ID > 0 ) { |
| 94 | $dimensions[ $attachment->ID ] = $dimension; |
| 95 | } else { |
| 96 | $dimensions[] = $dimension; |
| 97 | } |
| 98 | } |
| 99 | foogallery_render_debug_array( $dimensions ); |
| 100 | echo "\r\n"; |
| 101 | |
| 102 | |
| 103 | do_action( 'foogallery_gallery_debug_output', $gallery ); |
| 104 | echo 'FooGallery Debug Info : End -->'; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Add debug metabox to foogallery edit screen in admin |
| 109 | * |
| 110 | * @param WP_Post $post the current post being edited. |
| 111 | */ |
| 112 | public function add_meta_boxes_to_gallery( $post ) { |
| 113 | |
| 114 | if ( foogallery_is_debug() ) { |
| 115 | add_meta_box( |
| 116 | 'foogallery_debug', |
| 117 | __( 'Gallery Debugging', 'foogallery' ), |
| 118 | array( $this, 'render_upgrade_debug_metabox' ), |
| 119 | FOOGALLERY_CPT_GALLERY, |
| 120 | 'normal', |
| 121 | 'low' |
| 122 | ); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Render the debug metabox |
| 128 | * |
| 129 | * @param WP_Post $post the current post being edited. |
| 130 | */ |
| 131 | public function render_upgrade_debug_metabox( $post ) { |
| 132 | $gallery = FooGallery::get( $post ); |
| 133 | |
| 134 | if ( ! $gallery->is_new() ) { |
| 135 | $settings = $gallery->settings; |
| 136 | |
| 137 | if ( is_array( $settings ) ) { |
| 138 | ksort( $settings ); |
| 139 | } |
| 140 | ?> |
| 141 | <style> |
| 142 | #foogallery_debug .inside { overflow: scroll; } |
| 143 | #foogallery_debug table { font-size: 0.8em; } |
| 144 | #foogallery_debug td { vertical-align: top; } |
| 145 | </style> |
| 146 | <h3>Template</h3> |
| 147 | <?php echo esc_html( $gallery->gallery_template ); ?> |
| 148 | <h3>Datasource</h3> |
| 149 | <?php echo esc_html( $gallery->datasource_name ); ?> |
| 150 | <h3>Settings</h3> |
| 151 | <div style="width:100%; height: 300px; overflow: scroll"> |
| 152 | <?php var_dump( $settings ); ?> |
| 153 | </div> |
| 154 | <?php |
| 155 | } |
| 156 | |
| 157 | do_action( 'foogallery_admin_gallery_debug_output', $gallery ); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 |