PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.3
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 19.0 All 129 releases
wordpress-seo / src / helpers / import-cursor-helper.php

import-cursor-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at src/helpers/import-cursor-helper.php

55 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Helpers;
4
5 use Yoast\WP\SEO\Helpers\Options_Helper;
6
7 /**
8 * The Import Cursor Helper.
9 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
10 */
11 class Import_Cursor_Helper {
12
13 /**
14 * Class constructor.
15 *
16 * @param Options_Helper $options The options helper.
17 */
18 public function __construct(
19 Options_Helper $options
20 ) {
21 $this->options = $options;
22 }
23
24 /**
25 * Returns the stored cursor value.
26 *
27 * @param string $cursor_id The cursor id.
28 * @param mixed $default The default value if no cursor has been set yet.
29 *
30 * @return int The stored cursor value.
31 */
32 public function get_cursor( $cursor_id, $default = 0 ) {
33 $import_cursors = $this->options->get( 'import_cursors', [] );
34
35 return ( isset( $import_cursors[ $cursor_id ] ) ) ? $import_cursors[ $cursor_id ] : $default;
36 }
37
38 /**
39 * Stores the current cursor value.
40 *
41 * @param string $cursor_id The cursor id.
42 * @param int $last_imported_id The id of the lastly imported entry.
43 *
44 * @return void.
45 */
46 public function set_cursor( $cursor_id, $last_imported_id ) {
47 $current_cursors = $this->options->get( 'import_cursors', [] );
48
49 if ( ! isset( $current_cursors[ $cursor_id ] ) || $current_cursors[ $cursor_id ] < $last_imported_id ) {
50 $current_cursors[ $cursor_id ] = $last_imported_id;
51 $this->options->set( 'import_cursors', $current_cursors );
52 }
53 }
54 }
55