PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.8
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.8, at src/helpers/import-cursor-helper.php

53 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 /**
6 * The Import Cursor Helper.
7 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
8 */
9 class Import_Cursor_Helper {
10
11 /**
12 * Class constructor.
13 *
14 * @param Options_Helper $options The options helper.
15 */
16 public function __construct(
17 Options_Helper $options
18 ) {
19 $this->options = $options;
20 }
21
22 /**
23 * Returns the stored cursor value.
24 *
25 * @param string $cursor_id The cursor id.
26 * @param mixed $default_value The default value if no cursor has been set yet.
27 *
28 * @return int The stored cursor value.
29 */
30 public function get_cursor( $cursor_id, $default_value = 0 ) {
31 $import_cursors = $this->options->get( 'import_cursors', [] );
32
33 return ( isset( $import_cursors[ $cursor_id ] ) ) ? $import_cursors[ $cursor_id ] : $default_value;
34 }
35
36 /**
37 * Stores the current cursor value.
38 *
39 * @param string $cursor_id The cursor id.
40 * @param int $last_imported_id The id of the lastly imported entry.
41 *
42 * @return void
43 */
44 public function set_cursor( $cursor_id, $last_imported_id ) {
45 $current_cursors = $this->options->get( 'import_cursors', [] );
46
47 if ( ! isset( $current_cursors[ $cursor_id ] ) || $current_cursors[ $cursor_id ] < $last_imported_id ) {
48 $current_cursors[ $cursor_id ] = $last_imported_id;
49 $this->options->set( 'import_cursors', $current_cursors );
50 }
51 }
52 }
53