| 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 |
* @package automattic/jetpack |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* Load Jetpack widget files. |
| 18 |
*/ |
| 19 |
function jetpack_load_widgets() { |
| 20 |
$widgets_include = array(); |
| 21 |
|
| 22 |
foreach ( Jetpack::glob_php( __DIR__ . '/widgets' ) as $file ) { |
| 23 |
$widgets_include[] = $file; |
| 24 |
} |
| 25 |
/** |
| 26 |
* Modify which Jetpack Widgets to register. |
| 27 |
* |
| 28 |
* @module widgets |
| 29 |
* |
| 30 |
* @since 2.2.1 |
| 31 |
* |
| 32 |
* @param array $widgets_include An array of widgets to be registered. |
| 33 |
*/ |
| 34 |
$widgets_include = apply_filters( 'jetpack_widgets_to_include', $widgets_include ); |
| 35 |
|
| 36 |
foreach ( $widgets_include as $include ) { |
| 37 |
include_once $include; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
add_action( 'jetpack_modules_loaded', 'jetpack_widgets_loaded' ); |
| 42 |
/** |
| 43 |
* Actions to perform after Jetpack widgets are loaded. |
| 44 |
*/ |
| 45 |
function jetpack_widgets_loaded() { |
| 46 |
Jetpack::enable_module_configurable( __FILE__ ); |
| 47 |
add_filter( 'jetpack_module_configuration_url_widgets', 'jetpack_widgets_configuration_url' ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Overrides default configuration url |
| 52 |
* |
| 53 |
* @uses admin_url |
| 54 |
* @return string module settings URL |
| 55 |
*/ |
| 56 |
function jetpack_widgets_configuration_url() { |
| 57 |
return admin_url( 'customize.php?autofocus[panel]=widgets' ); |
| 58 |
} |
| 59 |
|
| 60 |
jetpack_load_widgets(); |
| 61 |
|
| 62 |
/** |
| 63 |
* Enqueue utilities to work with widgets in Customizer. |
| 64 |
* |
| 65 |
* @since 4.4.0 |
| 66 |
*/ |
| 67 |
function jetpack_widgets_customizer_assets_preview() { |
| 68 |
wp_enqueue_script( |
| 69 |
'jetpack-customizer-widget-utils', |
| 70 |
plugins_url( '/widgets/customizer-utils.js', __FILE__ ), |
| 71 |
array( 'jquery', 'customize-base' ), |
| 72 |
JETPACK__VERSION, |
| 73 |
false |
| 74 |
); |
| 75 |
} |
| 76 |
add_action( 'customize_preview_init', 'jetpack_widgets_customizer_assets_preview' ); |
| 77 |
|
| 78 |
/** |
| 79 |
* Enqueue styles to stylize widgets in Customizer. |
| 80 |
* |
| 81 |
* @since 4.4.0 |
| 82 |
*/ |
| 83 |
function jetpack_widgets_customizer_assets_controls() { |
| 84 |
wp_enqueue_style( |
| 85 |
'jetpack-customizer-widget-controls', |
| 86 |
plugins_url( '/widgets/customizer-controls.css', __FILE__ ), |
| 87 |
array( 'customize-widgets' ), |
| 88 |
JETPACK__VERSION |
| 89 |
); |
| 90 |
} |
| 91 |
add_action( 'customize_controls_enqueue_scripts', 'jetpack_widgets_customizer_assets_controls' ); |
| 92 |
|
| 93 |
/** |
| 94 |
* Cleanup old Jetpack widgets data. |
| 95 |
*/ |
| 96 |
function jetpack_widgets_remove_old_widgets() { |
| 97 |
$old_widgets = array( |
| 98 |
'googleplus-badge', |
| 99 |
); |
| 100 |
|
| 101 |
// Don't bother cleaning up the sidebars_widgets data. |
| 102 |
// That will get cleaned up the next time a widget is |
| 103 |
// added, removed, moved, etc. |
| 104 |
foreach ( $old_widgets as $old_widget ) { |
| 105 |
delete_option( "widget_{$old_widget}" ); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
add_action( 'updating_jetpack_version', 'jetpack_widgets_remove_old_widgets' ); |
| 110 |
|