PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.38.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.38.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / class.plugin.php

class.plugin.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.38.0, at inc/class.plugin.php

198 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Plugin {
4
5 public static $options = null;
6
7 /**
8 * Add initial ST options in DB, init roles/permissions
9 *
10 * @return void
11 * @author WebFactory Ltd
12 */
13 public static function activation() {
14 // Put default options
15 $options_from_table = get_option( STAGS_OPTIONS_NAME );
16 if ( empty( $options_from_table ) ) {
17 add_option( STAGS_OPTIONS_NAME, self::load_default_option() );
18 }
19
20 // Init roles
21 if ( function_exists( 'get_role' ) ) {
22 $role = get_role( 'administrator' );
23 if ( null !== $role && ! $role->has_cap( 'simple_tags' ) ) {
24 $role->add_cap( 'simple_tags' );
25 }
26
27 if ( null !== $role && ! $role->has_cap( 'admin_simple_tags' ) ) {
28 $role->add_cap( 'admin_simple_tags' );
29 }
30
31 $role = get_role( 'editor' );
32 if ( null !== $role && ! $role->has_cap( 'simple_tags' ) ) {
33 $role->add_cap( 'simple_tags' );
34 }
35 }
36
37 // disable media tag
38 taxopress_deactivate_taxonomy('media_tag');
39
40 // add activated option
41 add_option( 'taxopress_activate', true );
42 }
43
44 /**
45 * Do nothing :)
46 */
47 public static function deactivation() {
48 }
49
50 /**
51 * Load default option from specific file
52 *
53 * @return array
54 */
55 private static function load_default_option() {
56 $default_options = (array) include STAGS_DIR . '/inc/helper.options.default.php';
57
58 // add taxopress ai post type and taxonomies options so we can have all post types. TODO: This need to be a filter
59 foreach (get_post_types(['public' => true], 'names') as $post_type => $post_type_object) {
60 if ($post_type == 'post') {
61 $opt_default_value = 'post_tag';
62 } else {
63 $opt_default_value = 0;
64 }
65 $default_options['taxopress_ai_' . $post_type . '_metabox_default_taxonomy'] = $opt_default_value;
66 $default_options['taxopress_ai_' . $post_type . '_metabox_display_option'] = 'default';
67
68 $default_options['taxopress_ai_' . $post_type . '_metabox_orderby'] = 'count';
69 $default_options['taxopress_ai_' . $post_type . '_metabox_order'] = 'desc';
70 $default_options['taxopress_ai_' . $post_type . '_metabox_maximum_terms'] = 45;
71 $default_options['taxopress_ai_' . $post_type . '_metabox_show_post_count'] = 0;
72
73 $default_options['taxopress_ai_' . $post_type . '_minimum_term_length'] = 2;
74 $default_options['taxopress_ai_' . $post_type . '_maximum_term_length'] = 40;
75
76 $default_options['taxopress_ai_' . $post_type . '_support_private_taxonomy'] = 0;
77 $default_options['taxopress_ai_' . $post_type . '_exclusions'] = '';
78 $default_options['enable_taxopress_ai_' . $post_type . '_metabox'] = $opt_default_value;
79 foreach (['post_terms', 'existing_terms', 'suggest_local_terms', 'create_terms'] as $taxopress_ai_tab) {
80 $default_options['enable_taxopress_ai_' . $post_type . '_' . $taxopress_ai_tab . '_tab'] = 1;
81 }
82 }
83
84 // add metabox post type and taxonomies options so we can have all post types. TODO: This need to be a filter
85 $tax_names = array_keys(get_taxonomies([], 'names'));
86 foreach (taxopress_get_all_wp_roles() as $role_name => $role_info) {
87 if (in_array($role_name, ['administrator', 'editor', 'author', 'contributor'])) {
88 $enable_acess_default_value = 1;
89 } else {
90 $enable_acess_default_value = 0;
91 }
92 $default_options['enable_' . $role_name . '_metabox'] = $enable_acess_default_value;
93 $default_options['enable_restrict_' . $role_name . '_metabox'] = $enable_acess_default_value;
94
95 // ONLY admin + editor can edit the metabox label by default
96 $default_options['enable_edit_' . $role_name . '_metabox'] = in_array($role_name, ['administrator', 'editor']) ? 1 : 0;
97
98 $options['enable_metabox_' . $role_name . ''] = $tax_names;
99 $options['remove_taxonomy_metabox_' . $role_name . ''] = [];
100 }
101
102 return $default_options;
103 }
104
105 /**
106 * Load plugin option, combine DB options with default
107 */
108 private static function load_option() {
109 $saved_option = wp_parse_args( (array) get_option( STAGS_OPTIONS_NAME ), self::load_default_option() );
110
111 self::$options = $saved_option;
112 }
113
114 /*
115 * Get all options into an array
116 *
117 * @return array
118 */
119 public static function get_option() {
120 if ( null === self::$options ) {
121 self::load_option();
122 }
123
124 return self::$options;
125 }
126
127 /**
128 * Get one option value from all options
129 *
130 * @param string $key
131 *
132 * @return bool|mixed
133 */
134 public static function get_option_value( $key = '' ) {
135 if ( null === self::$options ) {
136 self::load_option();
137 }
138
139 return isset( self::$options[ $key ] ) ? self::$options[ $key ] : false;
140 }
141
142 /**
143 * Update one option value from all options
144 *
145 * @param string $key
146 * @param string $value
147 * @param bool $auto_update
148 */
149 public static function set_option_value( $key = '', $value = '', $auto_update = true ) {
150 if ( null === self::$options ) {
151 self::load_option();
152 }
153
154 if ( isset( self::$options[ $key ] ) ) {
155 self::$options[ $key ] = $value;
156
157 if ( true === $auto_update ) {
158 self::update_option();
159 }
160 }
161 }
162
163 /**
164 * Update all options
165 *
166 * @param $value
167 * @param bool $auto_update
168 */
169 public static function set_option( $value, $auto_update = true ) {
170 self::$options = $value;
171
172 if ( true === $auto_update ) {
173 self::update_option();
174 }
175 }
176
177 /**
178 * Set default option into DB
179 */
180 public static function set_default_option() {
181 self::$options = self::load_default_option();
182 self::update_option();
183 }
184
185 /**
186 * Update options into DB
187 *
188 * @return bool
189 */
190 public static function update_option() {
191 if ( null === self::$options ) {
192 self::load_option();
193 }
194
195 return update_option( STAGS_OPTIONS_NAME, self::$options );
196 }
197 }
198