PluginProbe
Widget Context / 1.0.2
Widget Context v1.0.2
1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 trunk 0.4.1 0.4.2 0.4.3 0.4.4 0.4.5 0.6 0.7 0.7.1 0.7.2 0.8 0.8.1 All 30 releases
widget-context / widget-context.php

widget-context.php in Widget Context 1.0.2, at widget-context.php

965 lines 26.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Widget Context
4 Plugin URI: http://wordpress.org/extend/plugins/widget-context/
5 Description: Show or hide widgets depending on the section of the site that is being viewed.
6 Version: 1.0.2
7 Author: Kaspars Dambis
8 Author URI: http://kaspars.net
9 Text Domain: widget-context
10 */
11
12 // Go!
13 widget_context::instance();
14
15 class widget_context {
16
17 private static $instance;
18 private $sidebars_widgets;
19 private $options_name = 'widget_logic_options'; // Context settings for widgets (visibility, etc)
20 private $settings_name = 'widget_context_settings'; // Widget Context global settings
21
22 private $core_modules = array(
23 'word-count/word-count.php',
24 'custom-post-types-taxonomies/custom-cpt-tax.php'
25 );
26
27 var $context_options = array(); // Store visibility settings
28 var $context_settings = array(); // Store admin settings
29 var $contexts = array();
30 var $plugin_path;
31
32
33 static function instance() {
34
35 if ( ! self::$instance )
36 self::$instance = new self();
37
38 return self::$instance;
39
40 }
41
42
43 private function widget_context() {
44
45 // Define available widget contexts
46 add_action( 'init', array( $this, 'define_widget_contexts' ), 5 );
47
48 // Load plugin settings and show/hide widgets by altering the
49 // $sidebars_widgets global variable
50 add_action( 'init', array( $this, 'init_widget_context' ) );
51
52 // Enable localization
53 add_action( 'plugins_loaded', array( $this, 'init_l10n' ) );
54
55 // Append Widget Context settings to widget controls
56 add_action( 'in_widget_form', array( $this, 'widget_context_controls' ), 10, 3 );
57
58 // Add admin menu for config
59 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
60
61 // Style things based on admin color scheme
62 add_action( 'admin_footer', array( $this, 'admin_styles_inline' ) );
63
64 // Save widget context settings, when in admin area
65 add_action( 'sidebar_admin_setup', array( $this, 'save_widget_context_settings' ) );
66
67 // Fix legacy context option naming
68 add_filter( 'widget_context_options', array( $this, 'fix_legacy_options' ) );
69
70 // Register admin settings menu
71 add_action( 'admin_menu', array( $this, 'widget_context_settings_menu' ) );
72
73 // Register admin settings
74 add_action( 'admin_init', array( $this, 'widget_context_settings_init' ) );
75
76 }
77
78
79 function define_widget_contexts() {
80
81 // Initialize core modules
82 $include_path = plugin_dir_path( __FILE__ ) . '/modules';
83
84 foreach ( $this->core_modules as $module ) {
85 include sprintf( '%s/%s', $include_path, $module );
86 }
87
88 // Default context
89 $default_contexts = array(
90 'incexc' => array(
91 'label' => __( 'Widget Context', 'widget-context' ),
92 'description' => __( 'Set the default logic to show or hide.', 'widget-context' ),
93 'weight' => -100,
94 'type' => 'core',
95 ),
96 'location' => array(
97 'label' => __( 'Global Sections', 'widget-context' ),
98 'description' => __( 'Based on standard WordPress template tags.', 'widget-context' ),
99 'weight' => 10
100 ),
101 'url' => array(
102 'label' => __( 'Target by URL', 'widget-context' ),
103 'description' => __( 'Based on URL patterns.', 'widget-context' ),
104 'weight' => 20
105 ),
106 'admin_notes' => array(
107 'label' => __( 'Notes (invisible to public)', 'widget-context' ),
108 'description' => __( 'Enables private notes on widget context settings.'),
109 'weight' => 90
110 )
111 );
112
113 // Add default context controls and checks
114 foreach ( $default_contexts as $context_name => $context_desc ) {
115
116 add_filter( 'widget_context_control-' . $context_name, array( $this, 'control_' . $context_name ), 10, 2 );
117 add_filter( 'widget_context_check-' . $context_name, array( $this, 'context_check_' . $context_name ), 10, 2 );
118
119 }
120
121 // Enable other plugins and themes to specify their own contexts
122 $this->contexts = apply_filters( 'widget_contexts', $default_contexts );
123
124 // Sort contexts by their weight
125 uasort( $this->contexts, array( $this, 'sort_context_by_weight' ) );
126
127 }
128
129
130 function sort_context_by_weight( $a, $b ) {
131
132 if ( ! isset( $a['weight'] ) )
133 $a['weight'] = 10;
134
135 if ( ! isset( $b['weight'] ) )
136 $b['weight'] = 10;
137
138 return ( $a['weight'] < $b['weight'] ) ? -1 : 1;
139
140 }
141
142
143 function init_widget_context() {
144
145 $this->context_options = apply_filters(
146 'widget_context_options',
147 (array) get_option( $this->options_name, array() )
148 );
149
150 $this->context_settings = wp_parse_args(
151 (array) get_option( $this->settings_name, array() ),
152 array(
153 'contexts' => array()
154 )
155 );
156
157 // Hide/show widgets for is_active_sidebar() to work
158 add_filter( 'sidebars_widgets', array( $this, 'maybe_unset_widgets_by_context' ), 10 );
159
160 }
161
162
163 function init_l10n() {
164
165 load_plugin_textdomain( 'widget-context', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
166
167 }
168
169
170 function admin_scripts( $page ) {
171
172 // Enqueue only on widgets and customizer view
173 if ( ! in_array( $page, array( 'widgets.php', 'settings_page_widget_context_settings' ) ) )
174 return;
175
176 wp_enqueue_style(
177 'widget-context-css',
178 plugins_url( 'css/admin.css', plugin_basename( __FILE__ ) )
179 );
180
181 wp_enqueue_script(
182 'widget-context-js',
183 plugins_url( 'js/widget-context.js', plugin_basename( __FILE__ ) ),
184 array( 'jquery' )
185 );
186
187 }
188
189
190 function admin_styles_inline() {
191
192 global $_wp_admin_css_colors;
193
194 $color_scheme = get_user_option( 'admin_color' );
195
196 if ( isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
197
198 printf(
199 '<style type="text/css">
200 .widget-context .widget-context-header h3:before { color:%1$s; }
201 </style>',
202 $_wp_admin_css_colors[ $color_scheme ]->colors[3]
203 );
204
205 }
206
207 }
208
209
210 function widget_context_controls( $object, $return, $instance ) {
211
212 echo $this->display_widget_context( $object->id );
213
214 }
215
216
217 function save_widget_context_settings() {
218
219 if ( ! current_user_can( 'edit_theme_options' ) || empty( $_POST ) || ! isset( $_POST['wl'] ) )
220 return;
221
222 // Delete a widget
223 if ( isset( $_POST['delete_widget'] ) && isset( $_POST['the-widget-id'] ) )
224 unset( $this->context_options[ $_POST['the-widget-id'] ] );
225
226 // Add / Update
227 $this->context_options = array_merge( $this->context_options, $_POST['wl'] );
228
229 $sidebars_widgets = wp_get_sidebars_widgets();
230 $all_widget_ids = array();
231
232 // Get a lits of all widget IDs
233 foreach ( $sidebars_widgets as $widget_area => $widgets )
234 foreach ( $widgets as $widget_order => $widget_id )
235 $all_widget_ids[] = $widget_id;
236
237 // Remove non-existant widget contexts from the settings
238 foreach ( $this->context_options as $widget_id => $widget_context )
239 if ( ! in_array( $widget_id, $all_widget_ids ) )
240 unset( $this->context_options[ $widget_id ] );
241
242 update_option( $this->options_name, $this->context_options );
243
244 }
245
246
247 function maybe_unset_widgets_by_context( $sidebars_widgets ) {
248
249 // Don't run this at the backend or before
250 // post query has been run
251 if ( is_admin() || ! did_action( 'parse_query' ) )
252 return $sidebars_widgets;
253
254 // Return from cache if we have done the context checks already
255 if ( ! empty( $this->sidebars_widgets ) )
256 return $this->sidebars_widgets;
257
258 foreach( $sidebars_widgets as $widget_area => $widget_list ) {
259
260 if ( $widget_area == 'wp_inactive_widgets' || empty( $widget_list ) )
261 continue;
262
263 foreach( $widget_list as $pos => $widget_id ) {
264
265 if ( ! $this->check_widget_visibility( $widget_id ) )
266 unset( $sidebars_widgets[ $widget_area ][ $pos ] );
267
268 }
269
270 }
271
272 // Store in class cache
273 $this->sidebars_widgets = $sidebars_widgets;
274
275 return $sidebars_widgets;
276
277 }
278
279
280 function check_widget_visibility( $widget_id ) {
281
282 // Check if this widget even has context set
283 if ( ! isset( $this->context_options[ $widget_id ] ) )
284 return true;
285
286 $matches = array();
287
288 foreach ( $this->contexts as $context_id => $context_settings ) {
289
290 // This context check has been disabled in the plugin settings
291 if ( isset( $this->context_settings['contexts'][ $context_id ] ) && ! $this->context_settings['contexts'][ $context_id ] )
292 continue;
293
294 // Make sure that context settings for this widget are defined
295 if ( ! isset( $this->context_options[ $widget_id ][ $context_id ] ) )
296 $widget_context_args = array();
297 else
298 $widget_context_args = $this->context_options[ $widget_id ][ $context_id ];
299
300 $matches[ $context_id ] = apply_filters(
301 'widget_context_check-' . $context_id,
302 null,
303 $widget_context_args
304 );
305
306 }
307
308 // Get the match rule for this widget (show/hide/selected/notselected)
309 $match_rule = $this->context_options[ $widget_id ][ 'incexc' ][ 'condition' ];
310
311 // Force show or hide the widget!
312 if ( $match_rule == 'show' )
313 return true;
314 elseif ( $match_rule == 'hide' )
315 return false;
316
317 if ( $match_rule == 'selected' )
318 $inc = true;
319 else
320 $inc = false;
321
322 if ( $inc && in_array( true, $matches ) )
323 return true;
324 elseif ( ! $inc && ! in_array( true, $matches ) )
325 return true;
326 else
327 return false;
328
329 }
330
331
332 /**
333 * Default context checks
334 */
335
336 function context_check_incexc( $check, $settings ) {
337
338 return $check;
339
340 }
341
342
343 function context_check_location( $check, $settings ) {
344
345 $status = array(
346 'is_front_page' => is_front_page(),
347 'is_home' => is_home(),
348 'is_singular' => is_singular(),
349 'is_single' => is_singular( 'post' ),
350 'is_page' => ( is_page() && ! is_front_page() ),
351 'is_attachment' => is_attachment(),
352 'is_search' => is_search(),
353 'is_404' => is_404(),
354 'is_archive' => is_archive(),
355 'is_date' => is_date(),
356 'is_day' => is_day(),
357 'is_month' => is_month(),
358 'is_year' => is_year(),
359 'is_category' => is_category(),
360 'is_tag' => is_tag(),
361 'is_author' => is_author()
362 );
363
364 $matched = array_intersect_assoc( $settings, $status );
365
366 if ( ! empty( $matched ) )
367 return true;
368
369 return $check;
370
371 }
372
373
374 function context_check_url( $check, $settings ) {
375
376 $urls = trim( $settings['urls'] );
377
378 if ( empty( $urls ) )
379 return $check;
380
381 if ( $this->match_path( $urls ) )
382 return true;
383
384 return $check;
385
386 }
387
388
389 // Thanks to Drupal: http://api.drupal.org/api/function/drupal_match_path/6
390 function match_path( $patterns ) {
391
392 global $wp;
393
394 $patterns_safe = array();
395
396 // Get the request URI from WP
397 $url_request = $wp->request;
398
399 // Append the query string
400 if ( ! empty( $_SERVER['QUERY_STRING'] ) )
401 $url_request .= '?' . $_SERVER['QUERY_STRING'];
402
403 foreach ( explode( "\n", $patterns ) as $pattern )
404 $patterns_safe[] = trim( trim( $pattern ), '/' ); // Trim trailing and leading slashes
405
406 // Remove empty URL patterns
407 $patterns_safe = array_filter( $patterns_safe );
408
409 $regexps = '/^('. preg_replace( array( '/(\r\n|\n| )+/', '/\\\\\*/' ), array( '|', '.*' ), preg_quote( implode( "\n", array_filter( $patterns_safe, 'trim' ) ), '/' ) ) .')$/';
410
411 return preg_match( $regexps, $url_request );
412
413 }
414
415
416 // Dummy function
417 function context_check_admin_notes( $check, $widget_id ) {}
418
419
420 // Dummy function
421 function context_check_general( $check, $widget_id ) {}
422
423
424 /*
425 Widget Controls
426 */
427
428 function display_widget_context( $widget_id = null ) {
429
430 $controls = array();
431 $controls_disabled = array();
432 $controls_core = array();
433
434 foreach ( $this->contexts as $context_name => $context_settings ) {
435
436 $context_classes = array(
437 'context-group',
438 sprintf( 'context-group-%s', esc_attr( $context_name ) )
439 );
440
441 // Hide this context from the admin UX. We can't remove them
442 // because settings will get lost if this page is submitted.
443 if ( isset( $this->context_settings['contexts'][ $context_name ] ) && ! $this->context_settings['contexts'][ $context_name ] ) {
444 $context_classes[] = 'context-inactive';
445 $controls_disabled[] = $context_name;
446 }
447
448 // Store core controls
449 if ( isset( $context_settings['type'] ) && 'core' == $context_settings['type'] ) {
450 $controls_core[] = $context_name;
451 }
452
453 $control_args = array(
454 'name' => $context_name,
455 'input_prefix' => 'wl' . $this->get_field_name( array( $widget_id, $context_name ) ),
456 'settings' => $this->get_field_value( array( $widget_id, $context_name ) ),
457 'widget_id' => $widget_id
458 );
459
460 $context_controls = apply_filters( 'widget_context_control-' . $context_name, $control_args );
461 $context_classes = apply_filters( 'widget_context_classes-' . $context_name, $context_classes, $control_args );
462
463 if ( ! empty( $context_controls ) && is_string( $context_controls ) ) {
464
465 $controls[ $context_name ] = sprintf(
466 '<div class="%s">
467 <h4 class="context-toggle">%s</h4>
468 <div class="context-group-wrap">
469 %s
470 </div>
471 </div>',
472 esc_attr( implode( ' ', $context_classes ) ),
473 esc_html( $context_settings['label'] ),
474 $context_controls
475 );
476
477 }
478
479 }
480
481
482
483 // Non-core controls that should be visible if enabled
484 $controls_not_core = array_diff( array_keys( $controls ), $controls_core );
485
486 // Check if any non-core context controls have been enabled
487 $has_controls = array_diff( $controls_not_core, $controls_disabled );
488
489 if ( empty( $controls ) || empty( $has_controls ) ) {
490
491 if ( current_user_can( 'edit_theme_options' ) ) {
492
493 $controls = array( sprintf(
494 '<p class="error">%s</p>',
495 sprintf(
496 __( 'No widget controls enabled. You can enable them in <a href="%s">Widget Context settings</a>.', 'widget-context' ),
497 admin_url( 'options-general.php?page=widget_context_settings' )
498 )
499 ) );
500
501 } else {
502
503 $controls = array( sprintf(
504 '<p class="error">%s</p>',
505 __( 'No widget controls enabled.', 'widget-context' )
506 ) );
507
508 }
509
510 }
511
512 if ( current_user_can( 'edit_theme_options' ) ) {
513
514 $controls[] = sprintf(
515 '<p class="widget-context-settings-link"><a href="%s">%s</a></p>',
516 admin_url( 'options-general.php?page=widget_context_settings' ),
517 __( 'Widget Context Settings', 'widget-context' )
518 );
519
520 }
521
522 return sprintf(
523 '<div class="widget-context">
524 <div class="widget-context-header">
525 <h3>%s</h3>
526 <!-- <a href="#widget-context-%s" class="toggle-contexts hide-if-no-js">
527 <span class="expand">%s</span>
528 <span class="collapse">%s</span>
529 </a> -->
530 </div>
531 <div class="widget-context-inside" id="widget-context-%s" data-widget-id="%s">
532 %s
533 </div>
534 </div>',
535 __( 'Widget Context', 'widget-context' ),
536 esc_attr( $widget_id ),
537 // Toggle buttons
538 __( 'Expand', 'widget-context' ),
539 __( 'Collapse', 'widget-context' ),
540 // Inslide classes
541 esc_attr( $widget_id ),
542 esc_attr( $widget_id ),
543 // Controls
544 implode( '', $controls )
545 );
546
547 }
548
549
550 function control_incexc( $control_args ) {
551
552 $options = array(
553 'show' => __( 'Show widget everywhere', 'widget-context' ),
554 'selected' => __( 'Show widget on selected', 'widget-context' ),
555 'notselected' => __( 'Hide widget on selected', 'widget-context' ),
556 'hide' => __( 'Hide widget everywhere', 'widget-context' )
557 );
558
559 return $this->make_simple_dropdown( $control_args, 'condition', $options );
560
561 }
562
563
564 function control_location( $control_args ) {
565
566 $options = array(
567 'is_front_page' => __( 'Front page', 'widget-context' ),
568 'is_home' => __( 'Blog page', 'widget-context' ),
569 'is_singular' => __( 'All posts, pages and custom post types', 'widget-context' ),
570 'is_single' => __( 'All posts', 'widget-context' ),
571 'is_page' => __( 'All pages', 'widget-context' ),
572 'is_attachment' => __( 'All attachments', 'widget-context' ),
573 'is_search' => __( 'Search results', 'widget-context' ),
574 'is_404' => __( '404 error page', 'widget-context' ),
575 'is_archive' => __( 'All archives', 'widget-context' ),
576 'is_date' => __( 'All date archives', 'widget-context' ),
577 'is_day' => __( 'Daily archives', 'widget-context' ),
578 'is_month' => __( 'Monthly archives', 'widget-context' ),
579 'is_year' => __( 'Yearly archives', 'widget-context' ),
580 'is_category' => __( 'All category archives', 'widget-context' ),
581 'is_tag' => __( 'All tag archives', 'widget-context' ),
582 'is_author' => __( 'All author archives', 'widget-context' )
583 );
584
585 foreach ( $options as $option => $label )
586 $out[] = $this->make_simple_checkbox( $control_args, $option, $label );
587
588 return implode( '', $out );
589
590 }
591
592
593 function control_url( $control_args ) {
594
595 return sprintf(
596 '<div>%s</div>
597 <p class="help">%s</p>',
598 $this->make_simple_textarea( $control_args, 'urls' ),
599 __( 'Enter one location fragment per line. Use <strong>*</strong> character as a wildcard. Example: <code>category/peace/*</code> to target all posts in category <em>peace</em>.', 'widget-context' )
600 );
601
602 }
603
604
605 function control_admin_notes( $control_args ) {
606
607 return sprintf(
608 '<div>%s</div>',
609 $this->make_simple_textarea( $control_args, 'notes' )
610 );
611
612 }
613
614
615
616 /**
617 * Widget control helpers
618 */
619
620
621 function make_simple_checkbox( $control_args, $option, $label ) {
622
623 if ( isset( $control_args['settings'][ $option ] ) && $control_args['settings'][ $option ] )
624 $value = true;
625 else
626 $value = false;
627
628 return sprintf(
629 '<label class="wc-field-checkbox-%s" data-widget-id="%s">
630 <input type="hidden" value="0" name="%s[%s]" />
631 <input type="checkbox" value="1" name="%s[%s]" %s />&nbsp;%s
632 </label>',
633 $this->get_field_classname( $option ),
634 esc_attr( $control_args['widget_id'] ),
635 // Input hidden
636 $control_args['input_prefix'],
637 esc_attr( $option ),
638 // Input value
639 $control_args['input_prefix'],
640 esc_attr( $option ),
641 checked( $value, true, false ),
642 // Label
643 esc_html( $label )
644 );
645
646 }
647
648
649 function make_simple_textarea( $control_args, $option, $label = null ) {
650
651 if ( isset( $control_args['settings'][ $option ] ) )
652 $value = esc_textarea( $control_args['settings'][ $option ] );
653 else
654 $value = '';
655
656 return sprintf(
657 '<label class="wc-field-textarea-%s" data-widget-id="%s">
658 <strong>%s</strong>
659 <textarea name="%s[%s]">%s</textarea>
660 </label>',
661 $this->get_field_classname( $option ),
662 esc_attr( $control_args['widget_id'] ),
663 // Label
664 esc_html( $label ),
665 // Input
666 $control_args['input_prefix'],
667 $option,
668 $value
669 );
670
671 }
672
673
674 function make_simple_textfield( $control_args, $option, $label_before = null, $label_after = null) {
675
676 if ( isset( $control_args['settings'][ $option ] ) )
677 $value = esc_attr( $control_args['settings'][ $option ] );
678 else
679 $value = false;
680
681 return sprintf(
682 '<label class="wc-field-text-%s" data-widget-id="%s">
683 %s
684 <input type="text" name="%s[%s]" value="%s" />
685 %s
686 </label>',
687 $this->get_field_classname( $option ),
688 esc_attr( $control_args['widget_id'] ),
689 // Before
690 $label_before,
691 // Input
692 $control_args['input_prefix'],
693 $option,
694 esc_attr( $value ),
695 // After
696 esc_html( $label_after )
697 );
698
699 }
700
701
702 function make_simple_dropdown( $control_args, $option, $selection = array(), $label_before = null, $label_after = null ) {
703
704 $options = array();
705
706 if ( isset( $control_args['settings'][ $option ] ) )
707 $value = $control_args['settings'][ $option ];
708 else
709 $value = false;
710
711 if ( empty( $selection ) )
712 $options[] = sprintf(
713 '<option value="">%s</option>',
714 esc_html__( 'No options available', 'widget-context' )
715 );
716
717 foreach ( $selection as $sid => $svalue )
718 $options[] = sprintf(
719 '<option value="%s" %s>%s</option>',
720 esc_attr( $sid ),
721 selected( $value, $sid, false ),
722 esc_html( $svalue )
723 );
724
725 return sprintf(
726 '<label class="wc-field-select-%s" data-widget-id="%s">
727 %s
728 <select name="%s[%s]">
729 %s
730 </select>
731 %s
732 </label>',
733 $this->get_field_classname( $option ),
734 esc_attr( $control_args['widget_id'] ),
735 // Before
736 $label_before,
737 // Input
738 $control_args['input_prefix'],
739 $option,
740 implode( '', $options ),
741 // After
742 $label_after
743 );
744
745 }
746
747
748 /**
749 * Returns [part1][part2][partN] from array( 'part1', 'part2', 'part3' )
750 * @param array $parts i.e. array( 'part1', 'part2', 'part3' )
751 * @return string i.e. [part1][part2][partN]
752 */
753 function get_field_name( $parts ) {
754
755 return esc_attr( sprintf( '[%s]', implode( '][', $parts ) ) );
756
757 }
758
759 function get_field_classname( $name ) {
760
761 if ( is_array( $name ) )
762 $name = end( $name );
763
764 return sanitize_html_class( str_replace( '_', '-', $name ) );
765
766 }
767
768
769 /**
770 * Given option keys return its value
771 * @param array $parts i.e. array( 'part1', 'part2', 'part3' )
772 * @param array $options i.e. array( 'part1' => array( 'part2' => array( 'part3' => 'VALUE' ) ) )
773 * @return string Returns option value
774 */
775 function get_field_value( $parts, $options = null ) {
776
777 if ( $options == null )
778 $options = $this->context_options;
779
780 $value = false;
781
782 if ( empty( $parts ) || ! is_array( $parts ) )
783 return false;
784
785 $part = array_shift( $parts );
786
787 if ( ! empty( $parts ) && isset( $options[ $part ] ) && is_array( $options[ $part ] ) )
788 $value = $this->get_field_value( $parts, $options[ $part ] );
789 elseif ( isset( $options[ $part ] ) )
790 return $options[ $part ];
791
792 return $value;
793
794 }
795
796
797 function fix_legacy_options( $options ) {
798
799 if ( empty( $options ) || ! is_array( $options ) )
800 return $options;
801
802 foreach ( $options as $widget_id => $option ) {
803
804 // This doesn't have an include/exclude rule defined
805 if ( ! isset( $option['incexc'] ) )
806 unset( $options[ $widget_id ] );
807
808 // We moved from [incexc] = 1/0 to [incexc][condition] = 1/0
809 if ( isset( $option['incexc'] ) && ! is_array( $option['incexc'] ) )
810 $options[ $widget_id ]['incexc'] = array( 'condition' => $option['incexc'] );
811
812 // Move notes from "general" group to "admin_notes"
813 if ( isset( $option['general']['notes'] ) ) {
814 $options[ $widget_id ]['admin_notes']['notes'] = $option['general']['notes'];
815 unset( $option['general']['notes'] );
816 }
817
818 // We moved word count out of location context group
819 if ( isset( $option['location']['check_wordcount'] ) )
820 $options[ $widget_id ]['word_count'] = array(
821 'check_wordcount' => true,
822 'check_wordcount_type' => $option['location']['check_wordcount_type'],
823 'word_count' => $option['location']['word_count']
824 );
825
826 }
827
828 return $options;
829
830 }
831
832
833
834 /**
835 * Admin Settings
836 */
837
838
839 function widget_context_settings_menu() {
840
841 add_options_page(
842 __( 'Widget Context Settings', 'widget-context' ),
843 __( 'Widget Context', 'widget-context' ),
844 'manage_options',
845 $this->settings_name,
846 array( $this, 'widget_context_admin_view' )
847 );
848
849 }
850
851
852 function widget_context_settings_init() {
853
854 register_setting( $this->settings_name, $this->settings_name );
855
856 }
857
858
859 function widget_context_admin_view() {
860
861 $context_controls = array();
862
863 foreach ( $this->contexts as $context_id => $context_args ) {
864
865 // Hide core modules from being disabled
866 if ( isset( $context_args['type'] ) && $context_args['type'] == 'core' )
867 continue;
868
869 if ( ! empty( $context_args['description'] ) )
870 $context_description = sprintf(
871 '<p class="context-desc">%s</p>',
872 esc_html( $context_args['description'] )
873 );
874 else
875 $context_description = null;
876
877 // Enable new modules by default
878 if ( ! isset( $this->context_settings['contexts'][ $context_id ] ) )
879 $this->context_settings['contexts'][ $context_id ] = 1;
880
881 $context_controls[] = sprintf(
882 '<li class="context-%s">
883 <label>
884 <input type="hidden" name="%s[contexts][%s]" value="0" />
885 <input type="checkbox" name="%s[contexts][%s]" value="1" %s /> %s
886 </label>
887 %s
888 </li>',
889 esc_attr( $context_id ),
890 $this->settings_name,
891 esc_attr( $context_id ),
892 $this->settings_name,
893 esc_attr( $context_id ),
894 checked( $this->context_settings['contexts'][ $context_id ], 1, false ),
895 esc_html( $context_args['label'] ),
896 $context_description
897 );
898
899 }
900
901 ?>
902 <div class="wrap wrap-widget-context">
903 <h2><?php esc_html_e( 'Widget Context Settings', 'widget-context' ); ?></h2>
904
905 <div class="widget-context-settings-wrap">
906
907 <div class="widget-context-form">
908 <form method="post" action="options.php">
909 <?php
910 settings_fields( $this->settings_name );
911 do_settings_sections( $this->settings_name );
912 ?>
913
914 <?php
915 printf(
916 '<div class="settings-section settings-section-modules">
917 <h3>%s</h3>
918 <ul>%s</ul>
919 </div>',
920 esc_html__( 'Enabled Context Modules', 'widget-context' ),
921 implode( '', $context_controls )
922 );
923 ?>
924
925 <?php
926 submit_button();
927 ?>
928 </form>
929 </div>
930
931 <div class="widget-context-sidebar">
932 <div class="wc-sidebar-in">
933
934 <div class="wc-sidebar-section wc-sidebar-credits">
935 <p>
936 <img src="http://gravatar.com/avatar/661eb21385c25c01ad64ab9e13b37331/?s=60" alt="Kaspars Dambis" width="60" height="60" />
937 <?php printf( esc_html__( 'Widget Context is created and maintained by %s.' ), '<a href="http://kaspars.net">Kaspars Dambis</a>' ); ?>
938 </p>
939 </div>
940
941 <div class="wc-sidebar-section wc-sidebar-newsletter">
942 <h3><?php esc_html_e( 'News & Updates' ); ?></h3>
943 <p><?php esc_html_e( 'Subscribe to receive news & updates about the plugin.' ); ?></p>
944 <form action="//osc.us2.list-manage.com/subscribe/post?u=e8d173fc54c0fc4286a2b52e8&amp;id=8afe96c5a3" method="post" target="_blank">
945 <?php $user = wp_get_current_user(); ?>
946 <p><label><?php _e( 'Your Name', 'widget-context' ); ?>: <input type="text" name="NAME" value="<?php echo esc_attr( sprintf( '%s %s', $user->first_name, $user->last_name ) ) ?>" /></label></p>
947 <p><label><?php _e( 'Your Email', 'widget-context' ); ?>: <input type="text" name="EMAIL" value="<?php echo esc_attr( $user->user_email ); ?>" /></label></p>
948 <p><input class="button" name="subscribe" type="submit" value="<?php _e( 'Subscribe', 'widget-context' ); ?>" /></p>
949 </form>
950 </div>
951
952 </div>
953 </div>
954
955 </div>
956 </div>
957 <?php
958
959 }
960
961
962 }
963
964
965