Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/seo-by-rank-math/includes/class-auto-updater.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Global functionality of the plugin.
4 + *
5 + * Defines the functionality loaded both on admin and frontend.
6 + *
7 + * @since 0.9.0
8 + * @package RankMath
9 + * @subpackage RankMath\Core
10 + * @author Rank Math <support@rankmath.com>
11 + */
12 +
13 + namespace RankMath;
14 +
15 + use RankMath\Traits\Hooker;
16 + use RankMath\Helper;
17 +
18 + defined( 'ABSPATH' ) || exit;
19 +
20 + /**
21 + * Common class.
22 + */
23 + class Auto_Updater {
24 +
25 + use Hooker;
26 +
27 + /**
28 + * Constructor method.
29 + */
30 + public function __construct() {
31 + $this->filter( 'auto_update_plugin', 'auto_update_plugin', 20, 2 );
32 + $this->filter( 'plugin_auto_update_setting_html', 'plugin_auto_update_setting_html', 10, 3 );
33 + }
34 +
35 + /**
36 + * Don't auto-update if it's a beta version.
37 + *
38 + * @param bool $update Whether to update the plugin or not.
39 + * @param array $item The update plugin object.
40 + *
41 + * @return bool
42 + */
43 + public function auto_update_plugin( $update, $item ) {
44 + // Show auto-updates control on Plugins page.
45 + if ( did_action( 'load-plugins.php' ) ) {
46 + return $update;
47 + }
48 +
49 + if ( $this->is_rm_update( $item ) && $this->is_beta_update( $item ) ) {
50 + return false;
51 + }
52 +
53 + return $update;
54 + }
55 +
56 + /**
57 + * Check if updatable object is RM.
58 + *
59 + * @param object $item Updatable object.
60 + * @return boolean
61 + */
62 + public function is_rm_update( $item ) {
63 + return isset( $item->slug ) &&
64 + 'seo-by-rank-math' === $item->slug &&
65 + isset( $item->new_version );
66 + }
67 +
68 + /**
69 + * Check if given version is beta.
70 + *
71 + * @param string $item Update object.
72 + * @return boolean
73 + */
74 + public function is_beta_update( $item ) {
75 + return ( is_object( $item ) && isset( $item->new_version ) && false !== stripos( $item->new_version, 'beta' ) );
76 + }
77 +
78 + /**
79 + * Hide "update scheduled in X hours" message if update is a beta version.
80 + *
81 + * @param string $html HTML string.
82 + * @param string $plugin_file Plugin file relative to the plugin directory.
83 + * @param array $plugin_data Plugin update data.
84 + * @return string
85 + */
86 + public function plugin_auto_update_setting_html( $html, $plugin_file, $plugin_data ) {
87 + if ( 'seo-by-rank-math/rank-math.php' !== $plugin_file ) {
88 + return $html;
89 + }
90 +
91 + if ( ! empty( $plugin_data['is_beta'] ) ) {
92 + $html = str_replace( 'class="auto-update-time"', 'class="auto-update-time hidden"', $html );
93 + }
94 +
95 + return $html;
96 + }
97 + }
98 +