PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.1
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.1
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
← All changes | src/class-stockpackadmin.php +131 -1 3.5.2 → 3.7.1 View file →
@@ -18,9 +18,9 @@
18 18
19 19 /**
20 20 * @var string plugin version
21 21 */
22 - public $version = '3.2.4';
22 + public $version = '3.7.1';
23 23
24 24 /**
25 25 * Returns the *Singleton* instance of this class.
26 26 *
@@ -86,8 +86,10 @@
86 86 $this->settings_api->set_sections( $this->get_settings_sections() );
87 87 $this->settings_api->set_fields( $this->get_settings_fields() );
88 88
89 89 //initialize them
90 + add_action( 'wsa_form_top_stockpack_basics', array( $this, 'credits_line' ) );
91 +
90 92 $this->settings_api->admin_init();
91 93 }
92 94
93 95 public function register_settings_page() {
@@ -267,8 +269,124 @@
267 269 ),
268 270 );
269 271 }
270 272
273 + private function ai_models(): array {
274 + $prices = StockPack::get_instance()->query->get_ai_prices();
275 + $models = isset( $prices['models'] ) && is_array( $prices['models'] ) ? $prices['models'] : array();
276 +
277 + if ( ! $models || ! $this->managed_credits() ) {
278 + return $models;
279 + }
280 +
281 + $sellable = array_filter( $models, function ( $model ) {
282 + return isset( $model['wallet_credits'] );
283 + } );
284 +
285 + return $sellable ?: $models;
286 + }
287 +
288 + private function ai_model_options(): array {
289 + $options = array();
290 + $managed = $this->managed_credits();
291 +
292 + foreach ( $this->ai_models() as $key => $model ) {
293 + if ( $managed ) {
294 + $price = isset( $model['wallet_credits'] ) ? sprintf( ' (%s)', $this->format_credits( $model['wallet_credits'] ) ) : '';
295 + } else {
296 + $price = isset( $model['eur'] ) ? sprintf( ' (€%s)', rtrim( rtrim( number_format( (float) $model['eur'], 3 ), '0' ), '.' ) ) : '';
297 + }
298 +
299 + $options[ $key ] = ( isset( $model['label'] ) ? $model['label'] : $key ) . $price;
300 + }
301 +
302 + return $options;
303 + }
304 +
305 + private function ai_wallet(): array {
306 + return StockPack::get_instance()->query->get_ai_wallet();
307 + }
308 +
309 + private function managed_credits(): bool {
310 + $wallet = $this->ai_wallet();
311 +
312 + return 'managed' === $wallet['mode'];
313 + }
314 +
315 + private function format_credits( $credits ): string {
316 + $credits = (int) $credits;
317 +
318 + return sprintf(
319 + /* translators: %s: number of credits, already formatted */
320 + _n( '%s credit', '%s credits', $credits, 'stockpack' ),
321 + number_format_i18n( $credits )
322 + );
323 + }
324 +
325 + public function credits_line() {
326 + $wallet = $this->ai_wallet();
327 +
328 + if ( 'byok' === $wallet['mode'] ) {
329 + return;
330 + }
331 +
332 + if ( 'unavailable' === $wallet['mode'] ) {
333 + printf(
334 + '<p class="description stockpack-credits-line">%s <a href="%s" target="_blank" rel="noopener">%s</a> · <a href="%s" target="_blank" rel="noopener">%s</a></p>',
335 + esc_html__( 'Image generation is not set up for this site yet. Connect your own Magnific key on stockpack.co, or buy StockPack credits.', 'stockpack' ),
336 + esc_url( $wallet['connect_url'] ),
337 + esc_html__( 'Connect Magnific', 'stockpack' ),
338 + esc_url( $wallet['top_up_url'] ),
339 + esc_html__( 'Top up credits', 'stockpack' )
340 + );
341 +
342 + return;
343 + }
344 +
345 + printf(
346 + '<p class="description stockpack-credits-line">%s · <a href="%s" target="_blank" rel="noopener">%s</a></p>',
347 + /* translators: %s: credit balance, already formatted */
348 + esc_html( sprintf( __( 'Credits: %s', 'stockpack' ), $wallet['balance_text'] ) ),
349 + esc_url( $wallet['top_up_url'] ),
350 + esc_html__( 'Manage on stockpack.co', 'stockpack' )
351 + );
352 + }
353 +
354 + private function ai_model_defaults(): array {
355 + $defaults = array();
356 +
357 + foreach ( $this->ai_models() as $key => $model ) {
358 + if ( ! empty( $model['default'] ) ) {
359 + $defaults[ $key ] = $key;
360 + }
361 + }
362 +
363 + return $defaults;
364 + }
365 +
366 + private function ai_models_description(): string {
367 + $all = count( $this->ai_models() );
368 +
369 + if ( $this->managed_credits() ) {
370 + return sprintf(
371 + /* translators: %d: number of models sellable on StockPack credits */
372 + _n(
373 + 'Choose which models appear in the generate dropdown. %d is available on StockPack credits and its price is per image. Models Magnific does not let us resell stay available on your own Magnific key.',
374 + 'Choose which models appear in the generate dropdown. %d are available on StockPack credits and prices are per image. Models Magnific does not let us resell stay available on your own Magnific key.',
375 + $all,
376 + 'stockpack'
377 + ),
378 + $all
379 + );
380 + }
381 +
382 + return sprintf(
383 + /* translators: %d: total number of models offered by the provider */
384 + __( 'Choose which models appear in the generate dropdown. %d are available and prices are per image, charged to the Magnific account you connect. Cheaper models are good for trying out a prompt; switch to a dearer one once you are happy with it.', 'stockpack' ),
385 + $all
386 + );
387 + }
388 +
271 389 /**
272 390 * @return array
273 391 */
274 392 private function get_settings_fields() {
@@ -299,8 +417,10 @@
299 417 'desc' => __( 'Select providers you want to use in the select', 'stockpack' ),
300 418 'options' => array(
301 419 'Adobe Stock' => __( 'Adobe Stock', 'stockpack' ),
302 420 'Deposit Photos' => __( 'Deposit Photos', 'stockpack' ),
421 + 'Freepik' => __( 'Freepik (Magnific)', 'stockpack' ),
422 + 'Magnific AI' => __( 'Magnific AI (generate)', 'stockpack' ),
303 423 'Getty' => __( 'Getty Images', 'stockpack' ),
304 424 'iStock' => __( 'iStock', 'stockpack' ),
305 425 'Pixabay' => __( 'Pixabay', 'stockpack' ),
306 426 'Pexels' => __( 'Pexels', 'stockpack' ),
@@ -310,8 +430,10 @@
310 430 'type' => 'multicheck',
311 431 'default' => [
312 432 'Adobe Stock'=> 'Adobe Stock',
313 433 'Deposit Photos'=> 'Deposit Photos',
434 + 'Freepik'=> 'Freepik',
435 + 'Magnific AI'=> 'Magnific AI',
314 436 'Getty'=> 'Getty',
315 437 'iStock'=> 'iStock',
316 438 'Pixabay' => 'Pixabay',
317 439 'Pexels' => 'Pexels',
@@ -316,8 +438,16 @@
316 438 'Pixabay' => 'Pixabay',
317 439 'Pexels' => 'Pexels',
318 440 'Unsplash' => 'Unsplash',
319 441 ],
442 + ),
443 + array(
444 + 'name' => 'ai_models',
445 + 'label' => __( 'AI models available', 'stockpack' ),
446 + 'desc' => $this->ai_models_description(),
447 + 'options' => $this->ai_model_options(),
448 + 'type' => 'multicheck',
449 + 'default' => $this->ai_model_defaults(),
320 450 ),
321 451 array(
322 452 'name' => 'file_name_change',
323 453 'label' => __( 'Enable file name change', 'stockpack' ),