widgets.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Module Name: Extra Sidebar Widgets
  4. * Module Description: Add images, Twitter streams, and more to your sidebar.
  5. * Sort Order: 4
  6. * First Introduced: 1.2
  7. * Requires Connection: No
  8. * Auto Activate: Yes
  9. * Module Tags: Social, Appearance
  10. * Feature: Appearance
  11. * Additional Search Queries: widget, widgets, facebook, gallery, twitter, gravatar, image, rss
  12. */
  13. function jetpack_load_widgets() {
  14. $widgets_include = array();
  15. foreach ( Jetpack::glob_php( dirname( __FILE__ ) . '/widgets' ) as $file ) {
  16. $widgets_include[] = $file;
  17. }
  18. /**
  19. * Modify which Jetpack Widgets to register.
  20. *
  21. * @module widgets
  22. *
  23. * @since 2.2.1
  24. *
  25. * @param array $widgets_include An array of widgets to be registered.
  26. */
  27. $widgets_include = apply_filters( 'jetpack_widgets_to_include', $widgets_include );
  28. foreach( $widgets_include as $include ) {
  29. include_once $include;
  30. }
  31. include_once dirname( __FILE__ ) . '/widgets/migrate-to-core/image-widget.php';
  32. include_once dirname( __FILE__ ) . '/widgets/migrate-to-core/gallery-widget.php';
  33. }
  34. add_action( 'jetpack_modules_loaded', 'jetpack_widgets_loaded' );
  35. function jetpack_widgets_loaded() {
  36. Jetpack::enable_module_configurable( __FILE__ );
  37. Jetpack::module_configuration_load( __FILE__, 'jetpack_widgets_configuration_load' );
  38. }
  39. function jetpack_widgets_configuration_load() {
  40. wp_safe_redirect( admin_url( 'widgets.php' ) );
  41. exit;
  42. }
  43. jetpack_load_widgets();
  44. /**
  45. * Enqueue utilities to work with widgets in Customizer.
  46. *
  47. * @since 4.4.0
  48. */
  49. function jetpack_widgets_customizer_assets_preview() {
  50. wp_enqueue_script( 'jetpack-customizer-widget-utils', plugins_url( '/widgets/customizer-utils.js', __FILE__ ), array( 'customize-base' ) );
  51. }
  52. add_action( 'customize_preview_init', 'jetpack_widgets_customizer_assets_preview' );
  53. /**
  54. * Enqueue styles to stylize widgets in Customizer.
  55. *
  56. * @since 4.4.0
  57. */
  58. function jetpack_widgets_customizer_assets_controls() {
  59. wp_enqueue_style( 'jetpack-customizer-widget-controls', plugins_url( '/widgets/customizer-controls.css', __FILE__ ), array( 'customize-widgets' ) );
  60. }
  61. add_action( 'customize_controls_enqueue_scripts', 'jetpack_widgets_customizer_assets_controls' );