PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | app/SiteSettings.php +43 -55 0.3.0 → trunk View file →
@@ -1,72 +1,60 @@
1 1 <?php
2 +
2 3 /**
3 - * Helper class for interacting with the user
4 + * Controls Draft
4 5 */
5 6
6 -namespace Extendify\Library;
7 +namespace Extendify;
7 8
9 +defined('ABSPATH') || die('No direct access.');
10 +
11 +
8 12 /**
9 - * Helper class for interacting with the user
13 + * The controller for interacting with site settings
10 14 */
15 +
11 16 class SiteSettings
12 17 {
13 -
14 18 /**
15 - * SiteSettings option_name - For historical reasons do not change.
19 + * Get when the site was created
16 20 *
17 - * @var string
21 + * @return string|NULL
18 22 */
19 - protected $key = 'extendifysdk_sitesettings';
23 + public static function getSiteCreatedAt()
24 + {
25 + $cacheKey = 'extendify_site_created_at';
26 + $cached = \wp_cache_get($cacheKey);
27 + if ($cached) {
28 + return $cached;
29 + }
20 30
21 - /**
22 - * SiteSettings default value
23 - *
24 - * @var Json
25 - */
26 - protected $default = '{"state":{"enabled":true}}';
31 + $userOne = \get_userdata(1);
32 + if ($userOne) {
33 + $createdAt = $userOne->user_registered;
34 + \wp_cache_set($cacheKey, $createdAt);
35 + return $createdAt;
36 + }
27 37
28 - /**
29 - * The class instance.
30 - *
31 - * @var $instance
32 - */
33 - protected static $instance = null;
38 + $wpdb = $GLOBALS['wpdb'];
39 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery
40 + $result = $wpdb->get_row($wpdb->prepare(
41 + 'SELECT CREATE_TIME
42 + FROM INFORMATION_SCHEMA.TABLES
43 + WHERE TABLE_SCHEMA = %s
44 + AND TABLE_NAME = %s
45 + LIMIT 1',
46 + $wpdb->dbname,
47 + $wpdb->posts
48 + ));
49 + if (!property_exists($result, 'CREATE_TIME')) {
50 + return null;
51 + }
34 52
35 - /**
36 - * Returns Setting
37 - * Use it like Setting::data()
38 - *
39 - * @return mixed - Setting Data
40 - */
41 - private function dataHandler()
42 - {
43 - return \get_option($this->key, $this->default);
44 - }
45 -
46 - /**
47 - * Returns Setting Key
48 - * Use it like Setting::key()
49 - *
50 - * @return string - Setting key
51 - */
52 - private function keyHandler()
53 - {
54 - return $this->key;
55 - }
56 -
57 - /**
58 - * Use it like Setting::method() e.g. Setting::data()
59 - *
60 - * @param string $name - The name of the method to call.
61 - * @param array $arguments - The arguments to pass in.
62 - *
63 - * @return mixed
64 - */
65 - public static function __callStatic($name, array $arguments)
66 - {
67 - $name = "{$name}Handler";
68 - self::$instance = new static();
69 - $r = self::$instance;
70 - return $r->$name(...$arguments);
53 + $createdAt = gmdate(
54 + 'Y-m-d H:i:s',
55 + strtotime($result->CREATE_TIME)
56 + );
57 + \wp_cache_set($cacheKey, $createdAt);
58 + return $createdAt;
71 59 }
72 60 }