1: <?php
2:
3: if ( ! defined( 'ABSPATH' ) ) exit;
4:
5: 6: 7:
8:
9: function is_sensei() {
10: global $post;
11:
12: $is_sensei = false;
13:
14: $post_types = array( 'lesson', 'course', 'quiz', 'question' );
15: $taxonomies = array( 'course-category', 'quiz-type', 'question-type', 'lesson-tag', 'module' );
16:
17: if( is_post_type_archive( $post_types ) || is_singular( $post_types ) || is_tax( $taxonomies ) ) {
18:
19: $is_sensei = true;
20:
21: }
22:
23: if( is_object( $post ) && ! is_wp_error( $post ) ) {
24:
25: $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
26: $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
27:
28: if( in_array( $post->ID, array( $course_page_id, $my_courses_page_id ) ) ) {
29:
30: $is_sensei = true;
31:
32: }
33:
34: }
35:
36: return apply_filters( 'is_sensei', $is_sensei, $post );
37: }
38:
39: 40: 41: 42: 43: 44: 45:
46: function sensei_all_access() {
47:
48: $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
49:
50: 51: 52: 53: 54: 55: 56: 57:
58: return apply_filters( 'sensei_all_access', $access );
59:
60: }
61:
62: if ( ! function_exists( 'sensei_light_or_dark' ) ) {
63:
64: 65: 66: 67: 68: 69: 70: 71: 72:
73: function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
74:
75: $hex = str_replace( '#', '', $color );
76:
77: $c_r = hexdec( substr( $hex, 0, 2 ) );
78: $c_g = hexdec( substr( $hex, 2, 2 ) );
79: $c_b = hexdec( substr( $hex, 4, 2 ) );
80: $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
81:
82: return $brightness > 155 ? $dark : $light;
83: }
84: }
85:
86: if ( ! function_exists( 'sensei_rgb_from_hex' ) ) {
87:
88: 89: 90: 91: 92: 93: 94:
95: function sensei_rgb_from_hex( $color ) {
96: $color = str_replace( '#', '', $color );
97:
98: $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
99:
100: $rgb['R'] = hexdec( $color{0}.$color{1} );
101: $rgb['G'] = hexdec( $color{2}.$color{3} );
102: $rgb['B'] = hexdec( $color{4}.$color{5} );
103: return $rgb;
104: }
105: }
106:
107: if ( ! function_exists( 'sensei_hex_darker' ) ) {
108:
109: 110: 111: 112: 113: 114: 115: 116:
117: function sensei_hex_darker( $color, $factor = 30 ) {
118: $base = sensei_rgb_from_hex( $color );
119: $color = '#';
120:
121: foreach ($base as $k => $v) :
122: $amount = $v / 100;
123: $amount = round($amount * $factor);
124: $new_decimal = $v - $amount;
125:
126: $new_hex_component = dechex($new_decimal);
127: if(strlen($new_hex_component) < 2) :
128: $new_hex_component = "0".$new_hex_component;
129: endif;
130: $color .= $new_hex_component;
131: endforeach;
132:
133: return $color;
134: }
135: }
136:
137: if ( ! function_exists( 'sensei_hex_lighter' ) ) {
138:
139: 140: 141: 142: 143: 144: 145: 146:
147: function sensei_hex_lighter( $color, $factor = 30 ) {
148: $base = sensei_rgb_from_hex( $color );
149: $color = '#';
150:
151: foreach ($base as $k => $v) :
152: $amount = 255 - $v;
153: $amount = $amount / 100;
154: $amount = round($amount * $factor);
155: $new_decimal = $v + $amount;
156:
157: $new_hex_component = dechex($new_decimal);
158: if(strlen($new_hex_component) < 2) :
159: $new_hex_component = "0".$new_hex_component;
160: endif;
161: $color .= $new_hex_component;
162: endforeach;
163:
164: return $color;
165: }
166: }
167:
168: 169: 170: 171: 172: 173:
174: if ( ! function_exists( 'is_woocommerce_active' ) ) {
175: function is_woocommerce_active() {
176:
177:
178:
179:
180:
181: return Sensei_WC::is_woocommerce_present();
182: }
183: }
184:
185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195:
196: function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array() ){
197:
198: if( has_action( $hook_tag ) ){
199:
200: $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
201:
202: if( !empty( $alternative ) ){
203:
204: $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
205:
206: }
207:
208: trigger_error( $error_message );
209: do_action( $hook_tag , $args );
210:
211: }
212:
213: }
214:
215: 216: 217: 218: 219: 220: 221: 222: 223:
224: function sensei_is_a_course( $post ){
225:
226: return "course" == get_post_type( $post );
227:
228: }
229:
230: 231: 232: 233: 234: 235: 236: 237: 238:
239: function sensei_user_login_url(){
240:
241: $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) );
242: $page = get_post( $my_courses_page_id );
243:
244: if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID ) ){
245:
246: return get_permalink( $page->ID );
247:
248: } else {
249:
250: return wp_login_url();
251:
252: }
253:
254: }
255:
256: 257: 258: 259: 260: 261: 262: 263: 264:
265: function sensei_is_login_required(){
266:
267: $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] );
268:
269: return $login_required;
270:
271: }