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

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