← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Dashboard_widget.php
+36
-77
3.10.13
→
3.4.2
View file →
| @@ -11,9 +11,8 @@ | ||
| 11 | 11 | |
| 12 | 12 | namespace ThemeisleSDK\Modules; |
| 13 | 13 | |
| 14 | 14 | use ThemeisleSDK\Common\Abstract_Module; |
| 15 | -use ThemeisleSDK\Loader; | |
| 16 | 15 | use ThemeisleSDK\Product; |
| 17 | 16 | |
| 18 | 17 | // Exit if accessed directly. |
| 19 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -76,15 +75,13 @@ | ||
| 76 | 75 | if ( apply_filters( 'themeisle_sdk_hide_dashboard_widget', false ) ) { |
| 77 | 76 | return; |
| 78 | 77 | } |
| 79 | 78 | $this->product = $product; |
| 80 | - $this->dashboard_name = apply_filters( 'themeisle_sdk_dashboard_widget_name', Loader::$labels['dashboard_widget']['title'] ); | |
| 79 | + $this->dashboard_name = apply_filters( 'themeisle_sdk_dashboard_widget_name', 'WordPress Guides/Tutorials' ); | |
| 81 | 80 | $this->feeds = apply_filters( |
| 82 | 81 | 'themeisle_sdk_dashboard_widget_feeds', |
| 83 | 82 | [ |
| 84 | 83 | 'https://themeisle.com/blog/feed', |
| 85 | - 'https://www.codeinwp.com/blog/feed', | |
| 86 | - 'https://wpshout.com/feed', | |
| 87 | 84 | ] |
| 88 | 85 | ); |
| 89 | 86 | add_action( 'wp_dashboard_setup', array( &$this, 'add_widget' ) ); |
| 90 | 87 | add_action( 'wp_network_dashboard_setup', array( &$this, 'add_widget' ) ); |
| @@ -98,9 +95,9 @@ | ||
| 98 | 95 | * Add widget to the dashboard |
| 99 | 96 | * |
| 100 | 97 | * @return string|void |
| 101 | 98 | */ |
| 102 | - public function add_widget() { | |
| 99 | + function add_widget() { | |
| 103 | 100 | global $wp_meta_boxes; |
| 104 | 101 | if ( isset( $wp_meta_boxes['dashboard']['normal']['core']['themeisle'] ) ) { |
| 105 | 102 | return; |
| 106 | 103 | } |
| @@ -116,9 +113,9 @@ | ||
| 116 | 113 | |
| 117 | 114 | /** |
| 118 | 115 | * Render widget content |
| 119 | 116 | */ |
| 120 | - public function render_dashboard_widget() { | |
| 117 | + function render_dashboard_widget() { | |
| 121 | 118 | $this->setup_feeds(); |
| 122 | 119 | if ( empty( $this->items ) || ! is_array( $this->items ) ) { |
| 123 | 120 | return; |
| 124 | 121 | } |
| @@ -133,11 +130,10 @@ | ||
| 133 | 130 | |
| 134 | 131 | #themeisle h2.hndle { |
| 135 | 132 | background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABbCAMAAADncTNAAAAAtFBMVEVHcEyAgIB/f3+xsbGgoaGBgYGCgoKKioqAgIC1tbW5ubnFx8iAgIDU1taBgYGCgoKAgIC0tLXW19jW2NiAgIC3uLiBgYHLzMy4uLhycnLW19d/f3/T1NW0tLTX19mVlZWvr6+BgYHl5eWKiottbW5JSUnW2Nm5ubnh4eHT1NWVlZVjY2N4eHh9fX6pqqq+v79PT0/39/fu7u7Nzc7Z2ttYWFgBAQHDw8P////JysoZGRk0NTZqJc/sAAAAIXRSTlMA0FL7/oEnEPL6eibivm9gwJya76/enFq2CXI+2lFAyM8GATmPAAADj0lEQVR4Xu2YaW/iOhSGAwRCWDosnXa6znjJvm8svf//f12TuARyhiR2pfnUR6gSEnr0+uT4xK7yRb755pvhHePli5K7Bfpkuhoq8ozRJdMH+WWha6Z3sqYparCSLRJqspjImVbANJU03cNMMpofAwQZCGsmpQYyFvVM0Q00OQ9koMl5IPcCoro+RA1Dt2Ea9n9eZ0+YHJLkgIlkDywQx00wCTyaReiKH8LbNU9ybJOdkchV6QFxyCFLbVvdfaREqgUWg/tx2UbqIcK2Hex2TdGLwFTjIj3XP3YfCZFsb23KRZn/3263oymSFI0/a5S4PqUBjoBIJBDjeEhCN0wxQSRybIxtJ3K5SGzuE/vAwIQc8ZmMMJFAIM4oikZItfEFtorGgoE43FObwqHU68OtPCnOz8KZ2Jbl5LgkSW0Tc7YyIz/EFWmS4jMbiZU5mJOmKRaJpKGGyLZtDJh3iyaNUu/3+xyKnrtFL71EG+FTiMpENhQtxUQ8kSOXCIr2tnCNhg/gTX0SHYFp0t7TCwQZ7U841yoHrW6rtGroUwTWVnLMssxx+H4bgZcSOFf5MYx0Ae8FghomMDyC2EBNImBywPkNTDNqGLQpIg2TjUNU8tBy9DQMo0DAZF16rAi7vJAtFTIYFAHUc6hIRW6OuOhJgaCSwmDEAYK4oa7ro+qIEyJU/US7KTJKPNSFT9tFgVFBu0SF1y7yjX4masRA9Da7EFGj28R/BkQz6xGIOurkx38T/bKs9Uk8aIiMwm/Jw0VP1yLrJwt13xAxvABBgsK4KWLov35DkRF7ZaqgzuZ7MQ8MOntmVYyAqKTwaICKqvSUFnVccMN5sziEP/5+xGDTahbH5Q3ZB76zr8fI+nJtvUUU3t3ml5GKviK/npCg3CGodnuJ4JVkfRFJYGVDBZrqKnn9RLf+CzDTS5PaN5J38+auzX4ykU4Qoj0rdKfcYs5ijfo9OL/uRUgZyQr7NCWtWwiUSLc4arfJa7lpszTA1OJZAQ8w8dXFrR5YHzCWSnS3pZ18tOi4Ps4vl/c7i/6qomjRecN+UubrPyPGn/VEMU3T0UFHkaPzpgjxmJsnjmrtionlMDZiog0TsY/DPtn8SXtlBvbtxKtwopy7lqW3smQO+yoGE1Uu55GJ3pmI8ygoejZNnqj0vnIRCyTKfLstRdtStGQi09myUsvwvlkuzSUXbV+Xz5ryBebV33fln/A/moud69FZiEYAAAAASUVORK5CYII='); |
| 136 | 133 | background-repeat: no-repeat; |
| 137 | - background-position: 2% 50%; | |
| 134 | + background-position: 92% 50%; | |
| 138 | 135 | background-size: 25px; |
| 139 | - padding-left: 39px; | |
| 140 | 136 | } |
| 141 | 137 | |
| 142 | 138 | #themeisle .inside { |
| 143 | 139 | padding: 0; |
| @@ -223,23 +219,21 @@ | ||
| 223 | 219 | ?> |
| 224 | 220 | <li class="ti-dw-feed-item"> |
| 225 | 221 | <a href=" |
| 226 | 222 | <?php |
| 227 | - echo esc_url( | |
| 228 | - add_query_arg( | |
| 229 | - array( | |
| 230 | - 'utm_source' => 'wpadmin', | |
| 231 | - 'utm_campaign' => 'feed', | |
| 232 | - 'utm_medium' => 'dashboard_widget', | |
| 233 | - ), | |
| 234 | - $item['link'] | |
| 235 | - ) | |
| 223 | + echo add_query_arg( | |
| 224 | + array( | |
| 225 | + 'utm_source' => 'wpadmin', | |
| 226 | + 'utm_campaign' => 'feed', | |
| 227 | + 'utm_medium' => 'dashboard_widget', | |
| 228 | + ), | |
| 229 | + $item['link'] | |
| 236 | 230 | ); |
| 237 | 231 | ?> |
| 238 | 232 | " target="_blank"> |
| 239 | 233 | <span class="ti-dw-date-container"><span |
| 240 | - class="ti-dw-day-container"><?php echo esc_attr( gmdate( 'd', $item['date'] ) ); ?></span> <span | |
| 241 | - class="ti-dw-month-container"><?php echo esc_attr( substr( gmdate( 'M', $item['date'] ), 0, 3 ) ); ?></span></span><?php echo esc_attr( $item['title'] ); ?> | |
| 234 | + class="ti-dw-day-container"><?php echo date( 'd', $item['date'] ); ?></span> <span | |
| 235 | + class="ti-dw-month-container"><?php echo substr( date( 'M', $item['date'] ), 0, 3 ); ?></span></span><?php echo $item['title']; ?> | |
| 242 | 236 | </a> |
| 243 | 237 | </li> |
| 244 | 238 | <?php |
| 245 | 239 | } |
| @@ -280,30 +274,28 @@ | ||
| 280 | 274 | } |
| 281 | 275 | ?> |
| 282 | 276 | <div class="ti-dw-footer"> |
| 283 | 277 | <span class="ti-dw-recommend-item "> |
| 284 | - <span class="ti-dw-recommend"><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_popular_label', sprintf( Loader::$labels['dashboard_widget']['popular'], ucwords( $type ) ) ) ); ?> | |
| 278 | + <span class="ti-dw-recommend"><?php echo apply_filters( 'themeisle_sdk_dashboard_popular_label', sprintf( 'Popular %s', ucwords( $type ) ) ); ?> | |
| 285 | 279 | : </span> |
| 286 | 280 | <?php |
| 287 | - echo esc_attr( | |
| 288 | - trim( | |
| 289 | - str_replace( | |
| 290 | - array( | |
| 291 | - 'lite', | |
| 292 | - 'Lite', | |
| 293 | - '(Lite)', | |
| 294 | - '(lite)', | |
| 295 | - ), | |
| 296 | - '', | |
| 297 | - $recommend['name'] | |
| 298 | - ) | |
| 281 | + echo trim( | |
| 282 | + str_replace( | |
| 283 | + array( | |
| 284 | + 'lite', | |
| 285 | + 'Lite', | |
| 286 | + '(Lite)', | |
| 287 | + '(lite)', | |
| 288 | + ), | |
| 289 | + '', | |
| 290 | + $recommend['name'] | |
| 299 | 291 | ) |
| 300 | 292 | ); |
| 301 | 293 | ?> |
| 302 | 294 | (<a class="thickbox open-plugin-details-modal" |
| 303 | - href="<?php echo esc_url( $url . '&TB_iframe=true&width=600&height=500' ); ?>"><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_install_label', Loader::$labels['dashboard_widget']['install'] ) ); ?></a>) | |
| 295 | + href="<?php echo $url . '&TB_iframe=true&width=600&height=500'; ?>"><?php echo apply_filters( 'themeisle_sdk_dashboard_install_label', 'Install' ); ?></a>) | |
| 304 | 296 | </span> |
| 305 | - <span class="ti-dw-powered-by"><span><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_widget_powered_by', sprintf( Loader::$labels['dashboard_widget']['powered'], $this->product->get_friendly_name() ) ) ); ?></span></span> | |
| 297 | + <span class="ti-dw-powered-by"><span><?php echo apply_filters( 'themeisle_sdk_dashboard_widget_powered_by', esc_attr( sprintf( 'Powered by %s', $this->product->get_friendly_name() ) ) ); ?></span></span> | |
| 306 | 298 | </div> |
| 307 | 299 | |
| 308 | 300 | <?php |
| 309 | 301 | |
| @@ -312,40 +304,11 @@ | ||
| 312 | 304 | /** |
| 313 | 305 | * Setup feed items. |
| 314 | 306 | */ |
| 315 | 307 | private function setup_feeds() { |
| 316 | - if ( false === ( $items_normalized = get_transient( 'themeisle_sdk_feed_items' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 317 | - // Do not force the feed for the items in the sdk feeds list. | |
| 318 | - // this prevents showing notices if another plugin will force all SimplePie feeds to load, instead it will | |
| 319 | - // use the regular SimplePie validation and abort early if the feed is not valid. | |
| 320 | - $sdk_feeds = $this->feeds; | |
| 321 | - add_action( | |
| 322 | - 'wp_feed_options', | |
| 323 | - function ( $feed, $url ) use ( $sdk_feeds ) { | |
| 324 | - if ( defined( 'TI_SDK_PHPUNIT' ) && true === TI_SDK_PHPUNIT ) { | |
| 325 | - return; | |
| 326 | - } | |
| 327 | - | |
| 328 | - if ( ! is_string( $url ) && in_array( $url, $sdk_feeds, true ) ) { | |
| 329 | - $feed->force_feed( false ); | |
| 330 | - | |
| 331 | - return; | |
| 332 | - } | |
| 333 | - if ( is_array( $url ) ) { | |
| 334 | - foreach ( $url as $feed_url ) { | |
| 335 | - if ( in_array( $feed_url, $sdk_feeds, true ) ) { | |
| 336 | - $feed->force_feed( false ); | |
| 337 | - | |
| 338 | - return; | |
| 339 | - } | |
| 340 | - } | |
| 341 | - } | |
| 342 | - }, | |
| 343 | - PHP_INT_MAX, | |
| 344 | - 2 | |
| 345 | - ); | |
| 308 | + if ( false === ( $items_normalized = get_transient( 'themeisle_sdk_feed_items' ) ) ) { | |
| 346 | 309 | // Load SimplePie Instance. |
| 347 | - $feed = fetch_feed( $sdk_feeds ); | |
| 310 | + $feed = fetch_feed( $this->feeds ); | |
| 348 | 311 | // TODO report error when is an error loading the feed. |
| 349 | 312 | if ( is_wp_error( $feed ) ) { |
| 350 | 313 | return; |
| 351 | 314 | } |
| @@ -350,13 +313,9 @@ | ||
| 350 | 313 | return; |
| 351 | 314 | } |
| 352 | 315 | |
| 353 | 316 | $items = $feed->get_items( 0, 5 ); |
| 354 | - $items = is_array( $items ) ? $items : []; | |
| 355 | - | |
| 356 | - $items_normalized = []; | |
| 357 | - | |
| 358 | - foreach ( $items as $item ) { | |
| 317 | + foreach ( (array) $items as $item ) { | |
| 359 | 318 | $items_normalized[] = array( |
| 360 | 319 | 'title' => $item->get_title(), |
| 361 | 320 | 'date' => $item->get_date( 'U' ), |
| 362 | 321 | 'link' => $item->get_permalink(), |
| @@ -393,9 +352,9 @@ | ||
| 393 | 352 | |
| 394 | 353 | /** |
| 395 | 354 | * Contact the API and fetch the recommended plugins/themes |
| 396 | 355 | */ |
| 397 | - public function recommend_plugin_or_theme() { | |
| 356 | + function recommend_plugin_or_theme() { | |
| 398 | 357 | $products = $this->get_product_from_api(); |
| 399 | 358 | if ( ! is_array( $products ) ) { |
| 400 | 359 | $products = array(); |
| 401 | 360 | } |
| @@ -414,10 +373,10 @@ | ||
| 414 | 373 | * Fetch products from the recomended section. |
| 415 | 374 | * |
| 416 | 375 | * @return array|mixed The list of products to use in recomended section. |
| 417 | 376 | */ |
| 418 | - public function get_product_from_api() { | |
| 419 | - if ( false === ( $products = get_transient( 'themeisle_sdk_products' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 377 | + function get_product_from_api() { | |
| 378 | + if ( false === ( $products = get_transient( 'themeisle_sdk_products' ) ) ) { | |
| 420 | 379 | $products = array(); |
| 421 | 380 | $all_themes = $this->get_themes_from_wporg( 'themeisle' ); |
| 422 | 381 | $all_plugins = $this->get_plugins_from_wporg( 'themeisle' ); |
| 423 | 382 | static $allowed_products = [ |
| @@ -469,10 +428,10 @@ | ||
| 469 | 428 | * @param string $author The author name. |
| 470 | 429 | * |
| 471 | 430 | * @return array The list of themes. |
| 472 | 431 | */ |
| 473 | - public function get_themes_from_wporg( $author ) { | |
| 474 | - $products = $this->safe_get( | |
| 432 | + function get_themes_from_wporg( $author ) { | |
| 433 | + $products = wp_remote_get( | |
| 475 | 434 | 'https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[author]=' . $author . '&request[per_page]=30&request[fields][active_installs]=true' |
| 476 | 435 | ); |
| 477 | 436 | $products = json_decode( wp_remote_retrieve_body( $products ) ); |
| 478 | 437 | if ( is_object( $products ) ) { |
| @@ -490,10 +449,10 @@ | ||
| 490 | 449 | * @param string $author The author slug. |
| 491 | 450 | * |
| 492 | 451 | * @return array The list of plugins for the selected author. |
| 493 | 452 | */ |
| 494 | - public function get_plugins_from_wporg( $author ) { | |
| 495 | - $products = $this->safe_get( | |
| 453 | + function get_plugins_from_wporg( $author ) { | |
| 454 | + $products = wp_remote_get( | |
| 496 | 455 | 'https://api.wordpress.org/plugins/info/1.1/?action=query_plugins&request[author]=' . $author . '&request[per_page]=40&request[fields][active_installs]=true' |
| 497 | 456 | ); |
| 498 | 457 | $products = json_decode( wp_remote_retrieve_body( $products ) ); |
| 499 | 458 | if ( is_object( $products ) ) { |