PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.44.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.44.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 3.6.2 All 177 releases
simple-tags / inc / class.plugin.php

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

201 lines 5.9 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 $default_options['taxopress_ai_' . $post_type . '_metabox_show_term_slug'] = 0;
73
74 $default_options['taxopress_ai_' . $post_type . '_minimum_term_length'] = 2;
75 $default_options['taxopress_ai_' . $post_type . '_maximum_term_length'] = 40;
76
77 $default_options['taxopress_ai_' . $post_type . '_support_private_taxonomy'] = 0;
78 $default_options['taxopress_ai_' . $post_type . '_exclusions'] = '';
79 $default_options['enable_taxopress_ai_' . $post_type . '_metabox'] = $opt_default_value;
80 $default_options['taxopress_ai_' . $post_type . '_metabox_filters'] = 1;
81
82 foreach (['post_terms', 'existing_terms', 'suggest_local_terms', 'create_terms'] as $taxopress_ai_tab) {
83 $default_options['enable_taxopress_ai_' . $post_type . '_' . $taxopress_ai_tab . '_tab'] = ($post_type == 'post') ? 1 : 0;
84 }
85 }
86
87 // add metabox post type and taxonomies options so we can have all post types. TODO: This need to be a filter
88 $tax_names = array_keys(get_taxonomies([], 'names'));
89 foreach (taxopress_get_all_wp_roles() as $role_name => $role_info) {
90 if (in_array($role_name, ['administrator', 'editor', 'author', 'contributor'])) {
91 $enable_acess_default_value = 1;
92 } else {
93 $enable_acess_default_value = 0;
94 }
95 $default_options['enable_' . $role_name . '_metabox'] = $enable_acess_default_value;
96 $default_options['enable_restrict_' . $role_name . '_metabox'] = $enable_acess_default_value;
97
98 // ONLY admin + editor can edit the metabox label by default
99 $default_options['enable_edit_' . $role_name . '_metabox'] = in_array($role_name, ['administrator', 'editor']) ? 1 : 0;
100
101 $options['enable_metabox_' . $role_name . ''] = $tax_names;
102 $options['remove_taxonomy_metabox_' . $role_name . ''] = [];
103 }
104
105 return $default_options;
106 }
107
108 /**
109 * Load plugin option, combine DB options with default
110 */
111 private static function load_option() {
112 $saved_option = wp_parse_args( (array) get_option( STAGS_OPTIONS_NAME ), self::load_default_option() );
113
114 self::$options = $saved_option;
115 }
116
117 /*
118 * Get all options into an array
119 *
120 * @return array
121 */
122 public static function get_option() {
123 if ( null === self::$options ) {
124 self::load_option();
125 }
126
127 return self::$options;
128 }
129
130 /**
131 * Get one option value from all options
132 *
133 * @param string $key
134 *
135 * @return bool|mixed
136 */
137 public static function get_option_value( $key = '' ) {
138 if ( null === self::$options ) {
139 self::load_option();
140 }
141
142 return isset( self::$options[ $key ] ) ? self::$options[ $key ] : false;
143 }
144
145 /**
146 * Update one option value from all options
147 *
148 * @param string $key
149 * @param string $value
150 * @param bool $auto_update
151 */
152 public static function set_option_value( $key = '', $value = '', $auto_update = true ) {
153 if ( null === self::$options ) {
154 self::load_option();
155 }
156
157 if ( isset( self::$options[ $key ] ) ) {
158 self::$options[ $key ] = $value;
159
160 if ( true === $auto_update ) {
161 self::update_option();
162 }
163 }
164 }
165
166 /**
167 * Update all options
168 *
169 * @param $value
170 * @param bool $auto_update
171 */
172 public static function set_option( $value, $auto_update = true ) {
173 self::$options = $value;
174
175 if ( true === $auto_update ) {
176 self::update_option();
177 }
178 }
179
180 /**
181 * Set default option into DB
182 */
183 public static function set_default_option() {
184 self::$options = self::load_default_option();
185 self::update_option();
186 }
187
188 /**
189 * Update options into DB
190 *
191 * @return bool
192 */
193 public static function update_option() {
194 if ( null === self::$options ) {
195 self::load_option();
196 }
197
198 return update_option( STAGS_OPTIONS_NAME, self::$options );
199 }
200 }
201