| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - | |
| 4 | 3 | namespace FL\Assistant\Providers; |
| 5 | 4 | |
| 5 | +use FL\Assistant\System\Contracts\ServiceProviderAbstract; | |
| 6 | 6 | |
| 7 | 7 | use FL\Assistant\Hooks\Actions\OnEditUserProfile; |
| 8 | 8 | use FL\Assistant\Hooks\Actions\OnEnqueueScripts; |
| 9 | 9 | use FL\Assistant\Hooks\Actions\OnPersonalOptionsUpdate; |
| @@ -9,16 +9,19 @@ | ||
| 9 | 9 | use FL\Assistant\Hooks\Actions\OnPersonalOptionsUpdate; |
| 10 | 10 | use FL\Assistant\Hooks\Actions\OnWPBeforeAdminBarRender; |
| 11 | 11 | use FL\Assistant\Hooks\Actions\OnBeforeDeletePost; |
| 12 | 12 | use FL\Assistant\Hooks\Actions\OnDeleteTerm; |
| 13 | +use FL\Assistant\Hooks\Actions\OnCustomizeRegister; | |
| 14 | + | |
| 13 | 15 | use FL\Assistant\Hooks\Filters\OnHeartbeatReceived; |
| 14 | 16 | use FL\Assistant\Hooks\Filters\OnFLBuilderUIBarButtons; |
| 15 | -use FL\Assistant\System\Contracts\ServiceProviderAbstract; | |
| 16 | -use FL\Assistant\Data\Transformers\NotationsTransformer; | |
| 17 | -use FL\Assistant\Data\Repository\NotationsRepository; | |
| 18 | -use FL\Assistant\Data\Repository\LabelsRepository; | |
| 19 | -use FL\Assistant\Data\Transformers\LabelsTransformer; | |
| 17 | +use FL\Assistant\Hooks\Filters\OnScriptLoaderTag; | |
| 20 | 18 | |
| 19 | +use FL\Assistant\Hooks\AdminColumns; | |
| 20 | +use FL\Assistant\Hooks\ImageProxy; | |
| 21 | +use FL\Assistant\Hooks\PostPreview; | |
| 22 | +use FL\Assistant\Hooks\CustomizerPreview; | |
| 23 | + | |
| 21 | 24 | class HooksServiceProvider extends ServiceProviderAbstract { |
| 22 | 25 | |
| 23 | 26 | /** |
| 24 | 27 | * @throws \FL\Assistant\System\Container\InjectionException |
| @@ -32,8 +35,13 @@ | ||
| 32 | 35 | ); |
| 33 | 36 | |
| 34 | 37 | $this->actions(); |
| 35 | 38 | $this->filters(); |
| 39 | + | |
| 40 | + new AdminColumns(); | |
| 41 | + new ImageProxy(); | |
| 42 | + new PostPreview(); | |
| 43 | + new CustomizerPreview(); | |
| 36 | 44 | } |
| 37 | 45 | |
| 38 | 46 | public function actions() { |
| 39 | 47 | |
| @@ -54,8 +62,11 @@ | ||
| 54 | 62 | |
| 55 | 63 | // taxonomy actions |
| 56 | 64 | add_action( 'delete_term', $this->injector->make( OnDeleteTerm::class ) ); |
| 57 | 65 | |
| 66 | + // Customize register | |
| 67 | + add_action( 'customize_register', $this->injector->make( OnCustomizeRegister::class ) ); | |
| 68 | + | |
| 58 | 69 | } |
| 59 | 70 | |
| 60 | 71 | public function filters() { |
| 61 | 72 | |
| @@ -63,54 +74,7 @@ | ||
| 63 | 74 | add_filter( 'heartbeat_received', $this->injector->make( OnHeartbeatReceived::class ), 11, 2 ); |
| 64 | 75 | |
| 65 | 76 | add_filter( 'fl_builder_ui_bar_buttons', $this->injector->make( OnFLBuilderUIBarButtons::class ) ); |
| 66 | 77 | |
| 67 | - // Setup custom WP admin post list columns | |
| 68 | - $this->enqueue_custom_admin_columns(); | |
| 69 | - } | |
| 70 | - | |
| 71 | - public function enqueue_custom_admin_columns() { | |
| 72 | - | |
| 73 | - $types = get_post_types( [ 'public' => true ], 'objects' ); | |
| 74 | - | |
| 75 | - foreach ( $types as $type => $info ) { | |
| 76 | - add_filter( "manage_{$type}_posts_columns", [ $this, 'add_columns' ] ); | |
| 77 | - add_action( "manage_{$type}_posts_custom_column", [ $this, 'render_column' ], 10, 2 ); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - public function add_columns( $columns ) { | |
| 82 | - $columns['fl_assistant'] = __( 'Assistant', 'fl-assistant' ); | |
| 83 | - return $columns; | |
| 84 | - } | |
| 85 | - | |
| 86 | - public function render_column( $column, $post_id ) { | |
| 87 | - $vars = '--fl-asst-red: #FF5335; --fl-asst-blue: #1BADF8; --fl-asst-green: #00D281; --fl-asst-yellow: #FFD000; --fl-asst-orange: #FF9500; --fl-asst-purple: #CC73E1; --fl-asst-pink: #FF2968;'; | |
| 88 | - $styles = "{$vars} padding: 2px 5px; display: inline-flex; flex: 0 0 auto; border-radius: 3px; border: 1px solid #d2d2d2; align-items: center; color: black; background: white; margin: 2px 5px 3px; margin-left:0; font-size: 12px;"; | |
| 89 | - $dot = 'width: 10px; height: 10px; flex: 0 0 10px; border-radius: 7px; background: blue; margin-right: 5px;'; | |
| 90 | - | |
| 91 | - if ( 'fl_assistant' === $column ) { | |
| 92 | - $transformer = new NotationsTransformer; | |
| 93 | - $repository = new NotationsRepository( $transformer ); | |
| 94 | - $labels = $repository->get_labels( 'post', $post_id ); | |
| 95 | - | |
| 96 | - $labels_repo = new LabelsRepository; | |
| 97 | - $labels_transformer = new LabelsTransformer( $labels_repo ); | |
| 98 | - $terms = $labels_repo->query( [ 'hide_empty' => false ] )->get_terms(); | |
| 99 | - | |
| 100 | - // Assemble term meta dataset | |
| 101 | - $term_meta = []; | |
| 102 | - foreach ( $terms as $key => $term ) { | |
| 103 | - $item = call_user_func( $labels_transformer, $term ); | |
| 104 | - $term_meta[ $item['id'] ] = $item; | |
| 105 | - } | |
| 106 | - | |
| 107 | - // Output labels | |
| 108 | - foreach ( $labels as $label ) { | |
| 109 | - $term = $term_meta[ $label['label_id'] ]; | |
| 110 | - if ( isset( $term ) ) { | |
| 111 | - print "<span style='{$styles}'><span style='{$dot}; background-color: {$term['color']}'></span>{$term['label']}</span>"; | |
| 112 | - } | |
| 113 | - } | |
| 114 | - } | |
| 78 | + add_filter( 'script_loader_tag', $this->injector->make( OnScriptLoaderTag::class ), 10, 3 ); | |
| 115 | 79 | } |
| 116 | 80 | } |