PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.2
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.2
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.4.2, at inc/class.plugin.php

146 lines 2.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
38 /**
39 * Do nothing :)
40 */
41 public static function deactivation() {
42 }
43
44 /**
45 * Load default option from specific file
46 *
47 * @return array
48 */
49 private static function load_default_option() {
50 return (array) include STAGS_DIR . '/inc/helper.options.default.php';
51 }
52
53 /**
54 * Load plugin option, combine DB options with default
55 */
56 private static function load_option() {
57 $saved_option = wp_parse_args( (array) get_option( STAGS_OPTIONS_NAME ), self::load_default_option() );
58
59 self::$options = $saved_option;
60 }
61
62 /*
63 * Get all options into an array
64 *
65 * @return array
66 */
67 public static function get_option() {
68 if ( null === self::$options ) {
69 self::load_option();
70 }
71
72 return self::$options;
73 }
74
75 /**
76 * Get one option value from all options
77 *
78 * @param string $key
79 *
80 * @return bool|mixed
81 */
82 public static function get_option_value( $key = '' ) {
83 if ( null === self::$options ) {
84 self::load_option();
85 }
86
87 return isset( self::$options[ $key ] ) ? self::$options[ $key ] : false;
88 }
89
90 /**
91 * Update one option value from all options
92 *
93 * @param string $key
94 * @param string $value
95 * @param bool $auto_update
96 */
97 public static function set_option_value( $key = '', $value = '', $auto_update = true ) {
98 if ( null === self::$options ) {
99 self::load_option();
100 }
101
102 if ( isset( self::$options[ $key ] ) ) {
103 self::$options[ $key ] = $value;
104
105 if ( true === $auto_update ) {
106 self::update_option();
107 }
108 }
109 }
110
111 /**
112 * Update all options
113 *
114 * @param $value
115 * @param bool $auto_update
116 */
117 public static function set_option( $value, $auto_update = true ) {
118 self::$options = $value;
119
120 if ( true === $auto_update ) {
121 self::update_option();
122 }
123 }
124
125 /**
126 * Set default option into DB
127 */
128 public static function set_default_option() {
129 self::$options = self::load_default_option();
130 self::update_option();
131 }
132
133 /**
134 * Update options into DB
135 *
136 * @return bool
137 */
138 public static function update_option() {
139 if ( null === self::$options ) {
140 self::load_option();
141 }
142
143 return update_option( STAGS_OPTIONS_NAME, self::$options );
144 }
145 }
146