builders
2 years ago
privacy
2 years ago
class-yit-ajax.php
2 years ago
class-yit-assets.php
2 years ago
class-yit-cpt-unlimited.php
5 years ago
class-yit-gradients.php
2 years ago
class-yit-help-desk.php
2 years ago
class-yit-icons.php
2 years ago
class-yit-metabox.php
2 years ago
class-yit-plugin-common.php
5 years ago
class-yit-plugin-licence.php
2 years ago
class-yit-plugin-panel-woocommerce.php
1 year ago
class-yit-plugin-panel.php
1 year ago
class-yit-plugin-subpanel.php
2 years ago
class-yit-pointers.php
2 years ago
class-yit-theme-licence.php
2 years ago
class-yit-upgrade.php
5 years ago
class-yit-video.php
5 years ago
class-yith-bh-onboarding.php
3 years ago
class-yith-dashboard.php
4 years ago
class-yith-debug.php
2 years ago
class-yith-external-services.php
1 year ago
class-yith-post-type-admin.php
2 years ago
class-yith-system-status.php
1 year ago
class-yith-dashboard.php
150 lines
| 1 | <?php |
| 2 | /** |
| 3 | * YITH Dashboard Class |
| 4 | * handle WordPress Admin Dashboard |
| 5 | * |
| 6 | * @class YITH_Dashboard |
| 7 | * @package YITH\PluginFramework\Classes |
| 8 | */ |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 11 | |
| 12 | if ( ! class_exists( 'YITH_Dashboard' ) ) { |
| 13 | /** |
| 14 | * YITH_Dashboard class. |
| 15 | */ |
| 16 | class YITH_Dashboard { |
| 17 | /** |
| 18 | * Products Feed URL |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | private static $products_feed = 'https://yithemes.com/latest-updates/feeds/'; |
| 23 | |
| 24 | /** |
| 25 | * Blog Feed URL |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | private static $blog_feed = 'https://yithemes.com/feed/'; |
| 30 | |
| 31 | /** |
| 32 | * Dashboard widget setup. |
| 33 | */ |
| 34 | public static function dashboard_widget_setup() { |
| 35 | wp_add_dashboard_widget( 'yith_dashboard_products_news', __( 'YITH Latest Updates', 'yith-plugin-fw' ), 'YITH_Dashboard::dashboard_products_news' ); |
| 36 | wp_add_dashboard_widget( 'yith_dashboard_blog_news', __( 'Latest news from YITH Blog', 'yith-plugin-fw' ), 'YITH_Dashboard::dashboard_blog_news' ); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Product news Widget |
| 42 | */ |
| 43 | public static function dashboard_products_news() { |
| 44 | $items = 10; |
| 45 | $rss = static::$products_feed; |
| 46 | if ( is_string( $rss ) ) { |
| 47 | $rss = fetch_feed( $rss ); |
| 48 | } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) { |
| 49 | $rss = fetch_feed( $rss['url'] ); |
| 50 | } elseif ( ! is_object( $rss ) ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if ( is_wp_error( $rss ) ) { |
| 55 | if ( is_admin() || current_user_can( 'manage_options' ) ) { |
| 56 | echo '<p><strong>' . esc_html__( 'RSS Error:', 'yith-plugin-fw' ) . '</strong> ' . wp_kses_post( $rss->get_error_message() ) . '</p>'; |
| 57 | } |
| 58 | |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if ( ! $rss->get_item_quantity() ) { |
| 63 | echo '<ul><li>' . esc_html__( 'An error has occurred, which probably means the feed is down. Try again later.', 'yith-plugin-fw' ) . '</li></ul>'; |
| 64 | $rss->__destruct(); |
| 65 | unset( $rss ); |
| 66 | |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * The feed items. |
| 72 | * |
| 73 | * @var SimplePie_Item[] $last_updates |
| 74 | */ |
| 75 | $last_updates = $rss->get_items( 0, $items ); |
| 76 | $html_classes = 'rsswidget yith-update-feeds'; |
| 77 | $output = ''; |
| 78 | |
| 79 | if ( count( $last_updates ) > 0 ) { |
| 80 | $output = '<ul class="yith-update-feeds">'; |
| 81 | } |
| 82 | |
| 83 | foreach ( $last_updates as $last_update ) { |
| 84 | $output .= '<li class="yith-update-feed">'; |
| 85 | |
| 86 | $date = $last_update->get_date( 'U' ); |
| 87 | $date_i18n = ! empty( $date ) ? date_i18n( get_option( 'date_format' ), $date ) : ''; |
| 88 | $html_date = ! empty( $date_i18n ) ? ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>' : ''; |
| 89 | |
| 90 | $output .= sprintf( '<a target="_blank" href="%s" class="%s">%s</a> %s', $last_update->get_permalink(), $html_classes, $last_update->get_title(), $html_date ); |
| 91 | |
| 92 | $changelog = $last_update->get_description(); |
| 93 | |
| 94 | if ( ! empty( $changelog ) ) { |
| 95 | $output .= ' - '; |
| 96 | $output .= sprintf( '<a class="yith-last-changelog" href="#" data-changelogid="%s" data-plugininfo="%s">%s</a>', $last_update->get_id( true ), $last_update->get_title(), _x( 'View Changelog', 'Plugin FW', 'yith-plugin-fw' ) ); |
| 97 | $output .= sprintf( '<div class="yith-feeds-wrapper" id="%s"><div class="yith-feeds-changelog-plugin-name"><img class="yith-feeds-logo" src="%s" /><h3 class="yith-feeds-plugin-name"><span style="font-weight: normal;">%s</span> %s</h3></div><p>%s</p></div>', $last_update->get_id( true ), yith_plugin_fw_get_default_logo(), _x( 'Latest update released on', 'Plugin FW', 'yith-plugin-fw' ), $date_i18n, $changelog ); |
| 98 | } |
| 99 | |
| 100 | $output .= '</li>'; |
| 101 | } |
| 102 | |
| 103 | if ( ! empty( $output ) ) { |
| 104 | $output .= '</ul>'; |
| 105 | } |
| 106 | |
| 107 | echo wp_kses_post( $output ); |
| 108 | $rss->__destruct(); |
| 109 | unset( $rss ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Blog news Widget |
| 114 | */ |
| 115 | public static function dashboard_blog_news() { |
| 116 | $args = array( |
| 117 | 'show_author' => 0, |
| 118 | 'show_date' => 1, |
| 119 | 'show_summary' => 1, |
| 120 | 'items' => 3, |
| 121 | ); |
| 122 | $feed = static::$blog_feed; |
| 123 | wp_widget_rss_output( $feed, $args ); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Enqueue Styles and Scripts for View Last Changelog widget |
| 128 | */ |
| 129 | public static function enqueue_scripts() { |
| 130 | if ( function_exists( 'get_current_screen' ) && get_current_screen() && 'dashboard' === get_current_screen()->id ) { |
| 131 | $script_path = defined( 'YIT_CORE_PLUGIN_URL' ) ? YIT_CORE_PLUGIN_URL : get_template_directory_uri() . '/core/plugin-fw'; |
| 132 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 133 | wp_enqueue_script( 'yith-dashboard', $script_path . '/assets/js/yith-dashboard' . $suffix . '.js', array( 'jquery-ui-dialog' ), yith_plugin_fw_get_version(), true ); |
| 134 | wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 135 | $l10n = array( |
| 136 | 'buttons' => array( |
| 137 | 'close' => _x( 'Close', 'Button label', 'yith-plugin-fw' ), |
| 138 | ), |
| 139 | ); |
| 140 | wp_localize_script( 'yith-dashboard', 'yith_dashboard', $l10n ); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if ( apply_filters( 'yith_plugin_fw_show_dashboard_widgets', true ) ) { |
| 146 | add_action( 'wp_dashboard_setup', 'YITH_Dashboard::dashboard_widget_setup' ); |
| 147 | add_action( 'admin_enqueue_scripts', 'YITH_Dashboard::enqueue_scripts', 20 ); |
| 148 | } |
| 149 | } |
| 150 |