PluginProbe
Assistant – Every Day Productivity Apps / 0.3.1
Assistant – Every Day Productivity Apps v0.3.1
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
assistant / backend / src / Data / Repository / LabelsRepository.php

LabelsRepository.php in Assistant – Every Day Productivity Apps 0.3.1, at backend/src/Data/Repository/LabelsRepository.php

70 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FL\Assistant\Data\Repository;
4
5
6 class LabelsRepository extends TermsRepository {
7
8 /**
9 * Storage keys.
10 */
11 const FL_ASST_INSTALLED_LABELS = 'fl_asst_installed_labels';
12 const FL_ASST_NOTATION_COLOR = 'fl_asst_notation_color';
13
14 /**
15 * @param array $args
16 *
17 * @return \WP_Query
18 */
19 public function query( array $args = [] ) {
20 $args = array_merge(
21 $args, [
22 'taxonomy' => 'fl_asst_label',
23 ]
24 );
25
26 return parent::query( $args );
27 }
28
29 public function save_defaults() {
30 $did_install = get_option( static::FL_ASST_INSTALLED_LABELS, false );
31 $existing = $this->query(
32 [
33 'hide_empty' => false,
34 ]
35 )->get_terms();
36
37 if ( $did_install || count( $existing ) > 0 ) {
38 return;
39 }
40
41 /**
42 * Note: Colors changed here need to be changed in
43 * Color.knownColors on the frontend as well.
44 *
45 * TODO: Load from server config.
46 */
47 $default_labels = [
48 '#FF305C' => __( 'Red', 'fl-assistant' ),
49 '#FF9500' => __( 'Orange', 'fl-assistant' ),
50 '#FFD000' => __( 'Yellow', 'fl-assistant' ),
51 '#00D281' => __( 'Green', 'fl-assistant' ),
52 '#1BADF8' => __( 'Blue', 'fl-assistant' ),
53 ];
54
55 foreach ( $default_labels as $color => $label ) {
56 $result = wp_insert_term(
57 $label, 'fl_asst_label', [
58 'slug' => sanitize_key( $label ),
59 ]
60 );
61
62 if ( ! is_wp_error( $result ) ) {
63 update_term_meta( $result['term_id'], static::FL_ASST_NOTATION_COLOR, $color );
64 }
65 }
66
67 update_option( static::FL_ASST_INSTALLED_LABELS, true );
68 }
69 }
70