data
9 years ago
widgets
4 years ago
admin-dashboard.php
6 years ago
admin-layouts.php
4 years ago
admin-widget-dialog.php
6 years ago
admin-widgets-bundle.php
9 years ago
admin.php
3 years ago
cache-renderer.php
6 years ago
css-builder.php
4 years ago
functions.php
6 years ago
home.php
9 years ago
live-editor.php
6 years ago
post-content-filters.php
5 years ago
renderer-legacy.php
3 years ago
renderer.php
3 years ago
revisions.php
6 years ago
settings.php
4 years ago
sidebars-emulator.php
4 years ago
styles-admin.php
3 years ago
styles.php
3 years ago
widget-shortcode.php
4 years ago
admin-widget-dialog.php
194 lines
| 1 | <?php |
| 2 | |
| 3 | class SiteOrigin_Panels_Admin_Widget_Dialog { |
| 4 | |
| 5 | function __construct() { |
| 6 | add_filter( 'siteorigin_panels_widgets', array( $this, 'add_recommended_widgets' ) ); |
| 7 | add_filter( 'siteorigin_panels_widget_dialog_tabs', array( $this, 'add_widgets_dialog_tabs' ), 20 ); |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * @return SiteOrigin_Panels_Admin_Widget_Dialog |
| 12 | */ |
| 13 | public static function single() { |
| 14 | static $single; |
| 15 | return empty( $single ) ? $single = new self() : $single; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Add some default recommended widgets. |
| 20 | * |
| 21 | * @param $widgets |
| 22 | * |
| 23 | * @return array |
| 24 | */ |
| 25 | function add_recommended_widgets( $widgets ) { |
| 26 | |
| 27 | if ( ! empty( $widgets['WP_Widget_Black_Studio_TinyMCE'] ) ) { |
| 28 | $widgets['WP_Widget_Black_Studio_TinyMCE']['groups'] = array( 'recommended' ); |
| 29 | $widgets['WP_Widget_Black_Studio_TinyMCE']['icon'] = 'dashicons dashicons-edit'; |
| 30 | } |
| 31 | |
| 32 | if ( siteorigin_panels_setting( 'recommended-widgets' ) ) { |
| 33 | // Add in all the widgets bundle widgets |
| 34 | $widgets = wp_parse_args( |
| 35 | $widgets, |
| 36 | include plugin_dir_path( __FILE__ ) . 'data/widgets-bundle.php' |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | foreach ( $widgets as $class => $data ) { |
| 41 | if ( strpos( $class, 'SiteOrigin_Panels_Widgets_' ) === 0 || strpos( $class, 'SiteOrigin_Panels_Widget_' ) === 0 ) { |
| 42 | $widgets[ $class ]['groups'] = array( 'panels' ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if ( ! empty( $widgets['SiteOrigin_Panels_Widgets_Layout'] ) ) { |
| 47 | $widgets['SiteOrigin_Panels_Widgets_Layout']['icon'] = 'dashicons dashicons-analytics'; |
| 48 | } |
| 49 | |
| 50 | $wordpress_widgets = array( |
| 51 | 'WP_Widget_Pages', |
| 52 | 'WP_Widget_Links', |
| 53 | 'WP_Widget_Search', |
| 54 | 'WP_Widget_Archives', |
| 55 | 'WP_Widget_Meta', |
| 56 | 'WP_Widget_Calendar', |
| 57 | 'WP_Widget_Text', |
| 58 | 'WP_Widget_Categories', |
| 59 | 'WP_Widget_Recent_Posts', |
| 60 | 'WP_Widget_Recent_Comments', |
| 61 | 'WP_Widget_RSS', |
| 62 | 'WP_Widget_Tag_Cloud', |
| 63 | 'WP_Nav_Menu_Widget', |
| 64 | ); |
| 65 | |
| 66 | foreach ( $wordpress_widgets as $wordpress_widget ) { |
| 67 | if ( isset( $widgets[ $wordpress_widget ] ) ) { |
| 68 | $widgets[ $wordpress_widget ]['groups'] = array( 'wordpress' ); |
| 69 | $widgets[ $wordpress_widget ]['icon'] = 'dashicons dashicons-wordpress'; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Third-party plugins dettection. |
| 74 | foreach ( $widgets as $widget_id => &$widget ) { |
| 75 | if ( strpos( $widget_id, 'WC_' ) === 0 || strpos( $widget_id, 'WooCommerce' ) !== false ) { |
| 76 | $widget['groups'][] = 'woocommerce'; |
| 77 | } |
| 78 | if ( strpos( $widget_id, 'BBP_' ) === 0 || strpos( $widget_id, 'BBPress' ) !== false ) { |
| 79 | $widget['groups'][] = 'bbpress'; |
| 80 | } |
| 81 | if ( strpos( $widget_id, 'Jetpack' ) !== false || strpos( $widget['title'], 'Jetpack' ) !== false ) { |
| 82 | $widget['groups'][] = 'jetpack'; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return $widgets; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Add tabs to the widget dialog |
| 91 | * |
| 92 | * @param $tabs |
| 93 | * |
| 94 | * @return array |
| 95 | */ |
| 96 | function add_widgets_dialog_tabs( $tabs ) { |
| 97 | |
| 98 | $tabs['widgets_bundle'] = array( |
| 99 | 'title' => __( 'Widgets Bundle', 'siteorigin-panels' ), |
| 100 | 'filter' => array( |
| 101 | 'groups' => array( 'so-widgets-bundle' ) |
| 102 | ) |
| 103 | ); |
| 104 | |
| 105 | if ( class_exists( 'SiteOrigin_Widgets_Bundle' ) ) { |
| 106 | // Add a message about enabling more widgets |
| 107 | $tabs['widgets_bundle']['message'] = preg_replace( |
| 108 | array( |
| 109 | '/1\{ *(.*?) *\}/' |
| 110 | ), |
| 111 | array( |
| 112 | '<a href="' . admin_url( 'plugins.php?page=so-widgets-plugins' ) . '">$1</a>' |
| 113 | ), |
| 114 | __( 'Enable more widgets in the 1{Widgets Bundle settings}.', 'siteorigin-panels' ) |
| 115 | ); |
| 116 | } else { |
| 117 | // Add a message about installing the widgets bundle |
| 118 | $tabs['widgets_bundle']['message'] = preg_replace( |
| 119 | '/1\{ *(.*?) *\}/', |
| 120 | '<a href="' . siteorigin_panels_plugin_activation_install_url( 'so-widgets-bundle', __( 'SiteOrigin Widgets Bundle', 'siteorigin-panels' ) ) . '">$1</a>', |
| 121 | __( 'Install the 1{Widgets Bundle} to get extra widgets.', 'siteorigin-panels' ) |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | // Add the Widgets Bundle message to the main widgets tab |
| 126 | $tabs[0]['message'] = $tabs['widgets_bundle']['message']; |
| 127 | |
| 128 | $tabs['page_builder'] = array( |
| 129 | 'title' => __( 'Page Builder Widgets', 'siteorigin-panels' ), |
| 130 | 'message' => preg_replace( |
| 131 | array( |
| 132 | '/1\{ *(.*?) *\}/' |
| 133 | ), |
| 134 | array( |
| 135 | '<a href="' . admin_url( 'options-general.php?page=siteorigin_panels' ) . '">$1</a>' |
| 136 | ), |
| 137 | __( 'You can enable the legacy (PB) widgets in the 1{Page Builder settings}.', 'siteorigin-panels' ) |
| 138 | ), |
| 139 | 'filter' => array( |
| 140 | 'groups' => array( 'panels' ) |
| 141 | ) |
| 142 | ); |
| 143 | |
| 144 | $tabs['wordpress'] = array( |
| 145 | 'title' => __( 'WordPress Widgets', 'siteorigin-panels' ), |
| 146 | 'filter' => array( |
| 147 | 'groups' => array( 'wordpress' ) |
| 148 | ) |
| 149 | ); |
| 150 | |
| 151 | // Check for woocommerce plugin. |
| 152 | if ( defined( 'WOOCOMMERCE_VERSION' ) ) { |
| 153 | $tabs['woocommerce'] = array( |
| 154 | // TRANSLATORS: The name of WordPress plugin |
| 155 | 'title' => __( 'WooCommerce', 'woocommerce' ), |
| 156 | 'filter' => array( |
| 157 | 'groups' => array( 'woocommerce' ) |
| 158 | ) |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | // Check for jetpack plugin. |
| 163 | if ( defined( 'JETPACK__VERSION' ) ) { |
| 164 | $tabs['jetpack'] = array( |
| 165 | // TRANSLATORS: The name of WordPress plugin |
| 166 | 'title' => __( 'Jetpack', 'jetpack' ), |
| 167 | 'filter' => array( |
| 168 | 'groups' => array( 'jetpack' ) |
| 169 | ), |
| 170 | ); |
| 171 | } |
| 172 | |
| 173 | // Check for bbpress plugin. |
| 174 | if ( function_exists( 'bbpress' ) ) { |
| 175 | $tabs['bbpress'] = array( |
| 176 | // TRANSLATORS: The name of WordPress plugin |
| 177 | 'title' => __( 'BBPress', 'bbpress' ), |
| 178 | 'filter' => array( |
| 179 | 'groups' => array( 'bbpress' ) |
| 180 | ), |
| 181 | ); |
| 182 | } |
| 183 | |
| 184 | $tabs['recommended'] = array( |
| 185 | 'title' => __( 'Recommended Widgets', 'siteorigin-panels' ), |
| 186 | 'filter' => array( |
| 187 | 'groups' => array( 'recommended' ) |
| 188 | ) |
| 189 | ); |
| 190 | |
| 191 | return $tabs; |
| 192 | } |
| 193 | } |
| 194 |