| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
|
| 6 |
// display other plugins page |
| 7 |
function etimeclockwp_extensions_page() { |
| 8 |
setlocale( LC_MONETARY, get_locale() ); |
| 9 |
$extensions = etimeclockwp_get_extensions(); |
| 10 |
$extensions = array_reverse($extensions); |
| 11 |
$tags = '<a><em><strong><blockquote><ul><ol><li><p>'; |
| 12 |
$length = 55; |
| 13 |
|
| 14 |
?> |
| 15 |
<div class="wrap about-wrap etimeclockwp-about-wrapp"> |
| 16 |
<h3> |
| 17 |
<?php _e( 'You may be interested in our other popular WordPress plugins:', 'etimeclockwp' ); ?> |
| 18 |
</h3> |
| 19 |
|
| 20 |
<div class="etimeclockwp-extension-wrapper grid3"> |
| 21 |
<?php foreach ( $extensions as $key => $extension ) : |
| 22 |
$the_excerpt = ''; |
| 23 |
$slug = $extension->info->slug; |
| 24 |
$price = false; |
| 25 |
$link = 'https://wpplugin.org/downloads/' . $slug .'/'; |
| 26 |
$link = esc_url( add_query_arg( array( |
| 27 |
'utm_source' => 'plugin-extensions-page', |
| 28 |
'utm_medium' => 'plugin', |
| 29 |
'utm_campaign' => 'etimeclockwp_extensions_page', |
| 30 |
'utm_content' => $extension->info->title |
| 31 |
), $link ) ); |
| 32 |
|
| 33 |
if ( ! empty( $extension->info->excerpt ) ) { |
| 34 |
$the_excerpt = $extension->info->excerpt; |
| 35 |
} |
| 36 |
|
| 37 |
$the_excerpt = strip_shortcodes( strip_tags( stripslashes( $the_excerpt ), $tags ) ); |
| 38 |
$the_excerpt = preg_split( '/\b/', $the_excerpt, $length * 2+1 ); |
| 39 |
$excerpt_waste = array_pop( $the_excerpt ); |
| 40 |
$the_excerpt = implode( $the_excerpt ); ?> |
| 41 |
|
| 42 |
<article class="col"> |
| 43 |
<div class="etimeclockwp-extension-item"> |
| 44 |
<div class="etimeclockwp-extension-item-img"> |
| 45 |
<a href="<?php echo $link; ?>" target="_blank"><img src="<?php echo $extension->info->thumbnail; ?>" /></a> |
| 46 |
</div> |
| 47 |
<div class="etimeclockwp-extension-item-desc"> |
| 48 |
<p class="etimeclockwp-extension-item-heading"><?php echo $extension->info->title; ?></p> |
| 49 |
<div class="etimeclockwp-extension-item-excerpt"> |
| 50 |
<p><?php echo $the_excerpt; ?></p> |
| 51 |
</div> |
| 52 |
<div class="etimeclockwp-extension-buy-now"> |
| 53 |
<a href="<?php echo $link; ?>" class="button-primary" target="_blank"><?php echo __( 'Learn More', 'etimeclockwp' ); ?></a> |
| 54 |
</div> |
| 55 |
</div> |
| 56 |
</div> |
| 57 |
</article> |
| 58 |
<?php endforeach; ?> |
| 59 |
</div> |
| 60 |
</div> |
| 61 |
<?php |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
/* Retrieve the published extensions from wpplugin.org and store within transient. */ |
| 67 |
function etimeclockwp_get_extensions() { |
| 68 |
$extensions = get_transient( '_etimeclockwp_extensions_feed' ); |
| 69 |
|
| 70 |
if ( false === $extensions || doing_action( 'etimeclockwp_daily_scheduled_events' ) ) { |
| 71 |
$route = esc_url( 'https://wpplugin.org/edd-api/products/' ); |
| 72 |
$number = 20; |
| 73 |
$endpoint = add_query_arg( array( 'number' => $number ), $route ); |
| 74 |
$response = wp_remote_get( $endpoint ); |
| 75 |
|
| 76 |
if ( 200 === wp_remote_retrieve_response_code( $response ) ) { |
| 77 |
$body = wp_remote_retrieve_body( $response ); |
| 78 |
$content = json_decode( $body ); |
| 79 |
|
| 80 |
if ( is_object( $content ) && isset( $content->products ) ) { |
| 81 |
set_transient( '_etimeclockwp_extensions_feed', $content->products, DAY_IN_SECONDS / 2 ); // Store for 24 hours |
| 82 |
$extensions = $content->products; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return $extensions; |
| 88 |
} |
| 89 |
add_action( 'etimeclockwp_daily_scheduled_events', 'etimeclockwp_get_extensions' ); |
| 90 |
|