PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.2
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.2
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-stockpackmedia.php +144 -8 3.6.0 → 3.7.2 View file →
@@ -24,9 +24,9 @@
24 24
25 25 /**
26 26 * @var string plugin version
27 27 */
28 - public $version = '3.6.0';
28 + public $version = '3.7.2';
29 29
30 30 /**
31 31 * Returns the *Singleton* instance of this class.
32 32 *
@@ -161,8 +161,9 @@
161 161 $actions[ 'stockpack_upscale_' . $factor ] = sprintf(
162 162 '<a href="#" class="stockpack-upscale" data-url="%s" data-factor="%d">%s</a>',
163 163 $url,
164 164 $factor,
165 + /* translators: %d: upscale factor, 2 or 4 */
165 166 sprintf( esc_html__( 'Upscale %dx', 'stockpack' ), $factor )
166 167 );
167 168 }
168 169
@@ -182,8 +183,10 @@
182 183 wp_localize_script( 'stockpack-upscale', 'stockpackUpscale', array(
183 184 'nonceGenerate' => wp_create_nonce( 'stockpack_generate' ),
184 185 'nonceDownload' => wp_create_nonce( 'stockpack_download' ),
185 186 'editUrl' => admin_url( 'post.php?action=edit&post=' ),
187 + 'wallet' => $this->ai_wallet(),
188 + 'upscale' => $this->upscale_quotes(),
186 189 'strings' => array(
187 190 'confirm' => __( "Upscaling uses credits on your Magnific plan. Precision upscales are priced by the size of the result, usually 200 credits or more.\n\nUpscale this image?", 'stockpack' ),
188 191 'working' => __( 'Upscaling with Magnific, this can take a minute. Keep this page open, or the upscale is still charged but the image is not saved.', 'stockpack' ),
189 192 'saving' => __( 'Saving the upscaled image to your media library. Keep this page open, it will open the image when it is done.', 'stockpack' ),
@@ -192,8 +195,9 @@
192 195 'done' => __( 'Upscaled image saved. Opening it now...', 'stockpack' ),
193 196 'timeout' => __( 'The upscale is taking longer than expected. Check your Magnific account before retrying.',
194 197 'stockpack' ),
195 198 'failed' => __( 'The upscale could not be completed.', 'stockpack' ),
199 + 'topUp' => __( 'Top up credits', 'stockpack' ),
196 200 ),
197 201 ) );
198 202 }
199 203
@@ -394,8 +398,9 @@
394 398 'invalid_token' => __( 'Double check the token on the settings page!', 'stockpack' ),
395 399 'premium_limit_reached' => __( 'Premium account requests limit reached', 'stockpack' ),
396 400 'free_limit_reached' => __( 'Free account requests limit reached', 'stockpack' ),
397 401 'anonymous_limit_reached' => __( 'Anonymous requests limit reached', 'stockpack' ),
402 + 'insufficient_credits' => __( 'Not enough credits', 'stockpack' ),
398 403 ],
399 404 'link' => __( 'Set token', 'stockpack' ),
400 405 'search' => __( 'Search images', 'stockpack' ),
401 406 'generate' => [
@@ -413,9 +418,10 @@
413 418 'multiply' => $this->ai_refine_multiplier(),
414 419 ],
415 420 /* translators: %s: price per image, already formatted */
416 421 'cost' => __( '%s / image', 'stockpack' ),
417 - 'note' => __( 'Each image is charged to the Magnific account you connected. Generating through StockPack always costs, even when your plan shows unlimited generation inside the Magnific app.', 'stockpack' ),
422 + 'note' => $this->ai_cost_note(),
423 + 'wallet' => $this->ai_wallet_l10n(),
418 424 ],
419 425 'close' => __( 'Close', 'stockpack' ),
420 426 'download' => __( 'Download', 'stockpack' ),
421 427 'licenseAction' => __( 'License', 'stockpack' ),
@@ -534,9 +540,9 @@
534 540 'link' => 'https://www.magnific.com/legal/terms-of-use'
535 541 ],
536 542 'magnific' => [
537 543 'title' => __( 'Terms agreement', 'stockpack' ),
538 - 'message' => __( 'Before you use the first generated image you need to agree to the terms of service of Magnific. This will only be asked once and then we will store it for all subsequent images. Images are generated on your own Magnific account, so you are a direct user of their website and their terms apply. ', 'stockpack' ),
544 + 'message' => $this->ai_terms_message(),
539 545 'link' => 'https://www.magnific.com/legal/terms-of-use'
540 546 ],
541 547 ],
542 548 'licensePopup' => [
@@ -630,10 +636,11 @@
630 636 'link' => 'https://www.magnific.com',
631 637 'link_title' => 'Freepik',
632 638 ],
633 639 'magnific' => [
634 - 'author_info' => __( 'Beta. Runs on the Magnific API key you connect. Earlier images are shown while Magnific still hosts them; download the ones you want to keep.', 'stockpack' ),
635 - 'message' => __( 'You are generating images with', 'stockpack' ),
640 + 'author_info' => $this->ai_attribution(),
641 + /* translators: attribution required by Magnific, shown directly before a link reading "Magnific" */
642 + 'message' => __( 'Powered by', 'stockpack' ),
636 643 'link' => 'https://www.magnific.com',
637 644 'link_title' => 'Magnific',
638 645 ],
639 646 ],
@@ -725,13 +732,25 @@
725 732 }
726 733
727 734
728 735
736 + private function sellable_ai_models( $models ) {
737 + if ( 'managed' !== $this->ai_mode() ) {
738 + return $models;
739 + }
740 +
741 + $sellable = array_filter( $models, function ( $model ) {
742 + return isset( $model['wallet_credits'] );
743 + } );
744 +
745 + return $sellable ?: $models;
746 + }
747 +
729 748 private function ai_models() {
730 749 $prices = StockPack::get_instance()->query->get_ai_prices();
731 750
732 751 if ( isset( $prices['models'] ) && is_array( $prices['models'] ) && $prices['models'] ) {
733 - return $prices['models'];
752 + return $this->sellable_ai_models( $prices['models'] );
734 753 }
735 754
736 755 return array(
737 756 'flux-1' => array( 'label' => 'Flux.1', 'eur' => 0.01, 'default' => true ),
@@ -760,9 +779,15 @@
760 779 }, $this->enabled_ai_models() );
761 780 }
762 781
763 782 private function ai_model_costs() {
764 - return array_map( function ( $model ) {
783 + $managed = 'managed' === $this->ai_mode();
784 +
785 + return array_map( function ( $model ) use ( $managed ) {
786 + if ( $managed ) {
787 + return isset( $model['wallet_credits'] ) ? $this->format_credits( $model['wallet_credits'] ) : '';
788 + }
789 +
765 790 if ( ! isset( $model['eur'] ) ) {
766 791 return '';
767 792 }
768 793
@@ -769,8 +794,119 @@
769 794 return '€' . rtrim( rtrim( number_format( (float) $model['eur'], 3 ), '0' ), '.' );
770 795 }, $this->enabled_ai_models() );
771 796 }
772 797
798 + private function ai_wallet() {
799 + return StockPack::get_instance()->query->get_ai_wallet();
800 + }
801 +
802 + private function ai_mode() {
803 + $wallet = $this->ai_wallet();
804 +
805 + return $wallet['mode'];
806 + }
807 +
808 + private function ai_wallet_l10n() {
809 + return $this->ai_wallet() + array(
810 + /* translators: %s: credit balance, already formatted */
811 + 'balance_label' => __( 'Balance: %s credits', 'stockpack' ),
812 + 'top_up' => __( 'Top up', 'stockpack' ),
813 + 'connect' => __( 'Connect Magnific', 'stockpack' ),
814 + 'unavailable' => __( 'Image generation is not set up for this site yet. Connect your own Magnific key on stockpack.co, or buy StockPack credits.', 'stockpack' ),
815 + );
816 + }
817 +
818 + private function ai_cost_note() {
819 + if ( 'managed' === $this->ai_mode() ) {
820 + return __( 'Each image is paid from your StockPack credits at the price shown, and refining costs double. Nothing is charged to a Magnific account.', 'stockpack' );
821 + }
822 +
823 + return __( 'Each image is charged to the Magnific account you connected. Generating through StockPack always costs, even when your plan shows unlimited generation inside the Magnific app.', 'stockpack' );
824 + }
825 +
826 + private function ai_terms_message() {
827 + if ( 'managed' === $this->ai_mode() ) {
828 + return __( 'Before you use the first generated image you need to agree to the terms of service of Magnific. This will only be asked once and then we will store it for all subsequent images. Images are generated on the StockPack Magnific account and paid from your StockPack credits, and Magnific terms still govern the images you receive. ', 'stockpack' );
829 + }
830 +
831 + return __( 'Before you use the first generated image you need to agree to the terms of service of Magnific. This will only be asked once and then we will store it for all subsequent images. Images are generated on your own Magnific account, so you are a direct user of their website and their terms apply. ', 'stockpack' );
832 + }
833 +
834 + private function ai_attribution() {
835 + if ( 'managed' === $this->ai_mode() ) {
836 + return __( 'Runs on your StockPack credits. Earlier images are shown while Magnific still hosts them; download the ones you want to keep.', 'stockpack' );
837 + }
838 +
839 + return __( 'Runs on the Magnific API key you connect. Earlier images are shown while Magnific still hosts them; download the ones you want to keep.', 'stockpack' );
840 + }
841 +
842 + private function format_credits( $credits ) {
843 + $credits = (int) $credits;
844 +
845 + return sprintf(
846 + /* translators: %s: number of credits, already formatted */
847 + _n( '%s credit', '%s credits', $credits, 'stockpack' ),
848 + number_format_i18n( $credits )
849 + );
850 + }
851 +
852 + private function upscale_quotes() {
853 + $wallet = $this->ai_wallet();
854 + $prices = StockPack::get_instance()->query->get_ai_prices();
855 + $quotes = array();
856 +
857 + foreach ( array( 2, 4 ) as $factor ) {
858 + $quotes[ $factor ] = $this->upscale_quote( $factor, $wallet, $prices );
859 + }
860 +
861 + return $quotes;
862 + }
863 +
864 + private function upscale_quote( $factor, $wallet, $prices ) {
865 + if ( 'unavailable' === $wallet['mode'] ) {
866 + $strings = $this->ai_wallet_l10n();
867 +
868 + return array( 'refuse' => $strings['unavailable'] );
869 + }
870 +
871 + if ( 'managed' !== $wallet['mode'] ) {
872 + return array();
873 + }
874 +
875 + if ( ! isset( $prices['upscale']['wallet_credits'][ $factor ] ) ) {
876 + return array(
877 + /* translators: %d: upscale factor, 2 or 4 */
878 + 'refuse' => sprintf( __( 'Upscale %dx is not available on StockPack credits yet. Connect your own Magnific key to upscale.', 'stockpack' ), $factor ),
879 + 'link' => false,
880 + );
881 + }
882 +
883 + $credits = (int) $prices['upscale']['wallet_credits'][ $factor ];
884 + $balance = (int) $wallet['balance'];
885 +
886 + if ( $balance < $credits ) {
887 + return array(
888 + 'refuse' => sprintf(
889 + /* translators: 1: upscale factor, 2: credits needed, 3: current balance, both already formatted */
890 + __( 'Upscale %1$dx needs %2$s credits and your balance is %3$s. Top up on stockpack.co first.', 'stockpack' ),
891 + $factor,
892 + number_format_i18n( $credits ),
893 + number_format_i18n( $balance )
894 + ),
895 + );
896 + }
897 +
898 + return array(
899 + 'confirm' => sprintf(
900 + /* translators: 1: upscale factor, 2: credits, already formatted, 3: balance after the upscale, already formatted */
901 + __( 'Upscale %1$dx for %2$s credits? Balance after: %3$s.', 'stockpack' ),
902 + $factor,
903 + number_format_i18n( $credits ),
904 + number_format_i18n( $balance - $credits )
905 + ),
906 + );
907 + }
908 +
773 909 private function ai_refine_multiplier() {
774 910 $prices = StockPack::get_instance()->query->get_ai_prices();
775 911
776 912 return isset( $prices['refine_multiplier'] ) ? (int) $prices['refine_multiplier'] : 2;
@@ -782,9 +918,9 @@
782 918 $providers = array(
783 919 'Adobe Stock' => __('Adobe Stock', 'stockpack'),
784 920 'Deposit Photos' => __('Deposit Photos', 'stockpack'),
785 921 'Freepik' => __('Freepik (Magnific, beta)', 'stockpack'),
786 - 'Magnific AI' => __('Magnific AI (generate, beta)', 'stockpack'),
922 + 'Magnific AI' => __('Magnific AI (generate)', 'stockpack'),
787 923 'Getty' => __('Getty Images', 'stockpack'),
788 924 'iStock' => __('iStock', 'stockpack'),
789 925 'Pixabay' => __('Pixabay', 'stockpack'),
790 926 'Pexels' => __('Pexels', 'stockpack'),