gutenberg-jalali-calendar.php
1 year ago
lists-fix.php
1 year ago
styles-fix.php
1 year ago
widgets.php
1 year ago
widgets.php
373 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or exit( 'No direct script access allowed' ); |
| 4 | |
| 5 | /** |
| 6 | * Replace wp-planet.ir to News and Events widget |
| 7 | * |
| 8 | * @author Morteza Geransayeh |
| 9 | * @package WP-Parsidate |
| 10 | * @subpackage Core/General |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * Widget primary link |
| 15 | * |
| 16 | * @return string |
| 17 | * @author Morteza Geransayeh |
| 18 | */ |
| 19 | function wpp_dashboard_primary_link() { |
| 20 | return 'https://wp-parsi.com/'; |
| 21 | } |
| 22 | |
| 23 | add_filter( 'dashboard_primary_link', 'wpp_dashboard_primary_link', 999, 1 ); |
| 24 | |
| 25 | /** |
| 26 | * Widget primary feed |
| 27 | * |
| 28 | * @return string |
| 29 | * @author Morteza Geransayeh |
| 30 | */ |
| 31 | function wpp_dashboard_primary_feed() { |
| 32 | return 'https://wp-parsi.com/feed/'; |
| 33 | } |
| 34 | |
| 35 | add_filter( 'dashboard_primary_feed', 'wpp_dashboard_primary_feed', 999, 1 ); |
| 36 | |
| 37 | /** |
| 38 | * Widget secondary link |
| 39 | * |
| 40 | * @return string |
| 41 | * @author Morteza Geransayeh |
| 42 | */ |
| 43 | function wpp_dashboard_secondary_link() { |
| 44 | return 'https://wp-planet.ir/'; |
| 45 | } |
| 46 | |
| 47 | add_filter( 'dashboard_secondary_link', 'wpp_dashboard_secondary_link', 999, 1 ); |
| 48 | |
| 49 | /** |
| 50 | * Widget secondary feed |
| 51 | * |
| 52 | * @return string |
| 53 | * @author Morteza Geransayeh |
| 54 | */ |
| 55 | function wpp_dashboard_secondary_feed() { |
| 56 | return 'https://wp-planet.ir/feed'; |
| 57 | } |
| 58 | |
| 59 | add_filter( 'dashboard_secondary_feed', 'wpp_dashboard_secondary_feed', 999, 1 ); |
| 60 | |
| 61 | |
| 62 | if ( ! function_exists( 'wpp_add_our_dashboard_primary_widget' ) ) { |
| 63 | /** |
| 64 | * Add Parsi-Date events and news widget |
| 65 | * |
| 66 | * @return void |
| 67 | * @author HamidReza Yazdani |
| 68 | * @sicne 5.1.0 |
| 69 | * |
| 70 | */ |
| 71 | function wpp_add_our_dashboard_primary_widget() { |
| 72 | add_meta_box( |
| 73 | 'wpp_dashboard_primary', |
| 74 | __( 'WP Parsidate' ), |
| 75 | 'wpp_dashboard_primary_widget_content', |
| 76 | 'dashboard', |
| 77 | 'normal', |
| 78 | 'high', |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | add_action( 'admin_init', 'wpp_add_our_dashboard_primary_widget', 1 ); |
| 83 | } |
| 84 | |
| 85 | if ( ! function_exists( 'wpp_dashboard_primary_widget_content' ) ) { |
| 86 | /** |
| 87 | * Put our content into the new widget |
| 88 | * |
| 89 | * @return void |
| 90 | * @author HamidReza Yazdani |
| 91 | * @sicne 5.1.0 |
| 92 | * |
| 93 | */ |
| 94 | function wpp_dashboard_primary_widget_content() { |
| 95 | ?> |
| 96 | <div id="sponsorship-guide"> |
| 97 | <div class="question"> |
| 98 | <span class="dashicons dashicons-info-outline"></span> |
| 99 | <span><?php esc_html_e( 'What is this?', 'wp-parsidate' ); ?></span> |
| 100 | </div> |
| 101 | <ul> |
| 102 | <li><a href="https://wp-parsi.com/donate/" target="_blank"><span |
| 103 | class="dashicons dashicons-external"></span> <?php esc_html_e( 'Why are you showing me this?', 'wp-parsidate' ); ?> |
| 104 | </a></li> |
| 105 | <li><a href="https://wp-parsi.com/sponser/" target="_blank"><span |
| 106 | class="dashicons dashicons-external"></span> <?php esc_html_e( 'How can I become a sponsor?', 'wp-parsidate' ); ?> |
| 107 | </a></li> |
| 108 | </ul> |
| 109 | </div> |
| 110 | <div id="wpp_sponsorship_placeholder"> |
| 111 | <img src="<?php echo WP_PARSI_URL; ?>assets/images/icon.svg" alt="<?php esc_html_e( 'Loading Sponsors', 'wp-parsidate' ); ?>"> |
| 112 | </div> |
| 113 | <div id="wpp_sponsorship" class="keen-slider"> |
| 114 | |
| 115 | </div> |
| 116 | <?php |
| 117 | wpp_dashboard_events_news(); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if ( ! function_exists( 'wpp_dashboard_events_news' ) ) { |
| 122 | /** |
| 123 | * Renders the Events and News dashboard widget. |
| 124 | * |
| 125 | * @since 4.8.0 |
| 126 | */ |
| 127 | function wpp_dashboard_events_news() { |
| 128 | ?> |
| 129 | |
| 130 | <div class="wordpress-news hide-if-no-js"> |
| 131 | <?php wpp_dashboard_primary(); ?> |
| 132 | </div> |
| 133 | |
| 134 | <p class="community-events-footer"> |
| 135 | <?php |
| 136 | printf( |
| 137 | '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', |
| 138 | 'https://wp-parsi.com/', |
| 139 | __( 'WordPress Parsi' ), |
| 140 | /* translators: Hidden accessibility text. */ |
| 141 | __( '(opens in a new tab)' ) |
| 142 | ); |
| 143 | ?> |
| 144 | |
| 145 | | |
| 146 | |
| 147 | <?php |
| 148 | printf( |
| 149 | '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', |
| 150 | 'https://wp-parsi.com/about/', |
| 151 | __( 'About' ), |
| 152 | /* translators: Hidden accessibility text. */ |
| 153 | __( '(opens in a new tab)' ) |
| 154 | ); |
| 155 | ?> |
| 156 | |
| 157 | | |
| 158 | |
| 159 | <?php |
| 160 | printf( |
| 161 | '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', |
| 162 | /* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */ |
| 163 | esc_url( _x( 'https://wp-parsi.com/sponser/', 'Sponsership plans' ) ), |
| 164 | __( 'Sponser' ), |
| 165 | /* translators: Hidden accessibility text. */ |
| 166 | __( '(opens in a new tab)' ) |
| 167 | ); |
| 168 | ?> |
| 169 | </p> |
| 170 | |
| 171 | <?php |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if ( ! function_exists( 'wpp_dashboard_primary' ) ) { |
| 176 | /** |
| 177 | * 'WordPress Events and News' dashboard widget. |
| 178 | * |
| 179 | * @since 2.7.0 |
| 180 | * @since 4.8.0 Removed popular plugins feed. |
| 181 | */ |
| 182 | function wpp_dashboard_primary() { |
| 183 | $feeds = array( |
| 184 | 'news' => array( |
| 185 | |
| 186 | /** |
| 187 | * Filters the primary link URL for the 'WordPress Events and News' dashboard widget. |
| 188 | * |
| 189 | * @param string $link The widget's primary link URL. |
| 190 | * |
| 191 | * @since 2.5.0 |
| 192 | * |
| 193 | */ |
| 194 | 'link' => 'https://wp-parsi.com/', |
| 195 | |
| 196 | /** |
| 197 | * Filters the primary feed URL for the 'WordPress Events and News' dashboard widget. |
| 198 | * |
| 199 | * @param string $url The widget's primary feed URL. |
| 200 | * |
| 201 | * @since 2.3.0 |
| 202 | * |
| 203 | */ |
| 204 | 'url' => 'https://wp-parsi.com/parsidate/feed/', |
| 205 | |
| 206 | /** |
| 207 | * Filters the primary link title for the 'WordPress Events and News' dashboard widget. |
| 208 | * |
| 209 | * @param string $title Title attribute for the widget's primary link. |
| 210 | * |
| 211 | * @since 2.3.0 |
| 212 | * |
| 213 | */ |
| 214 | 'title' => apply_filters( 'dashboard_primary_title', __( 'Parsidate' ) ), |
| 215 | 'items' => 5, |
| 216 | 'show_summary' => 0, |
| 217 | 'show_author' => 0, |
| 218 | 'show_date' => 0, |
| 219 | ), |
| 220 | //'planet' => array( |
| 221 | |
| 222 | /** |
| 223 | * Filters the secondary link URL for the 'WordPress Events and News' dashboard widget. |
| 224 | * |
| 225 | * @param string $link The widget's secondary link URL. |
| 226 | * |
| 227 | * @since 2.3.0 |
| 228 | * |
| 229 | */ |
| 230 | //'link' => __( 'https://wp-planet.ir/' ), |
| 231 | |
| 232 | /** |
| 233 | * Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget. |
| 234 | * |
| 235 | * @param string $url The widget's secondary feed URL. |
| 236 | * |
| 237 | * @since 2.3.0 |
| 238 | * |
| 239 | */ |
| 240 | //'url' => __( 'https://wp-planet.ir/feed' ), |
| 241 | |
| 242 | /** |
| 243 | * Filters the secondary link title for the 'WordPress Events and News' dashboard widget. |
| 244 | * |
| 245 | * @param string $title Title attribute for the widget's secondary link. |
| 246 | * |
| 247 | * @since 2.3.0 |
| 248 | * |
| 249 | */ |
| 250 | //'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ), |
| 251 | |
| 252 | /** |
| 253 | * Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget. |
| 254 | * |
| 255 | * @param string $items How many items to show in the secondary feed. |
| 256 | * |
| 257 | * @since 4.4.0 |
| 258 | * |
| 259 | */ |
| 260 | // 'items' => apply_filters( 'dashboard_secondary_items', 3 ), |
| 261 | // 'show_summary' => 0, |
| 262 | // 'show_author' => 0, |
| 263 | // 'show_date' => 0, |
| 264 | //), |
| 265 | ); |
| 266 | |
| 267 | wp_dashboard_cached_rss_widget( 'wpp_dashboard_primary', 'wpp_dashboard_primary_output', $feeds ); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if ( ! function_exists( 'wpp_dashboard_primary_output' ) ) { |
| 272 | /** |
| 273 | * Displays the WordPress events and news feeds. |
| 274 | * |
| 275 | * @param string $widget_id Widget ID. |
| 276 | * @param array $feeds Array of RSS feeds. |
| 277 | * |
| 278 | * @since 3.8.0 |
| 279 | * @since 4.8.0 Removed popular plugins feed. |
| 280 | * |
| 281 | */ |
| 282 | function wpp_dashboard_primary_output( $widget_id, $feeds ) { |
| 283 | foreach ( $feeds as $type => $args ) { |
| 284 | $args['type'] = $type; |
| 285 | echo '<div class="rss-widget">'; |
| 286 | wp_widget_rss_output( $args['url'], $args ); |
| 287 | echo '</div>'; |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | if ( ! function_exists( 'wpp_ajax_dashboard_widgets' ) ) { |
| 293 | /** |
| 294 | * Handles dashboard widgets via AJAX. |
| 295 | * |
| 296 | * @since 5.1.0 |
| 297 | */ |
| 298 | function wpp_ajax_dashboard_widgets() { |
| 299 | require_once ABSPATH . 'wp-admin/includes/dashboard.php'; |
| 300 | |
| 301 | $pagenow = $_GET['pagenow']; |
| 302 | if ( 'dashboard-user' === $pagenow || 'dashboard-network' === $pagenow || 'dashboard' === $pagenow ) { |
| 303 | set_current_screen( $pagenow ); |
| 304 | } |
| 305 | |
| 306 | switch ( $_GET['widget'] ) { |
| 307 | case 'wpp_dashboard_primary': |
| 308 | wpp_dashboard_primary(); |
| 309 | break; |
| 310 | } |
| 311 | wp_die(); |
| 312 | } |
| 313 | |
| 314 | add_action( 'wp_ajax_wpp-dashboard-widgets', 'wpp_ajax_dashboard_widgets' ); |
| 315 | } |
| 316 | |
| 317 | if ( ! function_exists( 'wpp_enqueue_admin_dashboard_assets' ) ) { |
| 318 | /** |
| 319 | * Enqueue our assets to WP admin dashboard |
| 320 | * |
| 321 | * @param $hook |
| 322 | * |
| 323 | * @return void |
| 324 | * @author HamidReza Yazdani |
| 325 | * @sicne 5.1.0 |
| 326 | * |
| 327 | */ |
| 328 | function wpp_enqueue_admin_dashboard_assets( $hook ) { |
| 329 | // Check if we are on the admin dashboard page |
| 330 | if ( $hook !== 'index.php' ) { |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || wpp_is_active( 'dev_mode' ) ? '' : '.min'; |
| 335 | |
| 336 | wp_enqueue_style( 'keen-slider', WP_PARSI_URL . "assets/css/keen-slider$suffix.css", false, '1.0.0' ); |
| 337 | wp_enqueue_style( 'wpp_dashboard', WP_PARSI_URL . "assets/css/dashboard$suffix.css", false, '1.0.0' ); |
| 338 | wp_enqueue_script( 'keen-slider', WP_PARSI_URL . "assets/js/keen-slider.min.js", array(), '1.6.0', true ); |
| 339 | wp_enqueue_script( 'wpp_dashboard', WP_PARSI_URL . "assets/js/dashboard$suffix.js", array( 'jquery', 'keen-slider' ), '1.0.0', true ); |
| 340 | } |
| 341 | |
| 342 | add_action( 'admin_enqueue_scripts', 'wpp_enqueue_admin_dashboard_assets' ); |
| 343 | } |
| 344 | |
| 345 | if ( ! function_exists( 'wpp_fetch_sponsorship_slides_callback' ) ) { |
| 346 | /** |
| 347 | * Fetch the sponsors banners |
| 348 | * |
| 349 | * @sicne 5.1.0 |
| 350 | * @return void |
| 351 | */ |
| 352 | function wpp_fetch_sponsorship_slides_callback() { |
| 353 | $sponsors_cache = get_transient( 'wpp_sponsors_cache' ); |
| 354 | |
| 355 | if ( $sponsors_cache ) { |
| 356 | wp_send_json_success( json_decode( $sponsors_cache, true ) ); |
| 357 | } |
| 358 | |
| 359 | $response = wp_remote_get( 'https://wp-parsi.com/wp-json/sponsorship/v1/sponsors/' ); |
| 360 | |
| 361 | if ( is_wp_error( $response ) ) { |
| 362 | wp_send_json_error( 'Error fetching slides' ); |
| 363 | } |
| 364 | |
| 365 | $slides = wp_remote_retrieve_body( $response ); |
| 366 | |
| 367 | set_transient( 'wpp_sponsors_cache', $slides, WEEK_IN_SECONDS ); |
| 368 | wp_send_json_success( json_decode( $slides, true ) ); |
| 369 | } |
| 370 | |
| 371 | add_action( 'wp_ajax_fetch_sponsorship_slides', 'wpp_fetch_sponsorship_slides_callback' ); |
| 372 | } |
| 373 |