| 1 |
<?php |
| 2 |
/** |
| 3 |
* LoginPress Settings |
| 4 |
* |
| 5 |
* @since 1.0.19 |
| 6 |
*/ |
| 7 |
if ( ! class_exists( 'LoginPress_Filter_API' ) ) : |
| 8 |
|
| 9 |
class LoginPress_Filter_API { |
| 10 |
|
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
|
| 14 |
add_filter( 'plugins_api_result', array( $this, 'filter_api_result' ), 10, 3 ); |
| 15 |
add_filter( 'plugin_install_action_links', array( $this, 'filter_action_links' ), 10, 2 ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Override the installation link for pro plugins |
| 20 |
* |
| 21 |
* @param $links Download link. |
| 22 |
* @param $plugin Plugins Attributes |
| 23 |
* |
| 24 |
* @since 1.0.19 |
| 25 |
*/ |
| 26 |
public function filter_action_links( $links, $plugin ) { |
| 27 |
|
| 28 |
if ( empty( $plugin['loginpress-result'] ) ) { |
| 29 |
return $links; |
| 30 |
} |
| 31 |
|
| 32 |
if ( ! empty( $plugin['buy-now'] ) ) { |
| 33 |
// End if(). |
| 34 |
array_pop( $links ); |
| 35 |
$link = '<a class="%s" target="_blank" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="%s" aria-label="%s" data-name="' . esc_attr( $plugin['name'] ) . '">%s</a>'; |
| 36 |
|
| 37 |
if ( ! empty( $links[0] ) && preg_match( '/install-now/', $links[0] ) ) { |
| 38 |
$links[0] = sprintf( |
| 39 |
$link, |
| 40 |
'button', |
| 41 |
esc_url( $plugin['buy-now'] ), |
| 42 |
esc_attr( sprintf( __( 'Buy %s now', 'loginpress' ), $plugin['name'] ) ), |
| 43 |
esc_html__( 'Buy Now', 'loginpress' ) |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
// $links[] = sprintf( |
| 48 |
// $link, |
| 49 |
// 'thickbox open-plugin-details-modal', |
| 50 |
// esc_url( $plugin['buy-now'] . '#TB_iframe=true&width=600&height=550' ), |
| 51 |
// esc_attr( sprintf( __( 'More information about %s', 'loginpress' ), $plugin['name'] ) ), |
| 52 |
// esc_html__( 'More Details', 'loginpress' ) |
| 53 |
// ); |
| 54 |
} |
| 55 |
|
| 56 |
return $links; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* Filter Plugin search result |
| 62 |
* |
| 63 |
* @since 1.0.19 |
| 64 |
*/ |
| 65 |
function filter_api_result( $result, $action, $args ) { |
| 66 |
|
| 67 |
if ( empty( $args->browse ) ) { |
| 68 |
return $result; |
| 69 |
} |
| 70 |
|
| 71 |
if ( 'featured' !== $args->browse && 'recommended' !== $args->browse ) { |
| 72 |
return $result; |
| 73 |
} |
| 74 |
|
| 75 |
if ( ! isset( $result->info['page'] ) || 1 < $result->info['page'] ) { |
| 76 |
return $result; |
| 77 |
} |
| 78 |
|
| 79 |
$result_slugs = wp_list_pluck( $result->plugins, 'slug' ); |
| 80 |
|
| 81 |
$products = $this->get_products(); |
| 82 |
|
| 83 |
$count = 0; |
| 84 |
$products_to_inject = array(); |
| 85 |
foreach ( $products as $key => $product ) { |
| 86 |
|
| 87 |
$products[ $key ] = $product = $this->build_product_data( $product ); |
| 88 |
|
| 89 |
// if the product is already installed, skip it |
| 90 |
if ( $product['is_activated'] || $product['is_installed'] ) { |
| 91 |
continue; |
| 92 |
} |
| 93 |
|
| 94 |
// if the product is already in the results, skip it |
| 95 |
if ( in_array( $product['slug'], $result_slugs ) ) { |
| 96 |
continue; |
| 97 |
} |
| 98 |
|
| 99 |
$products_to_inject[] = $product; |
| 100 |
|
| 101 |
$count++; |
| 102 |
|
| 103 |
// no of products to show |
| 104 |
if ( 3 === $count ) { |
| 105 |
break; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
// prepend the products that we wish to inject |
| 110 |
for ( $i = count( $products_to_inject ) - 1; 0 <= $i; $i-- ) { |
| 111 |
array_unshift( $result->plugins, $products_to_inject[ $i ] ); |
| 112 |
} |
| 113 |
return $result; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
/** |
| 119 |
* Set plugin data structure acording to code. |
| 120 |
* |
| 121 |
* @since 1.0.19 |
| 122 |
*/ |
| 123 |
function build_product_data( $product_data ) { |
| 124 |
$defaults = array( |
| 125 |
'name' => null, |
| 126 |
'slug' => null, |
| 127 |
'version' => null, |
| 128 |
'author' => '<a href="https://wpbrigade.com/">WPBrigade</a>', |
| 129 |
'author_profile' => null, |
| 130 |
'requires' => '3.9', |
| 131 |
'tested' => '4.8', |
| 132 |
'rating' => 100, |
| 133 |
'ratings' => array(), |
| 134 |
'num_ratings' => null, |
| 135 |
'support_threads' => null, |
| 136 |
'support_threads_resolved' => null, |
| 137 |
'active_installs' => null, |
| 138 |
'downloaded' => array(), |
| 139 |
'last_updated' => null, |
| 140 |
'added' => null, |
| 141 |
'homepage' => '', |
| 142 |
'sections' => array(), |
| 143 |
'short_description' => null, |
| 144 |
'download_link' => '', |
| 145 |
'screenshots' => array(), |
| 146 |
'tags' => array(), |
| 147 |
'versions' => array(), |
| 148 |
'donate_link' => null, |
| 149 |
'contributors' => array(), |
| 150 |
'loginpress-result' => true, |
| 151 |
'is_activated' => false, |
| 152 |
'is_installed' => false, |
| 153 |
'icons' => array( |
| 154 |
'default' => null, |
| 155 |
), |
| 156 |
); |
| 157 |
|
| 158 |
$product = array_merge( $defaults, $product_data ); |
| 159 |
|
| 160 |
if ( ! empty( $product['title'] ) && empty( $product['name'] ) ) { |
| 161 |
$product['name'] = $product['title']; |
| 162 |
} |
| 163 |
|
| 164 |
if ( ! empty( $product['description'] ) && empty( $product['short_description'] ) ) { |
| 165 |
$product['short_description'] = wp_trim_words( $product['description'], 27 ); |
| 166 |
} |
| 167 |
|
| 168 |
if ( ! empty( $product['image'] ) && empty( $product['icons']['default'] ) ) { |
| 169 |
if ( 0 === strpos( $product['image'], 'http' ) ) { |
| 170 |
$product['icons']['default'] = $product['image']; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
return $product; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
/** |
| 179 |
* Get product info |
| 180 |
* |
| 181 |
* @since 1.0.19 |
| 182 |
*/ |
| 183 |
function get_products() { |
| 184 |
$products = array( |
| 185 |
'wp-analytify' => array( |
| 186 |
'title' => __( 'Analytify', 'loginpress' ), |
| 187 |
'slug' => 'wp-analytify', |
| 188 |
'link' => 'https://analytify.io/', |
| 189 |
'image' => 'https://ps.w.org/wp-analytify/assets/icon-128x128.png?rev=1299138', |
| 190 |
'is_activated' => class_exists( 'WP_Analytify' ), |
| 191 |
'is_installed' => file_exists( WP_PLUGIN_DIR . '/wp-analytify/wp-analytify.php' ), |
| 192 |
'active_installs' => '10000', |
| 193 |
'num_ratings' => 75, |
| 194 |
'last_updated' => '2017-07-06 7:07pm GMT', |
| 195 |
'description' => __( 'Analytify is reshaping Google Analytics in WordPress. See Social Media, Keywords, Realtime, Country, Mobile and Browsers Statistics under pages and posts.', 'loginpress' ), |
| 196 |
), |
| 197 |
'related-posts-thumbnails' => array( |
| 198 |
'title' => __( 'Related Posts', 'loginpress' ), |
| 199 |
'slug' => 'related-posts-thumbnails', |
| 200 |
'link' => 'https://wpbrigade.com/wordpress/plugins/related-posts/', |
| 201 |
'image' => 'https://ps.w.org/related-posts-thumbnails/assets/icon-128x128.png?rev=1299138', |
| 202 |
'is_activated' => class_exists( 'RelatedPostsThumbnails' ), |
| 203 |
'is_installed' => file_exists( WP_PLUGIN_DIR . '/related-posts-thumbnails/related-posts-thumbnails.php' ), |
| 204 |
'active_installs' => '30000', |
| 205 |
'num_ratings' => 28, |
| 206 |
'last_updated' => '2017-06-14 8:37pm GMT', |
| 207 |
'description' => __( 'Related Post Thumbnails plugin is for those who want the showcase of their related posts after the post detail. The plugin allows customizing thumbnail sizes, display settings, and type of relations. The plugin is using original WordPress taxonomy. It returns generated HTML, that is essential for page load speed of blogs that use many Javascript widgets.', 'loginpress' ), |
| 208 |
), |
| 209 |
'loginpress-pro' => array( |
| 210 |
'title' => __( 'LoginPress Pro', 'loginpress' ), |
| 211 |
'slug' => 'loginpress-pro', |
| 212 |
'link' => 'https://wpbrigade.com/wordpress/plugins/loginpress/', |
| 213 |
'image' => 'https://ps.w.org/loginpress/assets/icon-128x128.png?rev=1299138', |
| 214 |
'is_activated' => class_exists( 'LoginPress_Pro' ), |
| 215 |
'is_installed' => file_exists( WP_PLUGIN_DIR . '/loginpress-pro/loginpress-pro.php' ), |
| 216 |
'active_installs' => '1000', |
| 217 |
'buy-now' => 'https://wpbrigade.com/wordpress/plugins/loginpress/?utm_source=loginpress-lite&utm_medium=featured-filter&utm_campaign=pro-upgrade', |
| 218 |
'num_ratings' => 51, |
| 219 |
'last_updated' => '2017-07-06 7:07pm GMT', |
| 220 |
'description' => __( 'LoginPress Plugin by LoginPress holds a lot of customization fields to change the layout of the login page of WordPress. You can modify the look and feel of login page completely even the login error messages, forgot error messages, registration error messages, forget password hint message and many more.', 'loginpress' ), |
| 221 |
), |
| 222 |
); |
| 223 |
|
| 224 |
return $products; |
| 225 |
} |
| 226 |
} |
| 227 |
endif; |
| 228 |
new LoginPress_Filter_API(); |
| 229 |
|