PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.0
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 / actions / importing / import-cursor-manager-trait.php

import-cursor-manager-trait.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.0, at src/actions/importing/import-cursor-manager-trait.php

46 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\Actions\Importing;
4
5 use Yoast\WP\SEO\Helpers\Options_Helper;
6
7 /**
8 * The Cursor Manager trait.
9 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
10 */
11 trait Import_Cursor_Manager_Trait {
12
13 /**
14 * Returns the stored cursor value.
15 *
16 * @param Options_Helper $options_helper The options helper.
17 * @param string $cursor_id The cursor id.
18 * @param mixed $default The default value if no cursor has been set yet.
19 *
20 * @return int The stored cursor value.
21 */
22 public function get_cursor( $options_helper, $cursor_id, $default = 0 ) {
23 $import_cursors = $options_helper->get( 'import_cursors', [] );
24
25 return ( isset( $import_cursors[ $cursor_id ] ) ) ? $import_cursors[ $cursor_id ] : $default;
26 }
27
28 /**
29 * Stores the current cursor value.
30 *
31 * @param Options_Helper $options_helper The options helper.
32 * @param string $cursor_id The cursor id.
33 * @param int $last_imported_id The id of the lastly imported entry.
34 *
35 * @return void.
36 */
37 public function set_cursor( $options_helper, $cursor_id, $last_imported_id ) {
38 $current_cursors = $options_helper->get( 'import_cursors', [] );
39
40 if ( ! isset( $current_cursors[ $cursor_id ] ) || $current_cursors[ $cursor_id ] < $last_imported_id ) {
41 $current_cursors[ $cursor_id ] = $last_imported_id;
42 $options_helper->set( 'import_cursors', $current_cursors );
43 }
44 }
45 }
46