PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / ai / free-sparks / application / free-sparks-handler.php

free-sparks-handler.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/ai/free-sparks/application/free-sparks-handler.php

65 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4
5 namespace Yoast\WP\SEO\AI\Free_Sparks\Application;
6
7 use Yoast\WP\SEO\Helpers\Options_Helper;
8
9 /**
10 * Handles the free sparks started on timestamp.
11 */
12 class Free_Sparks_Handler implements Free_Sparks_Handler_Interface {
13
14 /**
15 * The key used to store the timestamp when the user started using free sparks.
16 *
17 * @var string
18 */
19 public const OPTION_KEY = 'ai_free_sparks_started_on';
20
21 /**
22 * Holds the options helper instance.
23 *
24 * @var Options_Helper
25 */
26 private $options_helper;
27
28 /**
29 * Class constructor.
30 *
31 * @param Options_Helper $options_helper The options helper.
32 */
33 public function __construct( Options_Helper $options_helper ) {
34 $this->options_helper = $options_helper;
35 }
36
37 /**
38 * Retrieves the timestamp.
39 *
40 * @param string $format The format in which to return the timestamp. Defaults to 'Y-m-d H:i:s'.
41 *
42 * @return ?string The timestamp when the user started using free sparks, or null if not set.
43 */
44 public function get( string $format = 'Y-m-d H:i:s' ): ?string {
45 $timestamp = $this->options_helper->get( self::OPTION_KEY, null );
46 if ( $timestamp === null ) {
47 return null;
48 }
49
50 return \gmdate( $format, (int) $timestamp );
51 }
52
53 /**
54 * Registers the starting of the free sparks.
55 *
56 * @param ?int $timestamp The timestamp when the user started using free sparks. If null, the current time will be
57 * used.
58 *
59 * @return bool True if the operation was successful, false otherwise.
60 */
61 public function start( ?int $timestamp = null ): bool {
62 return (bool) $this->options_helper->set( self::OPTION_KEY, ( $timestamp === null ) ? \time() : $timestamp, 'wpseo' );
63 }
64 }
65