Aucune description

widgets.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Module Name: Extra Sidebar Widgets
  4. * Module Description: Provides additional widgets for use on your site.
  5. * Sort Order: 4
  6. * First Introduced: 1.2
  7. * Requires Connection: No
  8. * Auto Activate: No
  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. add_filter( 'jetpack_module_configuration_url_widgets', 'jetpack_widgets_configuration_url' );
  38. }
  39. /**
  40. * Overrides default configuration url
  41. *
  42. * @uses admin_url
  43. * @return string module settings URL
  44. */
  45. function jetpack_widgets_configuration_url() {
  46. return admin_url( 'customize.php?autofocus[panel]=widgets' );
  47. }
  48. jetpack_load_widgets();
  49. /**
  50. * Enqueue utilities to work with widgets in Customizer.
  51. *
  52. * @since 4.4.0
  53. */
  54. function jetpack_widgets_customizer_assets_preview() {
  55. wp_enqueue_script( 'jetpack-customizer-widget-utils', plugins_url( '/widgets/customizer-utils.js', __FILE__ ), array( 'customize-base' ) );
  56. }
  57. add_action( 'customize_preview_init', 'jetpack_widgets_customizer_assets_preview' );
  58. /**
  59. * Enqueue styles to stylize widgets in Customizer.
  60. *
  61. * @since 4.4.0
  62. */
  63. function jetpack_widgets_customizer_assets_controls() {
  64. wp_enqueue_style( 'jetpack-customizer-widget-controls', plugins_url( '/widgets/customizer-controls.css', __FILE__ ), array( 'customize-widgets' ) );
  65. }
  66. add_action( 'customize_controls_enqueue_scripts', 'jetpack_widgets_customizer_assets_controls' );
  67. function jetpack_widgets_remove_old_widgets() {
  68. $old_widgets = array(
  69. 'googleplus-badge',
  70. );
  71. // Don't bother cleaning up the sidebars_widgets data.
  72. // That will get cleaned up the next time a widget is
  73. // added, removed, moved, etc.
  74. foreach ( $old_widgets as $old_widget ) {
  75. delete_option( "widget_{$old_widget}" );
  76. }
  77. }
  78. add_action( 'updating_jetpack_version', 'jetpack_widgets_remove_old_widgets' );