s="file">app/backend/migrations/__pycache__/__init__.cpython-39.pyc
Voir le fichier

+ 50 - 39
app/backend/models.py

@@ -109,6 +109,8 @@ class Patient(models.Model):
109 109
     birth_date = models.DateField(null=True)
110 110
     age = models.IntegerField(null=True, blank=True)
111 111
     idcard = models.CharField(max_length=20, null=True, blank=False)
112
+    tel = models.CharField(max_length=100, null=True, blank=True)
113
+    line_id = models.CharField(max_length=100, null=True, blank=True)
112 114
     prefix = models.CharField(
113 115
         max_length=30,
114 116
         choices=GENDER_CHOICES,
@@ -148,51 +150,57 @@ class Patient(models.Model):
148 150
     def nearby_from_db(self, dlimit):
149 151
         bd = ""
150 152
         temps = []
151
-        for h0 in  Hospital.objects.all():
152
-            p2 = (h0.geolocation.lat, h0.geolocation.lon)
153
-            p1 = (self.geolocation.lat, self.geolocation.lon)
154
-            d = round(hs.haversine(p1,p2), 2)
155
-            if d < dlimit:
156
-                #bd += f"<tr><td>{h0.title}</td><td>{d}km</td></tr>"
157
-                temps.append({'title': h0.title, 'd': d, 'id': h0.id, 'beds': h0.free_beds()})
158
-                #print(f"to {h0.title} => {hs.haversine(p1, p2)}km")
159
-
160
-        temps.sort(key= lambda s: s['d'], reverse=False)
161
-        for t in temps:
162
-            bd += f"<tr><td><a href='/admin/backend/hospital/{t['id']}/change/' target='_blank'>{t['title']}</a></td><td>{t['d']} km</td><td>{t['beds']}</td></tr>"
163
-
164
-        rt = f'''
165
-<br>
166
-        <table><thead><tr><th>Hospital</th><th>Distance</th><th>Free Beds</th></tr></thead>
167
-        <tbody>
168
-            {bd}
169
-        </tbody>
170
-        </table>
171
-        '''
172
-        return rt
153
+        try:
154
+            for h0 in  Hospital.objects.all():
155
+                p2 = (h0.geolocation.lat, h0.geolocation.lon)
156
+                p1 = (self.geolocation.lat, self.geolocation.lon)
157
+                d = round(hs.haversine(p1,p2), 2)
158
+                if d < dlimit:
159
+                    #bd += f"<tr><td>{h0.title}</td><td>{d}km</td></tr>"
160
+                    temps.append({'title': h0.title, 'd': d, 'id': h0.id, 'beds': h0.free_beds()})
161
+                    #print(f"to {h0.title} => {hs.haversine(p1, p2)}km")
162
+
163
+            temps.sort(key= lambda s: s['d'], reverse=False)
164
+            for t in temps:
165
+                bd += f"<tr><td><a href='/admin/backend/hospital/{t['id']}/change/' target='_blank'>{t['title']}</a></td><td>{t['d']} km</td><td>{t['beds']}</td></tr>"
166
+
167
+            rt = f'''
168
+    <br>
169
+            <table><thead><tr><th>Hospital</th><th>Distance</th><th>Free Beds</th></tr></thead>
170
+            <tbody>
171
+                {bd}
172
+            </tbody>
173
+            </table>
174
+            '''
175
+            return rt
176
+        except:
177
+            return "-"
173 178
 
174 179
     def nearby(self):
175 180
         #self.nearby_from_db()
176
-        r = gmaps.places_nearby(location=(self.geolocation.lat, self.geolocation.lon), type="hospital", radius=10000)
177
-        bd = ""
178
-        for r0 in r['results']:
179
-            openh = "-"
180
-            if 'opening_hours' in r0:
181
-                openh = r0['opening_hours']['open_now']
182
-            else:
181
+        try:
182
+            r = gmaps.places_nearby(location=(self.geolocation.lat, self.geolocation.lon), type="hospital", radius=10000)
183
+            bd = ""
184
+            for r0 in r['results']:
183 185
                 openh = "-"
186
+                if 'opening_hours' in r0:
187
+                    openh = r0['opening_hours']['open_now']
188
+                else:
189
+                    openh = "-"
184 190
 
185
-            bd += f"<tr><td>{r0['name']}</td><td>{openh}</td><td>{r0['vicinity']}</td></tr>"
191
+                bd += f"<tr><td>{r0['name']}</td><td>{openh}</td><td>{r0['vicinity']}</td></tr>"
186 192
 
187
-        rt = f'''
188
-<br>
189
-        <table><thead><tr><th>Name</th><th>Opening Hours</th><th>Vicinity</th></tr></thead>
190
-        <tbody>
191
-            {bd}
192
-        </tbody>
193
-        </table>
194
-        '''
195
-        return rt
193
+            rt = f'''
194
+    <br>
195
+            <table><thead><tr><th>Name</th><th>Opening Hours</th><th>Vicinity</th></tr></thead>
196
+            <tbody>
197
+                {bd}
198
+            </tbody>
199
+            </table>
200
+            '''
201
+            return rt
202
+        except:
203
+            return "-"
196 204
 
197 205
 
198 206
 
@@ -250,6 +258,9 @@ class Hospital(models.Model):
250 258
     address = map_fields.AddressField(max_length=200)
251 259
     geolocation = map_fields.GeoLocationField(max_length=100)
252 260
 
261
+    tel = models.CharField(max_length=100, null=True, blank=True)
262
+    line_id = models.CharField(max_length=100, null=True, blank=True)
263
+
253 264
     created_at = models.DateTimeField(auto_now_add=True, null=True)
254 265
     updated_at = models.DateTimeField(auto_now=True)
255 266
 

BIN
app/front/__pycache__/urls.cpython-39.pyc


BIN
app/front/__pycache__/views.cpython-39.pyc


BIN
app/front/migrations/__pycache__/__init__.cpython-39.pyc


+ 8 - 0
app/front/templates/front/404.html

@@ -0,0 +1,8 @@
1
+
2
+{% extends "base.html" %}
3
+
4
+{% block content %}
5
+<div class="alert alert-success" role="alert">
6
+<h1>ไม่มี page นี้</h1>
7
+</div>
8
+{% endblock %}

+ 7 - 3
app/front/templates/front/index.html

@@ -11,8 +11,10 @@
11 11
         <br>
12 12
         <input type='text' name='lastName' class='form-control' placeholder='นามสกุล' required/>
13 13
         <br>
14
-        <input type='text' name='idCard' class='form-control' placeholder='หมายเลขบัตรประชาชน' required />
15
-        <br>
14
+        <!-- 
15
+        <input type='text' name='idCard' class='form-control' placeholder='หมายเลขบัตรประชาชน' required /> 
16
+        <br> -->
17
+        <label>วันเกิด</label>
16 18
         <input type='date' name='bd' class='form-control' placeholder='วันเกิด' required />
17 19
         <br>
18 20
         <textarea name='address' class='form-control' placeholder='ที่อยู่' required></textarea>  
@@ -21,8 +23,10 @@
21 23
         <br>
22 24
         <input type='tel' name='tel' class='form-control' placeholder='Tel.' required/>
23 25
         <br>
26
+        <input type='text' name='line_id' class='form-control' placeholder='Line ID'/>
27
+        <br>
24 28
         <label>อัพโหลดภาพ</label>
25
-        <input type="file" name='photo' accept="image/*;capture=camera" class='form-control' required> </br>
29
+        <input type="file" name='photo' accept="image/*;capture=camera" class='form-control'> </br>
26 30
         <span class="glyphicon glyphicon-map-marker"></span>
27 31
         <a class='btn btn-primary form-control' id="currentLocationBtn">
28 32
         <i class="bi bi-geo-alt-fill"></i>

+ 33 - 0
app/front/templates/front/tracking.html

@@ -0,0 +1,33 @@
1
+
2
+{% extends "base.html" %}
3
+
4
+{% block content %}
5
+<div class="alert alert-success" role="alert">
6
+<h1>Tracking</h1>
7
+        <input type='text' class='form-control' name='geo' id='geoText' readonly/><br>
8
+        <br>Last Update
9
+        <span id='lastUpdate'></span>
10
+</div>
11
+{% endblock %}
12
+{% block foot_script %}
13
+<script>
14
+    $(function() {
15
+
16
+        setInterval(function(){
17
+            console.log("Hello");
18
+            if ("geolocation" in navigator){ //check geolocation available
19
+                //try to get user current location using getCurrentPosition() method
20
+                console.log("current location");
21
+                navigator.geolocation.getCurrentPosition(function(position){
22
+                    console.log("xxxx");
23
+                    $("#geoText").val(position.coords.latitude+","+position.coords.longitude );
24
+                    $("#lastUpdate").html(new Date());
25
+
26
+                });
27
+            }else{
28
+                console.log("Browser doesn't support geolocation!");
29
+            }
30
+        }, 5000);
31
+    });
32
+</script>
33
+{% endblock %}

+ 1 - 0
app/front/urls.py

@@ -5,5 +5,6 @@ from . import views
5 5
 
6 6
 urlpatterns = [
7 7
     path('', views.index, name='index'),
8
+    path('tracking', views.tracking, name='tracking'),
8 9
     path('success', views.success, name='success'),
9 10
 ]

+ 11 - 1
app/front/views.py

@@ -10,11 +10,13 @@ def index(request):
10 10
         p = Patient()
11 11
         p.first_name = request.POST.get('firstName')
12 12
         p.last_name = request.POST.get('lastName')
13
-        p.idcard = request.POST.get('idCard')
13
+        #p.idcard = request.POST.get('idCard')
14 14
         p.address = request.POST.get('address')
15 15
         p.geolocation = request.POST.get('geo')
16 16
         p.birth_date = request.POST.get('bd')
17 17
         p.comment = request.POST.get('comment')
18
+        p.tel = request.POST.get('tel')
19
+        p.line_id = request.POST.get('line_id')
18 20
         p.photo = request.FILES.get('photo')
19 21
         p.patient_status = "request"
20 22
         p.save()
@@ -23,3 +25,11 @@ def index(request):
23 25
 
24 26
 def success(request):
25 27
     return render(request, 'front/success.html')
28
+
29
+def tracking(request):
30
+    return render(request, 'front/tracking.html')
31
+
32
+def my404(request,exception):
33
+    return render(request, 'front/404.html')
34
+    #return redirect("index")
35
+

BIN
app/shaqfindbed/__pycache__/settings.cpython-39.pyc


BIN
app/shaqfindbed/__pycache__/urls.cpython-39.pyc


+ 5 - 1
app/shaqfindbed/settings.py

@@ -27,7 +27,11 @@ SECRET_KEY = 'django-insecure-!=!d6rsewcddw=hr-j46#))^nd-32(kkjmnpxxioi(v&c9!*xn
27 27
 # SECURITY WARNING: don't run with debug turned on in production!
28 28
 DEBUG = True
29 29
 
30
-ALLOWED_HOSTS = []
30
+ALLOWED_HOSTS = [
31
+    "167.71.218.44",
32
+    "localhost",
33
+    '.findbed.xyz'
34
+]
31 35
 
32 36
 
33 37
 # Application definition

+ 6 - 1
app/shaqfindbed/urls.py

@@ -18,13 +18,18 @@ from django.urls import path, include
18 18
 from django.conf import settings
19 19
 from django.conf.urls import url
20 20
 from django.conf.urls.static import static
21
+from django.views.static import serve
22
+
21 23
 
22 24
 urlpatterns = [
25
+    path('', include('front.urls')),
23 26
     path('backend/', include('backend.urls')),
24
-    path('front/', include('front.urls')),
25 27
     path('admin/', admin.site.urls),
26 28
     url(r'^chaining/', include('smart_selects.urls')),
29
+    url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
27 30
 ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
28 31
 
32
+
29 33
 if settings.DEBUG:
30 34
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
35
+handler404 = 'front.views.my404'

+ 162 - 0
app/staticfile/autocomplete_light/autocomplete.init.js

@@ -0,0 +1,162 @@
1
+/*
2
+This script garantees that this will be called once in django admin.
3
+However, its the callback's responsability to clean up if the
4
+element was cloned with data - which should be the case.
5
+*/
6
+
7
+;(function ($) {
8
+    $.fn.getFormPrefix = function() {
9
+        /* Get the form prefix for a field.
10
+         *
11
+         * For example:
12
+         *
13
+         *     $(':input[name$=owner]').getFormsetPrefix()
14
+         *
15
+         * Would return an empty string for an input with name 'owner' but would return
16
+         * 'inline_model-0-' for an input named 'inline_model-0-owner'.
17
+         */
18
+        var parts = $(this).attr('name').split('-');
19
+        var prefix = '';
20
+
21
+        for (var i in parts) {
22
+            var testPrefix = parts.slice(0, -i).join('-');
23
+            if (! testPrefix.length) continue;
24
+            testPrefix += '-';
25
+
26
+            var result = $(':input[name^=' + testPrefix + ']')
27
+
28
+            if (result.length) {
29
+                return testPrefix;
30
+            }
31
+        }
32
+
33
+        return '';
34
+    }
35
+
36
+    $.fn.getFormPrefixes = function() {
37
+        /*
38
+         * Get the form prefixes for a field, from the most specific to the least.
39
+         *
40
+         * For example:
41
+         *
42
+         *      $(':input[name$=owner]').getFormPrefixes()
43
+         *
44
+         * Would return:
45
+         * - [''] for an input named 'owner'.
46
+         * - ['inline_model-0-', ''] for an input named 'inline_model-0-owner' (i.e. nested with a nested inline).
47
+         * - ['sections-0-items-0-', 'sections-0-', ''] for an input named 'sections-0-items-0-product'
48
+         *   (i.e. nested multiple time with django-nested-admin).
49
+         */
50
+        var parts = $(this).attr('name').split('-').slice(0, -1);
51
+        var prefixes = [];
52
+
53
+        for (i = 0; i < parts.length; i += 2) {
54
+            var testPrefix = parts.slice(0, -i || parts.length).join('-');
55
+            if (!testPrefix.length)
56
+                continue;
57
+
58
+            testPrefix += '-';
59
+
60
+            var result = $(':input[name^=' + testPrefix + ']')
61
+
62
+            if (result.length)
63
+                prefixes.push(testPrefix);
64
+        }
65
+
66
+        prefixes.push('');
67
+
68
+        return prefixes;
69
+    }
70
+
71
+    var initialized = [];
72
+
73
+    function initialize(element) {
74
+        if (typeof element === 'undefined' || typeof element === 'number') {
75
+            element = this;
76
+        }
77
+
78
+        if (window.__dal__initListenerIsSet !== true || initialized.indexOf(element) >= 0) {
79
+            return;
80
+        }
81
+
82
+        $(element).trigger('autocompleteLightInitialize');
83
+        initialized.push(element);
84
+    }
85
+
86
+    if (!window.__dal__initialize) {
87
+        window.__dal__initialize = initialize;
88
+
89
+        $(document).ready(function () {
90
+            $('[data-autocomplete-light-function=select2]:not([id*="__prefix__"])').each(initialize);
91
+        });
92
+
93
+        $(document).bind('DOMNodeInserted', function (e) {
94
+            $(e.target).find('[data-autocomplete-light-function=select2]').each(initialize);
95
+        });
96
+    }
97
+
98
+    // using jQuery
99
+    function getCookie(name) {
100
+        var cookieValue = null;
101
+        if (document.cookie && document.cookie != '') {
102
+            var cookies = document.cookie.split(';');
103
+            for (var i = 0; i < cookies.length; i++) {
104
+                var cookie = $.trim(cookies[i]);
105
+                // Does this cookie string begin with the name we want?
106
+                if (cookie.substring(0, name.length + 1) == (name + '=')) {
107
+                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
108
+                    break;
109
+                }
110
+            }
111
+        }
112
+        return cookieValue;
113
+    }
114
+
115
+    document.csrftoken = getCookie('csrftoken');
116
+    if (document.csrftoken === null) {
117
+        // Try to get CSRF token from DOM when cookie is missing
118
+        var $csrf = $('form :input[name="csrfmiddlewaretoken"]');
119
+        if ($csrf.length > 0) {
120
+            document.csrftoken = $csrf[0].value;
121
+        }
122
+    }
123
+})(yl.jQuery);
124
+
125
+// Does the same thing as django's admin/js/autocomplete.js, but uses yl.jQuery.
126
+(function($) {
127
+    'use strict';
128
+    var init = function($element, options) {
129
+        var settings = $.extend({
130
+            ajax: {
131
+                data: function(params) {
132
+                    return {
133
+                        term: params.term,
134
+                        page: params.page
135
+                    };
136
+                }
137
+            }
138
+        }, options);
139
+        $element.select2(settings);
140
+    };
141
+
142
+    $.fn.djangoAdminSelect2 = function(options) {
143
+        var settings = $.extend({}, options);
144
+        $.each(this, function(i, element) {
145
+            var $element = $(element);
146
+            init($element, settings);
147
+        });
148
+        return this;
149
+    };
150
+
151
+    $(function() {
152
+        // Initialize all autocomplete widgets except the one in the template
153
+        // form used when a new formset is added.
154
+        $('.admin-autocomplete').not('[name*=__prefix__]').djangoAdminSelect2();
155
+    });
156
+
157
+    $(document).on('formset:added', (function() {
158
+        return function(event, $newFormset) {
159
+            return $newFormset.find('.admin-autocomplete').djangoAdminSelect2();
160
+        };
161
+    })(this));
162
+}(yl.jQuery));

+ 191 - 0
app/staticfile/autocomplete_light/forward.js

@@ -0,0 +1,191 @@
1
+;(function($, yl) {
2
+    yl.forwardHandlerRegistry = yl.forwardHandlerRegistry || {};
3
+
4
+    yl.registerForwardHandler = function(name, handler) {
5
+        yl.forwardHandlerRegistry[name] = handler;
6
+    };
7
+
8
+    yl.getForwardHandler = function(name) {
9
+        return yl.forwardHandlerRegistry[name];
10
+    };
11
+
12
+    function getForwardStrategy(element) {
13
+        var checkForCheckboxes = function() {
14
+            var all = true;
15
+            $.each(element, function(ix, e) {
16
+                if ($(e).attr("type") !== "checkbox") {
17
+                    all = false;
18
+                }
19
+            });
20
+            return all;
21
+        };
22
+
23
+        if (element.length === 1 &&
24
+                element.attr("type") === "checkbox" &&
25
+                element.attr("value") === undefined) {
26
+            // Single checkbox without 'value' attribute
27
+            // Boolean field
28
+            return "exists";
29
+        } else if (element.length === 1 &&
30
+                element.attr("multiple") !== undefined) {
31
+            // Multiple by HTML semantics. E. g. multiple select
32
+            // Multiple choice field
33
+            return "multiple";
34
+        } else if (checkForCheckboxes()) {
35
+            // Multiple checkboxes or one checkbox with 'value' attribute.
36
+            // Multiple choice field represented by checkboxes
37
+            return "multiple";
38
+        } else {
39
+            // Other cases
40
+            return "single";
41
+        }
42
+    }
43
+
44
+    /**
45
+     * Get fields with name `name` relative to `element` with considering form
46
+     * prefixes.
47
+     * @param element the element
48
+     * @param name name of the field
49
+     * @returns jQuery object with found fields or empty jQuery object if no
50
+     * field was found
51
+     */
52
+    yl.getFieldRelativeTo = function(element, name) {
53
+        var prefixes = $(element).getFormPrefixes();
54
+
55
+        for (var i = 0; i < prefixes.length; i++) {
56
+            var fieldSelector = "[name=" + prefixes[i] + name + "]";
57
+            var field = $(fieldSelector);
58
+
59
+            if (field.length) {
60
+                return field;
61
+            }
62
+        }
63
+
64
+        return $();
65
+    };
66
+
67
+    /**
68
+     * Get field value which is put to forwarded dictionary
69
+     * @param field the field
70
+     * @returns forwarded value
71
+     */
72
+    yl.getValueFromField = function(field) {
73
+        var strategy = getForwardStrategy(field);
74
+        var serializedField = $(field).serializeArray();
75
+
76
+        if ((serializedField == false) && ($(field).prop('disabled'))) {
77
+            $(field).prop('disabled', false);
78
+            serializedField = $(field).serializeArray();
79
+            $(field).prop('disabled', true);
80
+        }
81
+
82
+        var getSerializedFieldElementAt = function (index) {
83
+            // Return serializedField[index]
84
+            // or null if something went wrong
85
+            if (serializedField.length > index) {
86
+                return serializedField[index];
87
+            } else {
88
+                return null;
89
+            }
90
+        };
91
+
92
+        var getValueOf = function (elem) {
93
+            // Return elem.value
94
+            // or null if something went wrong
95
+            if (elem.hasOwnProperty("value") &&
96
+                elem.value !== undefined
97
+            ) {
98
+                return elem.value;
99
+            } else {
100
+                return null;
101
+            }
102
+        };
103
+
104
+        var getSerializedFieldValueAt = function (index) {
105
+            // Return serializedField[index].value
106
+            // or null if something went wrong
107
+            var elem = getSerializedFieldElementAt(index);
108
+            if (elem !== null) {
109
+                return getValueOf(elem);
110
+            } else {
111
+                return null;
112
+            }
113
+        };
114
+
115
+        if (strategy === "multiple") {
116
+            return serializedField.map(
117
+                function (item) {
118
+                    return getValueOf(item);
119
+                }
120
+            );
121
+        } else if (strategy === "exists") {
122
+            return serializedField.length > 0;
123
+        } else {
124
+            return getSerializedFieldValueAt(0);
125
+        }
126
+    };
127
+
128
+    yl.getForwards = function(element) {
129
+        var forwardElem,
130
+            forwardList,
131
+            forwardedData,
132
+            divSelector,
133
+            form;
134
+        divSelector = "div.dal-forward-conf#dal-forward-conf-for-" +
135
+                element.attr("id") + ", " +
136
+                "div.dal-forward-conf#dal-forward-conf-for_" +
137
+                element.attr("id");
138
+        form = element.length > 0 ? $(element[0].form) : $();
139
+
140
+        forwardElem =
141
+            form.find(divSelector).find('script');
142
+        if (forwardElem.length === 0) {
143
+            return;
144
+        }
145
+        try {
146
+            forwardList = JSON.parse(forwardElem.text());
147
+        } catch (e) {
148
+            return;
149
+        }
150
+
151
+        if (!Array.isArray(forwardList)) {
152
+            return;
153
+        }
154
+
155
+        forwardedData = {};
156
+
157
+        $.each(forwardList, function(ix, field) {
158
+            var srcName, dstName;
159
+            if (field.type === "const") {
160
+                forwardedData[field.dst] = field.val;
161
+            } else if (field.type === "self") {
162
+                if (field.hasOwnProperty("dst")) {
163
+                    dstName = field.dst;
164
+                } else {
165
+                    dstName = "self";
166
+                }
167
+                forwardedData[dstName] = yl.getValueFromField(element);
168
+            } else if (field.type === "field") {
169
+                srcName = field.src;
170
+                if (field.hasOwnProperty("dst")) {
171
+                    dstName = field.dst;
172
+                } else {
173
+                    dstName = srcName;
174
+                }
175
+                var forwardedField = yl.getFieldRelativeTo(element, srcName);
176
+
177
+                if (!forwardedField.length) {
178
+                    return;
179
+                }
180
+
181
+                forwardedData[dstName] = yl.getValueFromField(forwardedField);
182
+            } else if (field.type === "javascript") {
183
+                var handler = yl.getForwardHandler(field.handler);
184
+                forwardedData[field.dst || field.handler] = handler(element);
185
+            }
186
+
187
+        });
188
+        return JSON.stringify(forwardedData);
189
+    };
190
+
191
+})(yl.jQuery, yl);

+ 36 - 0
app/staticfile/autocomplete_light/jquery.init.js

@@ -0,0 +1,36 @@
1
+var yl = yl || {};
2
+if (typeof django !== 'undefined' && typeof django.jQuery !== 'undefined') {
3
+    // If django.jQuery is already defined, use it.
4
+    yl.jQuery = django.jQuery;
5
+}
6
+else {
7
+    // We include jquery itself in our widget's media, because we need it.
8
+    // Normally, we expect our widget's reference to admin/js/vendor/jquery/jquery.js
9
+    // to be skipped, because django's own code has already included it.
10
+    // However, if django.jQuery is NOT defined, we know that jquery was not
11
+    // included before we did it ourselves. This can happen if we're not being
12
+    // rendered in a django admin form.
13
+    // However, someone ELSE'S jQuery may have been included before ours, in
14
+    // which case we must ensure that our jquery doesn't override theirs, since
15
+    // it might be a newer version that other code on the page relies on.
16
+    // Thus, we must run jQuery.noConflict(true) here to move our jQuery out of
17
+    // the way.
18
+    yl.jQuery = jQuery.noConflict(true);
19
+}
20
+
21
+// In addition to all of this, we must ensure that the global jQuery and $ are
22
+// defined, because Select2 requires that. jQuery will only be undefined at
23
+// this point if only we or django included it.
24
+if (typeof jQuery === 'undefined') {
25
+    jQuery = yl.jQuery;
26
+    $ = yl.jQuery;
27
+}
28
+else {
29
+    // jQuery IS still defined, which means someone else also included jQuery.
30
+    // In this situation, we need to store the old jQuery in a
31
+    // temp variable, set the global jQuery to our yl.jQuery, then let select2
32
+    // set itself up. We restore the global jQuery to its original value in
33
+    // jquery.post-setup.js.
34
+    dal_jquery_backup = jQuery.noConflict(true);
35
+    jQuery = yl.jQuery;
36
+}

+ 7 - 0
app/staticfile/autocomplete_light/jquery.post-setup.js

@@ -0,0 +1,7 @@
1
+if (typeof dal_jquery_backup !== 'undefined') {
2
+    // We made a backup of the original global jQuery before forcing it to our
3
+    // yl.jQuery value. Now that select2 has been set up, we need to restore
4
+    // our backup to its rightful place.
5
+    jQuery = dal_jquery_backup;
6
+    $ = dal_jquery_backup;
7
+}

+ 14 - 0
app/staticfile/autocomplete_light/select2.css

@@ -0,0 +1,14 @@
1
+.select2-container {
2
+    min-width: 20em;
3
+}
4
+
5
+ul li.select2-selection__choice,
6
+ul li.select2-search {
7
+    /* Cancel out django's style */
8
+    list-style-type: none;
9
+}
10
+
11
+.errors .select2-selection {
12
+    /* Highlight select box with error */
13
+    border-color: #ba2121;
14
+}

+ 122 - 0
app/staticfile/autocomplete_light/select2.js

@@ -0,0 +1,122 @@
1
+;(function ($) {
2
+    if (window.__dal__initListenerIsSet)
3
+        return;
4
+
5
+    $(document).on('autocompleteLightInitialize', '[data-autocomplete-light-function=select2]', function() {
6
+        var element = $(this);
7
+
8
+        // Templating helper
9
+        function template(text, is_html) {
10
+            if (is_html) {
11
+                var $result = $('<span>');
12
+                $result.html(text);
13
+                return $result;
14
+            } else {
15
+                return text;
16
+            }
17
+        }
18
+
19
+        function result_template(item) {
20
+            var text = template(item.text,
21
+                element.attr('data-html') !== undefined || element.attr('data-result-html') !== undefined
22
+            );
23
+
24
+            if (item.create_id) {
25
+                return $('<span></span>').text(text).addClass('dal-create')
26
+            } else {
27
+                return text
28
+            }
29
+        }
30
+
31
+        function selected_template(item) {
32
+            if (item.selected_text !== undefined) {
33
+                return template(item.selected_text,
34
+                    element.attr('data-html') !== undefined || element.attr('data-selected-html') !== undefined
35
+                );
36
+            } else {
37
+                return result_template(item);
38
+            }
39
+            return
40
+        }
41
+
42
+        var ajax = null;
43
+        if ($(this).attr('data-autocomplete-light-url')) {
44
+            ajax = {
45
+                url: $(this).attr('data-autocomplete-light-url'),
46
+                dataType: 'json',
47
+                delay: 250,
48
+
49
+                data: function (params) {
50
+                    var data = {
51
+                        q: params.term, // search term
52
+                        page: params.page,
53
+                        create: element.attr('data-autocomplete-light-create') && !element.attr('data-tags'),
54
+                        forward: yl.getForwards(element)
55
+                    };
56
+
57
+                    return data;
58
+                },
59
+                processResults: function (data, page) {
60
+                    if (element.attr('data-tags')) {
61
+                        $.each(data.results, function(index, value) {
62
+                            value.id = value.text;
63
+                        });
64
+                    }
65
+
66
+                    return data;
67
+                },
68
+                cache: true
69
+            };
70
+        }
71
+
72
+        $(this).select2({
73
+            tokenSeparators: element.attr('data-tags') ? [','] : null,
74
+            debug: true,
75
+            containerCssClass: ':all:',
76
+            placeholder: element.attr('data-placeholder') || '',
77
+            language: element.attr('data-autocomplete-light-language'),
78
+            minimumInputLength: element.attr('data-minimum-input-length') || 0,
79
+            allowClear: ! $(this).is('[required]'),
80
+            templateResult: result_template,
81
+            templateSelection: selected_template,
82
+            ajax: ajax,
83
+            tags: Boolean(element.attr('data-tags')),
84
+        });
85
+
86
+        $(this).on('select2:selecting', function (e) {
87
+            var data = e.params.args.data;
88
+
89
+            if (data.create_id !== true)
90
+                return;
91
+
92
+            e.preventDefault();
93
+
94
+            var select = $(this);
95
+
96
+            $.ajax({
97
+                url: $(this).attr('data-autocomplete-light-url'),
98
+                type: 'POST',
99
+                dataType: 'json',
100
+                data: {
101
+                    text: data.id,
102
+                    forward: yl.getForwards($(this))
103
+                },
104
+                beforeSend: function(xhr, settings) {
105
+                    xhr.setRequestHeader("X-CSRFToken", document.csrftoken);
106
+                },
107
+                success: function(data, textStatus, jqXHR ) {
108
+                    select.append(
109
+                        $('<option>', {value: data.id, text: data.text, selected: true})
110
+                    );
111
+                    select.trigger('change');
112
+                    select.select2('close');
113
+                }
114
+            });
115
+        });
116
+
117
+    });
118
+    window.__dal__initListenerIsSet = true;
119
+    $('[data-autocomplete-light-function=select2]:not([id*="__prefix__"])').each(function() {
120
+        window.__dal__initialize(this);
121
+    });
122
+})(yl.jQuery);

BIN
app/staticfile/img/heartbeat.png


+ 22 - 0
app/staticfile/import_export/action_formats.js

@@ -0,0 +1,22 @@
1
+(function($) {
2
+  $(document).ready(function() {
3
+    var $actionsSelect, $formatsElement;
4
+    if ($('body').hasClass('grp-change-list')) {
5
+        // using grappelli
6
+        $actionsSelect = $('#grp-changelist-form select[name="action"]');
7
+        $formatsElement = $('#grp-changelist-form select[name="file_format"]');
8
+    } else {
9
+        // using default admin
10
+        $actionsSelect = $('#changelist-form select[name="action"]');
11
+        $formatsElement = $('#changelist-form select[name="file_format"]').parent();
12
+    }
13
+    $actionsSelect.change(function() {
14
+      if ($(this).val() === 'export_admin_action') {
15
+        $formatsElement.show();
16
+      } else {
17
+        $formatsElement.hide();
18
+      }
19
+    });
20
+    $actionsSelect.change();
21
+  });
22
+})(django.jQuery);

+ 81 - 0
app/staticfile/import_export/import.css

@@ -0,0 +1,81 @@
1
+.import-preview .errors {
2
+  position: relative;
3
+}
4
+
5
+.validation-error-count {
6
+  display: inline-block;
7
+  background-color: #e40000;
8
+  border-radius: 6px;
9
+  color: white;
10
+  font-size: 0.9em;
11
+  position: relative;
12
+  font-weight: bold;
13
+  margin-top: -2px;
14
+  padding: 0.2em 0.4em;
15
+}
16
+
17
+.validation-error-container {
18
+  position: absolute;
19
+  opacity: 0;
20
+  pointer-events: none;
21
+  background-color: #ffc1c1;
22
+  padding: 14px 15px 10px;
23
+  top: 25px;
24
+  margin: 0 0 20px 0;
25
+  width: 200px;
26
+  z-index: 2;
27
+}
28
+
29
+table.import-preview tr.skip {
30
+  background-color: #d2d2d2;
31
+}
32
+
33
+table.import-preview tr.new {
34
+  background-color: #bdd8b2;
35
+}
36
+
37
+table.import-preview tr.delete {
38
+  background-color: #f9bebf;
39
+}
40
+
41
+table.import-preview tr.update {
42
+  background-color: #fdfdcf;
43
+}
44
+
45
+.import-preview td:hover .validation-error-count {
46
+  z-index: 3;
47
+}
48
+.import-preview td:hover .validation-error-container {
49
+  opacity: 1;
50
+  pointer-events: auto;
51
+}
52
+
53
+.validation-error-list {
54
+  margin: 0;
55
+  padding: 0;
56
+}
57
+
58
+.validation-error-list li {
59
+  list-style: none;
60
+  margin: 0;
61
+}
62
+
63
+.validation-error-list > li > ul {
64
+  margin: 8px 0;
65
+  padding: 0;
66
+}
67
+
68
+.validation-error-list > li > ul > li {
69
+  padding: 0;
70
+  margin: 0 0 10px;
71
+  line-height: 1.28em;
72
+}
73
+
74
+.validation-error-field-label {
75
+  display: block;
76
+  border-bottom: 1px solid #e40000;
77
+  color: #e40000;
78
+  text-transform: uppercase;
79
+  font-weight: bold;
80
+  font-size: 0.85em;
81
+}

+ 15 - 0
app/staticfile/js/main.js

@@ -0,0 +1,15 @@
1
+$(function(){
2
+    $("#currentLocationBtn").click(function(){
3
+        if ("geolocation" in navigator){ //check geolocation available
4
+            //try to get user current location using getCurrentPosition() method
5
+            console.log("current location");
6
+            navigator.geolocation.getCurrentPosition(function(position){
7
+                console.log("xxxx");
8
+                $("#geoText").val(position.coords.latitude+","+position.coords.longitude );
9
+
10
+            });
11
+        }else{
12
+            console.log("Browser doesn't support geolocation!");
13
+        }
14
+    });
15
+});

+ 262 - 0
app/staticfile/vendor/select2/Gruntfile.js

@@ -0,0 +1,262 @@
1
+const sass = require('node-sass');
2
+
3
+module.exports = function (grunt) {
4
+  // Full list of files that must be included by RequireJS
5
+  includes = [
6
+    'jquery.select2',
7
+    'almond',
8
+
9
+    'jquery-mousewheel' // shimmed for non-full builds
10
+  ];
11
+
12
+  fullIncludes = [
13
+    'jquery',
14
+
15
+    'select2/compat/containerCss',
16
+    'select2/compat/dropdownCss',
17
+
18
+    'select2/compat/initSelection',
19
+    'select2/compat/inputData',
20
+    'select2/compat/matcher',
21
+    'select2/compat/query',
22
+
23
+    'select2/dropdown/attachContainer',
24
+    'select2/dropdown/stopPropagation',
25
+
26
+    'select2/selection/stopPropagation'
27
+  ].concat(includes);
28
+
29
+  var i18nModules = [];
30
+  var i18nPaths = {};
31
+
32
+  var i18nFiles = grunt.file.expand({
33
+    cwd: 'src/js'
34
+  }, 'select2/i18n/*.js');
35
+
36
+  var testFiles = grunt.file.expand('tests/**/*.html');
37
+  var testUrls = testFiles.map(function (filePath) {
38
+    return 'http://localhost:9999/' + filePath;
39
+  });
40
+
41
+  var testBuildNumber = "unknown";
42
+
43
+  if (process.env.TRAVIS_JOB_ID) {
44
+    testBuildNumber = "travis-" + process.env.TRAVIS_JOB_ID;
45
+  } else {
46
+    var currentTime = new Date();
47
+
48
+    testBuildNumber = "manual-" + currentTime.getTime();
49
+  }
50
+
51
+  for (var i = 0; i < i18nFiles.length; i++) {
52
+    var file = i18nFiles[i];
53
+    var name = file.split('.')[0];
54
+
55
+    i18nModules.push({
56
+      name: name
57
+    });
58
+
59
+    i18nPaths[name] = '../../' + name;
60
+  }
61
+
62
+  var minifiedBanner = '/*! Select2 <%= package.version %> | https://github.com/select2/select2/blob/master/LICENSE.md */';
63
+
64
+  grunt.initConfig({
65
+    package: grunt.file.readJSON('package.json'),
66
+
67
+    concat: {
68
+      'dist': {
69
+        options: {
70
+          banner: grunt.file.read('src/js/wrapper.start.js'),
71
+        },
72
+        src: [
73
+          'dist/js/select2.js',
74
+          'src/js/wrapper.end.js'
75
+        ],
76
+        dest: 'dist/js/select2.js'
77
+      },
78
+      'dist.full': {
79
+        options: {
80
+          banner: grunt.file.read('src/js/wrapper.start.js'),
81
+        },
82
+        src: [
83
+          'dist/js/select2.full.js',
84
+          'src/js/wrapper.end.js'
85
+        ],
86
+        dest: 'dist/js/select2.full.js'
87
+      }
88
+    },
89
+
90
+    connect: {
91
+      tests: {
92
+        options: {
93
+          base: '.',
94
+          hostname: '127.0.0.1',
95
+          port: 9999
96
+        }
97
+      }
98
+    },
99
+
100
+    uglify: {
101
+      'dist': {
102
+        src: 'dist/js/select2.js',
103
+        dest: 'dist/js/select2.min.js',
104
+        options: {
105
+          banner: minifiedBanner
106
+        }
107
+      },
108
+      'dist.full': {
109
+        src: 'dist/js/select2.full.js',
110
+        dest: 'dist/js/select2.full.min.js',
111
+        options: {
112
+          banner: minifiedBanner
113
+        }
114
+      }
115
+    },
116
+
117
+    qunit: {
118
+      all: {
119
+        options: {
120
+          urls: testUrls
121
+        }
122
+      }
123
+    },
124
+
125
+    jshint: {
126
+      options: {
127
+        jshintrc: true,
128
+        reporterOutput: ''
129
+      },
130
+      code: {
131
+        src: ['src/js/**/*.js']
132
+      },
133
+      tests: {
134
+        src: ['tests/**/*.js']
135
+      }
136
+    },
137
+
138
+    sass: {
139
+      dist: {
140
+        options: {
141
+          implementation: sass,
142
+          outputStyle: 'compressed'
143
+        },
144
+        files: {
145
+          'dist/css/select2.min.css': [
146
+            'src/scss/core.scss',
147
+            'src/scss/theme/default/layout.css'
148
+          ]
149
+        }
150
+      },
151
+      dev: {
152
+        options: {
153
+          implementation: sass,
154
+          outputStyle: 'nested'
155
+        },
156
+        files: {
157
+          'dist/css/select2.css': [
158
+            'src/scss/core.scss',
159
+            'src/scss/theme/default/layout.css'
160
+          ]
161
+        }
162
+      }
163
+    },
164
+
165
+    requirejs: {
166
+      'dist': {
167
+        options: {
168
+          baseUrl: 'src/js',
169
+          optimize: 'none',
170
+          name: 'select2/core',
171
+          out: 'dist/js/select2.js',
172
+          include: includes,
173
+          namespace: 'S2',
174
+          paths: {
175
+            'almond': require.resolve('almond').slice(0, -3),
176
+            'jquery': 'jquery.shim',
177
+            'jquery-mousewheel': 'jquery.mousewheel.shim'
178
+          },
179
+          wrap: {
180
+            startFile: 'src/js/banner.start.js',
181
+            endFile: 'src/js/banner.end.js'
182
+          }
183
+        }
184
+      },
185
+      'dist.full': {
186
+        options: {
187
+          baseUrl: 'src/js',
188
+          optimize: 'none',
189
+          name: 'select2/core',
190
+          out: 'dist/js/select2.full.js',
191
+          include: fullIncludes,
192
+          namespace: 'S2',
193
+          paths: {
194
+            'almond': require.resolve('almond').slice(0, -3),
195
+            'jquery': 'jquery.shim',
196
+            'jquery-mousewheel': require.resolve('jquery-mousewheel').slice(0, -3)
197
+          },
198
+          wrap: {
199
+            startFile: 'src/js/banner.start.js',
200
+            endFile: 'src/js/banner.end.js'
201
+          }
202
+        }
203
+      },
204
+      'i18n': {
205
+        options: {
206
+          baseUrl: 'src/js/select2/i18n',
207
+          dir: 'dist/js/i18n',
208
+          paths: i18nPaths,
209
+          modules: i18nModules,
210
+          namespace: 'S2',
211
+          wrap: {
212
+            start: minifiedBanner + grunt.file.read('src/js/banner.start.js'),
213
+            end: grunt.file.read('src/js/banner.end.js')
214
+          }
215
+        }
216
+      }
217
+    },
218
+
219
+    watch: {
220
+      js: {
221
+        files: [
222
+          'src/js/select2/**/*.js',
223
+          'tests/**/*.js'
224
+        ],
225
+        tasks: [
226
+          'compile',
227
+          'test',
228
+          'minify'
229
+        ]
230
+      },
231
+      css: {
232
+        files: [
233
+          'src/scss/**/*.scss'
234
+        ],
235
+        tasks: [
236
+          'compile',
237
+          'minify'
238
+        ]
239
+      }
240
+    }
241
+  });
242
+
243
+  grunt.loadNpmTasks('grunt-contrib-concat');
244
+  grunt.loadNpmTasks('grunt-contrib-connect');
245
+  grunt.loadNpmTasks('grunt-contrib-jshint');
246
+  grunt.loadNpmTasks('grunt-contrib-qunit');
247
+  grunt.loadNpmTasks('grunt-contrib-requirejs');
248
+  grunt.loadNpmTasks('grunt-contrib-uglify');
249
+  grunt.loadNpmTasks('grunt-contrib-watch');
250
+
251
+  grunt.loadNpmTasks('grunt-sass');
252
+
253
+  grunt.registerTask('default', ['compile', 'test', 'minify']);
254
+
255
+  grunt.registerTask('compile', [
256
+    'requirejs:dist', 'requirejs:dist.full', 'requirejs:i18n',
257
+    'concat:dist', 'concat:dist.full',
258
+    'sass:dev'
259
+  ]);
260
+  grunt.registerTask('minify', ['uglify', 'sass:dist']);
261
+  grunt.registerTask('test', ['connect:tests', 'qunit', 'jshint']);
262
+};

+ 13 - 0
app/staticfile/vendor/select2/bower.json

@@ -0,0 +1,13 @@
1
+{
2
+    "name": "select2",
3
+    "description": "Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.",
4
+    "main": [
5
+        "dist/js/select2.js",
6
+        "src/scss/core.scss"
7
+    ],
8
+    "license": "MIT",
9
+    "repository": {
10
+        "type": "git",
11
+        "url": "git@github.com:select2/select2.git"
12
+    }
13
+}

+ 19 - 0
app/staticfile/vendor/select2/component.json

@@ -0,0 +1,19 @@
1
+{
2
+  "name": "select2",
3
+  "repo": "select/select2",
4
+  "description": "Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.",
5
+  "version": "4.0.7",
6
+  "demo": "https://select2.org/",
7
+  "keywords": [
8
+    "jquery"
9
+  ],
10
+  "main": "dist/js/select2.js",
11
+  "styles": [
12
+    "dist/css/select2.css"
13
+  ],
14
+  "scripts": [
15
+    "dist/js/select2.js",
16
+    "dist/js/i18n/*.js"
17
+  ],
18
+  "license": "MIT"
19
+}

+ 22 - 0
app/staticfile/vendor/select2/composer.json

@@ -0,0 +1,22 @@
1
+{
2
+  "name": "select2/select2",
3
+  "description": "Select2 is a jQuery based replacement for select boxes.",
4
+  "type": "component",
5
+  "homepage": "https://select2.org/",
6
+  "license": "MIT",
7
+  "extra": {
8
+    "component": {
9
+      "scripts": [
10
+        "dist/js/select2.js"
11
+      ],
12
+      "styles": [
13
+        "dist/css/select2.css"
14
+      ],
15
+      "files": [
16
+        "dist/js/select2.js",
17
+        "dist/js/i18n/*.js",
18
+        "dist/css/select2.css"
19
+      ]
20
+    }
21
+  }
22
+}

+ 484 - 0
app/staticfile/vendor/select2/dist/css/select2.css

@@ -0,0 +1,484 @@
1
+.select2-container {
2
+  box-sizing: border-box;
3
+  display: inline-block;
4
+  margin: 0;
5
+  position: relative;
6
+  vertical-align: middle; }
7
+  .select2-container .select2-selection--single {
8
+    box-sizing: border-box;
9
+    cursor: pointer;
10
+    display: block;
11
+    height: 28px;
12
+    user-select: none;
13
+    -webkit-user-select: none; }
14
+    .select2-container .select2-selection--single .select2-selection__rendered {
15
+      display: block;
16
+      padding-left: 8px;
17
+      padding-right: 20px;
18
+      overflow: hidden;
19
+      text-overflow: ellipsis;
20
+      white-space: nowrap; }
21
+    .select2-container .select2-selection--single .select2-selection__clear {
22
+      position: relative; }
23
+  .select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered {
24
+    padding-right: 8px;
25
+    padding-left: 20px; }
26
+  .select2-container .select2-selection--multiple {
27
+    box-sizing: border-box;
28
+    cursor: pointer;
29
+    display: block;
30
+    min-height: 32px;
31
+    user-select: none;
32
+    -webkit-user-select: none; }
33
+    .select2-container .select2-selection--multiple .select2-selection__rendered {
34
+      display: inline-block;
35
+      overflow: hidden;
36
+      padding-left: 8px;
37
+      text-overflow: ellipsis;
38
+      white-space: nowrap; }
39
+  .select2-container .select2-search--inline {
40
+    float: left; }
41
+    .select2-container .select2-search--inline .select2-search__field {
42
+      box-sizing: border-box;
43
+      border: none;
44
+      font-size: 100%;
45
+      margin-top: 5px;
46
+      padding: 0; }
47
+      .select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button {
48
+        -webkit-appearance: none; }
49
+
50
+.select2-dropdown {
51
+  background-color: white;
52
+  border: 1px solid #aaa;
53
+  border-radius: 4px;
54
+  box-sizing: border-box;
55
+  display: block;
56
+  position: absolute;
57
+  left: -100000px;
58
+  width: 100%;
59
+  z-index: 1051; }
60
+
61
+.select2-results {
62
+  display: block; }
63
+
64
+.select2-results__options {
65
+  list-style: none;
66
+  margin: 0;
67
+  padding: 0; }
68
+
69
+.select2-results__option {
70
+  padding: 6px;
71
+  user-select: none;
72
+  -webkit-user-select: none; }
73
+  .select2-results__option[aria-selected] {
74
+    cursor: pointer; }
75
+
76
+.select2-container--open .select2-dropdown {
77
+  left: 0; }
78
+
79
+.select2-container--open .select2-dropdown--above {
80
+  border-bottom: none;
81
+  border-bottom-left-radius: 0;
82
+  border-bottom-right-radius: 0; }
83
+
84
+.select2-container--open .select2-dropdown--below {
85
+  border-top: none;
86
+  border-top-left-radius: 0;
87
+  border-top-right-radius: 0; }
88
+
89
+.select2-search--dropdown {
90
+  display: block;
91
+  padding: 4px; }
92
+  .select2-search--dropdown .select2-search__field {
93
+    padding: 4px;
94
+    width: 100%;
95
+    box-sizing: border-box; }
96
+    .select2-search--dropdown .select2-search__field::-webkit-search-cancel-button {
97
+      -webkit-appearance: none; }
98
+  .select2-search--dropdown.select2-search--hide {
99
+    display: none; }
100
+
101
+.select2-close-mask {
102
+  border: 0;
103
+  margin: 0;
104
+  padding: 0;
105
+  display: block;
106
+  position: fixed;
107
+  left: 0;
108
+  top: 0;
109
+  min-height: 100%;
110
+  min-width: 100%;
111
+  height: auto;
112
+  width: auto;
113
+  opacity: 0;
114
+  z-index: 99;
115
+  background-color: #fff;
116
+  filter: alpha(opacity=0); }
117
+
118
+.select2-hidden-accessible {
119
+  border: 0 !important;
120
+  clip: rect(0 0 0 0) !important;
121
+  -webkit-clip-path: inset(50%) !important;
122
+  clip-path: inset(50%) !important;
123
+  height: 1px !important;
124
+  overflow: hidden !important;
125
+  padding: 0 !important;
126
+  position: absolute !important;
127
+  width: 1px !important;
128
+  white-space: nowrap !important; }
129
+
130
+.select2-container--default .select2-selection--single {
131
+  background-color: #fff;
132
+  border: 1px solid #aaa;
133
+  border-radius: 4px; }
134
+  .select2-container--default .select2-selection--single .select2-selection__rendered {
135
+    color: #444;
136
+    line-height: 28px; }
137
+  .select2-container--default .select2-selection--single .select2-selection__clear {
138
+    cursor: pointer;
139
+    float: right;
140
+    font-weight: bold; }
141
+  .select2-container--default .select2-selection--single .select2-selection__placeholder {
142
+    color: #999; }
143
+  .select2-container--default .select2-selection--single .select2-selection__arrow {
144
+    height: 26px;
145
+    position: absolute;
146
+    top: 1px;
147
+    right: 1px;
148
+    width: 20px; }
149
+    .select2-container--default .select2-selection--single .select2-selection__arrow b {
150
+      border-color: #888 transparent transparent transparent;
151
+      border-style: solid;
152
+      border-width: 5px 4px 0 4px;
153
+      height: 0;
154
+      left: 50%;
155
+      margin-left: -4px;
156
+      margin-top: -2px;
157
+      position: absolute;
158
+      top: 50%;
159
+      width: 0; }
160
+
161
+.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__clear {
162
+  float: left; }
163
+
164
+.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow {
165
+  left: 1px;
166
+  right: auto; }
167
+
168
+.select2-container--default.select2-container--disabled .select2-selection--single {
169
+  background-color: #eee;
170
+  cursor: default; }
171
+  .select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear {
172
+    display: none; }
173
+
174
+.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
175
+  border-color: transparent transparent #888 transparent;
176
+  border-width: 0 4px 5px 4px; }
177
+
178
+.select2-container--default .select2-selection--multiple {
179
+  background-color: white;
180
+  border: 1px solid #aaa;
181
+  border-radius: 4px;
182
+  cursor: text; }
183
+  .select2-container--default .select2-selection--multiple .select2-selection__rendered {
184
+    box-sizing: border-box;
185
+    list-style: none;
186
+    margin: 0;
187
+    padding: 0 5px;
188
+    width: 100%; }
189
+    .select2-container--default .select2-selection--multiple .select2-selection__rendered li {
190
+      list-style: none; }
191
+  .select2-container--default .select2-selection--multiple .select2-selection__placeholder {
192
+    color: #999;
193
+    margin-top: 5px;
194
+    float: left; }
195
+  .select2-container--default .select2-selection--multiple .select2-selection__clear {
196
+    cursor: pointer;
197
+    float: right;
198
+    font-weight: bold;
199
+    margin-top: 5px;
200
+    margin-right: 10px; }
201
+  .select2-container--default .select2-selection--multiple .select2-selection__choice {
202
+    background-color: #e4e4e4;
203
+    border: 1px solid #aaa;
204
+    border-radius: 4px;
205
+    cursor: default;
206
+    float: left;
207
+    margin-right: 5px;
208
+    margin-top: 5px;
209
+    padding: 0 5px; }
210
+  .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
211
+    color: #999;
212
+    cursor: pointer;
213
+    display: inline-block;
214
+    font-weight: bold;
215
+    margin-right: 2px; }
216
+    .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
217
+      color: #333; }
218
+
219
+.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice, .select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder, .select2-container--default[dir="rtl"] .select2-selection--multiple .select2-search--inline {
220
+  float: right; }
221
+
222
+.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
223
+  margin-left: 5px;
224
+  margin-right: auto; }
225
+
226
+.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
227
+  margin-left: 2px;
228
+  margin-right: auto; }
229
+
230
+.select2-container--default.select2-container--focus .select2-selection--multiple {
231
+  border: solid black 1px;
232
+  outline: 0; }
233
+
234
+.select2-container--default.select2-container--disabled .select2-selection--multiple {
235
+  background-color: #eee;
236
+  cursor: default; }
237
+
238
+.select2-container--default.select2-container--disabled .select2-selection__choice__remove {
239
+  display: none; }
240
+
241
+.select2-container--default.select2-container--open.select2-container--above .select2-selection--single, .select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple {
242
+  border-top-left-radius: 0;
243
+  border-top-right-radius: 0; }
244
+
245
+.select2-container--default.select2-container--open.select2-container--below .select2-selection--single, .select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple {
246
+  border-bottom-left-radius: 0;
247
+  border-bottom-right-radius: 0; }
248
+
249
+.select2-container--default .select2-search--dropdown .select2-search__field {
250
+  border: 1px solid #aaa; }
251
+
252
+.select2-container--default .select2-search--inline .select2-search__field {
253
+  background: transparent;
254
+  border: none;
255
+  outline: 0;
256
+  box-shadow: none;
257
+  -webkit-appearance: textfield; }
258
+
259
+.select2-container--default .select2-results > .select2-results__options {
260
+  max-height: 200px;
261
+  overflow-y: auto; }
262
+
263
+.select2-container--default .select2-results__option[role=group] {
264
+  padding: 0; }
265
+
266
+.select2-container--default .select2-results__option[aria-disabled=true] {
267
+  color: #999; }
268
+
269
+.select2-container--default .select2-results__option[aria-selected=true] {
270
+  background-color: #ddd; }
271
+
272
+.select2-container--default .select2-results__option .select2-results__option {
273
+  padding-left: 1em; }
274
+  .select2-container--default .select2-results__option .select2-results__option .select2-results__group {
275
+    padding-left: 0; }
276
+  .select2-container--default .select2-results__option .select2-results__option .select2-results__option {
277
+    margin-left: -1em;
278
+    padding-left: 2em; }
279
+    .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
280
+      margin-left: -2em;
281
+      padding-left: 3em; }
282
+      .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
283
+        margin-left: -3em;
284
+        padding-left: 4em; }
285
+        .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
286
+          margin-left: -4em;
287
+          padding-left: 5em; }
288
+          .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
289
+            margin-left: -5em;
290
+            padding-left: 6em; }
291
+
292
+.select2-container--default .select2-results__option--highlighted[aria-selected] {
293
+  background-color: #5897fb;
294
+  color: white; }
295
+
296
+.select2-container--default .select2-results__group {
297
+  cursor: default;
298
+  display: block;
299
+  padding: 6px; }
300
+
301
+.select2-container--classic .select2-selection--single {
302
+  background-color: #f7f7f7;
303
+  border: 1px solid #aaa;
304
+  border-radius: 4px;
305
+  outline: 0;
306
+  background-image: -webkit-linear-gradient(top, white 50%, #eeeeee 100%);
307
+  background-image: -o-linear-gradient(top, white 50%, #eeeeee 100%);
308
+  background-image: linear-gradient(to bottom, white 50%, #eeeeee 100%);
309
+  background-repeat: repeat-x;
310
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0); }
311
+  .select2-container--classic .select2-selection--single:focus {
312
+    border: 1px solid #5897fb; }
313
+  .select2-container--classic .select2-selection--single .select2-selection__rendered {
314
+    color: #444;
315
+    line-height: 28px; }
316
+  .select2-container--classic .select2-selection--single .select2-selection__clear {
317
+    cursor: pointer;
318
+    float: right;
319
+    font-weight: bold;
320
+    margin-right: 10px; }
321
+  .select2-container--classic .select2-selection--single .select2-selection__placeholder {
322
+    color: #999; }
323
+  .select2-container--classic .select2-selection--single .select2-selection__arrow {
324
+    background-color: #ddd;
325
+    border: none;
326
+    border-left: 1px solid #aaa;
327
+    border-top-right-radius: 4px;
328
+    border-bottom-right-radius: 4px;
329
+    height: 26px;
330
+    position: absolute;
331
+    top: 1px;
332
+    right: 1px;
333
+    width: 20px;
334
+    background-image: -webkit-linear-gradient(top, #eeeeee 50%, #cccccc 100%);
335
+    background-image: -o-linear-gradient(top, #eeeeee 50%, #cccccc 100%);
336
+    background-image: linear-gradient(to bottom, #eeeeee 50%, #cccccc 100%);
337
+    background-repeat: repeat-x;
338
+    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFCCCCCC', GradientType=0); }
339
+    .select2-container--classic .select2-selection--single .select2-selection__arrow b {
340
+      border-color: #888 transparent transparent transparent;
341
+      border-style: solid;
342
+      border-width: 5px 4px 0 4px;
343
+      height: 0;
344
+      left: 50%;
345
+      margin-left: -4px;
346
+      margin-top: -2px;
347
+      position: absolute;
348
+      top: 50%;
349
+      width: 0; }
350
+
351
+.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__clear {
352
+  float: left; }
353
+
354
+.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__arrow {
355
+  border: none;
356
+  border-right: 1px solid #aaa;
357
+  border-radius: 0;
358
+  border-top-left-radius: 4px;
359
+  border-bottom-left-radius: 4px;
360
+  left: 1px;
361
+  right: auto; }
362
+
363
+.select2-container--classic.select2-container--open .select2-selection--single {
364
+  border: 1px solid #5897fb; }
365
+  .select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow {
366
+    background: transparent;
367
+    border: none; }
368
+    .select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow b {
369
+      border-color: transparent transparent #888 transparent;
370
+      border-width: 0 4px 5px 4px; }
371
+
372
+.select2-container--classic.select2-container--open.select2-container--above .select2-selection--single {
373
+  border-top: none;
374
+  border-top-left-radius: 0;
375
+  border-top-right-radius: 0;
376
+  background-image: -webkit-linear-gradient(top, white 0%, #eeeeee 50%);
377
+  background-image: -o-linear-gradient(top, white 0%, #eeeeee 50%);
378
+  background-image: linear-gradient(to bottom, white 0%, #eeeeee 50%);
379
+  background-repeat: repeat-x;
380
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0); }
381
+
382
+.select2-container--classic.select2-container--open.select2-container--below .select2-selection--single {
383
+  border-bottom: none;
384
+  border-bottom-left-radius: 0;
385
+  border-bottom-right-radius: 0;
386
+  background-image: -webkit-linear-gradient(top, #eeeeee 50%, white 100%);
387
+  background-image: -o-linear-gradient(top, #eeeeee 50%, white 100%);
388
+  background-image: linear-gradient(to bottom, #eeeeee 50%, white 100%);
389
+  background-repeat: repeat-x;
390
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF', GradientType=0); }
391
+
392
+.select2-container--classic .select2-selection--multiple {
393
+  background-color: white;
394
+  border: 1px solid #aaa;
395
+  border-radius: 4px;
396
+  cursor: text;
397
+  outline: 0; }
398
+  .select2-container--classic .select2-selection--multiple:focus {
399
+    border: 1px solid #5897fb; }
400
+  .select2-container--classic .select2-selection--multiple .select2-selection__rendered {
401
+    list-style: none;
402
+    margin: 0;
403
+    padding: 0 5px; }
404
+  .select2-container--classic .select2-selection--multiple .select2-selection__clear {
405
+    display: none; }
406
+  .select2-container--classic .select2-selection--multiple .select2-selection__choice {
407
+    background-color: #e4e4e4;
408
+    border: 1px solid #aaa;
409
+    border-radius: 4px;
410
+    cursor: default;
411
+    float: left;
412
+    margin-right: 5px;
413
+    margin-top: 5px;
414
+    padding: 0 5px; }
415
+  .select2-container--classic .select2-selection--multiple .select2-selection__choice__remove {
416
+    color: #888;
417
+    cursor: pointer;
418
+    display: inline-block;
419
+    font-weight: bold;
420
+    margin-right: 2px; }
421
+    .select2-container--classic .select2-selection--multiple .select2-selection__choice__remove:hover {
422
+      color: #555; }
423
+
424
+.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
425
+  float: right;
426
+  margin-left: 5px;
427
+  margin-right: auto; }
428
+
429
+.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
430
+  margin-left: 2px;
431
+  margin-right: auto; }
432
+
433
+.select2-container--classic.select2-container--open .select2-selection--multiple {
434
+  border: 1px solid #5897fb; }
435
+
436
+.select2-container--classic.select2-container--open.select2-container--above .select2-selection--multiple {
437
+  border-top: none;
438
+  border-top-left-radius: 0;
439
+  border-top-right-radius: 0; }
440
+
441
+.select2-container--classic.select2-container--open.select2-container--below .select2-selection--multiple {
442
+  border-bottom: none;
443
+  border-bottom-left-radius: 0;
444
+  border-bottom-right-radius: 0; }
445
+
446
+.select2-container--classic .select2-search--dropdown .select2-search__field {
447
+  border: 1px solid #aaa;
448
+  outline: 0; }
449
+
450
+.select2-container--classic .select2-search--inline .select2-search__field {
451
+  outline: 0;
452
+  box-shadow: none; }
453
+
454
+.select2-container--classic .select2-dropdown {
455
+  background-color: white;
456
+  border: 1px solid transparent; }
457
+
458
+.select2-container--classic .select2-dropdown--above {
459
+  border-bottom: none; }
460
+
461
+.select2-container--classic .select2-dropdown--below {
462
+  border-top: none; }
463
+
464
+.select2-container--classic .select2-results > .select2-results__options {
465
+  max-height: 200px;
466
+  overflow-y: auto; }
467
+
468
+.select2-container--classic .select2-results__option[role=group] {
469
+  padding: 0; }
470
+
471
+.select2-container--classic .select2-results__option[aria-disabled=true] {
472
+  color: grey; }
473
+
474
+.select2-container--classic .select2-results__option--highlighted[aria-selected] {
475
+  background-color: #3875d7;
476
+  color: white; }
477
+
478
+.select2-container--classic .select2-results__group {
479
+  cursor: default;
480
+  display: block;
481
+  padding: 6px; }
482
+
483
+.select2-container--classic.select2-container--open .select2-dropdown {
484
+  border-color: #5897fb; }

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 0
app/staticfile/vendor/select2/dist/css/select2.min.css


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/af.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/ar.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/az.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/bg.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/bn.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/bs.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/ca.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/cs.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/da.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/de.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/dsb.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/el.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/en.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/es.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/et.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/eu.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/fa.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/fi.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/fr.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/gl.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/he.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/hi.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/hr.js


Fichier diff supprimé car celui-ci est trop grand
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/hsb.js


+ 0 - 0
app/staticfile/vendor/select2/dist/js/i18n/hu.js


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff

tum/whitesports - Gogs: Simplico Git Service

Geen omschrijving

option.php 75KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500
  1. <?php
  2. /**
  3. * Option API
  4. *
  5. * @package WordPress
  6. * @subpackage Option
  7. */
  8. /**
  9. * Retrieves an option value based on an option name.
  10. *
  11. * If the option does not exist, and a default value is not provided,
  12. * boolean false is returned. This could be used to check whether you need
  13. * to initialize an option during installation of a plugin, however that
  14. * can be done better by using add_option() which will not overwrite
  15. * existing options.
  16. *
  17. * Not initializing an option and using boolean `false` as a return value
  18. * is a bad practice as it triggers an additional database query.
  19. *
  20. * The type of the returned value can be different from the type that was passed
  21. * when saving or updating the option. If the option value was serialized,
  22. * then it will be unserialized when it is returned. In this case the type will
  23. * be the same. For example, storing a non-scalar value like an array will
  24. * return the same array.
  25. *
  26. * In most cases non-string scalar and null values will be converted and returned
  27. * as string equivalents.
  28. *
  29. * Exceptions:
  30. * 1. When the option has not been saved in the database, the `$default` value
  31. * is returned if provided. If not, boolean `false` is returned.
  32. * 2. When one of the Options API filters is used: {@see 'pre_option_{$option}'},
  33. * {@see 'default_option_{$option}'}, or {@see 'option_{$option}'}, the returned
  34. * value may not match the expected type.
  35. * 3. When the option has just been saved in the database, and get_option()
  36. * is used right after, non-string scalar and null values are not converted to
  37. * string equivalents and the original type is returned.
  38. *
  39. * Examples:
  40. *
  41. * When adding options like this: `add_option( 'my_option_name', 'value' );`
  42. * and then retrieving them with `get_option( 'my_option_name' );`, the returned
  43. * values will be:
  44. *
  45. * `false` returns `string(0) ""`
  46. * `true` returns `string(1) "1"`
  47. * `0` returns `string(1) "0"`
  48. * `1` returns `string(1) "1"`
  49. * `'0'` returns `string(1) "0"`
  50. * `'1'` returns `string(1) "1"`
  51. * `null` returns `string(0) ""`
  52. *
  53. * When adding options with non-scalar values like
  54. * `add_option( 'my_array', array( false, 'str', null ) );`, the returned value
  55. * will be identical to the original as it is serialized before saving
  56. * it in the database:
  57. *
  58. * array(3) {
  59. * [0] => bool(false)
  60. * [1] => string(3) "str"
  61. * [2] => NULL
  62. * }
  63. *
  64. * @since 1.5.0
  65. *
  66. * @global wpdb $wpdb WordPress database abstraction object.
  67. *
  68. * @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
  69. * @param mixed $default Optional. Default value to return if the option does not exist.
  70. * @return mixed Value of the option. A value of any type may be returned, including
  71. * scalar (string, boolean, float, integer), null, array, object.
  72. * Scalar and null values will be returned as strings as long as they originate
  73. * from a database stored option value. If there is no option in the database,
  74. * boolean `false` is returned.
  75. */
  76. function get_option( $option, $default = false ) {
  77. global $wpdb;
  78. $option = trim( $option );
  79. if ( empty( $option ) ) {
  80. return false;
  81. }
  82. /*
  83. * Until a proper _deprecated_option() function can be introduced,
  84. * redirect requests to deprecated keys to the new, correct ones.
  85. */
  86. $deprecated_keys = array(
  87. 'blacklist_keys' => 'disallowed_keys',
  88. 'comment_whitelist' => 'comment_previously_approved',
  89. );
  90. if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
  91. _deprecated_argument(
  92. __FUNCTION__,
  93. '5.5.0',
  94. sprintf(
  95. /* translators: 1: Deprecated option key, 2: New option key. */
  96. __( 'The "%1$s" option key has been renamed to "%2$s".' ),
  97. $option,
  98. $deprecated_keys[ $option ]
  99. )
  100. );
  101. return get_option( $deprecated_keys[ $option ], $default );
  102. }
  103. /**
  104. * Filters the value of an existing option before it is retrieved.
  105. *
  106. * The dynamic portion of the hook name, `$option`, refers to the option name.
  107. *
  108. * Returning a truthy value from the filter will effectively short-circuit retrieval
  109. * and return the passed value instead.
  110. *
  111. * @since 1.5.0
  112. * @since 4.4.0 The `$option` parameter was added.
  113. * @since 4.9.0 The `$default` parameter was added.
  114. *
  115. * @param mixed $pre_option The value to return instead of the option value. This differs
  116. * from `$default`, which is used as the fallback value in the event
  117. * the option doesn't exist elsewhere in get_option().
  118. * Default false (to skip past the short-circuit).
  119. * @param string $option Option name.
  120. * @param mixed $default The fallback value to return if the option does not exist.
  121. * Default false.
  122. */
  123. $pre = apply_filters( "pre_option_{$option}", false, $option, $default );
  124. if ( false !== $pre ) {
  125. return $pre;
  126. }
  127. if ( defined( 'WP_SETUP_CONFIG' ) ) {
  128. return false;
  129. }
  130. // Distinguish between `false` as a default, and not passing one.
  131. $passed_default = func_num_args() > 1;
  132. if ( ! wp_installing() ) {
  133. // Prevent non-existent options from triggering multiple queries.
  134. $notoptions = wp_cache_get( 'notoptions', 'options' );
  135. if ( isset( $notoptions[ $option ] ) ) {
  136. /**
  137. * Filters the default value for an option.
  138. *
  139. * The dynamic portion of the hook name, `$option`, refers to the option name.
  140. *
  141. * @since 3.4.0
  142. * @since 4.4.0 The `$option` parameter was added.
  143. * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value.
  144. *
  145. * @param mixed $default The default value to return if the option does not exist
  146. * in the database.
  147. * @param string $option Option name.
  148. * @param bool $passed_default Was `get_option()` passed a default value?
  149. */
  150. return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
  151. }
  152. $alloptions = wp_load_alloptions();
  153. if ( isset( $alloptions[ $option ] ) ) {
  154. $value = $alloptions[ $option ];
  155. } else {
  156. $value = wp_cache_get( $option, 'options' );
  157. if ( false === $value ) {
  158. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
  159. // Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
  160. if ( is_object( $row ) ) {
  161. $value = $row->option_value;
  162. wp_cache_add( $option, $value, 'options' );
  163. } else { // Option does not exist, so we must cache its non-existence.
  164. if ( ! is_array( $notoptions ) ) {
  165. $notoptions = array();
  166. }
  167. $notoptions[ $option ] = true;
  168. wp_cache_set( 'notoptions', $notoptions, 'options' );
  169. /** This filter is documented in wp-includes/option.php */
  170. return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
  171. }
  172. }
  173. }
  174. } else {
  175. $suppress = $wpdb->suppress_errors();
  176. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
  177. $wpdb->suppress_errors( $suppress );
  178. if ( is_object( $row ) ) {
  179. $value = $row->option_value;
  180. } else {
  181. /** This filter is documented in wp-includes/option.php */
  182. return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
  183. }
  184. }
  185. // If home is not set, use siteurl.
  186. if ( 'home' === $option && '' === $value ) {
  187. return get_option( 'siteurl' );
  188. }
  189. if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
  190. $value = untrailingslashit( $value );
  191. }
  192. /**
  193. * Filters the value of an existing option.
  194. *
  195. * The dynamic portion of the hook name, `$option`, refers to the option name.
  196. *
  197. * @since 1.5.0 As 'option_' . $setting
  198. * @since 3.0.0
  199. * @since 4.4.0 The `$option` parameter was added.
  200. *
  201. * @param mixed $value Value of the option. If stored serialized, it will be
  202. * unserialized prior to being returned.
  203. * @param string $option Option name.
  204. */
  205. return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option );
  206. }
  207. /**
  208. * Protects WordPress special option from being modified.
  209. *
  210. * Will die if $option is in protected list. Protected options are 'alloptions'
  211. * and 'notoptions' options.
  212. *
  213. * @since 2.2.0
  214. *
  215. * @param string $option Option name.
  216. */
  217. function wp_protect_special_option( $option ) {
  218. if ( 'alloptions' === $option || 'notoptions' === $option ) {
  219. wp_die(
  220. sprintf(
  221. /* translators: %s: Option name. */
  222. __( '%s is a protected WP option and may not be modified' ),
  223. esc_html( $option )
  224. )
  225. );
  226. }
  227. }
  228. /**
  229. * Prints option value after sanitizing for forms.
  230. *
  231. * @since 1.5.0
  232. *
  233. * @param string $option Option name.
  234. */
  235. function form_option( $option ) {
  236. echo esc_attr( get_option( $option ) );
  237. }
  238. /**
  239. * Loads and caches all autoloaded options, if available or all options.
  240. *
  241. * @since 2.2.0
  242. * @since 5.3.1 The `$force_cache` parameter was added.
  243. *
  244. * @global wpdb $wpdb WordPress database abstraction object.
  245. *
  246. * @param bool $force_cache Optional. Whether to force an update of the local cache
  247. * from the persistent cache. Default false.
  248. * @return array List of all options.
  249. */
  250. function wp_load_alloptions( $force_cache = false ) {
  251. global $wpdb;
  252. if ( ! wp_installing() || ! is_multisite() ) {
  253. $alloptions = wp_cache_get( 'alloptions', 'options', $force_cache );
  254. } else {
  255. $alloptions = false;
  256. }
  257. if ( ! $alloptions ) {
  258. $suppress = $wpdb->suppress_errors();
  259. $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" );
  260. if ( ! $alloptions_db ) {
  261. $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
  262. }
  263. $wpdb->suppress_errors( $suppress );
  264. $alloptions = array();
  265. foreach ( (array) $alloptions_db as $o ) {
  266. $alloptions[ $o->option_name ] = $o->option_value;
  267. }
  268. if ( ! wp_installing() || ! is_multisite() ) {
  269. /**
  270. * Filters all options before caching them.
  271. *
  272. * @since 4.9.0
  273. *
  274. * @param array $alloptions Array with all options.
  275. */
  276. $alloptions = apply_filters( 'pre_cache_alloptions', $alloptions );
  277. wp_cache_add( 'alloptions', $alloptions, 'options' );
  278. }
  279. }
  280. /**
  281. * Filters all options after retrieving them.
  282. *
  283. * @since 4.9.0
  284. *
  285. * @param array $alloptions Array with all options.
  286. */
  287. return apply_filters( 'alloptions', $alloptions );
  288. }
  289. /**
  290. * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
  291. *
  292. * @since 3.0.0
  293. *
  294. * @global wpdb $wpdb WordPress database abstraction object.
  295. *
  296. * @param int $network_id Optional site ID for which to query the options. Defaults to the current site.
  297. */
  298. function wp_load_core_site_options( $network_id = null ) {
  299. global $wpdb;
  300. if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) {
  301. return;
  302. }
  303. if ( empty( $network_id ) ) {
  304. $network_id = get_current_network_id();
  305. }
  306. $core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
  307. $core_options_in = "'" . implode( "', '", $core_options ) . "'";
  308. $options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) );
  309. foreach ( $options as $option ) {
  310. $key = $option->meta_key;
  311. $cache_key = "{$network_id}:$key";
  312. $option->meta_value = maybe_unserialize( $option->meta_value );
  313. wp_cache_set( $cache_key, $option->meta_value, 'site-options' );
  314. }
  315. }
  316. /**
  317. * Updates the value of an option that was already added.
  318. *
  319. * You do not need to serialize values. If the value needs to be serialized,
  320. * then it will be serialized before it is inserted into the database.
  321. * Remember, resources cannot be serialized or added as an option.
  322. *
  323. * If the option does not exist, it will be created.
  324. * This function is designed to work with or without a logged-in user. In terms of security,
  325. * plugin developers should check the current user's capabilities before updating any options.
  326. *
  327. * @since 1.0.0
  328. * @since 4.2.0 The `$autoload` parameter was added.
  329. *
  330. * @global wpdb $wpdb WordPress database abstraction object.
  331. *
  332. * @param string $option Name of the option to update. Expected to not be SQL-escaped.
  333. * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
  334. * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options,
  335. * `$autoload` can only be updated using `update_option()` if `$value` is also changed.
  336. * Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options,
  337. * the default value is 'yes'. Default null.
  338. * @return bool True if the value was updated, false otherwise.
  339. */
  340. function update_option( $option, $value, $autoload = null ) {
  341. global $wpdb;
  342. $option = trim( $option );
  343. if ( empty( $option ) ) {
  344. return false;
  345. }
  346. /*
  347. * Until a proper _deprecated_option() function can be introduced,
  348. * redirect requests to deprecated keys to the new, correct ones.
  349. */
  350. $deprecated_keys = array(
  351. 'blacklist_keys' => 'disallowed_keys',
  352. 'comment_whitelist' => 'comment_previously_approved',
  353. );
  354. if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
  355. _deprecated_argument(
  356. __FUNCTION__,
  357. '5.5.0',
  358. sprintf(
  359. /* translators: 1: Deprecated option key, 2: New option key. */
  360. __( 'The "%1$s" option key has been renamed to "%2$s".' ),
  361. $option,
  362. $deprecated_keys[ $option ]
  363. )
  364. );
  365. return update_option( $deprecated_keys[ $option ], $value, $autoload );
  366. }
  367. wp_protect_special_option( $option );
  368. if ( is_object( $value ) ) {
  369. $value = clone $value;
  370. }
  371. $value = sanitize_option( $option, $value );
  372. $old_value = get_option( $option );
  373. /**
  374. * Filters a specific option before its value is (maybe) serialized and updated.
  375. *
  376. * The dynamic portion of the hook name, `$option`, refers to the option name.
  377. *
  378. * @since 2.6.0
  379. * @since 4.4.0 The `$option` parameter was added.
  380. *
  381. * @param mixed $value The new, unserialized option value.
  382. * @param mixed $old_value The old option value.
  383. * @param string $option Option name.
  384. */
  385. $value = apply_filters( "pre_update_option_{$option}", $value, $old_value, $option );
  386. /**
  387. * Filters an option before its value is (maybe) serialized and updated.
  388. *
  389. * @since 3.9.0
  390. *
  391. * @param mixed $value The new, unserialized option value.
  392. * @param string $option Name of the option.
  393. * @param mixed $old_value The old option value.
  394. */
  395. $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
  396. /*
  397. * If the new and old values are the same, no need to update.
  398. *
  399. * Unserialized values will be adequate in most cases. If the unserialized
  400. * data differs, the (maybe) serialized data is checked to avoid
  401. * unnecessary database calls for otherwise identical object instances.
  402. *
  403. * See https://core.trac.wordpress.org/ticket/38903
  404. */
  405. if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
  406. return false;
  407. }
  408. /** This filter is documented in wp-includes/option.php */
  409. if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) {
  410. // Default setting for new options is 'yes'.
  411. if ( null === $autoload ) {
  412. $autoload = 'yes';
  413. }
  414. return add_option( $option, $value, '', $autoload );
  415. }
  416. $serialized_value = maybe_serialize( $value );
  417. /**
  418. * Fires immediately before an option value is updated.
  419. *
  420. * @since 2.9.0
  421. *
  422. * @param string $option Name of the option to update.
  423. * @param mixed $old_value The old option value.
  424. * @param mixed $value The new option value.
  425. */
  426. do_action( 'update_option', $option, $old_value, $value );
  427. $update_args = array(
  428. 'option_value' => $serialized_value,
  429. );
  430. if ( null !== $autoload ) {
  431. $update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
  432. }
  433. $result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) );
  434. if ( ! $result ) {
  435. return false;
  436. }
  437. $notoptions = wp_cache_get( 'notoptions', 'options' );
  438. if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
  439. unset( $notoptions[ $option ] );
  440. wp_cache_set( 'notoptions', $notoptions, 'options' );
  441. }
  442. if ( ! wp_installing() ) {
  443. $alloptions = wp_load_alloptions( true );
  444. if ( isset( $alloptions[ $option ] ) ) {
  445. $alloptions[ $option ] = $serialized_value;
  446. wp_cache_set( 'alloptions', $alloptions, 'options' );
  447. } else {
  448. wp_cache_set( $option, $serialized_value, 'options' );
  449. }
  450. }
  451. /**
  452. * Fires after the value of a specific option has been successfully updated.
  453. *
  454. * The dynamic portion of the hook name, `$option`, refers to the option name.
  455. *
  456. * @since 2.0.1
  457. * @since 4.4.0 The `$option` parameter was added.
  458. *
  459. * @param mixed $old_value The old option value.
  460. * @param mixed $value The new option value.
  461. * @param string $option Option name.
  462. */
  463. do_action( "update_option_{$option}", $old_value, $value, $option );
  464. /**
  465. * Fires after the value of an option has been successfully updated.
  466. *
  467. * @since 2.9.0
  468. *
  469. * @param string $option Name of the updated option.
  470. * @param mixed $old_value The old option value.
  471. * @param mixed $value The new option value.
  472. */
  473. do_action( 'updated_option', $option, $old_value, $value );
  474. return true;
  475. }
  476. /**
  477. * Adds a new option.
  478. *
  479. * You do not need to serialize values. If the value needs to be serialized,
  480. * then it will be serialized before it is inserted into the database.
  481. * Remember, resources cannot be serialized or added as an option.
  482. *
  483. * You can create options without values and then update the values later.
  484. * Existing options will not be updated and checks are performed to ensure that you
  485. * aren't adding a protected WordPress option. Care should be taken to not name
  486. * options the same as the ones which are protected.
  487. *
  488. * @since 1.0.0
  489. *
  490. * @global wpdb $wpdb WordPress database abstraction object.
  491. *
  492. * @param string $option Name of the option to add. Expected to not be SQL-escaped.
  493. * @param mixed $value Optional. Option value. Must be serializable if non-scalar.
  494. * Expected to not be SQL-escaped.
  495. * @param string $deprecated Optional. Description. Not used anymore.
  496. * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up.
  497. * Default is enabled. Accepts 'no' to disable for legacy reasons.
  498. * @return bool True if the option was added, false otherwise.
  499. */
  500. function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
  501. global $wpdb;
  502. if ( ! empty( $deprecated ) ) {
  503. _deprecated_argument( __FUNCTION__, '2.3.0' );
  504. }
  505. $option = trim( $option );
  506. if ( empty( $option ) ) {
  507. return false;
  508. }
  509. /*
  510. * Until a proper _deprecated_option() function can be introduced,
  511. * redirect requests to deprecated keys to the new, correct ones.
  512. */
  513. $deprecated_keys = array(
  514. 'blacklist_keys' => 'disallowed_keys',
  515. 'comment_whitelist' => 'comment_previously_approved',
  516. );
  517. if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
  518. _deprecated_argument(
  519. __FUNCTION__,
  520. '5.5.0',
  521. sprintf(
  522. /* translators: 1: Deprecated option key, 2: New option key. */
  523. __( 'The "%1$s" option key has been renamed to "%2$s".' ),
  524. $option,
  525. $deprecated_keys[ $option ]
  526. )
  527. );
  528. return add_option( $deprecated_keys[ $option ], $value, $deprecated, $autoload );
  529. }
  530. wp_protect_special_option( $option );
  531. if ( is_object( $value ) ) {
  532. $value = clone $value;
  533. }
  534. $value = sanitize_option( $option, $value );
  535. // Make sure the option doesn't already exist.
  536. // We can check the 'notoptions' cache before we ask for a DB query.
  537. $notoptions = wp_cache_get( 'notoptions', 'options' );
  538. if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
  539. /** This filter is documented in wp-includes/option.php */
  540. if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) {
  541. return false;
  542. }
  543. }
  544. $serialized_value = maybe_serialize( $value );
  545. $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
  546. /**
  547. * Fires before an option is added.
  548. *
  549. * @since 2.9.0
  550. *
  551. * @param string $option Name of the option to add.
  552. * @param mixed $value Value of the option.
  553. */
  554. do_action( 'add_option', $option, $value );
  555. $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
  556. if ( ! $result ) {
  557. return false;
  558. }
  559. if ( ! wp_installing() ) {
  560. if ( 'yes' === $autoload ) {
  561. $alloptions = wp_load_alloptions( true );
  562. $alloptions[ $option ] = $serialized_value;
  563. wp_cache_set( 'alloptions', $alloptions, 'options' );
  564. } else {
  565. wp_cache_set( $option, $serialized_value, 'options' );
  566. }
  567. }
  568. // This option exists now.
  569. $notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh.
  570. if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
  571. unset( $notoptions[ $option ] );
  572. wp_cache_set( 'notoptions', $notoptions, 'options' );
  573. }
  574. /**
  575. * Fires after a specific option has been added.
  576. *
  577. * The dynamic portion of the hook name, `$option`, refers to the option name.
  578. *
  579. * @since 2.5.0 As "add_option_{$name}"
  580. * @since 3.0.0
  581. *
  582. * @param string $option Name of the option to add.
  583. * @param mixed $value Value of the option.
  584. */
  585. do_action( "add_option_{$option}", $option, $value );
  586. /**
  587. * Fires after an option has been added.
  588. *
  589. * @since 2.9.0
  590. *
  591. * @param string $option Name of the added option.
  592. * @param mixed $value Value of the option.
  593. */
  594. do_action( 'added_option', $option, $value );
  595. return true;
  596. }
  597. /**
  598. * Removes option by name. Prevents removal of protected WordPress options.
  599. *
  600. * @since 1.2.0
  601. *
  602. * @global wpdb $wpdb WordPress database abstraction object.
  603. *
  604. * @param string $option Name of the option to delete. Expected to not be SQL-escaped.
  605. * @return bool True if the option was deleted, false otherwise.
  606. */
  607. function delete_option( $option ) {
  608. global $wpdb;
  609. $option = trim( $option );
  610. if ( empty( $option ) ) {
  611. return false;
  612. }
  613. wp_protect_special_option( $option );
  614. // Get the ID, if no ID then return.
  615. $row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
  616. if ( is_null( $row ) ) {
  617. return false;
  618. }
  619. /**
  620. * Fires immediately before an option is deleted.
  621. *
  622. * @since 2.9.0
  623. *
  624. * @param string $option Name of the option to delete.
  625. */
  626. do_action( 'delete_option', $option );
  627. $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
  628. if ( ! wp_installing() ) {
  629. if ( 'yes' === $row->autoload ) {
  630. $alloptions = wp_load_alloptions( true );
  631. if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
  632. unset( $alloptions[ $option ] );
  633. wp_cache_set( 'alloptions', $alloptions, 'options' );
  634. }
  635. } else {
  636. wp_cache_delete( $option, 'options' );
  637. }
  638. }
  639. if ( $result ) {
  640. /**
  641. * Fires after a specific option has been deleted.
  642. *
  643. * The dynamic portion of the hook name, `$option`, refers to the option name.
  644. *
  645. * @since 3.0.0
  646. *
  647. * @param string $option Name of the deleted option.
  648. */
  649. do_action( "delete_option_{$option}", $option );
  650. /**
  651. * Fires after an option has been deleted.
  652. *
  653. * @since 2.9.0
  654. *
  655. * @param string $option Name of the deleted option.
  656. */
  657. do_action( 'deleted_option', $option );
  658. return true;
  659. }
  660. return false;
  661. }
  662. /**
  663. * Deletes a transient.
  664. *
  665. * @since 2.8.0
  666. *
  667. * @param string $transient Transient name. Expected to not be SQL-escaped.
  668. * @return bool True if the transient was deleted, false otherwise.
  669. */
  670. function delete_transient( $transient ) {
  671. /**
  672. * Fires immediately before a specific transient is deleted.
  673. *
  674. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  675. *
  676. * @since 3.0.0
  677. *
  678. * @param string $transient Transient name.
  679. */
  680. do_action( "delete_transient_{$transient}", $transient );
  681. if ( wp_using_ext_object_cache() ) {
  682. $result = wp_cache_delete( $transient, 'transient' );
  683. } else {
  684. $option_timeout = '_transient_timeout_' . $transient;
  685. $option = '_transient_' . $transient;
  686. $result = delete_option( $option );
  687. if ( $result ) {
  688. delete_option( $option_timeout );
  689. }
  690. }
  691. if ( $result ) {
  692. /**
  693. * Fires after a transient is deleted.
  694. *
  695. * @since 3.0.0
  696. *
  697. * @param string $transient Deleted transient name.
  698. */
  699. do_action( 'deleted_transient', $transient );
  700. }
  701. return $result;
  702. }
  703. /**
  704. * Retrieves the value of a transient.
  705. *
  706. * If the transient does not exist, does not have a value, or has expired,
  707. * then the return value will be false.
  708. *
  709. * @since 2.8.0
  710. *
  711. * @param string $transient Transient name. Expected to not be SQL-escaped.
  712. * @return mixed Value of transient.
  713. */
  714. function get_transient( $transient ) {
  715. /**
  716. * Filters the value of an existing transient before it is retrieved.
  717. *
  718. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  719. *
  720. * Returning a truthy value from the filter will effectively short-circuit retrieval
  721. * and return the passed value instead.
  722. *
  723. * @since 2.8.0
  724. * @since 4.4.0 The `$transient` parameter was added
  725. *
  726. * @param mixed $pre_transient The default value to return if the transient does not exist.
  727. * Any value other than false will short-circuit the retrieval
  728. * of the transient, and return that value.
  729. * @param string $transient Transient name.
  730. */
  731. $pre = apply_filters( "pre_transient_{$transient}", false, $transient );
  732. if ( false !== $pre ) {
  733. return $pre;
  734. }
  735. if ( wp_using_ext_object_cache() ) {
  736. $value = wp_cache_get( $transient, 'transient' );
  737. } else {
  738. $transient_option = '_transient_' . $transient;
  739. if ( ! wp_installing() ) {
  740. // If option is not in alloptions, it is not autoloaded and thus has a timeout.
  741. $alloptions = wp_load_alloptions();
  742. if ( ! isset( $alloptions[ $transient_option ] ) ) {
  743. $transient_timeout = '_transient_timeout_' . $transient;
  744. $timeout = get_option( $transient_timeout );
  745. if ( false !== $timeout && $timeout < time() ) {
  746. delete_option( $transient_option );
  747. delete_option( $transient_timeout );
  748. $value = false;
  749. }
  750. }
  751. }
  752. if ( ! isset( $value ) ) {
  753. $value = get_option( $transient_option );
  754. }
  755. }
  756. /**
  757. * Filters an existing transient's value.
  758. *
  759. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  760. *
  761. * @since 2.8.0
  762. * @since 4.4.0 The `$transient` parameter was added
  763. *
  764. * @param mixed $value Value of transient.
  765. * @param string $transient Transient name.
  766. */
  767. return apply_filters( "transient_{$transient}", $value, $transient );
  768. }
  769. /**
  770. * Sets/updates the value of a transient.
  771. *
  772. * You do not need to serialize values. If the value needs to be serialized,
  773. * then it will be serialized before it is set.
  774. *
  775. * @since 2.8.0
  776. *
  777. * @param string $transient Transient name. Expected to not be SQL-escaped.
  778. * Must be 172 characters or fewer in length.
  779. * @param mixed $value Transient value. Must be serializable if non-scalar.
  780. * Expected to not be SQL-escaped.
  781. * @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
  782. * @return bool True if the value was set, false otherwise.
  783. */
  784. function set_transient( $transient, $value, $expiration = 0 ) {
  785. $expiration = (int) $expiration;
  786. /**
  787. * Filters a specific transient before its value is set.
  788. *
  789. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  790. *
  791. * @since 3.0.0
  792. * @since 4.2.0 The `$expiration` parameter was added.
  793. * @since 4.4.0 The `$transient` parameter was added.
  794. *
  795. * @param mixed $value New value of transient.
  796. * @param int $expiration Time until expiration in seconds.
  797. * @param string $transient Transient name.
  798. */
  799. $value = apply_filters( "pre_set_transient_{$transient}", $value, $expiration, $transient );
  800. /**
  801. * Filters the expiration for a transient before its value is set.
  802. *
  803. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  804. *
  805. * @since 4.4.0
  806. *
  807. * @param int $expiration Time until expiration in seconds. Use 0 for no expiration.
  808. * @param mixed $value New value of transient.
  809. * @param string $transient Transient name.
  810. */
  811. $expiration = apply_filters( "expiration_of_transient_{$transient}", $expiration, $value, $transient );
  812. if ( wp_using_ext_object_cache() ) {
  813. $result = wp_cache_set( $transient, $value, 'transient', $expiration );
  814. } else {
  815. $transient_timeout = '_transient_timeout_' . $transient;
  816. $transient_option = '_transient_' . $transient;
  817. if ( false === get_option( $transient_option ) ) {
  818. $autoload = 'yes';
  819. if ( $expiration ) {
  820. $autoload = 'no';
  821. add_option( $transient_timeout, time() + $expiration, '', 'no' );
  822. }
  823. $result = add_option( $transient_option, $value, '', $autoload );
  824. } else {
  825. // If expiration is requested, but the transient has no timeout option,
  826. // delete, then re-create transient rather than update.
  827. $update = true;
  828. if ( $expiration ) {
  829. if ( false === get_option( $transient_timeout ) ) {
  830. delete_option( $transient_option );
  831. add_option( $transient_timeout, time() + $expiration, '', 'no' );
  832. $result = add_option( $transient_option, $value, '', 'no' );
  833. $update = false;
  834. } else {
  835. update_option( $transient_timeout, time() + $expiration );
  836. }
  837. }
  838. if ( $update ) {
  839. $result = update_option( $transient_option, $value );
  840. }
  841. }
  842. }
  843. if ( $result ) {
  844. /**
  845. * Fires after the value for a specific transient has been set.
  846. *
  847. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  848. *
  849. * @since 3.0.0
  850. * @since 3.6.0 The `$value` and `$expiration` parameters were added.
  851. * @since 4.4.0 The `$transient` parameter was added.
  852. *
  853. * @param mixed $value Transient value.
  854. * @param int $expiration Time until expiration in seconds.
  855. * @param string $transient The name of the transient.
  856. */
  857. do_action( "set_transient_{$transient}", $value, $expiration, $transient );
  858. /**
  859. * Fires after the value for a transient has been set.
  860. *
  861. * @since 3.0.0
  862. * @since 3.6.0 The `$value` and `$expiration` parameters were added.
  863. *
  864. * @param string $transient The name of the transient.
  865. * @param mixed $value Transient value.
  866. * @param int $expiration Time until expiration in seconds.
  867. */
  868. do_action( 'setted_transient', $transient, $value, $expiration );
  869. }
  870. return $result;
  871. }
  872. /**
  873. * Deletes all expired transients.
  874. *
  875. * The multi-table delete syntax is used to delete the transient record
  876. * from table a, and the corresponding transient_timeout record from table b.
  877. *
  878. * @since 4.9.0
  879. *
  880. * @param bool $force_db Optional. Force cleanup to run against the database even when an external object cache is used.
  881. */
  882. function delete_expired_transients( $force_db = false ) {
  883. global $wpdb;
  884. if ( ! $force_db && wp_using_ext_object_cache() ) {
  885. return;
  886. }
  887. $wpdb->query(
  888. $wpdb->prepare(
  889. "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
  890. WHERE a.option_name LIKE %s
  891. AND a.option_name NOT LIKE %s
  892. AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
  893. AND b.option_value < %d",
  894. $wpdb->esc_like( '_transient_' ) . '%',
  895. $wpdb->esc_like( '_transient_timeout_' ) . '%',
  896. time()
  897. )
  898. );
  899. if ( ! is_multisite() ) {
  900. // Single site stores site transients in the options table.
  901. $wpdb->query(
  902. $wpdb->prepare(
  903. "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
  904. WHERE a.option_name LIKE %s
  905. AND a.option_name NOT LIKE %s
  906. AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )
  907. AND b.option_value < %d",
  908. $wpdb->esc_like( '_site_transient_' ) . '%',
  909. $wpdb->esc_like( '_site_transient_timeout_' ) . '%',
  910. time()
  911. )
  912. );
  913. } elseif ( is_multisite() && is_main_site() && is_main_network() ) {
  914. // Multisite stores site transients in the sitemeta table.
  915. $wpdb->query(
  916. $wpdb->prepare(
  917. "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b
  918. WHERE a.meta_key LIKE %s
  919. AND a.meta_key NOT LIKE %s
  920. AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
  921. AND b.meta_value < %d",
  922. $wpdb->esc_like( '_site_transient_' ) . '%',
  923. $wpdb->esc_like( '_site_transient_timeout_' ) . '%',
  924. time()
  925. )
  926. );
  927. }
  928. }
  929. /**
  930. * Saves and restores user interface settings stored in a cookie.
  931. *
  932. * Checks if the current user-settings cookie is updated and stores it. When no
  933. * cookie exists (different browser used), adds the last saved cookie restoring
  934. * the settings.
  935. *
  936. * @since 2.7.0
  937. */
  938. function wp_user_settings() {
  939. if ( ! is_admin() || wp_doing_ajax() ) {
  940. return;
  941. }
  942. $user_id = get_current_user_id();
  943. if ( ! $user_id ) {
  944. return;
  945. }
  946. if ( ! is_user_member_of_blog() ) {
  947. return;
  948. }
  949. $settings = (string) get_user_option( 'user-settings', $user_id );
  950. if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
  951. $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
  952. // No change or both empty.
  953. if ( $cookie == $settings ) {
  954. return;
  955. }
  956. $last_saved = (int) get_user_option( 'user-settings-time', $user_id );
  957. $current = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0;
  958. // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
  959. if ( $current > $last_saved ) {
  960. update_user_option( $user_id, 'user-settings', $cookie, false );
  961. update_user_option( $user_id, 'user-settings-time', time() - 5, false );
  962. return;
  963. }
  964. }
  965. // The cookie is not set in the current browser or the saved value is newer.
  966. $secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) );
  967. setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
  968. setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
  969. $_COOKIE[ 'wp-settings-' . $user_id ] = $settings;
  970. }
  971. /**
  972. * Retrieves user interface setting value based on setting name.
  973. *
  974. * @since 2.7.0
  975. *
  976. * @param string $name The name of the setting.
  977. * @param string|false $default Optional. Default value to return when $name is not set. Default false.
  978. * @return mixed The last saved user setting or the default value/false if it doesn't exist.
  979. */
  980. function get_user_setting( $name, $default = false ) {
  981. $all_user_settings = get_all_user_settings();
  982. return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default;
  983. }
  984. /**
  985. * Adds or updates user interface setting.
  986. *
  987. * Both $name and $value can contain only ASCII letters, numbers, hyphens, and underscores.
  988. *
  989. * This function has to be used before any output has started as it calls setcookie().
  990. *
  991. * @since 2.8.0
  992. *
  993. * @param string $name The name of the setting.
  994. * @param string $value The value for the setting.
  995. * @return bool|null True if set successfully, false otherwise.
  996. * Null if the current user is not a member of the site.
  997. */
  998. function set_user_setting( $name, $value ) {
  999. if ( headers_sent() ) {
  1000. return false;
  1001. }
  1002. $all_user_settings = get_all_user_settings();
  1003. $all_user_settings[ $name ] = $value;
  1004. return wp_set_all_user_settings( $all_user_settings );
  1005. }
  1006. /**
  1007. * Deletes user interface settings.
  1008. *
  1009. * Deleting settings would reset them to the defaults.
  1010. *
  1011. * This function has to be used before any output has started as it calls setcookie().
  1012. *
  1013. * @since 2.7.0
  1014. *
  1015. * @param string $names The name or array of names of the setting to be deleted.
  1016. * @return bool|null True if deleted successfully, false otherwise.
  1017. * Null if the current user is not a member of the site.
  1018. */
  1019. function delete_user_setting( $names ) {
  1020. if ( headers_sent() ) {
  1021. return false;
  1022. }
  1023. $all_user_settings = get_all_user_settings();
  1024. $names = (array) $names;
  1025. $deleted = false;
  1026. foreach ( $names as $name ) {
  1027. if ( isset( $all_user_settings[ $name ] ) ) {
  1028. unset( $all_user_settings[ $name ] );
  1029. $deleted = true;
  1030. }
  1031. }
  1032. if ( $deleted ) {
  1033. return wp_set_all_user_settings( $all_user_settings );
  1034. }
  1035. return false;
  1036. }
  1037. /**
  1038. * Retrieves all user interface settings.
  1039. *
  1040. * @since 2.7.0
  1041. *
  1042. * @global array $_updated_user_settings
  1043. *
  1044. * @return array The last saved user settings or empty array.
  1045. */
  1046. function get_all_user_settings() {
  1047. global $_updated_user_settings;
  1048. $user_id = get_current_user_id();
  1049. if ( ! $user_id ) {
  1050. return array();
  1051. }
  1052. if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) {
  1053. return $_updated_user_settings;
  1054. }
  1055. $user_settings = array();
  1056. if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
  1057. $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
  1058. if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char.
  1059. parse_str( $cookie, $user_settings );
  1060. }
  1061. } else {
  1062. $option = get_user_option( 'user-settings', $user_id );
  1063. if ( $option && is_string( $option ) ) {
  1064. parse_str( $option, $user_settings );
  1065. }
  1066. }
  1067. $_updated_user_settings = $user_settings;
  1068. return $user_settings;
  1069. }
  1070. /**
  1071. * Private. Sets all user interface settings.
  1072. *
  1073. * @since 2.8.0
  1074. * @access private
  1075. *
  1076. * @global array $_updated_user_settings
  1077. *
  1078. * @param array $user_settings User settings.
  1079. * @return bool|null True if set successfully, false if the current user could not be found.
  1080. * Null if the current user is not a member of the site.
  1081. */
  1082. function wp_set_all_user_settings( $user_settings ) {
  1083. global $_updated_user_settings;
  1084. $user_id = get_current_user_id();
  1085. if ( ! $user_id ) {
  1086. return false;
  1087. }
  1088. if ( ! is_user_member_of_blog() ) {
  1089. return;
  1090. }
  1091. $settings = '';
  1092. foreach ( $user_settings as $name => $value ) {
  1093. $_name = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name );
  1094. $_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value );
  1095. if ( ! empty( $_name ) ) {
  1096. $settings .= $_name . '=' . $_value . '&';
  1097. }
  1098. }
  1099. $settings = rtrim( $settings, '&' );
  1100. parse_str( $settings, $_updated_user_settings );
  1101. update_user_option( $user_id, 'user-settings', $settings, false );
  1102. update_user_option( $user_id, 'user-settings-time', time(), false );
  1103. return true;
  1104. }
  1105. /**
  1106. * Deletes the user settings of the current user.
  1107. *
  1108. * @since 2.7.0
  1109. */
  1110. function delete_all_user_settings() {
  1111. $user_id = get_current_user_id();
  1112. if ( ! $user_id ) {
  1113. return;
  1114. }
  1115. update_user_option( $user_id, 'user-settings', '', false );
  1116. setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
  1117. }
  1118. /**
  1119. * Retrieve an option value for the current network based on name of option.
  1120. *
  1121. * @since 2.8.0
  1122. * @since 4.4.0 The `$use_cache` parameter was deprecated.
  1123. * @since 4.4.0 Modified into wrapper for get_network_option()
  1124. *
  1125. * @see get_network_option()
  1126. *
  1127. * @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
  1128. * @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
  1129. * @param bool $deprecated Whether to use cache. Multisite only. Always set to true.
  1130. * @return mixed Value set for the option.
  1131. */
  1132. function get_site_option( $option, $default = false, $deprecated = true ) {
  1133. return get_network_option( null, $option, $default );
  1134. }
  1135. /**
  1136. * Adds a new option for the current network.
  1137. *
  1138. * Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
  1139. *
  1140. * @since 2.8.0
  1141. * @since 4.4.0 Modified into wrapper for add_network_option()
  1142. *
  1143. * @see add_network_option()
  1144. *
  1145. * @param string $option Name of the option to add. Expected to not be SQL-escaped.
  1146. * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.
  1147. * @return bool True if the option was added, false otherwise.
  1148. */
  1149. function add_site_option( $option, $value ) {
  1150. return add_network_option( null, $option, $value );
  1151. }
  1152. /**
  1153. * Removes a option by name for the current network.
  1154. *
  1155. * @since 2.8.0
  1156. * @since 4.4.0 Modified into wrapper for delete_network_option()
  1157. *
  1158. * @see delete_network_option()
  1159. *
  1160. * @param string $option Name of the option to delete. Expected to not be SQL-escaped.
  1161. * @return bool True if the option was deleted, false otherwise.
  1162. */
  1163. function delete_site_option( $option ) {
  1164. return delete_network_option( null, $option );
  1165. }
  1166. /**
  1167. * Updates the value of an option that was already added for the current network.
  1168. *
  1169. * @since 2.8.0
  1170. * @since 4.4.0 Modified into wrapper for update_network_option()
  1171. *
  1172. * @see update_network_option()
  1173. *
  1174. * @param string $option Name of the option. Expected to not be SQL-escaped.
  1175. * @param mixed $value Option value. Expected to not be SQL-escaped.
  1176. * @return bool True if the value was updated, false otherwise.
  1177. */
  1178. function update_site_option( $option, $value ) {
  1179. return update_network_option( null, $option, $value );
  1180. }
  1181. /**
  1182. * Retrieves a network's option value based on the option name.
  1183. *
  1184. * @since 4.4.0
  1185. *
  1186. * @see get_option()
  1187. *
  1188. * @global wpdb $wpdb WordPress database abstraction object.
  1189. *
  1190. * @param int $network_id ID of the network. Can be null to default to the current network ID.
  1191. * @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
  1192. * @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
  1193. * @return mixed Value set for the option.
  1194. */
  1195. function get_network_option( $network_id, $option, $default = false ) {
  1196. global $wpdb;
  1197. if ( $network_id && ! is_numeric( $network_id ) ) {
  1198. return false;
  1199. }
  1200. $network_id = (int) $network_id;
  1201. // Fallback to the current network if a network ID is not specified.
  1202. if ( ! $network_id ) {
  1203. $network_id = get_current_network_id();
  1204. }
  1205. /**
  1206. * Filters the value of an existing network option before it is retrieved.
  1207. *
  1208. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1209. *
  1210. * Returning a truthy value from the filter will effectively short-circuit retrieval
  1211. * and return the passed value instead.
  1212. *
  1213. * @since 2.9.0 As 'pre_site_option_' . $key
  1214. * @since 3.0.0
  1215. * @since 4.4.0 The `$option` parameter was added.
  1216. * @since 4.7.0 The `$network_id` parameter was added.
  1217. * @since 4.9.0 The `$default` parameter was added.
  1218. *
  1219. * @param mixed $pre_option The value to return instead of the option value. This differs
  1220. * from `$default`, which is used as the fallback value in the event
  1221. * the option doesn't exist elsewhere in get_network_option().
  1222. * Default false (to skip past the short-circuit).
  1223. * @param string $option Option name.
  1224. * @param int $network_id ID of the network.
  1225. * @param mixed $default The fallback value to return if the option does not exist.
  1226. * Default false.
  1227. */
  1228. $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default );
  1229. if ( false !== $pre ) {
  1230. return $pre;
  1231. }
  1232. // Prevent non-existent options from triggering multiple queries.
  1233. $notoptions_key = "$network_id:notoptions";
  1234. $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
  1235. if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
  1236. /**
  1237. * Filters a specific default network option.
  1238. *
  1239. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1240. *
  1241. * @since 3.4.0
  1242. * @since 4.4.0 The `$option` parameter was added.
  1243. * @since 4.7.0 The `$network_id` parameter was added.
  1244. *
  1245. * @param mixed $default The value to return if the site option does not exist
  1246. * in the database.
  1247. * @param string $option Option name.
  1248. * @param int $network_id ID of the network.
  1249. */
  1250. return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );
  1251. }
  1252. if ( ! is_multisite() ) {
  1253. /** This filter is documented in wp-includes/option.php */
  1254. $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
  1255. $value = get_option( $option, $default );
  1256. } else {
  1257. $cache_key = "$network_id:$option";
  1258. $value = wp_cache_get( $cache_key, 'site-options' );
  1259. if ( ! isset( $value ) || false === $value ) {
  1260. $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
  1261. // Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
  1262. if ( is_object( $row ) ) {
  1263. $value = $row->meta_value;
  1264. $value = maybe_unserialize( $value );
  1265. wp_cache_set( $cache_key, $value, 'site-options' );
  1266. } else {
  1267. if ( ! is_array( $notoptions ) ) {
  1268. $notoptions = array();
  1269. }
  1270. $notoptions[ $option ] = true;
  1271. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  1272. /** This filter is documented in wp-includes/option.php */
  1273. $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
  1274. }
  1275. }
  1276. }
  1277. if ( ! is_array( $notoptions ) ) {
  1278. $notoptions = array();
  1279. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  1280. }
  1281. /**
  1282. * Filters the value of an existing network option.
  1283. *
  1284. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1285. *
  1286. * @since 2.9.0 As 'site_option_' . $key
  1287. * @since 3.0.0
  1288. * @since 4.4.0 The `$option` parameter was added.
  1289. * @since 4.7.0 The `$network_id` parameter was added.
  1290. *
  1291. * @param mixed $value Value of network option.
  1292. * @param string $option Option name.
  1293. * @param int $network_id ID of the network.
  1294. */
  1295. return apply_filters( "site_option_{$option}", $value, $option, $network_id );
  1296. }
  1297. /**
  1298. * Adds a new network option.
  1299. *
  1300. * Existing options will not be updated.
  1301. *
  1302. * @since 4.4.0
  1303. *
  1304. * @see add_option()
  1305. *
  1306. * @global wpdb $wpdb WordPress database abstraction object.
  1307. *
  1308. * @param int $network_id ID of the network. Can be null to default to the current network ID.
  1309. * @param string $option Name of the option to add. Expected to not be SQL-escaped.
  1310. * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.
  1311. * @return bool True if the option was added, false otherwise.
  1312. */
  1313. function add_network_option( $network_id, $option, $value ) {
  1314. global $wpdb;
  1315. if ( $network_id && ! is_numeric( $network_id ) ) {
  1316. return false;
  1317. }
  1318. $network_id = (int) $network_id;
  1319. // Fallback to the current network if a network ID is not specified.
  1320. if ( ! $network_id ) {
  1321. $network_id = get_current_network_id();
  1322. }
  1323. wp_protect_special_option( $option );
  1324. /**
  1325. * Filters the value of a specific network option before it is added.
  1326. *
  1327. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1328. *
  1329. * @since 2.9.0 As 'pre_add_site_option_' . $key
  1330. * @since 3.0.0
  1331. * @since 4.4.0 The `$option` parameter was added.
  1332. * @since 4.7.0 The `$network_id` parameter was added.
  1333. *
  1334. * @param mixed $value Value of network option.
  1335. * @param string $option Option name.
  1336. * @param int $network_id ID of the network.
  1337. */
  1338. $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id );
  1339. $notoptions_key = "$network_id:notoptions";
  1340. if ( ! is_multisite() ) {
  1341. $result = add_option( $option, $value, '', 'no' );
  1342. } else {
  1343. $cache_key = "$network_id:$option";
  1344. // Make sure the option doesn't already exist.
  1345. // We can check the 'notoptions' cache before we ask for a DB query.
  1346. $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
  1347. if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
  1348. if ( false !== get_network_option( $network_id, $option, false ) ) {
  1349. return false;
  1350. }
  1351. }
  1352. $value = sanitize_option( $option, $value );
  1353. $serialized_value = maybe_serialize( $value );
  1354. $result = $wpdb->insert(
  1355. $wpdb->sitemeta,
  1356. array(
  1357. 'site_id' => $network_id,
  1358. 'meta_key' => $option,
  1359. 'meta_value' => $serialized_value,
  1360. )
  1361. );
  1362. if ( ! $result ) {
  1363. return false;
  1364. }
  1365. wp_cache_set( $cache_key, $value, 'site-options' );
  1366. // This option exists now.
  1367. $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // Yes, again... we need it to be fresh.
  1368. if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
  1369. unset( $notoptions[ $option ] );
  1370. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  1371. }
  1372. }
  1373. if ( $result ) {
  1374. /**
  1375. * Fires after a specific network option has been successfully added.
  1376. *
  1377. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1378. *
  1379. * @since 2.9.0 As "add_site_option_{$key}"
  1380. * @since 3.0.0
  1381. * @since 4.7.0 The `$network_id` parameter was added.
  1382. *
  1383. * @param string $option Name of the network option.
  1384. * @param mixed $value Value of the network option.
  1385. * @param int $network_id ID of the network.
  1386. */
  1387. do_action( "add_site_option_{$option}", $option, $value, $network_id );
  1388. /**
  1389. * Fires after a network option has been successfully added.
  1390. *
  1391. * @since 3.0.0
  1392. * @since 4.7.0 The `$network_id` parameter was added.
  1393. *
  1394. * @param string $option Name of the network option.
  1395. * @param mixed $value Value of the network option.
  1396. * @param int $network_id ID of the network.
  1397. */
  1398. do_action( 'add_site_option', $option, $value, $network_id );
  1399. return true;
  1400. }
  1401. return false;
  1402. }
  1403. /**
  1404. * Removes a network option by name.
  1405. *
  1406. * @since 4.4.0
  1407. *
  1408. * @see delete_option()
  1409. *
  1410. * @global wpdb $wpdb WordPress database abstraction object.
  1411. *
  1412. * @param int $network_id ID of the network. Can be null to default to the current network ID.
  1413. * @param string $option Name of the option to delete. Expected to not be SQL-escaped.
  1414. * @return bool True if the option was deleted, false otherwise.
  1415. */
  1416. function delete_network_option( $network_id, $option ) {
  1417. global $wpdb;
  1418. if ( $network_id && ! is_numeric( $network_id ) ) {
  1419. return false;
  1420. }
  1421. $network_id = (int) $network_id;
  1422. // Fallback to the current network if a network ID is not specified.
  1423. if ( ! $network_id ) {
  1424. $network_id = get_current_network_id();
  1425. }
  1426. /**
  1427. * Fires immediately before a specific network option is deleted.
  1428. *
  1429. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1430. *
  1431. * @since 3.0.0
  1432. * @since 4.4.0 The `$option` parameter was added.
  1433. * @since 4.7.0 The `$network_id` parameter was added.
  1434. *
  1435. * @param string $option Option name.
  1436. * @param int $network_id ID of the network.
  1437. */
  1438. do_action( "pre_delete_site_option_{$option}", $option, $network_id );
  1439. if ( ! is_multisite() ) {
  1440. $result = delete_option( $option );
  1441. } else {
  1442. $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
  1443. if ( is_null( $row ) || ! $row->meta_id ) {
  1444. return false;
  1445. }
  1446. $cache_key = "$network_id:$option";
  1447. wp_cache_delete( $cache_key, 'site-options' );
  1448. $result = $wpdb->delete(
  1449. $wpdb->sitemeta,
  1450. array(
  1451. 'meta_key' => $option,
  1452. 'site_id' => $network_id,
  1453. )
  1454. );
  1455. }
  1456. if ( $result ) {
  1457. /**
  1458. * Fires after a specific network option has been deleted.
  1459. *
  1460. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1461. *
  1462. * @since 2.9.0 As "delete_site_option_{$key}"
  1463. * @since 3.0.0
  1464. * @since 4.7.0 The `$network_id` parameter was added.
  1465. *
  1466. * @param string $option Name of the network option.
  1467. * @param int $network_id ID of the network.
  1468. */
  1469. do_action( "delete_site_option_{$option}", $option, $network_id );
  1470. /**
  1471. * Fires after a network option has been deleted.
  1472. *
  1473. * @since 3.0.0
  1474. * @since 4.7.0 The `$network_id` parameter was added.
  1475. *
  1476. * @param string $option Name of the network option.
  1477. * @param int $network_id ID of the network.
  1478. */
  1479. do_action( 'delete_site_option', $option, $network_id );
  1480. return true;
  1481. }
  1482. return false;
  1483. }
  1484. /**
  1485. * Updates the value of a network option that was already added.
  1486. *
  1487. * @since 4.4.0
  1488. *
  1489. * @see update_option()
  1490. *
  1491. * @global wpdb $wpdb WordPress database abstraction object.
  1492. *
  1493. * @param int $network_id ID of the network. Can be null to default to the current network ID.
  1494. * @param string $option Name of the option. Expected to not be SQL-escaped.
  1495. * @param mixed $value Option value. Expected to not be SQL-escaped.
  1496. * @return bool True if the value was updated, false otherwise.
  1497. */
  1498. function update_network_option( $network_id, $option, $value ) {
  1499. global $wpdb;
  1500. if ( $network_id && ! is_numeric( $network_id ) ) {
  1501. return false;
  1502. }
  1503. $network_id = (int) $network_id;
  1504. // Fallback to the current network if a network ID is not specified.
  1505. if ( ! $network_id ) {
  1506. $network_id = get_current_network_id();
  1507. }
  1508. wp_protect_special_option( $option );
  1509. $old_value = get_network_option( $network_id, $option, false );
  1510. /**
  1511. * Filters a specific network option before its value is updated.
  1512. *
  1513. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1514. *
  1515. * @since 2.9.0 As 'pre_update_site_option_' . $key
  1516. * @since 3.0.0
  1517. * @since 4.4.0 The `$option` parameter was added.
  1518. * @since 4.7.0 The `$network_id` parameter was added.
  1519. *
  1520. * @param mixed $value New value of the network option.
  1521. * @param mixed $old_value Old value of the network option.
  1522. * @param string $option Option name.
  1523. * @param int $network_id ID of the network.
  1524. */
  1525. $value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id );
  1526. /*
  1527. * If the new and old values are the same, no need to update.
  1528. *
  1529. * Unserialized values will be adequate in most cases. If the unserialized
  1530. * data differs, the (maybe) serialized data is checked to avoid
  1531. * unnecessary database calls for otherwise identical object instances.
  1532. *
  1533. * See https://core.trac.wordpress.org/ticket/44956
  1534. */
  1535. if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
  1536. return false;
  1537. }
  1538. if ( false === $old_value ) {
  1539. return add_network_option( $network_id, $option, $value );
  1540. }
  1541. $notoptions_key = "$network_id:notoptions";
  1542. $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
  1543. if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
  1544. unset( $notoptions[ $option ] );
  1545. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  1546. }
  1547. if ( ! is_multisite() ) {
  1548. $result = update_option( $option, $value, 'no' );
  1549. } else {
  1550. $value = sanitize_option( $option, $value );
  1551. $serialized_value = maybe_serialize( $value );
  1552. $result = $wpdb->update(
  1553. $wpdb->sitemeta,
  1554. array( 'meta_value' => $serialized_value ),
  1555. array(
  1556. 'site_id' => $network_id,
  1557. 'meta_key' => $option,
  1558. )
  1559. );
  1560. if ( $result ) {
  1561. $cache_key = "$network_id:$option";
  1562. wp_cache_set( $cache_key, $value, 'site-options' );
  1563. }
  1564. }
  1565. if ( $result ) {
  1566. /**
  1567. * Fires after the value of a specific network option has been successfully updated.
  1568. *
  1569. * The dynamic portion of the hook name, `$option`, refers to the option name.
  1570. *
  1571. * @since 2.9.0 As "update_site_option_{$key}"
  1572. * @since 3.0.0
  1573. * @since 4.7.0 The `$network_id` parameter was added.
  1574. *
  1575. * @param string $option Name of the network option.
  1576. * @param mixed $value Current value of the network option.
  1577. * @param mixed $old_value Old value of the network option.
  1578. * @param int $network_id ID of the network.
  1579. */
  1580. do_action( "update_site_option_{$option}", $option, $value, $old_value, $network_id );
  1581. /**
  1582. * Fires after the value of a network option has been successfully updated.
  1583. *
  1584. * @since 3.0.0
  1585. * @since 4.7.0 The `$network_id` parameter was added.
  1586. *
  1587. * @param string $option Name of the network option.
  1588. * @param mixed $value Current value of the network option.
  1589. * @param mixed $old_value Old value of the network option.
  1590. * @param int $network_id ID of the network.
  1591. */
  1592. do_action( 'update_site_option', $option, $value, $old_value, $network_id );
  1593. return true;
  1594. }
  1595. return false;
  1596. }
  1597. /**
  1598. * Deletes a site transient.
  1599. *
  1600. * @since 2.9.0
  1601. *
  1602. * @param string $transient Transient name. Expected to not be SQL-escaped.
  1603. * @return bool True if the transient was deleted, false otherwise.
  1604. */
  1605. function delete_site_transient( $transient ) {
  1606. /**
  1607. * Fires immediately before a specific site transient is deleted.
  1608. *
  1609. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  1610. *
  1611. * @since 3.0.0
  1612. *
  1613. * @param string $transient Transient name.
  1614. */
  1615. do_action( "delete_site_transient_{$transient}", $transient );
  1616. if ( wp_using_ext_object_cache() ) {
  1617. $result = wp_cache_delete( $transient, 'site-transient' );
  1618. } else {
  1619. $option_timeout = '_site_transient_timeout_' . $transient;
  1620. $option = '_site_transient_' . $transient;
  1621. $result = delete_site_option( $option );
  1622. if ( $result ) {
  1623. delete_site_option( $option_timeout );
  1624. }
  1625. }
  1626. if ( $result ) {
  1627. /**
  1628. * Fires after a transient is deleted.
  1629. *
  1630. * @since 3.0.0
  1631. *
  1632. * @param string $transient Deleted transient name.
  1633. */
  1634. do_action( 'deleted_site_transient', $transient );
  1635. }
  1636. return $result;
  1637. }
  1638. /**
  1639. * Retrieves the value of a site transient.
  1640. *
  1641. * If the transient does not exist, does not have a value, or has expired,
  1642. * then the return value will be false.
  1643. *
  1644. * @since 2.9.0
  1645. *
  1646. * @see get_transient()
  1647. *
  1648. * @param string $transient Transient name. Expected to not be SQL-escaped.
  1649. * @return mixed Value of transient.
  1650. */
  1651. function get_site_transient( $transient ) {
  1652. /**
  1653. * Filters the value of an existing site transient before it is retrieved.
  1654. *
  1655. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  1656. *
  1657. * Returning a truthy value from the filter will effectively short-circuit retrieval
  1658. * and return the passed value instead.
  1659. *
  1660. * @since 2.9.0
  1661. * @since 4.4.0 The `$transient` parameter was added.
  1662. *
  1663. * @param mixed $pre_site_transient The default value to return if the site transient does not exist.
  1664. * Any value other than false will short-circuit the retrieval
  1665. * of the transient, and return that value.
  1666. * @param string $transient Transient name.
  1667. */
  1668. $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );
  1669. if ( false !== $pre ) {
  1670. return $pre;
  1671. }
  1672. if ( wp_using_ext_object_cache() ) {
  1673. $value = wp_cache_get( $transient, 'site-transient' );
  1674. } else {
  1675. // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
  1676. $no_timeout = array( 'update_core', 'update_plugins', 'update_themes' );
  1677. $transient_option = '_site_transient_' . $transient;
  1678. if ( ! in_array( $transient, $no_timeout, true ) ) {
  1679. $transient_timeout = '_site_transient_timeout_' . $transient;
  1680. $timeout = get_site_option( $transient_timeout );
  1681. if ( false !== $timeout && $timeout < time() ) {
  1682. delete_site_option( $transient_option );
  1683. delete_site_option( $transient_timeout );
  1684. $value = false;
  1685. }
  1686. }
  1687. if ( ! isset( $value ) ) {
  1688. $value = get_site_option( $transient_option );
  1689. }
  1690. }
  1691. /**
  1692. * Filters the value of an existing site transient.
  1693. *
  1694. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  1695. *
  1696. * @since 2.9.0
  1697. * @since 4.4.0 The `$transient` parameter was added.
  1698. *
  1699. * @param mixed $value Value of site transient.
  1700. * @param string $transient Transient name.
  1701. */
  1702. return apply_filters( "site_transient_{$transient}", $value, $transient );
  1703. }
  1704. /**
  1705. * Sets/updates the value of a site transient.
  1706. *
  1707. * You do not need to serialize values. If the value needs to be serialized,
  1708. * then it will be serialized before it is set.
  1709. *
  1710. * @since 2.9.0
  1711. *
  1712. * @see set_transient()
  1713. *
  1714. * @param string $transient Transient name. Expected to not be SQL-escaped. Must be
  1715. * 167 characters or fewer in length.
  1716. * @param mixed $value Transient value. Expected to not be SQL-escaped.
  1717. * @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
  1718. * @return bool True if the value was set, false otherwise.
  1719. */
  1720. function set_site_transient( $transient, $value, $expiration = 0 ) {
  1721. /**
  1722. * Filters the value of a specific site transient before it is set.
  1723. *
  1724. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  1725. *
  1726. * @since 3.0.0
  1727. * @since 4.4.0 The `$transient` parameter was added.
  1728. *
  1729. * @param mixed $value New value of site transient.
  1730. * @param string $transient Transient name.
  1731. */
  1732. $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient );
  1733. $expiration = (int) $expiration;
  1734. /**
  1735. * Filters the expiration for a site transient before its value is set.
  1736. *
  1737. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  1738. *
  1739. * @since 4.4.0
  1740. *
  1741. * @param int $expiration Time until expiration in seconds. Use 0 for no expiration.
  1742. * @param mixed $value New value of site transient.
  1743. * @param string $transient Transient name.
  1744. */
  1745. $expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient );
  1746. if ( wp_using_ext_object_cache() ) {
  1747. $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
  1748. } else {
  1749. $transient_timeout = '_site_transient_timeout_' . $transient;
  1750. $option = '_site_transient_' . $transient;
  1751. if ( false === get_site_option( $option ) ) {
  1752. if ( $expiration ) {
  1753. add_site_option( $transient_timeout, time() + $expiration );
  1754. }
  1755. $result = add_site_option( $option, $value );
  1756. } else {
  1757. if ( $expiration ) {
  1758. update_site_option( $transient_timeout, time() + $expiration );
  1759. }
  1760. $result = update_site_option( $option, $value );
  1761. }
  1762. }
  1763. if ( $result ) {
  1764. /**
  1765. * Fires after the value for a specific site transient has been set.
  1766. *
  1767. * The dynamic portion of the hook name, `$transient`, refers to the transient name.
  1768. *
  1769. * @since 3.0.0
  1770. * @since 4.4.0 The `$transient` parameter was added
  1771. *
  1772. * @param mixed $value Site transient value.
  1773. * @param int $expiration Time until expiration in seconds.
  1774. * @param string $transient Transient name.
  1775. */
  1776. do_action( "set_site_transient_{$transient}", $value, $expiration, $transient );
  1777. /**
  1778. * Fires after the value for a site transient has been set.
  1779. *
  1780. * @since 3.0.0
  1781. *
  1782. * @param string $transient The name of the site transient.
  1783. * @param mixed $value Site transient value.
  1784. * @param int $expiration Time until expiration in seconds.
  1785. */
  1786. do_action( 'setted_site_transient', $transient, $value, $expiration );
  1787. }
  1788. return $result;
  1789. }
  1790. /**
  1791. * Registers default settings available in WordPress.
  1792. *
  1793. * The settings registered here are primarily useful for the REST API, so this
  1794. * does not encompass all settings available in WordPress.
  1795. *
  1796. * @since 4.7.0
  1797. */
  1798. function register_initial_settings() {
  1799. register_setting(
  1800. 'general',
  1801. 'blogname',
  1802. array(
  1803. 'show_in_rest' => array(
  1804. 'name' => 'title',
  1805. ),
  1806. 'type' => 'string',
  1807. 'description' => __( 'Site title.' ),
  1808. )
  1809. );
  1810. register_setting(
  1811. 'general',
  1812. 'blogdescription',
  1813. array(
  1814. 'show_in_rest' => array(
  1815. 'name' => 'description',
  1816. ),
  1817. 'type' => 'string',
  1818. 'description' => __( 'Site tagline.' ),
  1819. )
  1820. );
  1821. if ( ! is_multisite() ) {
  1822. register_setting(
  1823. 'general',
  1824. 'siteurl',
  1825. array(
  1826. 'show_in_rest' => array(
  1827. 'name' => 'url',
  1828. 'schema' => array(
  1829. 'format' => 'uri',
  1830. ),
  1831. ),
  1832. 'type' => 'string',
  1833. 'description' => __( 'Site URL.' ),
  1834. )
  1835. );
  1836. }
  1837. if ( ! is_multisite() ) {
  1838. register_setting(
  1839. 'general',
  1840. 'admin_email',
  1841. array(
  1842. 'show_in_rest' => array(
  1843. 'name' => 'email',
  1844. 'schema' => array(
  1845. 'format' => 'email',
  1846. ),
  1847. ),
  1848. 'type' => 'string',
  1849. 'description' => __( 'This address is used for admin purposes, like new user notification.' ),
  1850. )
  1851. );
  1852. }
  1853. register_setting(
  1854. 'general',
  1855. 'timezone_string',
  1856. array(
  1857. 'show_in_rest' => array(
  1858. 'name' => 'timezone',
  1859. ),
  1860. 'type' => 'string',
  1861. 'description' => __( 'A city in the same timezone as you.' ),
  1862. )
  1863. );
  1864. register_setting(
  1865. 'general',
  1866. 'date_format',
  1867. array(
  1868. 'show_in_rest' => true,
  1869. 'type' => 'string',
  1870. 'description' => __( 'A date format for all date strings.' ),
  1871. )
  1872. );
  1873. register_setting(
  1874. 'general',
  1875. 'time_format',
  1876. array(
  1877. 'show_in_rest' => true,
  1878. 'type' => 'string',
  1879. 'description' => __( 'A time format for all time strings.' ),
  1880. )
  1881. );
  1882. register_setting(
  1883. 'general',
  1884. 'start_of_week',
  1885. array(
  1886. 'show_in_rest' => true,
  1887. 'type' => 'integer',
  1888. 'description' => __( 'A day number of the week that the week should start on.' ),
  1889. )
  1890. );
  1891. register_setting(
  1892. 'general',
  1893. 'WPLANG',
  1894. array(
  1895. 'show_in_rest' => array(
  1896. 'name' => 'language',
  1897. ),
  1898. 'type' => 'string',
  1899. 'description' => __( 'WordPress locale code.' ),
  1900. 'default' => 'en_US',
  1901. )
  1902. );
  1903. register_setting(
  1904. 'writing',
  1905. 'use_smilies',
  1906. array(
  1907. 'show_in_rest' => true,
  1908. 'type' => 'boolean',
  1909. 'description' => __( 'Convert emoticons like :-) and :-P to graphics on display.' ),
  1910. 'default' => true,
  1911. )
  1912. );
  1913. register_setting(
  1914. 'writing',
  1915. 'default_category',
  1916. array(
  1917. 'show_in_rest' => true,
  1918. 'type' => 'integer',
  1919. 'description' => __( 'Default post category.' ),
  1920. )
  1921. );
  1922. register_setting(
  1923. 'writing',
  1924. 'default_post_format',
  1925. array(
  1926. 'show_in_rest' => true,
  1927. 'type' => 'string',
  1928. 'description' => __( 'Default post format.' ),
  1929. )
  1930. );
  1931. register_setting(
  1932. 'reading',
  1933. 'posts_per_page',
  1934. array(
  1935. 'show_in_rest' => true,
  1936. 'type' => 'integer',
  1937. 'description' => __( 'Blog pages show at most.' ),
  1938. 'default' => 10,
  1939. )
  1940. );
  1941. register_setting(
  1942. 'discussion',
  1943. 'default_ping_status',
  1944. array(
  1945. 'show_in_rest' => array(
  1946. 'schema' => array(
  1947. 'enum' => array( 'open', 'closed' ),
  1948. ),
  1949. ),
  1950. 'type' => 'string',
  1951. 'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ),
  1952. )
  1953. );
  1954. register_setting(
  1955. 'discussion',
  1956. 'default_comment_status',
  1957. array(
  1958. 'show_in_rest' => array(
  1959. 'schema' => array(
  1960. 'enum' => array( 'open', 'closed' ),
  1961. ),
  1962. ),
  1963. 'type' => 'string',
  1964. 'description' => __( 'Allow people to submit comments on new posts.' ),
  1965. )
  1966. );
  1967. }
  1968. /**
  1969. * Registers a setting and its data.
  1970. *
  1971. * @since 2.7.0
  1972. * @since 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`.
  1973. * @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`.
  1974. * Please consider writing more inclusive code.
  1975. *
  1976. * @global array $new_allowed_options
  1977. * @global array $wp_registered_settings
  1978. *
  1979. * @param string $option_group A settings group name. Should correspond to an allowed option key name.
  1980. * Default allowed option key names include 'general', 'discussion', 'media',
  1981. * 'reading', 'writing', 'misc', 'options', and 'privacy'.
  1982. * @param string $option_name The name of an option to sanitize and save.
  1983. * @param array $args {
  1984. * Data used to describe the setting when registered.
  1985. *
  1986. * @type string $type The type of data associated with this setting.
  1987. * Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
  1988. * @type string $description A description of the data attached to this setting.
  1989. * @type callable $sanitize_callback A callback function that sanitizes the option's value.
  1990. * @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API.
  1991. * When registering complex settings, this argument may optionally be an
  1992. * array with a 'schema' key.
  1993. * @type mixed $default Default value when calling `get_option()`.
  1994. * }
  1995. */
  1996. function register_setting( $option_group, $option_name, $args = array() ) {
  1997. global $new_allowed_options, $wp_registered_settings;
  1998. /*
  1999. * In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`.
  2000. * Please consider writing more inclusive code.
  2001. */
  2002. $GLOBALS['new_whitelist_options'] = &$new_allowed_options;
  2003. $defaults = array(
  2004. 'type' => 'string',
  2005. 'group' => $option_group,
  2006. 'description' => '',
  2007. 'sanitize_callback' => null,
  2008. 'show_in_rest' => false,
  2009. );
  2010. // Back-compat: old sanitize callback is added.
  2011. if ( is_callable( $args ) ) {
  2012. $args = array(
  2013. 'sanitize_callback' => $args,
  2014. );
  2015. }
  2016. /**
  2017. * Filters the registration arguments when registering a setting.
  2018. *
  2019. * @since 4.7.0
  2020. *
  2021. * @param array $args Array of setting registration arguments.
  2022. * @param array $defaults Array of default arguments.
  2023. * @param string $option_group Setting group.
  2024. * @param string $option_name Setting name.
  2025. */
  2026. $args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name );
  2027. $args = wp_parse_args( $args, $defaults );
  2028. // Require an item schema when registering settings with an array type.
  2029. if ( false !== $args['show_in_rest'] && 'array' === $args['type'] && ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) ) {
  2030. _doing_it_wrong( __FUNCTION__, __( 'When registering an "array" setting to show in the REST API, you must specify the schema for each array item in "show_in_rest.schema.items".' ), '5.4.0' );
  2031. }
  2032. if ( ! is_array( $wp_registered_settings ) ) {
  2033. $wp_registered_settings = array();
  2034. }
  2035. if ( 'misc' === $option_group ) {
  2036. _deprecated_argument(
  2037. __FUNCTION__,
  2038. '3.0.0',
  2039. sprintf(
  2040. /* translators: %s: misc */
  2041. __( 'The "%s" options group has been removed. Use another settings group.' ),
  2042. 'misc'
  2043. )
  2044. );
  2045. $option_group = 'general';
  2046. }
  2047. if ( 'privacy' === $option_group ) {
  2048. _deprecated_argument(
  2049. __FUNCTION__,
  2050. '3.5.0',
  2051. sprintf(
  2052. /* translators: %s: privacy */
  2053. __( 'The "%s" options group has been removed. Use another settings group.' ),
  2054. 'privacy'
  2055. )
  2056. );
  2057. $option_group = 'reading';
  2058. }
  2059. $new_allowed_options[ $option_group ][] = $option_name;
  2060. if ( ! empty( $args['sanitize_callback'] ) ) {
  2061. add_filter( "sanitize_option_{$option_name}", $args['sanitize_callback'] );
  2062. }
  2063. if ( array_key_exists( 'default', $args ) ) {
  2064. add_filter( "default_option_{$option_name}", 'filter_default_option', 10, 3 );
  2065. }
  2066. /**
  2067. * Fires immediately before the setting is registered but after its filters are in place.
  2068. *
  2069. * @since 5.5.0
  2070. *
  2071. * @param string $option_group Setting group.
  2072. * @param string $option_name Setting name.
  2073. * @param array $args Array of setting registration arguments.
  2074. */
  2075. do_action( 'register_setting', $option_group, $option_name, $args );
  2076. $wp_registered_settings[ $option_name ] = $args;
  2077. }
  2078. /**
  2079. * Unregisters a setting.
  2080. *
  2081. * @since 2.7.0
  2082. * @since 4.7.0 `$sanitize_callback` was deprecated. The callback from `register_setting()` is now used instead.
  2083. * @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`.
  2084. * Please consider writing more inclusive code.
  2085. *
  2086. * @global array $new_allowed_options
  2087. * @global array $wp_registered_settings
  2088. *
  2089. * @param string $option_group The settings group name used during registration.
  2090. * @param string $option_name The name of the option to unregister.
  2091. * @param callable|string $deprecated Deprecated.
  2092. */
  2093. function unregister_setting( $option_group, $option_name, $deprecated = '' ) {
  2094. global $new_allowed_options, $wp_registered_settings;
  2095. /*
  2096. * In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`.
  2097. * Please consider writing more inclusive code.
  2098. */
  2099. $GLOBALS['new_whitelist_options'] = &$new_allowed_options;
  2100. if ( 'misc' === $option_group ) {
  2101. _deprecated_argument(
  2102. __FUNCTION__,
  2103. '3.0.0',
  2104. sprintf(
  2105. /* translators: %s: misc */
  2106. __( 'The "%s" options group has been removed. Use another settings group.' ),
  2107. 'misc'
  2108. )
  2109. );
  2110. $option_group = 'general';
  2111. }
  2112. if ( 'privacy' === $option_group ) {
  2113. _deprecated_argument(
  2114. __FUNCTION__,
  2115. '3.5.0',
  2116. sprintf(
  2117. /* translators: %s: privacy */
  2118. __( 'The "%s" options group has been removed. Use another settings group.' ),
  2119. 'privacy'
  2120. )
  2121. );
  2122. $option_group = 'reading';
  2123. }
  2124. $pos = array_search( $option_name, (array) $new_allowed_options[ $option_group ], true );
  2125. if ( false !== $pos ) {
  2126. unset( $new_allowed_options[ $option_group ][ $pos ] );
  2127. }
  2128. if ( '' !== $deprecated ) {
  2129. _deprecated_argument(
  2130. __FUNCTION__,
  2131. '4.7.0',
  2132. sprintf(
  2133. /* translators: 1: $sanitize_callback, 2: register_setting() */
  2134. __( '%1$s is deprecated. The callback from %2$s is used instead.' ),
  2135. '<code>$sanitize_callback</code>',
  2136. '<code>register_setting()</code>'
  2137. )
  2138. );
  2139. remove_filter( "sanitize_option_{$option_name}", $deprecated );
  2140. }
  2141. if ( isset( $wp_registered_settings[ $option_name ] ) ) {
  2142. // Remove the sanitize callback if one was set during registration.
  2143. if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) {
  2144. remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] );
  2145. }
  2146. // Remove the default filter if a default was provided during registration.
  2147. if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) {
  2148. remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 );
  2149. }
  2150. /**
  2151. * Fires immediately before the setting is unregistered and after its filters have been removed.
  2152. *
  2153. * @since 5.5.0
  2154. *
  2155. * @param string $option_group Setting group.
  2156. * @param string $option_name Setting name.
  2157. */
  2158. do_action( 'unregister_setting', $option_group, $option_name );
  2159. unset( $wp_registered_settings[ $option_name ] );
  2160. }
  2161. }
  2162. /**
  2163. * Retrieves an array of registered settings.
  2164. *
  2165. * @since 4.7.0
  2166. *
  2167. * @global array $wp_registered_settings
  2168. *
  2169. * @return array List of registered settings, keyed by option name.
  2170. */
  2171. function get_registered_settings() {
  2172. global $wp_registered_settings;
  2173. if ( ! is_array( $wp_registered_settings ) ) {
  2174. return array();
  2175. }
  2176. return $wp_registered_settings;
  2177. }
  2178. /**
  2179. * Filters the default value for the option.
  2180. *
  2181. * For settings which register a default setting in `register_setting()`, this
  2182. * function is added as a filter to `default_option_{$option}`.
  2183. *
  2184. * @since 4.7.0
  2185. *
  2186. * @param mixed $default Existing default value to return.
  2187. * @param string $option Option name.
  2188. * @param bool $passed_default Was `get_option()` passed a default value?
  2189. * @return mixed Filtered default value.
  2190. */
  2191. function filter_default_option( $default, $option, $passed_default ) {
  2192. if ( $passed_default ) {
  2193. return $default;
  2194. }
  2195. $registered = get_registered_settings();
  2196. if ( empty( $registered[ $option ] ) ) {
  2197. return $default;
  2198. }
  2199. return $registered[ $option ]['default'];
  2200. }