+1,135 @@ 1
+<?php
2
+
3
+namespace NSL;
4
+
5
+use NextendSocialLogin;
6
+
7
+class GDPR {
8
+
9
+    public function __construct() {
10
+        add_action('admin_init', array(
11
+            $this,
12
+            'add_privacy_policy_content'
13
+        ));
14
+
15
+        add_filter('wp_privacy_personal_data_exporters', array(
16
+            $this,
17
+            'register_exporter'
18
+        ), -1);
19
+
20
+        /*
21
+        add_filter('wp_privacy_personal_data_erasers', array(
22
+            $this,
23
+            'register_eraser'
24
+        ));
25
+        */
26
+    }
27
+
28
+    public function add_privacy_policy_content() {
29
+        if (!function_exists('wp_add_privacy_policy_content')) {
30
+            return;
31
+        }
32
+
33
+        $content = '';
34
+        $content .= '<h2>' . __('What personal data we collect and why we collect it') . '</h2>';
35
+        $content .= '<p class="privacy-policy-tutorial">' . sprintf(__('%1$s collects data when a visitor register, login or link the account with with any of the enabled social provider. It collects the following data: email address, name, social provider identifier and access token. Also it can collect profile picture and more fields with the Pro Addon\'s sync data feature.', 'nextend-facebook-connect'), 'Nextend Social Login') . '</p>';
36
+
37
+        $content .= '<h2>' . __('Who we share your data with') . '</h2>';
38
+        $content .= '<p class="privacy-policy-tutorial">' . sprintf(__('%1$s stores the personal data on your site and does not share it with anyone except the access token which used for the authenticated communication with the social providers.', 'nextend-facebook-connect'), 'Nextend Social Login') . '</p>';
39
+
40
+        $content .= '<h2>' . __('Does the plugin share personal data with third parties', 'nextend-facebook-connect') . '</h2>';
41
+        $content .= '<p class="privacy-policy-tutorial">' . sprintf(__('%1$s use the access token what the social provider gave to communicate with the providers to verify account and securely access personal data.', 'nextend-facebook-connect'), 'Nextend Social Login') . '</p>';
42
+
43
+        $content .= '<h2>' . __('How long we retain your data', 'nextend-facebook-connect') . '</h2>';
44
+        $content .= '<p class="privacy-policy-tutorial">' . sprintf(__('%1$s removes the collected personal data when the user deleted from WordPress.', 'nextend-facebook-connect'), 'Nextend Social Login') . '</p>';
45
+
46
+        $content .= '<h2>' . __('Does the plugin use personal data collected by others?', 'nextend-facebook-connect') . '</h2>';
47
+        $content .= '<p class="privacy-policy-tutorial">' . sprintf(__('%1$s use the personal data collected by the social providers to create account on your site when the visitor authorize it.', 'nextend-facebook-connect'), 'Nextend Social Login') . '</p>';
48
+
49
+        $content .= '<h2>' . __('Does the plugin store things in the browser?', 'nextend-facebook-connect') . '</h2>';
50
+        $content .= '<p class="privacy-policy-tutorial">' . sprintf(__('Yes, %1$s must create a cookie for visitors who use the social login authorization flow. This cookie required for every provider to secure the communication and to redirect the user back to the last location.', 'nextend-facebook-connect'), 'Nextend Social Login') . '</p>';
51
+
52
+        $content .= '<h2>' . __('Does the plugin collect telemetry data, directly or indirectly?', 'nextend-facebook-connect') . '</h2>';
53
+        $content .= '<p class="privacy-policy-tutorial">' . __('No') . '</p>';
54
+
55
+        $content .= '<h2>' . __('Does the plugin enqueue JavaScript, tracking pixels or embed iframes from a third party?', 'nextend-facebook-connect') . '</h2>';
56
+        $content .= '<p class="privacy-policy-tutorial">' . __('No') . '</p>';
57
+
58
+
59
+        wp_add_privacy_policy_content('Nextend Social Login', wp_kses_post($content));
60
+    }
61
+
62
+
63
+    public function register_exporter($exporters) {
64
+        $exporters['nextend-facebook-connect'] = array(
65
+            'exporter_friendly_name' => 'Nextend Social Login',
66
+            'callback'               => array(
67
+                $this,
68
+                'exporter'
69
+            ),
70
+        );
71
+
72
+        return $exporters;
73
+    }
74
+
75
+    public function exporter($email_address, $page = 1) {
76
+        $email_address = trim($email_address);
77
+
78
+        $data_to_export = array();
79
+
80
+        $user = get_user_by('email', $email_address);
81
+
82
+        if (!$user) {
83
+            return array(
84
+                'data' => array(),
85
+                'done' => true,
86
+            );
87
+        }
88
+
89
+        $user_data_to_export = array();
90
+
91
+        foreach (NextendSocialLogin::$allowedProviders as $provider) {
92
+            $user_data_to_export = array_merge($user_data_to_export, $provider->exportPersonalData($user->ID));
93
+        }
94
+
95
+
96
+        if (!empty($user_data_to_export)) {
97
+            $data_to_export[] = array(
98
+                'group_id'    => 'user',
99
+                'group_label' => __('User'),
100
+                'item_id'     => "user-{$user->ID}",
101
+                'data'        => $user_data_to_export,
102
+            );
103
+        }
104
+
105
+
106
+        return array(
107
+            'data' => $data_to_export,
108
+            'done' => true,
109
+        );
110
+    }
111
+
112
+    public function register_eraser($erasers) {
113
+        $erasers['nextend-facebook-connect'] = array(
114
+            'exporter_friendly_name' => 'Nextend Social Login',
115
+            'callback'               => array(
116
+                $this,
117
+                'eraser'
118
+            ),
119
+        );
120
+
121
+        return $erasers;
122
+    }
123
+
124
+    public function eraser($email_address, $page = 1) {
125
+        return array(
126
+            'items_removed'  => false,
127
+            'items_retained' => false,
128
+            'messages'       => array(),
129
+            'done'           => true,
130
+        );
131
+    }
132
+}
133
+
134
+
135
+new GDPR();

+ 214 - 0
app/wp-content/plugins/nextend-facebook-connect/NSL/Notices.php

@@ -0,0 +1,214 @@
1
+<?php
2
+
3
+namespace NSL;
4
+
5
+use NSL\Persistent\Persistent;
6
+use WP_Error;
7
+
8
+class Notices {
9
+
10
+    private static $notices;
11
+
12
+    private static $instance;
13
+
14
+    public static function init() {
15
+        if (self::$instance === null) {
16
+            self::$instance = new self;
17
+        }
18
+    }
19
+
20
+    private function __construct() {
21
+        if (is_admin() || (isset($_GET['nsl-notice']) && $_GET['nsl-notice'] == 1)) {
22
+            add_action('init', array(
23
+                $this,
24
+                'load'
25
+            ), 11);
26
+
27
+            if (basename($_SERVER['PHP_SELF']) !== 'options-general.php' || empty($_GET['page']) || $_GET['page'] !== 'nextend-social-login') {
28
+                add_action('admin_notices', array(
29
+                    $this,
30
+                    'admin_notices'
31
+                ));
32
+            }
33
+
34
+            add_action('admin_print_footer_scripts', array(
35
+                $this,
36
+                'notices_fallback'
37
+            ));
38
+            add_action('wp_print_footer_scripts', array(
39
+                $this,
40
+                'notices_fallback'
41
+            ));
42
+        }
43
+    }
44
+
45
+    public function load() {
46
+        self::$notices = maybe_unserialize(self::get());
47
+        if (!is_array(self::$notices)) {
48
+            self::$notices = array();
49
+        }
50
+    }
51
+
52
+    private static function add($type, $message) {
53
+        if (!isset(self::$notices[$type])) {
54
+            self::$notices[$type] = array();
55
+        }
56
+
57
+        if (!in_array($message, self::$notices[$type])) {
58
+            self::$notices[$type][] = $message;
59
+        }
60
+
61
+        self::set();
62
+    }
63
+
64
+    /**
65
+     * @param $message string|WP_Error
66
+     */
67
+    public static function addError($message) {
68
+        if (is_wp_error($message)) {
69
+            foreach ($message->get_error_messages() as $m) {
70
+                self::add('error', $m);
71
+            }
72
+        } else {
73
+            self::add('error', $message);
74
+        }
75
+    }
76
+
77
+    public static function getErrors() {
78
+        if (isset(self::$notices['error'])) {
79
+
80
+            $errors = self::$notices['error'];
81
+
82
+            unset(self::$notices['error']);
83
+            self::set();
84
+
85
+            return $errors;
86
+        }
87
+
88
+        return false;
89
+    }
90
+
91
+    public static function addSuccess($message) {
92
+        self::add('success', $message);
93
+    }
94
+
95
+    public static function displayNotices() {
96
+
97
+        $html = self::getHTML();
98
+
99
+        if (!empty($html)) {
100
+            echo '<div class="nsl-admin-notices">' . $html . '</div>';
101
+        }
102
+    }
103
+
104
+    public function admin_notices() {
105
+        echo self::getHTML();
106
+    }
107
+
108
+    /**
109
+     * Displays the non-displayed notices in lightbox as a fallback
110
+     */
111
+    public function notices_fallback() {
112
+
113
+        $html = self::getHTML();
114
+
115
+        if (!empty($html)) {
116
+            ?>
117
+            <div id="nsl-notices-fallback" onclick="this.parentNode.removeChild(this);">
118
+                <?php echo $html; ?>
119
+                <style>
120
+                    #nsl-notices-fallback {
121
+                        position: fixed;
122
+                        right: 10px;
123
+                        top: 10px;
124
+                        z-index: 10000;
125
+                    }
126
+
127
+                    .admin-bar #nsl-notices-fallback {
128
+                        top: 42px;
129
+                    }
130
+
131
+                    #nsl-notices-fallback > div {
132
+                        position: relative;
133
+                        background: #fff;
134
+                        border-left: 4px solid #fff;
135
+                        box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .1);
136
+                        margin: 5px 15px 2px;
137
+                        padding: 1px 20px;
138
+                    }
139
+
140
+                    #nsl-notices-fallback > div.error {
141
+                        display: block;
142
+                        border-left-color: #dc3232;
143
+                    }
144
+
145
+                    #nsl-notices-fallback > div.updated {
146
+                        display: block;
147
+                        border-left-color: #46b450;
148
+                    }
149
+
150
+                    #nsl-notices-fallback p {
151
+                        margin: .5em 0;
152
+                        padding: 2px;
153
+                    }
154
+
155
+                    #nsl-notices-fallback > div:after {
156
+                        position: absolute;
157
+                        right: 5px;
158
+                        top: 5px;
159
+                        content: '\00d7';
160
+                        display: block;
161
+                        height: 16px;
162
+                        width: 16px;
163
+                        line-height: 16px;
164
+                        text-align: center;
165
+                        font-size: 20px;
166
+                        cursor: pointer;
167
+                    }
168
+                </style>
169
+            </div>
170
+            <?php
171
+        }
172
+    }
173
+
174
+    private static function getHTML() {
175
+        $html = '';
176
+        if (isset(self::$notices['success'])) {
177
+            foreach (self::$notices['success'] AS $message) {
178
+                $html .= '<div class="updated"><p>' . $message . '</p></div>';
179
+            }
180
+        }
181
+
182
+        if (isset(self::$notices['error'])) {
183
+            foreach (self::$notices['error'] AS $message) {
184
+                $html .= '<div class="error"><p>' . $message . '</p></div>';
185
+            }
186
+        }
187
+
188
+        self::clear();
189
+
190
+        return $html;
191
+    }
192
+
193
+    private static function get() {
194
+        return Persistent::get('notices');
195
+    }
196
+
197
+    private static function set() {
198
+        Persistent::set('notices', self::$notices);
199
+    }
200
+
201
+    public static function clear() {
202
+
203
+        Persistent::delete('notices');
204
+        self::$notices = array();
205
+    }
206
+
207
+    public static function hasErrors() {
208
+        if (isset(self::$notices['error'])) {
209
+            return true;
210
+        }
211
+
212
+        return false;
213
+    }
214
+}

+ 93 - 0
app/wp-content/plugins/nextend-facebook-connect/NSL/Persistent/Persistent.php

@@ -0,0 +1,93 @@
1
+<?php
2
+
3
+namespace NSL\Persistent;
4
+
5
+use NSL\Persistent\Storage\Session;
6
+use NSL\Persistent\Storage\StorageAbstract;
7
+use NSL\Persistent\Storage\Transient;
8
+use WP_User;
9
+
10
+require_once dirname(__FILE__) . '/Storage/Abstract.php';
11
+require_once dirname(__FILE__) . '/Storage/Session.php';
12
+require_once dirname(__FILE__) . '/Storage/Transient.php';
13
+
14
+class Persistent {
15
+
16
+    private static $instance;
17
+
18
+    /** @var StorageAbstract */
19
+    private $storage;
20
+
21
+    public function __construct() {
22
+        self::$instance = $this;
23
+        add_action('init', array(
24
+            $this,
25
+            'init'
26
+        ), 0);
27
+
28
+        add_action('wp_login', array(
29
+            $this,
30
+            'transferSessionToUser'
31
+        ), 10, 2);
32
+    }
33
+
34
+    public function init() {
35
+        if ($this->storage === NULL) {
36
+            if (is_user_logged_in()) {
37
+                $this->storage = new Transient();
38
+            } else {
39
+                $this->storage = new Session();
40
+            }
41
+        }
42
+    }
43
+
44
+    public static function set($key, $value) {
45
+        if (self::$instance->storage) {
46
+            self::$instance->storage->set($key, $value);
47
+        }
48
+    }
49
+
50
+    public static function get($key) {
51
+        if (self::$instance->storage) {
52
+            return self::$instance->storage->get($key);
53
+        }
54
+
55
+        return false;
56
+    }
57
+
58
+    public static function delete($key) {
59
+        if (self::$instance->storage) {
60
+            self::$instance->storage->delete($key);
61
+        }
62
+    }
63
+
64
+    /**
65
+     * @param          $user_login
66
+     * @param WP_User  $user
67
+     */
68
+    public function transferSessionToUser($user_login, $user = null) {
69
+
70
+        if (!$user) { // For do_action( 'wp_login' ) calls that lacked passing the 2nd arg.
71
+            $user = get_user_by('login', $user_login);
72
+        }
73
+
74
+        $newStorage = new Transient($user->ID);
75
+        /**
76
+         * $this->storage might be NULL if init action not called yet
77
+         */
78
+        if ($this->storage !== NULL) {
79
+            $newStorage->transferData($this->storage);
80
+        }
81
+
82
+        $this->storage = $newStorage;
83
+    }
84
+
85
+    public static function clear() {
86
+        if (self::$instance->storage) {
87
+            self::$instance->storage->clear();
88
+        }
89
+    }
90
+}
91
+
92
+
93
+new Persistent();

+ 72 - 0
app/wp-content/plugins/nextend-facebook-connect/NSL/Persistent/Storage/Abstract.php

@@ -0,0 +1,72 @@
1
+<?php
2
+
3
+namespace NSL\Persistent\Storage;
4
+
5
+abstract class StorageAbstract {
6
+
7
+    protected $sessionId = null;
8
+
9
+    protected $data = array();
10
+
11
+    public function set($key, $value) {
12
+        $this->load(true);
13
+
14
+        $this->data[$key] = $value;
15
+
16
+        $this->store();
17
+    }
18
+
19
+    public function get($key) {
20
+        $this->load();
21
+
22
+        if (isset($this->data[$key])) {
23
+            return $this->data[$key];
24
+        }
25
+
26
+        return null;
27
+    }
28
+
29
+    public function delete($key) {
30
+        $this->load();
31
+
32
+        if (isset($this->data[$key])) {
33
+            unset($this->data[$key]);
34
+            $this->store();
35
+        }
36
+    }
37
+
38
+    public function clear() {
39
+        $this->data = array();
40
+        $this->store();
41
+    }
42
+
43
+    protected function load($createSession = false) {
44
+        static $isLoaded = false;
45
+
46
+        if (!$isLoaded) {
47
+            $data = maybe_unserialize(get_site_transient($this->sessionId));
48
+            if (is_array($data)) {
49
+                $this->data = $data;
50
+            }
51
+            $isLoaded = true;
52
+        }
53
+    }
54
+
55
+    private function store() {
56
+        if (empty($this->data)) {
57
+            delete_site_transient($this->sessionId);
58
+        } else {
59
+            set_site_transient($this->sessionId, $this->data, apply_filters('nsl_persistent_expiration', HOUR_IN_SECONDS));
60
+        }
61
+    }
62
+
63
+    /**
64
+     * @param StorageAbstract $storage
65
+     */
66
+    public function transferData($storage) {
67
+        $this->data = $storage->data;
68
+        $this->store();
69
+
70
+        $storage->clear();
71
+    }
72
+}

+ 86 - 0
app/wp-content/plugins/nextend-facebook-connect/NSL/Persistent/Storage/Session.php

@@ -0,0 +1,86 @@
1
+<?php
2
+
3
+namespace NSL\Persistent\Storage;
4
+
5
+class Session extends StorageAbstract {
6
+
7
+    /**
8
+     * @var string name of the cookie. Can be changed with nsl_session_name filter and NSL_SESSION_NAME constant.
9
+     *
10
+     * @see https://pantheon.io/docs/caching-advanced-topics/
11
+     */
12
+    private $sessionName = 'SESSnsl';
13
+
14
+    public function __construct() {
15
+
16
+        /**
17
+         * WP Engine hosting needs custom cookie name to prevent caching.
18
+         *
19
+         * @see https://wpengine.com/support/wpengine-ecommerce/
20
+         */
21
+        if (class_exists('WpePlugin_common', false)) {
22
+            $this->sessionName = 'wordpress_nsl';
23
+        }
24
+        if (defined('NSL_SESSION_NAME')) {
25
+            $this->sessionName = NSL_SESSION_NAME;
26
+        }
27
+        $this->sessionName = apply_filters('nsl_session_name', $this->sessionName);
28
+    }
29
+
30
+    public function clear() {
31
+        parent::clear();
32
+
33
+        $this->destroy();
34
+    }
35
+
36
+    private function destroy() {
37
+        $sessionID = $this->sessionId;
38
+        if ($sessionID) {
39
+            $this->setCookie($sessionID, time() - YEAR_IN_SECONDS, apply_filters('nsl_session_use_secure_cookie', false));
40
+
41
+            add_action('shutdown', array(
42
+                $this,
43
+                'destroySiteTransient'
44
+            ));
45
+        }
46
+    }
47
+
48
+    public function destroySiteTransient() {
49
+        $sessionID = $this->sessionId;
50
+        if ($sessionID) {
51
+            delete_site_transient('nsl_' . $sessionID);
52
+        }
53
+    }
54
+
55
+    protected function load($createSession = false) {
56
+        static $isLoaded = false;
57
+        if ($this->sessionId === null) {
58
+            if (isset($_COOKIE[$this->sessionName])) {
59
+                $this->sessionId = 'nsl_persistent_' . md5(SECURE_AUTH_KEY . $_COOKIE[$this->sessionName]);
60
+            } else if ($createSession) {
61
+                $unique = uniqid('nsl', true);
62
+
63
+                $this->setCookie($unique, apply_filters('nsl_session_cookie_expiration', 0), apply_filters('nsl_session_use_secure_cookie', false));
64
+
65
+                $this->sessionId = 'nsl_persistent_' . md5(SECURE_AUTH_KEY . $unique);
66
+
67
+                $isLoaded = true;
68
+            }
69
+        }
70
+
71
+        if (!$isLoaded) {
72
+            if ($this->sessionId !== null) {
73
+                $data = maybe_unserialize(get_site_transient($this->sessionId));
74
+                if (is_array($data)) {
75
+                    $this->data = $data;
76
+                }
77
+                $isLoaded = true;
78
+            }
79
+        }
80
+    }
81
+
82
+    private function setCookie($value, $expire, $secure = false) {
83
+
84
+        setcookie($this->sessionName, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure);
85
+    }
86
+}

+ 13 - 0
app/wp-content/plugins/nextend-facebook-connect/NSL/Persistent/Storage/Transient.php

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace NSL\Persistent\Storage;
4
+
5
+class Transient extends StorageAbstract {
6
+
7
+    public function __construct($user_id = false) {
8
+        if ($user_id === false) {
9
+            $user_id = get_current_user_id();
10
+        }
11
+        $this->sessionId = 'nsl_persistent_' . $user_id;
12
+    }
13
+}

+ 72 - 0
app/wp-content/plugins/nextend-facebook-connect/NSL/REST.php

@@ -0,0 +1,72 @@
1
+<?php
2
+
3
+namespace NSL;
4
+
5
+use Exception;
6
+use NextendSocialLogin;
7
+use WP_Error;
8
+use WP_REST_Request;
9
+use WP_REST_Response;
10
+use function add_action;
11
+use function register_rest_route;
12
+
13
+class REST {
14
+
15
+    public function __construct() {
16
+        add_action('rest_api_init', array(
17
+            $this,
18
+            'rest_api_init'
19
+        ));
20
+    }
21
+
22
+    public function rest_api_init() {
23
+        register_rest_route('nextend-social-login/v1', '/(?P<provider>\w[\w\s\-]*)/get_user', array(
24
+            'args' => array(
25
+                'provider'     => array(
26
+                    'required'          => true,
27
+                    'validate_callback' => array(
28
+                        $this,
29
+                        'validate_provider'
30
+                    )
31
+                ),
32
+                'access_token' => array(
33
+                    'required' => true,
34
+                ),
35
+            ),
36
+            array(
37
+                'methods'             => 'POST',
38
+                'callback'            => array(
39
+                    $this,
40
+                    'get_user'
41
+                ),
42
+                'permission_callback' => '__return_true'
43
+            ),
44
+        ));
45
+
46
+    }
47
+
48
+    public function validate_provider($providerID) {
49
+        return NextendSocialLogin::isProviderEnabled($providerID);
50
+    }
51
+
52
+    /**
53
+     * @param WP_REST_Request $request Full details about the request.
54
+     *
55
+     * @return WP_Error|WP_REST_Response
56
+     */
57
+    public function get_user($request) {
58
+
59
+        $provider = NextendSocialLogin::$enabledProviders[$request['provider']];
60
+        try {
61
+            $user = $provider->findUserByAccessToken($request['access_token']);
62
+        } catch (Exception $e) {
63
+            return new WP_Error('error', $e->getMessage());
64
+        }
65
+
66
+        return $user;
67
+    }
68
+
69
+}
70
+
71
+new REST();
72
+

+ 71 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/EditUser.php

@@ -0,0 +1,71 @@
1
+<?php
2
+/** @var $user WP_User */
3
+?>
4
+
5
+<?php foreach (NextendSocialLogin::$enabledProviders AS $provider): ?>
6
+    <?php
7
+    $settings = $provider->settings;
8
+    if (!$provider->isUserConnected($user->ID)) continue;
9
+    $hasData = false;
10
+    ob_start();
11
+    ?>
12
+
13
+    <h2><?php echo $provider->getLabel(); ?></h2>
14
+
15
+    <table class="form-table">
16
+        <tbody>
17
+        <?php foreach ($provider->getSyncFields() AS $fieldName => $fieldData): ?>
18
+            <tr>
19
+                <?php
20
+                $meta_key = $settings->get('sync_fields/fields/' . $fieldName . '/meta_key');
21
+                $value    = get_user_meta($user->ID, $meta_key, true);
22
+                if (isset($value) && $value !== '') {
23
+                    ?>
24
+                    <th><label><?php echo $fieldData['label'] ?></label></th>
25
+                    <td>
26
+                        <?php
27
+
28
+                        $unSerialized = maybe_unserialize($value);
29
+                        if (is_array($unSerialized) || is_object($unSerialized)) {
30
+
31
+                            echo "<pre>";
32
+                            print_r(formatUserMeta((array)$unSerialized));
33
+
34
+                            echo "</pre>";
35
+                        } else {
36
+                            echo esc_html($value);
37
+                        }
38
+                        $hasData = true;
39
+                        ?>
40
+                    </td>
41
+                    <?php
42
+                }
43
+                ?>
44
+            </tr>
45
+        <?php endforeach; ?>
46
+
47
+        </tbody>
48
+    </table>
49
+    <?php
50
+    if ($hasData) {
51
+        echo ob_get_clean();
52
+    } else {
53
+        ob_end_clean();
54
+    }
55
+    ?>
56
+<?php endforeach; ?>
57
+
58
+<?php
59
+
60
+function formatUserMeta($user_meta, $level = '') {
61
+    $formatted_usermeta = '';
62
+    if (is_array($user_meta)) {
63
+        foreach ($user_meta as $meta_key => $meta_value) {
64
+            $formatted_usermeta .= formatUserMeta($meta_value, $level . '[' . $meta_key . ']');
65
+        }
66
+    } else {
67
+        $formatted_usermeta .= "\n" . $level . ' = ' . $user_meta;
68
+    }
69
+
70
+    return $formatted_usermeta;
71
+}

File diff suppressed because it is too large
+ 1023 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/admin.php


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/buttons/default.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/buttons/fullwidth.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/buttons/icon.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/error.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/exclamation-mark.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/facebook/black.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/facebook/dark.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/facebook/light.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/facebook/white.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/google/dark.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/google/light.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/google/uniform.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/above-separator.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/above.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/below-floating.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/below-separator.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/below.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/default-separator.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/layouts/default.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/notice.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/notice/nslnotice.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/nsl-logo.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/ok.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/padlock.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/stars-big.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/stars-small.png


二進制
app/wp-content/plugins/nextend-facebook-connect/admin/images/test-needed.png


+ 38 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/interim.php

@@ -0,0 +1,38 @@
1
+<?php
2
+if (!defined('ABSPATH')) {
3
+    exit;
4
+}
5
+
6
+global $interim_login;
7
+$customize_login = isset($_REQUEST['customize-login']);
8
+if ($customize_login) {
9
+    wp_enqueue_script('customize-base');
10
+}
11
+
12
+$message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
13
+$interim_login = 'success';
14
+?><!DOCTYPE html>
15
+<!--[if IE 8]>
16
+<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
17
+<![endif]-->
18
+<!--[if !(IE 8) ]><!-->
19
+<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
20
+<!--<![endif]-->
21
+<head>
22
+    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>"/>
23
+    <title><?php __('You have logged in successfully.'); ?></title>
24
+</head>
25
+<body class="login interim-login interim-login-success">
26
+<?php
27
+echo $message;
28
+/** This action is documented in wp-login.php */
29
+do_action('login_footer'); ?>
30
+<?php if ($customize_login) : ?>
31
+    <script type="text/javascript">setTimeout(function () {
32
+            new wp.customize.Messenger({url: '<?php echo wp_customize_url(); ?>', channel: 'login'}).send(
33
+                'login');
34
+        }, 1000);</script>
35
+<?php endif; ?>
36
+</body>
37
+</html>
38
+<?php exit;

+ 77 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/notice.php

@@ -0,0 +1,77 @@
1
+<?php
2
+
3
+
4
+$current = time();
5
+if (mktime(0, 0, 0, 11, 23, 2021) <= $current && $current < mktime(0, 0, 0, 12, 1, 2021)) {
6
+    if (get_option('nsl_bf_2021') != '1') {
7
+
8
+        add_action('admin_notices', function () {
9
+            ?>
10
+            <div class="notice notice-info is-dismissible" data-nsldismissable="nsl_bf_2021" style="display:grid;grid-template-columns: 100px auto;padding-top: 25px; padding-bottom: 22px;">
11
+                <img alt="Nextend Social Login" src="<?php echo plugins_url('images/notice/nslnotice.png', NSL_ADMIN_PATH) ?>" width="74" height="74" style="grid-row: 1 / 4; align-self: center;justify-self: center">
12
+                <h3 style="margin:0;">Nextend Social Login - Black Friday Deal</h3>
13
+                <p style="margin:0 0 2px;">Don't miss out on our biggest sale of the year! Get your <b>Pro Addon</b>
14
+                    with <b>40% OFF</b> to access <b>WooCommerce support</b>, Apple provider and much more!
15
+                    Limited time offer expires on November 30.</p>
16
+                <p style="margin:0;">
17
+                    <a class="button button-primary" href="https://nextendweb.com/social-login/?coupon=SAVE4021&utm_source=wpfree&utm_medium=wp&utm_campaign=bf21#pricing" target="_blank">
18
+                        Buy Now</a>
19
+                    <a class="button button-dismiss" href="#">Dismiss</a>
20
+                </p>
21
+            </div>
22
+            <?php
23
+        });
24
+
25
+        add_action('admin_footer', function () {
26
+            ?>
27
+            <script>
28
+                (function () {
29
+                    function ready(fn) {
30
+                        if (document.readyState === "complete" || document.readyState === "interactive") {
31
+                            fn();
32
+                        } else {
33
+                            document.addEventListener("DOMContentLoaded", fn);
34
+                        }
35
+                    }
36
+
37
+                    function serialize(obj) {
38
+                        return Object.keys(obj).reduce(function (a, k) {
39
+                            a.push(k + '=' + encodeURIComponent(obj[k]));
40
+                            return a;
41
+                        }, []).join('&');
42
+                    }
43
+
44
+                    ready(function () {
45
+                        setTimeout(function () {
46
+                            const buttons = document.querySelectorAll("div[data-nsldismissable] .notice-dismiss, div[data-nsldismissable] .button-dismiss");
47
+                            for (let i = 0; i < buttons.length; i++) {
48
+                                buttons[i].addEventListener('click', function (e) {
49
+                                    e.preventDefault();
50
+
51
+                                    const http = new XMLHttpRequest();
52
+                                    http.open('POST', ajaxurl, true);
53
+                                    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
54
+
55
+                                    http.send(serialize({
56
+                                        'action': 'nsl_dismiss_admin_notice',
57
+                                        'nonce': <?php echo json_encode(wp_create_nonce('nsl-dismissible-notice')); ?>
58
+                                    }));
59
+
60
+                                    e.target.closest('.is-dismissible').remove();
61
+                                });
62
+                            }
63
+                        }, 1000);
64
+                    });
65
+                })();
66
+            </script>
67
+            <?php
68
+        });
69
+
70
+        add_action('wp_ajax_nsl_dismiss_admin_notice', function () {
71
+            check_ajax_referer('nsl-dismissible-notice', 'nonce');
72
+
73
+            update_option('nsl_bf_2021', '1');
74
+            wp_die();
75
+        });
76
+    }
77
+}

File diff suppressed because it is too large
+ 529 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/style.css


+ 201 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates-provider/buttons.php

@@ -0,0 +1,201 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+/** @var $this NextendSocialProviderAdmin */
4
+
5
+$provider = $this->getProvider();
6
+
7
+$settings = $provider->settings;
8
+
9
+$isPRO = apply_filters('nsl-pro', false);
10
+?>
11
+<div class="nsl-admin-sub-content">
12
+    <script type="text/javascript">
13
+
14
+        document.addEventListener("DOMContentLoaded", function () {
15
+            window.resetButtonToDefault = function (id) {
16
+                var defaultButtonValues = {
17
+                    '#login_label': <?php echo wp_json_encode($settings->get('login_label', 'default')); ?>,
18
+                    '#register_label': <?php echo wp_json_encode($settings->get('register_label', 'default')); ?>,
19
+                    '#link_label': <?php echo wp_json_encode($settings->get('link_label', 'default')); ?>,
20
+                    '#unlink_label': <?php echo wp_json_encode($settings->get('unlink_label', 'default')); ?>,
21
+                    '#custom_default_button': <?php echo wp_json_encode($provider->getRawDefaultButton()); ?>,
22
+                    '#custom_icon_button': <?php echo wp_json_encode($provider->getRawIconButton()); ?>
23
+                };
24
+
25
+                var inputField = document.querySelector(id),
26
+                    codeMirror = inputField.parentNode.querySelector('.CodeMirror');
27
+
28
+                inputField.value = defaultButtonValues[id];
29
+                if (codeMirror) {
30
+                    codeMirror.CodeMirror.setValue(defaultButtonValues[id]);
31
+                }
32
+                return false;
33
+            };
34
+
35
+            var defaultButton = document.getElementById('custom_default_button_enabled');
36
+            defaultButton.addEventListener('change', function () {
37
+                if (this.checked) {
38
+                    document.getElementById('custom_default_button_textarea_container').style.removeProperty('display');
39
+
40
+                    var inputField = document.getElementById('custom_default_button'),
41
+                        codeMirror = inputField.parentNode.querySelector('.CodeMirror');
42
+                    if (codeMirror) {
43
+                        codeMirror.CodeMirror.refresh();
44
+                    }
45
+                } else {
46
+                    document.getElementById('custom_default_button_textarea_container').style.display = 'none';
47
+                }
48
+            });
49
+
50
+            var defaultIcon = document.getElementById('custom_icon_button_enabled');
51
+            defaultIcon.addEventListener('change', function () {
52
+                if (this.checked) {
53
+                    document.getElementById('custom_icon_button_textarea_container').style.removeProperty('display');
54
+
55
+                    var inputField = document.getElementById('custom_icon_button');
56
+                    var codeMirror = inputField.parentNode.querySelector('.CodeMirror');
57
+                    if (codeMirror) {
58
+                        codeMirror.CodeMirror.refresh();
59
+                    }
60
+                } else {
61
+                    document.getElementById('custom_icon_button_textarea_container').style.display = 'none';
62
+                }
63
+            });
64
+        });
65
+
66
+    </script>
67
+
68
+    <form method="post" action="<?php echo admin_url('admin-post.php'); ?>" novalidate="novalidate">
69
+
70
+        <?php wp_nonce_field('nextend-social-login'); ?>
71
+        <input type="hidden" name="action" value="nextend-social-login"/>
72
+        <input type="hidden" name="view" value="provider-<?php echo $provider->getId(); ?>"/>
73
+        <input type="hidden" name="subview" value="buttons"/>
74
+
75
+        <table class="form-table">
76
+            <tbody>
77
+            <?php
78
+            $buttonsPath = $provider->getPath() . '/admin/buttons.php';
79
+            if (file_exists($buttonsPath)) {
80
+                include($buttonsPath);
81
+            }
82
+            ?>
83
+
84
+            <tr>
85
+                <th scope="row"><label
86
+                            for="login_label"><?php _e('Login label', 'nextend-facebook-connect'); ?></label></th>
87
+                <td>
88
+                    <input name="login_label" type="text" id="login_label"
89
+                           value="<?php echo esc_attr($settings->get('login_label')); ?>" class="regular-text">
90
+                    <p class="description"><a href="#"
91
+                                              onclick="return resetButtonToDefault('#login_label');"><?php _e('Reset to default', 'nextend-facebook-connect'); ?></a>
92
+                    </p>
93
+                </td>
94
+            </tr>
95
+
96
+            <?php
97
+            $useCustomRegisterLabel = NextendSocialLogin::$settings->get('custom_register_label');
98
+            if ($useCustomRegisterLabel): ?>
99
+                <tr>
100
+                    <th scope="row"><label
101
+                                for="register_label"><?php _e('Register label', 'nextend-facebook-connect'); ?></label>
102
+                    </th>
103
+                    <td>
104
+                        <input name="register_label" type="text" id="register_label"
105
+                               value="<?php echo esc_attr($settings->get('register_label')); ?>" class="regular-text">
106
+                        <p class="description"><a href="#"
107
+                                                  onclick="return resetButtonToDefault('#register_label');"><?php _e('Reset to default', 'nextend-facebook-connect'); ?></a>
108
+                        </p>
109
+                    </td>
110
+                </tr>
111
+            <?php endif; ?>
112
+
113
+            <tr>
114
+                <th scope="row"><label for="link_label"><?php _e('Link label', 'nextend-facebook-connect'); ?></label>
115
+                </th>
116
+                <td>
117
+                    <input name="link_label" type="text" id="link_label"
118
+                           value="<?php echo esc_attr($settings->get('link_label')); ?>" class="regular-text">
119
+                    <p class="description"><a href="#"
120
+                                              onclick="return resetButtonToDefault('#link_label');"><?php _e('Reset to default', 'nextend-facebook-connect'); ?></a>
121
+                    </p>
122
+                </td>
123
+            </tr>
124
+            <tr>
125
+                <th scope="row"><label
126
+                            for="unlink_label"><?php _e('Unlink label', 'nextend-facebook-connect'); ?></label></th>
127
+                <td>
128
+                    <input name="unlink_label" type="text" id="unlink_label"
129
+                           value="<?php echo esc_attr($settings->get('unlink_label')); ?>" class="regular-text">
130
+                    <p class="description"><a href="#"
131
+                                              onclick="return resetButtonToDefault('#unlink_label');"><?php _e('Reset to default', 'nextend-facebook-connect'); ?></a>
132
+                    </p>
133
+                </td>
134
+            </tr>
135
+            <tr>
136
+                <th scope="row"><label
137
+                            for="custom_default_button"><?php _e('Default button', 'nextend-facebook-connect'); ?></label>
138
+                </th>
139
+                <td>
140
+                    <?php
141
+                    $useCustom      = false;
142
+                    $buttonTemplate = $settings->get('custom_default_button');
143
+                    if (!empty($buttonTemplate)) {
144
+                        $useCustom = true;
145
+                    } else {
146
+                        $buttonTemplate = $provider->getRawDefaultButton();
147
+                    }
148
+                    ?>
149
+                    <fieldset><label for="custom_default_button_enabled">
150
+                            <input name="custom_default_button_enabled" type="checkbox"
151
+                                   id="custom_default_button_enabled"
152
+                                   value="1" <?php if ($useCustom): ?> checked<?php endif; ?>>
153
+                            <?php _e('Use custom button', 'nextend-facebook-connect'); ?></label>
154
+                    </fieldset>
155
+                    <div id="custom_default_button_textarea_container" <?php if (!$useCustom): ?> style="display:none;"<?php endif; ?>>
156
+                        <textarea cols="160" rows="6" name="custom_default_button" id="custom_default_button"
157
+                                  class="nextend-html-editor"
158
+                                  aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo esc_textarea($buttonTemplate); ?></textarea>
159
+                        <p class="description"><a href="#"
160
+                                                  onclick="return resetButtonToDefault('#custom_default_button');"><?php _e('Reset to default', 'nextend-facebook-connect'); ?></a><br><br><?php printf(__('Use the %s in your custom button\'s code to make the label show up.', 'nextend-facebook-connect'), "<code>{{label}}</code>"); ?>
161
+                        </p>
162
+                    </div>
163
+                </td>
164
+            </tr>
165
+            <?php if ($isPRO): ?>
166
+                <tr>
167
+                    <th scope="row"><label
168
+                                for="custom_icon_button"><?php _e('Icon button', 'nextend-facebook-connect'); ?></label>
169
+                    </th>
170
+                    <td>
171
+                        <?php
172
+                        $useCustom      = false;
173
+                        $buttonTemplate = $settings->get('custom_icon_button');
174
+                        if (!empty($buttonTemplate)) {
175
+                            $useCustom = true;
176
+                        } else {
177
+                            $buttonTemplate = $provider->getRawIconButton();
178
+                        }
179
+                        ?>
180
+                        <fieldset><label for="custom_icon_button_enabled">
181
+                                <input name="custom_icon_button_enabled" type="checkbox" id="custom_icon_button_enabled"
182
+                                       value="1" <?php if ($useCustom): ?> checked<?php endif; ?>>
183
+                                <?php _e('Use custom button', 'nextend-facebook-connect'); ?></label>
184
+                        </fieldset>
185
+                        <div id="custom_icon_button_textarea_container" <?php if (!$useCustom): ?> style="display:none;"<?php endif; ?>>
186
+                        <textarea cols="160" rows="6" name="custom_icon_button" id="custom_icon_button"
187
+                                  class="nextend-html-editor"
188
+                                  aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo esc_textarea($buttonTemplate); ?></textarea>
189
+                            <p class="description"><a href="#"
190
+                                                      onclick="return resetButtonToDefault('#custom_icon_button');"><?php _e('Reset to default', 'nextend-facebook-connect'); ?></a>
191
+                            </p>
192
+                        </div>
193
+                    </td>
194
+                </tr>
195
+            <?php endif; ?>
196
+            </tbody>
197
+        </table>
198
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary"
199
+                                 value="<?php _e('Save Changes'); ?>"></p>
200
+    </form>
201
+</div>

+ 25 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates-provider/menu.php

@@ -0,0 +1,25 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+/** @var $this NextendSocialProviderAdmin */
4
+/** @var $view string */
5
+
6
+$proBadge = '';
7
+if (!NextendSocialLoginAdmin::isPro()) {
8
+    $proBadge = '<span class="nsl-pro-badge">Pro</span>';
9
+}
10
+?>
11
+<div class="nsl-admin-sub-nav-bar">
12
+    <a href="<?php echo $this->getUrl(); ?>"
13
+       class="nsl-admin-nav-tab<?php if ($view === 'getting-started'): ?> nsl-admin-nav-tab-active<?php endif; ?>"><?php _e('Getting Started', 'nextend-facebook-connect'); ?></a>
14
+    <a href="<?php echo $this->getUrl('settings'); ?>"
15
+       class="nsl-admin-nav-tab<?php if ($view === 'settings'): ?> nsl-admin-nav-tab-active<?php endif; ?>"><?php _e('Settings', 'nextend-facebook-connect'); ?></a>
16
+    <a href="<?php echo $this->getUrl('buttons'); ?>"
17
+       class="nsl-admin-nav-tab<?php if ($view === 'buttons'): ?> nsl-admin-nav-tab-active<?php endif; ?>"><?php _e('Buttons', 'nextend-facebook-connect'); ?></a>
18
+
19
+    <?php if ($this->provider->hasSyncFields()): ?>
20
+        <a href="<?php echo $this->getUrl('sync-data'); ?>"
21
+           class="nsl-admin-nav-tab<?php if ($view === 'sync-data'): ?> nsl-admin-nav-tab-active<?php endif; ?>"><?php _e('Sync data', 'nextend-facebook-connect'); ?><?php echo $proBadge; ?></a>
22
+    <?php endif; ?>
23
+    <a href="<?php echo $this->getUrl('usage'); ?>"
24
+       class="nsl-admin-nav-tab<?php if ($view === 'usage'): ?> nsl-admin-nav-tab-active<?php endif; ?>"><?php _e('Usage', 'nextend-facebook-connect'); ?></a>
25
+</div>

+ 73 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates-provider/settings-other.php

@@ -0,0 +1,73 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+/** @var $this NextendSocialProviderAdmin */
4
+
5
+$provider = $this->getProvider();
6
+
7
+$settings = $provider->settings;
8
+?>
9
+
10
+<hr/>
11
+<h2><?php _e('Other settings', 'nextend-facebook-connect'); ?></h2>
12
+<table class="form-table">
13
+    <tbody>
14
+    <tr>
15
+        <th scope="row"><label
16
+                    for="user_prefix"><?php _e('Username prefix on register', 'nextend-facebook-connect'); ?></label>
17
+        </th>
18
+        <td><input name="user_prefix" type="text" id="user_prefix"
19
+                   value="<?php echo esc_attr($settings->get('user_prefix')); ?>" class="regular-text"></td>
20
+    </tr>
21
+    <tr>
22
+        <th scope="row"><label
23
+                    for="user_fallback"><?php _e('Fallback username prefix on register', 'nextend-facebook-connect'); ?></label>
24
+        </th>
25
+        <td><input name="user_fallback" type="text" id="user_fallback"
26
+                   value="<?php echo esc_attr($settings->get('user_fallback')); ?>" class="regular-text">
27
+            <p class="description" id="tagline-user_fallback"><?php _e('Used when username is invalid or not stored', 'nextend-facebook-connect'); ?></p>
28
+        </td>
29
+    </tr>
30
+    <?php if (NextendSocialLogin::$settings->get('terms_show') == 1): ?>
31
+        <tr>
32
+            <th scope="row"><?php _e('Terms and conditions', 'nextend-facebook-connect'); ?></th>
33
+            <td>
34
+                <?php
35
+                $terms              = $settings->get('terms');
36
+                $hasOverriddenTerms = !empty($terms);
37
+                ?>
38
+                <fieldset>
39
+                    <label for="terms_override">
40
+                        <input type="hidden" name="terms_override" value="0">
41
+                        <input type="checkbox" name="terms_override" id="terms_override"
42
+                               value="1" <?php if ($hasOverriddenTerms) : ?> checked="checked" <?php endif; ?>>
43
+                        <?php printf(__('Override global "%1$s"', 'nextend-facebook-connect'), __('Terms and conditions', 'nextend-facebook-connect')); ?>
44
+                    </label>
45
+
46
+                    <div id="nsl-terms" <?php if (!$hasOverriddenTerms) : ?> style="display:none;" <?php endif; ?>>
47
+                        <?php
48
+                        wp_editor($terms, 'terms', array(
49
+                            'textarea_rows' => 4,
50
+                            'media_buttons' => false
51
+                        ));
52
+                        ?>
53
+                    </div>
54
+                </fieldset>
55
+                <script type="text/javascript">
56
+                    (function ($) {
57
+
58
+                        $(document).ready(function () {
59
+                            $('#terms_override').on('change', function () {
60
+                                if ($(this).is(':checked')) {
61
+                                    $('#nsl-terms').css('display', '');
62
+                                } else {
63
+                                    $('#nsl-terms').css('display', 'none');
64
+                                }
65
+                            });
66
+                        });
67
+                    })(jQuery);
68
+                </script>
69
+            </td>
70
+        </tr>
71
+    <?php endif; ?>
72
+    </tbody>
73
+</table>

+ 141 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates-provider/settings-pro.php

@@ -0,0 +1,141 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+/** @var $this NextendSocialProviderAdmin */
4
+
5
+$provider = $this->getProvider();
6
+
7
+$settings = $provider->settings;
8
+
9
+$isPRO = apply_filters('nsl-pro', false);
10
+
11
+$attr = '';
12
+if (!$isPRO) {
13
+    $attr = ' disabled ';
14
+}
15
+?>
16
+
17
+    <hr/>
18
+    <h1><?php _e('PRO settings', 'nextend-facebook-connect'); ?></h1>
19
+
20
+
21
+<?php
22
+NextendSocialLoginAdmin::showProBox();
23
+?>
24
+    <input type="hidden" name="tested" id="tested" value="<?php echo esc_attr($settings->get('tested')); ?>"/>
25
+    <table class="form-table" <?php if (!$isPRO): ?> style="opacity:0.5;"<?php endif; ?>>
26
+        <tbody>
27
+        <tr>
28
+            <th scope="row"><?php _e('Ask E-mail on registration', 'nextend-facebook-connect'); ?></th>
29
+            <td>
30
+                <fieldset>
31
+                    <legend class="screen-reader-text">
32
+                        <span><?php _e('Ask E-mail on registration', 'nextend-facebook-connect'); ?></span></legend>
33
+                    <label><input type="radio" name="ask_email"
34
+                                  value="never" <?php if ($settings->get('ask_email') == 'never') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
35
+                        <span><?php _e('Never', 'nextend-facebook-connect'); ?></span></label><br>
36
+                    <label><input type="radio" name="ask_email"
37
+                                  value="when-empty" <?php if ($settings->get('ask_email') == 'when-empty') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
38
+                        <span><?php _e('When email is not provided or empty', 'nextend-facebook-connect'); ?></span></label><br>
39
+                    <label><input type="radio" name="ask_email"
40
+                                  value="always" <?php if ($settings->get('ask_email') == 'always') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
41
+                        <span><?php _e('Always', 'nextend-facebook-connect'); ?></span></label><br>
42
+                </fieldset>
43
+            </td>
44
+        </tr>
45
+        <tr>
46
+            <th scope="row"><?php _e('Ask Username on registration', 'nextend-facebook-connect'); ?></th>
47
+            <td>
48
+                <fieldset>
49
+                    <legend class="screen-reader-text">
50
+                        <span><?php _e('Ask Username on registration', 'nextend-facebook-connect'); ?></span></legend>
51
+                    <label><input type="radio" name="ask_user"
52
+                                  value="never" <?php if ($settings->get('ask_user') == 'never') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
53
+                        <span><?php _e('Never, generate automatically', 'nextend-facebook-connect'); ?></span></label><br>
54
+                    <label><input type="radio" name="ask_user"
55
+                                  value="when-empty" <?php if ($settings->get('ask_user') == 'when-empty') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
56
+                        <span><?php _e('When username is empty or invalid', 'nextend-facebook-connect'); ?></span></label><br>
57
+                    <label><input type="radio" name="ask_user"
58
+                                  value="always" <?php if ($settings->get('ask_user') == 'always') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
59
+                        <span><?php _e('Always', 'nextend-facebook-connect'); ?></span></label><br>
60
+                </fieldset>
61
+            </td>
62
+        </tr>
63
+        <tr>
64
+            <th scope="row"><?php _e('Ask Password on registration', 'nextend-facebook-connect'); ?></th>
65
+            <td>
66
+                <fieldset>
67
+                    <label><input type="radio" name="ask_password"
68
+                                  value="never" <?php if ($settings->get('ask_password') == 'never') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
69
+                        <span><?php _e('Never', 'nextend-facebook-connect'); ?></span></label><br>
70
+                    <label><input type="radio" name="ask_password"
71
+                                  value="always" <?php if ($settings->get('ask_password') == 'always') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
72
+                        <span><?php _e('Always', 'nextend-facebook-connect'); ?></span></label><br>
73
+                </fieldset>
74
+            </td>
75
+        </tr>
76
+        <tr>
77
+            <th scope="row"><?php _e('Automatically connect the existing account upon registration', 'nextend-facebook-connect'); ?></th>
78
+            <td>
79
+                <fieldset>
80
+                    <legend class="screen-reader-text">
81
+                        <span><?php _e('Automatically connect the existing account upon registration', 'nextend-facebook-connect'); ?></span>
82
+                    </legend>
83
+                    <label><input type="radio" name="auto_link"
84
+                                  value="disabled" <?php if ($settings->get('auto_link') == 'disabled') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
85
+                        <span><?php _e('Disabled', 'nextend-facebook-connect'); ?></span></label><br>
86
+                    <label><input type="radio" name="auto_link"
87
+                                  value="email" <?php if ($settings->get('auto_link') == 'email') : ?> checked="checked" <?php endif; ?><?php echo $attr; ?>>
88
+                        <span><?php _e('Automatic, based on email address', 'nextend-facebook-connect'); ?></span></label><br>
89
+                </fieldset>
90
+            </td>
91
+        </tr>
92
+        <tr>
93
+            <th scope="row"><?php _e('Disable login for the selected roles', 'nextend-facebook-connect'); ?></th>
94
+            <td>
95
+                <?php
96
+                $wp_roles = new WP_Roles();
97
+                $roles    = $wp_roles->get_names();
98
+
99
+                $disable_roles = $settings->get('disabled_roles');
100
+                foreach ($roles AS $roleKey => $label):
101
+                    ?>
102
+                    <fieldset><label for="disabled_roles_<?php echo esc_attr($roleKey); ?>">
103
+                            <input name="disabled_roles[]" type="checkbox"
104
+                                   id="disabled_roles_<?php echo esc_attr($roleKey); ?>"
105
+                                   value="<?php echo esc_attr($roleKey); ?>" <?php if (in_array($roleKey, $disable_roles)) : ?> checked <?php endif ?> <?php echo $attr; ?> />
106
+                            <?php echo $label; ?></label>
107
+                    </fieldset>
108
+                <?php endforeach; ?>
109
+                <input type="hidden" name="disabled_roles[]" value=""/>
110
+            </td>
111
+        </tr>
112
+        <tr>
113
+            <th scope="row"><?php _e('Default roles for user who registered with this provider', 'nextend-facebook-connect'); ?></th>
114
+            <td>
115
+                <?php
116
+                $register_roles = $settings->get('register_roles');
117
+                ?>
118
+                <fieldset><label for="register_roles_default">
119
+                        <input name="register_roles[]" type="checkbox" id="register_roles_default"
120
+                               value="default" <?php if (in_array('default', $register_roles)) : ?> checked <?php endif ?> <?php echo $attr; ?> />
121
+                        <?php _e('Default', 'nextend-facebook-connect'); ?></label>
122
+                </fieldset>
123
+                <?php
124
+                foreach ($roles AS $roleKey => $label):
125
+                    ?>
126
+                    <fieldset><label for="register_roles_<?php echo esc_attr($roleKey); ?>">
127
+                            <input name="register_roles[]" type="checkbox"
128
+                                   id="register_roles_<?php echo esc_attr($roleKey); ?>"
129
+                                   value="<?php echo esc_attr($roleKey); ?>" <?php if (in_array($roleKey, $register_roles)) : ?> checked <?php endif ?> <?php echo $attr; ?> />
130
+                            <?php echo $label; ?></label>
131
+                    </fieldset>
132
+                <?php endforeach; ?>
133
+                <input type="hidden" name="register_roles[]" value=""/>
134
+            </td>
135
+        </tr>
136
+        </tbody>
137
+    </table>
138
+<?php if ($isPRO): ?>
139
+    <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary"
140
+                             value="<?php _e('Save Changes'); ?>"></p>
141
+<?php endif; ?>

+ 126 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates-provider/sync-data.php

@@ -0,0 +1,126 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+/** @var $this NextendSocialProviderAdmin */
4
+
5
+$provider = $this->getProvider();
6
+
7
+$settings = $provider->settings;
8
+
9
+$isPRO = apply_filters('nsl-pro', false);
10
+
11
+$attr = '';
12
+if (!$isPRO) {
13
+    $attr = ' disabled ';
14
+}
15
+?>
16
+
17
+<div class="nsl-admin-sub-content">
18
+
19
+    <?php
20
+    NextendSocialLoginAdmin::showProBox();
21
+    ?>
22
+
23
+    <form method="post" action="<?php echo admin_url('admin-post.php'); ?>" novalidate="novalidate">
24
+
25
+        <?php wp_nonce_field('nextend-social-login'); ?>
26
+        <input type="hidden" name="action" value="nextend-social-login"/>
27
+        <input type="hidden" name="view" value="provider-<?php echo $provider->getId(); ?>"/>
28
+        <input type="hidden" name="subview" value="sync-data"/>
29
+        <input type="hidden" name="settings_saved" value="1"/>
30
+
31
+        <?php
32
+        $sync_warning_message = apply_filters('nsl_' . $provider->getId() . '_sync_warning', false);
33
+        if (!empty($sync_warning_message)): ?>
34
+            <div class="notice notice-warning">
35
+                <p>
36
+                    <?php echo $sync_warning_message; ?>
37
+                </p>
38
+            </div>
39
+        <?php endif; ?>
40
+
41
+        <table class="form-table">
42
+            <tbody>
43
+            <tr>
44
+                <th scope="row"><label>Sync fields</label></th>
45
+                <td>
46
+                    <fieldset>
47
+                        <label for="sync_fields_register">
48
+                            <input type="checkbox" id="sync_fields_register"
49
+                                   value="1" checked disabled/>
50
+                            <?php _e('Register', 'nextend-facebook-connect'); ?>
51
+                        </label>
52
+                    </fieldset>
53
+                    <fieldset>
54
+                        <label for="sync_fields_login">
55
+                            <input name="sync_fields[login]" type="hidden" value="0"/>
56
+                            <input name="sync_fields[login]" type="checkbox" id="sync_fields_login"
57
+                                   value="1" <?php if ($settings->get('sync_fields/login')): ?> checked<?php endif; ?> <?php echo $attr; ?>/>
58
+                            <?php _e('Login', 'nextend-facebook-connect'); ?>
59
+                        </label>
60
+                    </fieldset>
61
+                    <fieldset>
62
+                        <label for="sync_fields_link">
63
+                            <input name="sync_fields[link]" type="hidden" value="0"/>
64
+                            <input name="sync_fields[link]" type="checkbox" id="sync_fields_link"
65
+                                   value="1" <?php if ($settings->get('sync_fields/link')): ?> checked<?php endif; ?> <?php echo $attr; ?>/>
66
+                            <?php _e('Link', 'nextend-facebook-connect'); ?>
67
+                        </label>
68
+                    </fieldset>
69
+                </td>
70
+            </tr>
71
+            <?php
72
+
73
+            $syncFields = $provider->getSyncFields();
74
+            foreach ($syncFields AS $fieldName => $fieldData):
75
+                ?>
76
+                <tr>
77
+                    <th scope="row"><label for="sync_fields_locale"><?php echo $fieldData['label']; ?></label></th>
78
+                    <td>
79
+                        <fieldset>
80
+                            <label for="sync_fields_<?php echo $fieldName; ?>_enabled">
81
+                                <input name="sync_fields[fields][<?php echo $fieldName; ?>][enabled]" type="hidden" value="0" <?php echo $attr; ?>/>
82
+                                <input name="sync_fields[fields][<?php echo $fieldName; ?>][enabled]" type="checkbox" id="sync_fields_<?php echo $fieldName; ?>_enabled"
83
+                                       value="1" <?php if ($settings->get('sync_fields/fields/' . $fieldName . '/enabled')): ?> checked<?php endif; ?> <?php echo $attr; ?>/>
84
+                                <?php _e('Store in meta key', 'nextend-facebook-connect'); ?>
85
+                            </label>
86
+                            <input name="sync_fields[fields][<?php echo $fieldName; ?>][meta_key]" type="text" id="sync_fields_<?php echo $fieldName; ?>_meta_key"
87
+                                   value="<?php echo esc_attr($settings->get('sync_fields/fields/' . $fieldName . '/meta_key')); ?>" class="regular-text" <?php echo $attr; ?>/>
88
+                        </fieldset>
89
+                        <?php
90
+                        $description = $provider->getSyncDataFieldDescription($fieldName);
91
+                        ?>
92
+                        <?php if (!empty($description)): ?>
93
+                            <p class="description">
94
+                                <?php echo $description; ?>
95
+                            </p>
96
+                        <?php endif; ?>
97
+                    </td>
98
+                </tr>
99
+            <?php endforeach; ?>
100
+            </tbody>
101
+        </table>
102
+        <?php if ($isPRO): ?>
103
+            <p class="submit">
104
+                <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes'); ?>">
105
+            </p>
106
+        <?php endif; ?>
107
+    </form>
108
+</div>
109
+
110
+<script type="text/javascript">
111
+    (function ($) {
112
+
113
+        $(document).ready(function () {
114
+            var $checkboxes = $('input[type="checkbox"]');
115
+            $checkboxes.on('change', function (e) {
116
+                var $checkbox = $(this);
117
+                $checkbox.closest('td').toggleClass('nsl-admin-setting-disabled', !$checkbox.is(':checked'));
118
+            });
119
+
120
+            $checkboxes.each(function () {
121
+                var $checkbox = $(this);
122
+                $checkbox.closest('td').toggleClass('nsl-admin-setting-disabled', !$checkbox.is(':checked'));
123
+            });
124
+        });
125
+    })(jQuery);
126
+</script>

+ 47 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates-provider/usage.php

@@ -0,0 +1,47 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+/** @var $this NextendSocialProviderAdmin */
4
+
5
+$provider = $this->getProvider();
6
+?>
7
+<div class="nsl-admin-sub-content">
8
+
9
+    <h4><?php _e('Shortcode', 'nextend-facebook-connect'); ?></h4>
10
+
11
+    <p>
12
+        <b><?php _e('Important!', 'nextend-facebook-connect'); ?></b>
13
+        &nbsp;<?php _e('The shortcodes are only rendered for users who haven\'t logged in yet!', 'nextend-facebook-connect'); ?>
14
+        &nbsp;<a href="https://nextendweb.com/nextend-social-login-docs/theme-developer/#shortcode"><?php _e('See the full list of shortcode parameters.', 'nextend-facebook-connect'); ?></a>
15
+    </p>
16
+
17
+    <?php
18
+    $shortcodes = array(
19
+        '[nextend_social_login]',
20
+        '[nextend_social_login provider="' . $provider->getId() . '"]',
21
+        '[nextend_social_login provider="' . $provider->getId() . '" style="icon"]',
22
+        '[nextend_social_login provider="' . $provider->getId() . '" style="icon" redirect="https://nextendweb.com/"]',
23
+        '[nextend_social_login trackerdata="source"]'
24
+    );
25
+    ?>
26
+
27
+    <textarea readonly cols="160" rows="6" class="nextend-html-editor-readonly"
28
+              aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo implode("\n\n", $shortcodes); ?></textarea>
29
+
30
+
31
+    <h4><?php _e('Simple link', 'nextend-facebook-connect'); ?></h4>
32
+
33
+    <?php
34
+    $html = '<a href="' . $provider->getLoginUrl() . '" data-plugin="nsl" data-action="connect" data-redirect="current" data-provider="' . esc_attr($provider->getId()) . '" data-popupwidth="' . $provider->getPopupWidth() . '" data-popupheight="' . $provider->getPopupHeight() . '">' . "\n\t" . __('Click here to login or register', 'nextend-facebook-connect') . "\n" . '</a>';
35
+    ?>
36
+    <textarea readonly cols="160" rows="6" class="nextend-html-editor-readonly"
37
+              aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo esc_textarea($html); ?></textarea>
38
+
39
+    <h4><?php _e('Image button', 'nextend-facebook-connect'); ?></h4>
40
+
41
+    <?php
42
+    $html = '<a href="' . $provider->getLoginUrl() . '" data-plugin="nsl" data-action="connect" data-redirect="current" data-provider="' . esc_attr($provider->getId()) . '" data-popupwidth="' . $provider->getPopupWidth() . '" data-popupheight="' . $provider->getPopupHeight() . '">' . "\n\t" . '<img src="' . __('Image url', 'nextend-facebook-connect') . '" alt="" />' . "\n" . '</a>';
43
+    ?>
44
+    <textarea readonly cols="160" rows="6" class="nextend-html-editor-readonly"
45
+              aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo esc_textarea($html); ?></textarea>
46
+
47
+</div>

+ 66 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates/debug.php

@@ -0,0 +1,66 @@
1
+<div class="nsl-admin-content">
2
+    <style>
3
+        .nsl-admin-notices {
4
+            display: none;
5
+        }
6
+    </style>
7
+    <h1 class="title"><?php _e('Debug', 'nextend-facebook-connect'); ?></h1>
8
+    <?php
9
+
10
+
11
+    if (NextendSocialLoginAdmin::isPro()) {
12
+        $activation_data = NextendSocialLogin::getLicense();
13
+
14
+        $proAddonState = NextendSocialLoginAdmin::getProState();
15
+        echo "<p><b>Pro Addon State</b>: " . $proAddonState . "</p>";
16
+
17
+        echo "<p><b>Authorized Domain</b>: " . $activation_data['domain'] . "</p>";
18
+
19
+        $currentDomain = NextendSocialLogin::getDomain();
20
+        echo "<p><b>Current Domain</b>: " . $currentDomain . "</p><br>";
21
+
22
+        $licenseKey = substr($activation_data['license_key'], 0, 8);
23
+        echo "<p><b>License Key</b>: " . $licenseKey . "...</p>";
24
+
25
+        $isLicenseKeyOk = NextendSocialLogin::hasLicense();
26
+        echo "<p><b>License Key OK</b>: " . (boolval($isLicenseKeyOk) ? 'Yes' : 'No') . "</p><br>";
27
+    }
28
+
29
+    $defaultRedirect = NextendSocialLogin::$settings->get('default_redirect');
30
+    echo "<p><b>Default Redirect URL</b>: " . $defaultRedirect . "</p>";
31
+
32
+    $defaultRedirectReg = NextendSocialLogin::$settings->get('default_redirect_reg');
33
+    echo "<p><b>Default Reg Redirect URL</b>: " . $defaultRedirectReg . "</p><br>";
34
+
35
+    $fixRedirect = NextendSocialLogin::$settings->get('redirect');
36
+    echo "<p><b>Fix Redirect URL</b>: " . $fixRedirect . "</p>";
37
+
38
+    $fixRedirectReg = NextendSocialLogin::$settings->get('redirect_reg');
39
+    echo "<p><b>Fix Reg Redirect URL</b>: " . $fixRedirectReg . "</p><br>";
40
+
41
+    echo '<h1>' . __('Test network connection with providers', 'nextend-facebook-connect') . '</h1>';
42
+
43
+    if (!function_exists('curl_init')) {
44
+        ?>
45
+
46
+        <div class="error">
47
+            <p>
48
+                <?php _e('You don\'t have cURL support, please enable it in php.ini!', 'nextend-facebook-connect'); ?>
49
+            </p>
50
+        </div>
51
+
52
+        <?php
53
+    } else {
54
+        foreach (NextendSocialLogin::$allowedProviders AS $provider) {
55
+            ?>
56
+            <p>
57
+                <a target="_blank" href="<?php echo add_query_arg('provider', $provider->getId(), NextendSocialLoginAdmin::getAdminUrl('test-connection')); ?>" class="button button-primary">
58
+                    <?php printf(__('Test %1$s connection', 'nextend-facebook-connect'), $provider->getLabel()); ?>
59
+                </a>
60
+            </p>
61
+            <?php
62
+        }
63
+    }
64
+
65
+    ?>
66
+</div>

+ 40 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates/fix-redirect-uri.php

@@ -0,0 +1,40 @@
1
+<div class="nsl-admin-content">
2
+    <h1 class="title"><?php _e('Fix Oauth Redirect URIs', 'nextend-facebook-connect'); ?></h1>
3
+    <?php
4
+    /** @var NextendSocialProvider[] $wrongOauthProviders */
5
+    $wrongOauthProviders = array();
6
+    foreach (NextendSocialLogin::$enabledProviders AS $provider) {
7
+        if (!$provider->checkOauthRedirectUrl()) {
8
+            $wrongOauthProviders[] = $provider;
9
+        }
10
+    }
11
+    ?>
12
+
13
+    <div class="nsl-admin-fix-redirect-uri">
14
+        <?php
15
+        if (count($wrongOauthProviders) === 0) {
16
+            echo '<div class="updated"><p>' . __('Every Oauth Redirect URI seems fine', 'nextend-facebook-connect') . '</p></div>';
17
+
18
+            foreach (NextendSocialLogin::$enabledProviders AS $provider) {
19
+                $provider->getAdmin()
20
+                         ->renderOauthChangedInstruction();
21
+            }
22
+        } else {
23
+            ?>
24
+            <p><?php printf(__('%s detected that your login url changed. You must update the Oauth redirect URIs in the related social applications.', 'nextend-facebook-connect'), '<b>Nextend Social Login</b>'); ?></p>
25
+
26
+            <?php
27
+            foreach ($wrongOauthProviders AS $provider) {
28
+                $provider->getAdmin()
29
+                         ->renderOauthChangedInstruction();
30
+            }
31
+            ?>
32
+
33
+
34
+            <a href="<?php echo wp_nonce_url(NextendSocialLoginAdmin::getAdminUrl('update_oauth_redirect_url'), 'nextend-social-login_update_oauth_redirect_url'); ?>" class="button button-primary">
35
+                <?php _e('Got it', 'nextend-facebook-connect'); ?>
36
+            </a>
37
+
38
+        <?php } ?>
39
+    </div>
40
+</div>

+ 4 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates/footer.php

@@ -0,0 +1,4 @@
1
+<?php
2
+defined('ABSPATH') || die();
3
+?>
4
+</div>

+ 0 - 0
app/wp-content/plugins/nextend-facebook-connect/admin/templates/global-settings.php


Some files were not shown because too many files changed in this diff

tum/whitesports - Gogs: Simplico Git Service

Açıklama Yok

post.php 73KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  1. <?php
  2. /**
  3. * WordPress Post Administration API.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * Rename $_POST data from form names to DB post columns.
  10. *
  11. * Manipulates $_POST directly.
  12. *
  13. * @since 2.6.0
  14. *
  15. * @param bool $update Are we updating a pre-existing post?
  16. * @param array $post_data Array of post data. Defaults to the contents of $_POST.
  17. * @return array|WP_Error Array of post data on success, WP_Error on failure.
  18. */
  19. function _wp_translate_postdata( $update = false, $post_data = null ) {
  20. if ( empty( $post_data ) ) {
  21. $post_data = &$_POST;
  22. }
  23. if ( $update ) {
  24. $post_data['ID'] = (int) $post_data['post_ID'];
  25. }
  26. $ptype = get_post_type_object( $post_data['post_type'] );
  27. if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
  28. if ( 'page' === $post_data['post_type'] ) {
  29. return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
  30. } else {
  31. return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
  32. }
  33. } elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
  34. if ( 'page' === $post_data['post_type'] ) {
  35. return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
  36. } else {
  37. return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
  38. }
  39. }
  40. if ( isset( $post_data['content'] ) ) {
  41. $post_data['post_content'] = $post_data['content'];
  42. }
  43. if ( isset( $post_data['excerpt'] ) ) {
  44. $post_data['post_excerpt'] = $post_data['excerpt'];
  45. }
  46. if ( isset( $post_data['parent_id'] ) ) {
  47. $post_data['post_parent'] = (int) $post_data['parent_id'];
  48. }
  49. if ( isset( $post_data['trackback_url'] ) ) {
  50. $post_data['to_ping'] = $post_data['trackback_url'];
  51. }
  52. $post_data['user_ID'] = get_current_user_id();
  53. if ( ! empty( $post_data['post_author_override'] ) ) {
  54. $post_data['post_author'] = (int) $post_data['post_author_override'];
  55. } else {
  56. if ( ! empty( $post_data['post_author'] ) ) {
  57. $post_data['post_author'] = (int) $post_data['post_author'];
  58. } else {
  59. $post_data['post_author'] = (int) $post_data['user_ID'];
  60. }
  61. }
  62. if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
  63. && ! current_user_can( $ptype->cap->edit_others_posts ) ) {
  64. if ( $update ) {
  65. if ( 'page' === $post_data['post_type'] ) {
  66. return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
  67. } else {
  68. return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
  69. }
  70. } else {
  71. if ( 'page' === $post_data['post_type'] ) {
  72. return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
  73. } else {
  74. return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
  75. }
  76. }
  77. }
  78. if ( ! empty( $post_data['post_status'] ) ) {
  79. $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
  80. // No longer an auto-draft.
  81. if ( 'auto-draft' === $post_data['post_status'] ) {
  82. $post_data['post_status'] = 'draft';
  83. }
  84. if ( ! get_post_status_object( $post_data['post_status'] ) ) {
  85. unset( $post_data['post_status'] );
  86. }
  87. }
  88. // What to do based on which button they pressed.
  89. if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
  90. $post_data['post_status'] = 'draft';
  91. }
  92. if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
  93. $post_data['post_status'] = 'private';
  94. }
  95. if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
  96. && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
  97. ) {
  98. $post_data['post_status'] = 'publish';
  99. }
  100. if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
  101. $post_data['post_status'] = 'draft';
  102. }
  103. if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
  104. $post_data['post_status'] = 'pending';
  105. }
  106. if ( isset( $post_data['ID'] ) ) {
  107. $post_id = $post_data['ID'];
  108. } else {
  109. $post_id = false;
  110. }
  111. $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
  112. if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
  113. $post_data['post_status'] = $previous_status ? $previous_status : 'pending';
  114. }
  115. $published_statuses = array( 'publish', 'future' );
  116. // Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
  117. // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
  118. if ( isset( $post_data['post_status'] )
  119. && ( in_array( $post_data['post_status'], $published_statuses, true )
  120. && ! current_user_can( $ptype->cap->publish_posts ) )
  121. ) {
  122. if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
  123. $post_data['post_status'] = 'pending';
  124. }
  125. }
  126. if ( ! isset( $post_data['post_status'] ) ) {
  127. $post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status;
  128. }
  129. if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) {
  130. unset( $post_data['post_password'] );
  131. }
  132. if ( ! isset( $post_data['comment_status'] ) ) {
  133. $post_data['comment_status'] = 'closed';
  134. }
  135. if ( ! isset( $post_data['ping_status'] ) ) {
  136. $post_data['ping_status'] = 'closed';
  137. }
  138. foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
  139. if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] != $post_data[ $timeunit ] ) {
  140. $post_data['edit_date'] = '1';
  141. break;
  142. }
  143. }
  144. if ( ! empty( $post_data['edit_date'] ) ) {
  145. $aa = $post_data['aa'];
  146. $mm = $post_data['mm'];
  147. $jj = $post_data['jj'];
  148. $hh = $post_data['hh'];
  149. $mn = $post_data['mn'];
  150. $ss = $post_data['ss'];
  151. $aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
  152. $mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
  153. $jj = ( $jj > 31 ) ? 31 : $jj;
  154. $jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
  155. $hh = ( $hh > 23 ) ? $hh - 24 : $hh;
  156. $mn = ( $mn > 59 ) ? $mn - 60 : $mn;
  157. $ss = ( $ss > 59 ) ? $ss - 60 : $ss;
  158. $post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
  159. $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
  160. if ( ! $valid_date ) {
  161. return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
  162. }
  163. $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
  164. }
  165. if ( isset( $post_data['post_category'] ) ) {
  166. $category_object = get_taxonomy( 'category' );
  167. if ( ! current_user_can( $category_object->cap->assign_terms ) ) {
  168. unset( $post_data['post_category'] );
  169. }
  170. }
  171. return $post_data;
  172. }
  173. /**
  174. * Returns only allowed post data fields
  175. *
  176. * @since 5.0.1
  177. *
  178. * @param array $post_data Array of post data. Defaults to the contents of $_POST.
  179. * @return array|WP_Error Array of post data on success, WP_Error on failure.
  180. */
  181. function _wp_get_allowed_postdata( $post_data = null ) {
  182. if ( empty( $post_data ) ) {
  183. $post_data = $_POST;
  184. }
  185. // Pass through errors.
  186. if ( is_wp_error( $post_data ) ) {
  187. return $post_data;
  188. }
  189. return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
  190. }
  191. /**
  192. * Update an existing post with values provided in $_POST.
  193. *
  194. * If post data is passed as an argument, it is treated as an array of data
  195. * keyed appropriately for turning into a post object.
  196. *
  197. * If post data is not passed, the $_POST global variable is used instead.
  198. *
  199. * @since 1.5.0
  200. *
  201. * @global wpdb $wpdb WordPress database abstraction object.
  202. *
  203. * @param array $post_data Optional. Defaults to the $_POST global.
  204. * @return int Post ID.
  205. */
  206. function edit_post( $post_data = null ) {
  207. global $wpdb;
  208. if ( empty( $post_data ) ) {
  209. $post_data = &$_POST;
  210. }
  211. // Clear out any data in internal vars.
  212. unset( $post_data['filter'] );
  213. $post_ID = (int) $post_data['post_ID'];
  214. $post = get_post( $post_ID );
  215. $post_data['post_type'] = $post->post_type;
  216. $post_data['post_mime_type'] = $post->post_mime_type;
  217. if ( ! empty( $post_data['post_status'] ) ) {
  218. $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
  219. if ( 'inherit' === $post_data['post_status'] ) {
  220. unset( $post_data['post_status'] );
  221. }
  222. }
  223. $ptype = get_post_type_object( $post_data['post_type'] );
  224. if ( ! current_user_can( 'edit_post', $post_ID ) ) {
  225. if ( 'page' === $post_data['post_type'] ) {
  226. wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
  227. } else {
  228. wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  229. }
  230. }
  231. if ( post_type_supports( $ptype->name, 'revisions' ) ) {
  232. $revisions = wp_get_post_revisions(
  233. $post_ID,
  234. array(
  235. 'order' => 'ASC',
  236. 'posts_per_page' => 1,
  237. )
  238. );
  239. $revision = current( $revisions );
  240. // Check if the revisions have been upgraded.
  241. if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
  242. _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
  243. }
  244. }
  245. if ( isset( $post_data['visibility'] ) ) {
  246. switch ( $post_data['visibility'] ) {
  247. case 'public':
  248. $post_data['post_password'] = '';
  249. break;
  250. case 'password':
  251. unset( $post_data['sticky'] );
  252. break;
  253. case 'private':
  254. $post_data['post_status'] = 'private';
  255. $post_data['post_password'] = '';
  256. unset( $post_data['sticky'] );
  257. break;
  258. }
  259. }
  260. $post_data = _wp_translate_postdata( true, $post_data );
  261. if ( is_wp_error( $post_data ) ) {
  262. wp_die( $post_data->get_error_message() );
  263. }
  264. $translated = _wp_get_allowed_postdata( $post_data );
  265. // Post formats.
  266. if ( isset( $post_data['post_format'] ) ) {
  267. set_post_format( $post_ID, $post_data['post_format'] );
  268. }
  269. $format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
  270. foreach ( $format_meta_urls as $format_meta_url ) {
  271. $keyed = '_format_' . $format_meta_url;
  272. if ( isset( $post_data[ $keyed ] ) ) {
  273. update_post_meta( $post_ID, $keyed, wp_slash( esc_url_raw( wp_unslash( $post_data[ $keyed ] ) ) ) );
  274. }
  275. }
  276. $format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' );
  277. foreach ( $format_keys as $key ) {
  278. $keyed = '_format_' . $key;
  279. if ( isset( $post_data[ $keyed ] ) ) {
  280. if ( current_user_can( 'unfiltered_html' ) ) {
  281. update_post_meta( $post_ID, $keyed, $post_data[ $keyed ] );
  282. } else {
  283. update_post_meta( $post_ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );
  284. }
  285. }
  286. }
  287. if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) {
  288. $id3data = wp_get_attachment_metadata( $post_ID );
  289. if ( ! is_array( $id3data ) ) {
  290. $id3data = array();
  291. }
  292. foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
  293. if ( isset( $post_data[ 'id3_' . $key ] ) ) {
  294. $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
  295. }
  296. }
  297. wp_update_attachment_metadata( $post_ID, $id3data );
  298. }
  299. // Meta stuff.
  300. if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
  301. foreach ( $post_data['meta'] as $key => $value ) {
  302. $meta = get_post_meta_by_id( $key );
  303. if ( ! $meta ) {
  304. continue;
  305. }
  306. if ( $meta->post_id != $post_ID ) {
  307. continue;
  308. }
  309. if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $meta->meta_key ) ) {
  310. continue;
  311. }
  312. if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) ) {
  313. continue;
  314. }
  315. update_meta( $key, $value['key'], $value['value'] );
  316. }
  317. }
  318. if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
  319. foreach ( $post_data['deletemeta'] as $key => $value ) {
  320. $meta = get_post_meta_by_id( $key );
  321. if ( ! $meta ) {
  322. continue;
  323. }
  324. if ( $meta->post_id != $post_ID ) {
  325. continue;
  326. }
  327. if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) ) {
  328. continue;
  329. }
  330. delete_meta( $key );
  331. }
  332. }
  333. // Attachment stuff.
  334. if ( 'attachment' === $post_data['post_type'] ) {
  335. if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
  336. $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
  337. if ( get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) !== $image_alt ) {
  338. $image_alt = wp_strip_all_tags( $image_alt, true );
  339. // update_post_meta() expects slashed.
  340. update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
  341. }
  342. }
  343. $attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array();
  344. /** This filter is documented in wp-admin/includes/media.php */
  345. $translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
  346. }
  347. // Convert taxonomy input to term IDs, to avoid ambiguity.
  348. if ( isset( $post_data['tax_input'] ) ) {
  349. foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) {
  350. $tax_object = get_taxonomy( $taxonomy );
  351. if ( $tax_object && isset( $tax_object->meta_box_sanitize_cb ) ) {
  352. $translated['tax_input'][ $taxonomy ] = call_user_func_array( $tax_object->meta_box_sanitize_cb, array( $taxonomy, $terms ) );
  353. }
  354. }
  355. }
  356. add_meta( $post_ID );
  357. update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
  358. $success = wp_update_post( $translated );
  359. // If the save failed, see if we can sanity check the main fields and try again.
  360. if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
  361. $fields = array( 'post_title', 'post_content', 'post_excerpt' );
  362. foreach ( $fields as $field ) {
  363. if ( isset( $translated[ $field ] ) ) {
  364. $translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] );
  365. }
  366. }
  367. wp_update_post( $translated );
  368. }
  369. // Now that we have an ID we can fix any attachment anchor hrefs.
  370. _fix_attachment_links( $post_ID );
  371. wp_set_post_lock( $post_ID );
  372. if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
  373. if ( ! empty( $post_data['sticky'] ) ) {
  374. stick_post( $post_ID );
  375. } else {
  376. unstick_post( $post_ID );
  377. }
  378. }
  379. return $post_ID;
  380. }
  381. /**
  382. * Process the post data for the bulk editing of posts.
  383. *
  384. * Updates all bulk edited posts/pages, adding (but not removing) tags and
  385. * categories. Skips pages when they would be their own parent or child.
  386. *
  387. * @since 2.7.0
  388. *
  389. * @global wpdb $wpdb WordPress database abstraction object.
  390. *
  391. * @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal.
  392. * @return array
  393. */
  394. function bulk_edit_posts( $post_data = null ) {
  395. global $wpdb;
  396. if ( empty( $post_data ) ) {
  397. $post_data = &$_POST;
  398. }
  399. if ( isset( $post_data['post_type'] ) ) {
  400. $ptype = get_post_type_object( $post_data['post_type'] );
  401. } else {
  402. $ptype = get_post_type_object( 'post' );
  403. }
  404. if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
  405. if ( 'page' === $ptype->name ) {
  406. wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
  407. } else {
  408. wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
  409. }
  410. }
  411. if ( -1 == $post_data['_status'] ) {
  412. $post_data['post_status'] = null;
  413. unset( $post_data['post_status'] );
  414. } else {
  415. $post_data['post_status'] = $post_data['_status'];
  416. }
  417. unset( $post_data['_status'] );
  418. if ( ! empty( $post_data['post_status'] ) ) {
  419. $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
  420. if ( 'inherit' === $post_data['post_status'] ) {
  421. unset( $post_data['post_status'] );
  422. }
  423. }
  424. $post_IDs = array_map( 'intval', (array) $post_data['post'] );
  425. $reset = array(
  426. 'post_author',
  427. 'post_status',
  428. 'post_password',
  429. 'post_parent',
  430. 'page_template',
  431. 'comment_status',
  432. 'ping_status',
  433. 'keep_private',
  434. 'tax_input',
  435. 'post_category',
  436. 'sticky',
  437. 'post_format',
  438. );
  439. foreach ( $reset as $field ) {
  440. if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
  441. unset( $post_data[ $field ] );
  442. }
  443. }
  444. if ( isset( $post_data['post_category'] ) ) {
  445. if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) {
  446. $new_cats = array_map( 'absint', $post_data['post_category'] );
  447. } else {
  448. unset( $post_data['post_category'] );
  449. }
  450. }
  451. $tax_input = array();
  452. if ( isset( $post_data['tax_input'] ) ) {
  453. foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
  454. if ( empty( $terms ) ) {
  455. continue;
  456. }
  457. if ( is_taxonomy_hierarchical( $tax_name ) ) {
  458. $tax_input[ $tax_name ] = array_map( 'absint', $terms );
  459. } else {
  460. $comma = _x( ',', 'tag delimiter' );
  461. if ( ',' !== $comma ) {
  462. $terms = str_replace( $comma, ',', $terms );
  463. }
  464. $tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
  465. }
  466. }
  467. }
  468. if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
  469. $parent = (int) $post_data['post_parent'];
  470. $pages = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
  471. $children = array();
  472. for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
  473. $children[] = $parent;
  474. foreach ( $pages as $page ) {
  475. if ( (int) $page->ID === $parent ) {
  476. $parent = (int) $page->post_parent;
  477. break;
  478. }
  479. }
  480. }
  481. }
  482. $updated = array();
  483. $skipped = array();
  484. $locked = array();
  485. $shared_post_data = $post_data;
  486. foreach ( $post_IDs as $post_ID ) {
  487. // Start with fresh post data with each iteration.
  488. $post_data = $shared_post_data;
  489. $post_type_object = get_post_type_object( get_post_type( $post_ID ) );
  490. if ( ! isset( $post_type_object )
  491. || ( isset( $children ) && in_array( $post_ID, $children, true ) )
  492. || ! current_user_can( 'edit_post', $post_ID )
  493. ) {
  494. $skipped[] = $post_ID;
  495. continue;
  496. }
  497. if ( wp_check_post_lock( $post_ID ) ) {
  498. $locked[] = $post_ID;
  499. continue;
  500. }
  501. $post = get_post( $post_ID );
  502. $tax_names = get_object_taxonomies( $post );
  503. foreach ( $tax_names as $tax_name ) {
  504. $taxonomy_obj = get_taxonomy( $tax_name );
  505. if ( isset( $tax_input[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
  506. $new_terms = $tax_input[ $tax_name ];
  507. } else {
  508. $new_terms = array();
  509. }
  510. if ( $taxonomy_obj->hierarchical ) {
  511. $current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'ids' ) );
  512. } else {
  513. $current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'names' ) );
  514. }
  515. $post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
  516. }
  517. if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
  518. $cats = (array) wp_get_post_categories( $post_ID );
  519. $post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
  520. unset( $post_data['tax_input']['category'] );
  521. }
  522. $post_data['post_ID'] = $post_ID;
  523. $post_data['post_type'] = $post->post_type;
  524. $post_data['post_mime_type'] = $post->post_mime_type;
  525. foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
  526. if ( ! isset( $post_data[ $field ] ) ) {
  527. $post_data[ $field ] = $post->$field;
  528. }
  529. }
  530. $post_data = _wp_translate_postdata( true, $post_data );
  531. if ( is_wp_error( $post_data ) ) {
  532. $skipped[] = $post_ID;
  533. continue;
  534. }
  535. $post_data = _wp_get_allowed_postdata( $post_data );
  536. if ( isset( $shared_post_data['post_format'] ) ) {
  537. set_post_format( $post_ID, $shared_post_data['post_format'] );
  538. }
  539. // Prevent wp_insert_post() from overwriting post format with the old data.
  540. unset( $post_data['tax_input']['post_format'] );
  541. $updated[] = wp_update_post( $post_data );
  542. if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
  543. if ( 'sticky' === $post_data['sticky'] ) {
  544. stick_post( $post_ID );
  545. } else {
  546. unstick_post( $post_ID );
  547. }
  548. }
  549. }
  550. return array(
  551. 'updated' => $updated,
  552. 'skipped' => $skipped,
  553. 'locked' => $locked,
  554. );
  555. }
  556. /**
  557. * Default post information to use when populating the "Write Post" form.
  558. *
  559. * @since 2.0.0
  560. *
  561. * @param string $post_type Optional. A post type string. Default 'post'.
  562. * @param bool $create_in_db Optional. Whether to insert the post into database. Default false.
  563. * @return WP_Post Post object containing all the default post data as attributes
  564. */
  565. function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
  566. $post_title = '';
  567. if ( ! empty( $_REQUEST['post_title'] ) ) {
  568. $post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) );
  569. }
  570. $post_content = '';
  571. if ( ! empty( $_REQUEST['content'] ) ) {
  572. $post_content = esc_html( wp_unslash( $_REQUEST['content'] ) );
  573. }
  574. $post_excerpt = '';
  575. if ( ! empty( $_REQUEST['excerpt'] ) ) {
  576. $post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) );
  577. }
  578. if ( $create_in_db ) {
  579. $post_id = wp_insert_post(
  580. array(
  581. 'post_title' => __( 'Auto Draft' ),
  582. 'post_type' => $post_type,
  583. 'post_status' => 'auto-draft',
  584. ),
  585. false,
  586. false
  587. );
  588. $post = get_post( $post_id );
  589. if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
  590. set_post_format( $post, get_option( 'default_post_format' ) );
  591. }
  592. wp_after_insert_post( $post, false, null );
  593. // Schedule auto-draft cleanup.
  594. if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
  595. wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
  596. }
  597. } else {
  598. $post = new stdClass;
  599. $post->ID = 0;
  600. $post->post_author = '';
  601. $post->post_date = '';
  602. $post->post_date_gmt = '';
  603. $post->post_password = '';
  604. $post->post_name = '';
  605. $post->post_type = $post_type;
  606. $post->post_status = 'draft';
  607. $post->to_ping = '';
  608. $post->pinged = '';
  609. $post->comment_status = get_default_comment_status( $post_type );
  610. $post->ping_status = get_default_comment_status( $post_type, 'pingback' );
  611. $post->post_pingback = get_option( 'default_pingback_flag' );
  612. $post->post_category = get_option( 'default_category' );
  613. $post->page_template = 'default';
  614. $post->post_parent = 0;
  615. $post->menu_order = 0;
  616. $post = new WP_Post( $post );
  617. }
  618. /**
  619. * Filters the default post content initially used in the "Write Post" form.
  620. *
  621. * @since 1.5.0
  622. *
  623. * @param string $post_content Default post content.
  624. * @param WP_Post $post Post object.
  625. */
  626. $post->post_content = (string) apply_filters( 'default_content', $post_content, $post );
  627. /**
  628. * Filters the default post title initially used in the "Write Post" form.
  629. *
  630. * @since 1.5.0
  631. *
  632. * @param string $post_title Default post title.
  633. * @param WP_Post $post Post object.
  634. */
  635. $post->post_title = (string) apply_filters( 'default_title', $post_title, $post );
  636. /**
  637. * Filters the default post excerpt initially used in the "Write Post" form.
  638. *
  639. * @since 1.5.0
  640. *
  641. * @param string $post_excerpt Default post excerpt.
  642. * @param WP_Post $post Post object.
  643. */
  644. $post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post );
  645. return $post;
  646. }
  647. /**
  648. * Determines if a post exists based on title, content, date and type.
  649. *
  650. * @since 2.0.0
  651. * @since 5.2.0 Added the `$type` parameter.
  652. * @since 5.8.0 Added the `$status` parameter.
  653. *
  654. * @global wpdb $wpdb WordPress database abstraction object.
  655. *
  656. * @param string $title Post title.
  657. * @param string $content Optional post content.
  658. * @param string $date Optional post date.
  659. * @param string $type Optional post type.
  660. * @param string $status Optional post status.
  661. * @return int Post ID if post exists, 0 otherwise.
  662. */
  663. function post_exists( $title, $content = '', $date = '', $type = '', $status = '' ) {
  664. global $wpdb;
  665. $post_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
  666. $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
  667. $post_date = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
  668. $post_type = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
  669. $post_status = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) );
  670. $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
  671. $args = array();
  672. if ( ! empty( $date ) ) {
  673. $query .= ' AND post_date = %s';
  674. $args[] = $post_date;
  675. }
  676. if ( ! empty( $title ) ) {
  677. $query .= ' AND post_title = %s';
  678. $args[] = $post_title;
  679. }
  680. if ( ! empty( $content ) ) {
  681. $query .= ' AND post_content = %s';
  682. $args[] = $post_content;
  683. }
  684. if ( ! empty( $type ) ) {
  685. $query .= ' AND post_type = %s';
  686. $args[] = $post_type;
  687. }
  688. if ( ! empty( $status ) ) {
  689. $query .= ' AND post_status = %s';
  690. $args[] = $post_status;
  691. }
  692. if ( ! empty( $args ) ) {
  693. return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) );
  694. }
  695. return 0;
  696. }
  697. /**
  698. * Creates a new post from the "Write Post" form using $_POST information.
  699. *
  700. * @since 2.1.0
  701. *
  702. * @global WP_User $current_user
  703. *
  704. * @return int|WP_Error Post ID on success, WP_Error on failure.
  705. */
  706. function wp_write_post() {
  707. if ( isset( $_POST['post_type'] ) ) {
  708. $ptype = get_post_type_object( $_POST['post_type'] );
  709. } else {
  710. $ptype = get_post_type_object( 'post' );
  711. }
  712. if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
  713. if ( 'page' === $ptype->name ) {
  714. return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
  715. } else {
  716. return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
  717. }
  718. }
  719. $_POST['post_mime_type'] = '';
  720. // Clear out any data in internal vars.
  721. unset( $_POST['filter'] );
  722. // Edit, don't write, if we have a post ID.
  723. if ( isset( $_POST['post_ID'] ) ) {
  724. return edit_post();
  725. }
  726. if ( isset( $_POST['visibility'] ) ) {
  727. switch ( $_POST['visibility'] ) {
  728. case 'public':
  729. $_POST['post_password'] = '';
  730. break;
  731. case 'password':
  732. unset( $_POST['sticky'] );
  733. break;
  734. case 'private':
  735. $_POST['post_status'] = 'private';
  736. $_POST['post_password'] = '';
  737. unset( $_POST['sticky'] );
  738. break;
  739. }
  740. }
  741. $translated = _wp_translate_postdata( false );
  742. if ( is_wp_error( $translated ) ) {
  743. return $translated;
  744. }
  745. $translated = _wp_get_allowed_postdata( $translated );
  746. // Create the post.
  747. $post_ID = wp_insert_post( $translated );
  748. if ( is_wp_error( $post_ID ) ) {
  749. return $post_ID;
  750. }
  751. if ( empty( $post_ID ) ) {
  752. return 0;
  753. }
  754. add_meta( $post_ID );
  755. add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
  756. // Now that we have an ID we can fix any attachment anchor hrefs.
  757. _fix_attachment_links( $post_ID );
  758. wp_set_post_lock( $post_ID );
  759. return $post_ID;
  760. }
  761. /**
  762. * Calls wp_write_post() and handles the errors.
  763. *
  764. * @since 2.0.0
  765. *
  766. * @return int|void Post ID on success, void on failure.
  767. */
  768. function write_post() {
  769. $result = wp_write_post();
  770. if ( is_wp_error( $result ) ) {
  771. wp_die( $result->get_error_message() );
  772. } else {
  773. return $result;
  774. }
  775. }
  776. //
  777. // Post Meta.
  778. //
  779. /**
  780. * Add post meta data defined in $_POST superglobal for post with given ID.
  781. *
  782. * @since 1.2.0
  783. *
  784. * @param int $post_ID
  785. * @return int|bool
  786. */
  787. function add_meta( $post_ID ) {
  788. $post_ID = (int) $post_ID;
  789. $metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : '';
  790. $metakeyinput = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : '';
  791. $metavalue = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
  792. if ( is_string( $metavalue ) ) {
  793. $metavalue = trim( $metavalue );
  794. }
  795. if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
  796. /*
  797. * We have a key/value pair. If both the select and the input
  798. * for the key have data, the input takes precedence.
  799. */
  800. if ( '#NONE#' !== $metakeyselect ) {
  801. $metakey = $metakeyselect;
  802. }
  803. if ( $metakeyinput ) {
  804. $metakey = $metakeyinput; // Default.
  805. }
  806. if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) {
  807. return false;
  808. }
  809. $metakey = wp_slash( $metakey );
  810. return add_post_meta( $post_ID, $metakey, $metavalue );
  811. }
  812. return false;
  813. }
  814. /**
  815. * Delete post meta data by meta ID.
  816. *
  817. * @since 1.2.0
  818. *
  819. * @param int $mid
  820. * @return bool
  821. */
  822. function delete_meta( $mid ) {
  823. return delete_metadata_by_mid( 'post', $mid );
  824. }
  825. /**
  826. * Get a list of previously defined keys.
  827. *
  828. * @since 1.2.0
  829. *
  830. * @global wpdb $wpdb WordPress database abstraction object.
  831. *
  832. * @return mixed
  833. */
  834. function get_meta_keys() {
  835. global $wpdb;
  836. $keys = $wpdb->get_col(
  837. "
  838. SELECT meta_key
  839. FROM $wpdb->postmeta
  840. GROUP BY meta_key
  841. ORDER BY meta_key"
  842. );
  843. return $keys;
  844. }
  845. /**
  846. * Get post meta data by meta ID.
  847. *
  848. * @since 2.1.0
  849. *
  850. * @param int $mid
  851. * @return object|bool
  852. */
  853. function get_post_meta_by_id( $mid ) {
  854. return get_metadata_by_mid( 'post', $mid );
  855. }
  856. /**
  857. * Get meta data for the given post ID.
  858. *
  859. * @since 1.2.0
  860. *
  861. * @global wpdb $wpdb WordPress database abstraction object.
  862. *
  863. * @param int $postid
  864. * @return mixed
  865. */
  866. function has_meta( $postid ) {
  867. global $wpdb;
  868. return $wpdb->get_results(
  869. $wpdb->prepare(
  870. "SELECT meta_key, meta_value, meta_id, post_id
  871. FROM $wpdb->postmeta WHERE post_id = %d
  872. ORDER BY meta_key,meta_id",
  873. $postid
  874. ),
  875. ARRAY_A
  876. );
  877. }
  878. /**
  879. * Update post meta data by meta ID.
  880. *
  881. * @since 1.2.0
  882. *
  883. * @param int $meta_id
  884. * @param string $meta_key Expect Slashed
  885. * @param string $meta_value Expect Slashed
  886. * @return bool
  887. */
  888. function update_meta( $meta_id, $meta_key, $meta_value ) {
  889. $meta_key = wp_unslash( $meta_key );
  890. $meta_value = wp_unslash( $meta_value );
  891. return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key );
  892. }
  893. //
  894. // Private.
  895. //
  896. /**
  897. * Replace hrefs of attachment anchors with up-to-date permalinks.
  898. *
  899. * @since 2.3.0
  900. * @access private
  901. *
  902. * @param int|object $post Post ID or post object.
  903. * @return void|int|WP_Error Void if nothing fixed. 0 or WP_Error on update failure. The post ID on update success.
  904. */
  905. function _fix_attachment_links( $post ) {
  906. $post = get_post( $post, ARRAY_A );
  907. $content = $post['post_content'];
  908. // Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
  909. if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) {
  910. return;
  911. }
  912. // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero).
  913. if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
  914. return;
  915. }
  916. $site_url = get_bloginfo( 'url' );
  917. $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s).
  918. $replace = '';
  919. foreach ( $link_matches[1] as $key => $value ) {
  920. if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' )
  921. || ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
  922. || ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) {
  923. continue;
  924. }
  925. $quote = $url_match[1]; // The quote (single or double).
  926. $url_id = (int) $url_match[2];
  927. $rel_id = (int) $rel_match[1];
  928. if ( ! $url_id || ! $rel_id || $url_id != $rel_id || strpos( $url_match[0], $site_url ) === false ) {
  929. continue;
  930. }
  931. $link = $link_matches[0][ $key ];
  932. $replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
  933. $content = str_replace( $link, $replace, $content );
  934. }
  935. if ( $replace ) {
  936. $post['post_content'] = $content;
  937. // Escape data pulled from DB.
  938. $post = add_magic_quotes( $post );
  939. return wp_update_post( $post );
  940. }
  941. }
  942. /**
  943. * Get all the possible statuses for a post_type
  944. *
  945. * @since 2.5.0
  946. *
  947. * @param string $type The post_type you want the statuses for. Default 'post'.
  948. * @return string[] An array of all the statuses for the supplied post type.
  949. */
  950. function get_available_post_statuses( $type = 'post' ) {
  951. $stati = wp_count_posts( $type );
  952. return array_keys( get_object_vars( $stati ) );
  953. }
  954. /**
  955. * Run the wp query to fetch the posts for listing on the edit posts page
  956. *
  957. * @since 2.5.0
  958. *
  959. * @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
  960. * @return array
  961. */
  962. function wp_edit_posts_query( $q = false ) {
  963. if ( false === $q ) {
  964. $q = $_GET;
  965. }
  966. $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
  967. $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
  968. $post_stati = get_post_stati();
  969. if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {
  970. $post_type = $q['post_type'];
  971. } else {
  972. $post_type = 'post';
  973. }
  974. $avail_post_stati = get_available_post_statuses( $post_type );
  975. $post_status = '';
  976. $perm = '';
  977. if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati, true ) ) {
  978. $post_status = $q['post_status'];
  979. $perm = 'readable';
  980. }
  981. $orderby = '';
  982. if ( isset( $q['orderby'] ) ) {
  983. $orderby = $q['orderby'];
  984. } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {
  985. $orderby = 'modified';
  986. }
  987. $order = '';
  988. if ( isset( $q['order'] ) ) {
  989. $order = $q['order'];
  990. } elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {
  991. $order = 'ASC';
  992. }
  993. $per_page = "edit_{$post_type}_per_page";
  994. $posts_per_page = (int) get_user_option( $per_page );
  995. if ( empty( $posts_per_page ) || $posts_per_page < 1 ) {
  996. $posts_per_page = 20;
  997. }
  998. /**
  999. * Filters the number of items per page to show for a specific 'per_page' type.
  1000. *
  1001. * The dynamic portion of the hook name, `$post_type`, refers to the post type.
  1002. *
  1003. * Possible hook names include:
  1004. *
  1005. * - `edit_post_per_page`
  1006. * - `edit_page_per_page`
  1007. * - `edit_attachment_per_page`
  1008. *
  1009. * @since 3.0.0
  1010. *
  1011. * @param int $posts_per_page Number of posts to display per page for the given post
  1012. * type. Default 20.
  1013. */
  1014. $posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page );
  1015. /**
  1016. * Filters the number of posts displayed per page when specifically listing "posts".
  1017. *
  1018. * @since 2.8.0
  1019. *
  1020. * @param int $posts_per_page Number of posts to be displayed. Default 20.
  1021. * @param string $post_type The post type.
  1022. */
  1023. $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type );
  1024. $query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' );
  1025. // Hierarchical types require special args.
  1026. if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) {
  1027. $query['orderby'] = 'menu_order title';
  1028. $query['order'] = 'asc';
  1029. $query['posts_per_page'] = -1;
  1030. $query['posts_per_archive_page'] = -1;
  1031. $query['fields'] = 'id=>parent';
  1032. }
  1033. if ( ! empty( $q['show_sticky'] ) ) {
  1034. $query['post__in'] = (array) get_option( 'sticky_posts' );
  1035. }
  1036. wp( $query );
  1037. return $avail_post_stati;
  1038. }
  1039. /**
  1040. * Get the query variables for the current attachments request.
  1041. *
  1042. * @since 4.2.0
  1043. *
  1044. * @param array|false $q Optional. Array of query variables to use to build the query or false
  1045. * to use $_GET superglobal. Default false.
  1046. * @return array The parsed query vars.
  1047. */
  1048. function wp_edit_attachments_query_vars( $q = false ) {
  1049. if ( false === $q ) {
  1050. $q = $_GET;
  1051. }
  1052. $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
  1053. $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
  1054. $q['post_type'] = 'attachment';
  1055. $post_type = get_post_type_object( 'attachment' );
  1056. $states = 'inherit';
  1057. if ( current_user_can( $post_type->cap->read_private_posts ) ) {
  1058. $states .= ',private';
  1059. }
  1060. $q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
  1061. $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;
  1062. $media_per_page = (int) get_user_option( 'upload_per_page' );
  1063. if ( empty( $media_per_page ) || $media_per_page < 1 ) {
  1064. $media_per_page = 20;
  1065. }
  1066. /**
  1067. * Filters the number of items to list per page when listing media items.
  1068. *
  1069. * @since 2.9.0
  1070. *
  1071. * @param int $media_per_page Number of media to list. Default 20.
  1072. */
  1073. $q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
  1074. $post_mime_types = get_post_mime_types();
  1075. if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {
  1076. unset( $q['post_mime_type'] );
  1077. }
  1078. foreach ( array_keys( $post_mime_types ) as $type ) {
  1079. if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
  1080. $q['post_mime_type'] = $type;
  1081. break;
  1082. }
  1083. }
  1084. if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
  1085. $q['post_parent'] = 0;
  1086. }
  1087. if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
  1088. $q['author'] = get_current_user_id();
  1089. }
  1090. // Filter query clauses to include filenames.
  1091. if ( isset( $q['s'] ) ) {
  1092. add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
  1093. }
  1094. return $q;
  1095. }
  1096. /**
  1097. * Executes a query for attachments. An array of WP_Query arguments
  1098. * can be passed in, which will override the arguments set by this function.
  1099. *
  1100. * @since 2.5.0
  1101. *
  1102. * @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
  1103. * @return array
  1104. */
  1105. function wp_edit_attachments_query( $q = false ) {
  1106. wp( wp_edit_attachments_query_vars( $q ) );
  1107. $post_mime_types = get_post_mime_types();
  1108. $avail_post_mime_types = get_available_post_mime_types( 'attachment' );
  1109. return array( $post_mime_types, $avail_post_mime_types );
  1110. }
  1111. /**
  1112. * Returns the list of classes to be used by a meta box.
  1113. *
  1114. * @since 2.5.0
  1115. *
  1116. * @param string $box_id Meta box ID (used in the 'id' attribute for the meta box).
  1117. * @param string $screen_id The screen on which the meta box is shown.
  1118. * @return string Space-separated string of class names.
  1119. */
  1120. function postbox_classes( $box_id, $screen_id ) {
  1121. if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
  1122. $classes = array( '' );
  1123. } elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
  1124. $closed = get_user_option( 'closedpostboxes_' . $screen_id );
  1125. if ( ! is_array( $closed ) ) {
  1126. $classes = array( '' );
  1127. } else {
  1128. $classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
  1129. }
  1130. } else {
  1131. $classes = array( '' );
  1132. }
  1133. /**
  1134. * Filters the postbox classes for a specific screen and box ID combo.
  1135. *
  1136. * The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to
  1137. * the screen ID and meta box ID, respectively.
  1138. *
  1139. * @since 3.2.0
  1140. *
  1141. * @param string[] $classes An array of postbox classes.
  1142. */
  1143. $classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes );
  1144. return implode( ' ', $classes );
  1145. }
  1146. /**
  1147. * Get a sample permalink based off of the post name.
  1148. *
  1149. * @since 2.5.0
  1150. *
  1151. * @param int|WP_Post $id Post ID or post object.
  1152. * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
  1153. * @param string $name Optional. Name to override the post name. Default null.
  1154. * @return array {
  1155. * Array containing the sample permalink with placeholder for the post name, and the post name.
  1156. *
  1157. * @type string $0 The permalink with placeholder for the post name.
  1158. * @type string $1 The post name.
  1159. * }
  1160. */
  1161. function get_sample_permalink( $id, $title = null, $name = null ) {
  1162. $post = get_post( $id );
  1163. if ( ! $post ) {
  1164. return array( '', '' );
  1165. }
  1166. $ptype = get_post_type_object( $post->post_type );
  1167. $original_status = $post->post_status;
  1168. $original_date = $post->post_date;
  1169. $original_name = $post->post_name;
  1170. // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
  1171. if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
  1172. $post->post_status = 'publish';
  1173. $post->post_name = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
  1174. }
  1175. // If the user wants to set a new name -- override the current one.
  1176. // Note: if empty name is supplied -- use the title instead, see #6072.
  1177. if ( ! is_null( $name ) ) {
  1178. $post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
  1179. }
  1180. $post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
  1181. $post->filter = 'sample';
  1182. $permalink = get_permalink( $post, true );
  1183. // Replace custom post_type token with generic pagename token for ease of use.
  1184. $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
  1185. // Handle page hierarchy.
  1186. if ( $ptype->hierarchical ) {
  1187. $uri = get_page_uri( $post );
  1188. if ( $uri ) {
  1189. $uri = untrailingslashit( $uri );
  1190. $uri = strrev( stristr( strrev( $uri ), '/' ) );
  1191. $uri = untrailingslashit( $uri );
  1192. }
  1193. /** This filter is documented in wp-admin/edit-tag-form.php */
  1194. $uri = apply_filters( 'editable_slug', $uri, $post );
  1195. if ( ! empty( $uri ) ) {
  1196. $uri .= '/';
  1197. }
  1198. $permalink = str_replace( '%pagename%', "{$uri}%pagename%", $permalink );
  1199. }
  1200. /** This filter is documented in wp-admin/edit-tag-form.php */
  1201. $permalink = array( $permalink, apply_filters( 'editable_slug', $post->post_name, $post ) );
  1202. $post->post_status = $original_status;
  1203. $post->post_date = $original_date;
  1204. $post->post_name = $original_name;
  1205. unset( $post->filter );
  1206. /**
  1207. * Filters the sample permalink.
  1208. *
  1209. * @since 4.4.0
  1210. *
  1211. * @param array $permalink {
  1212. * Array containing the sample permalink with placeholder for the post name, and the post name.
  1213. *
  1214. * @type string $0 The permalink with placeholder for the post name.
  1215. * @type string $1 The post name.
  1216. * }
  1217. * @param int $post_id Post ID.
  1218. * @param string $title Post title.
  1219. * @param string $name Post name (slug).
  1220. * @param WP_Post $post Post object.
  1221. */
  1222. return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post );
  1223. }
  1224. /**
  1225. * Returns the HTML of the sample permalink slug editor.
  1226. *
  1227. * @since 2.5.0
  1228. *
  1229. * @param int $id Post ID or post object.
  1230. * @param string $new_title Optional. New title. Default null.
  1231. * @param string $new_slug Optional. New slug. Default null.
  1232. * @return string The HTML of the sample permalink slug editor.
  1233. */
  1234. function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
  1235. $post = get_post( $id );
  1236. if ( ! $post ) {
  1237. return '';
  1238. }
  1239. list($permalink, $post_name) = get_sample_permalink( $post->ID, $new_title, $new_slug );
  1240. $view_link = false;
  1241. $preview_target = '';
  1242. if ( current_user_can( 'read_post', $post->ID ) ) {
  1243. if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
  1244. $view_link = get_preview_post_link( $post );
  1245. $preview_target = " target='wp-preview-{$post->ID}'";
  1246. } else {
  1247. if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
  1248. $view_link = get_permalink( $post );
  1249. } else {
  1250. // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set.
  1251. $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
  1252. }
  1253. }
  1254. }
  1255. // Permalinks without a post/page name placeholder don't have anything to edit.
  1256. if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
  1257. $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
  1258. if ( false !== $view_link ) {
  1259. $display_link = urldecode( $view_link );
  1260. $return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n";
  1261. } else {
  1262. $return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
  1263. }
  1264. // Encourage a pretty permalink setting.
  1265. if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
  1266. && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
  1267. ) {
  1268. $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n";
  1269. }
  1270. } else {
  1271. if ( mb_strlen( $post_name ) > 34 ) {
  1272. $post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
  1273. } else {
  1274. $post_name_abridged = $post_name;
  1275. }
  1276. $post_name_html = '<span id="editable-post-name">' . esc_html( $post_name_abridged ) . '</span>';
  1277. $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, esc_html( urldecode( $permalink ) ) );
  1278. $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
  1279. $return .= '<span id="sample-permalink"><a href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a></span>\n";
  1280. $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
  1281. $return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __( 'Edit permalink' ) . '">' . __( 'Edit' ) . "</button></span>\n";
  1282. $return .= '<span id="editable-post-name-full">' . esc_html( $post_name ) . "</span>\n";
  1283. }
  1284. /**
  1285. * Filters the sample permalink HTML markup.
  1286. *
  1287. * @since 2.9.0
  1288. * @since 4.4.0 Added `$post` parameter.
  1289. *
  1290. * @param string $return Sample permalink HTML markup.
  1291. * @param int $post_id Post ID.
  1292. * @param string $new_title New sample permalink title.
  1293. * @param string $new_slug New sample permalink slug.
  1294. * @param WP_Post $post Post object.
  1295. */
  1296. $return = apply_filters( 'get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post );
  1297. return $return;
  1298. }
  1299. /**
  1300. * Returns HTML for the post thumbnail meta box.
  1301. *
  1302. * @since 2.9.0
  1303. *
  1304. * @param int $thumbnail_id ID of the attachment used for thumbnail
  1305. * @param int|WP_Post $post Optional. The post ID or object associated with the thumbnail, defaults to global $post.
  1306. * @return string The post thumbnail HTML.
  1307. */
  1308. function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
  1309. $_wp_additional_image_sizes = wp_get_additional_image_sizes();
  1310. $post = get_post( $post );
  1311. $post_type_object = get_post_type_object( $post->post_type );
  1312. $set_thumbnail_link = '<p class="hide-if-no-js"><a href="%s" id="set-post-thumbnail"%s class="thickbox">%s</a></p>';
  1313. $upload_iframe_src = get_upload_iframe_src( 'image', $post->ID );
  1314. $content = sprintf(
  1315. $set_thumbnail_link,
  1316. esc_url( $upload_iframe_src ),
  1317. '', // Empty when there's no featured image set, `aria-describedby` attribute otherwise.
  1318. esc_html( $post_type_object->labels->set_featured_image )
  1319. );
  1320. if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
  1321. $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
  1322. /**
  1323. * Filters the size used to display the post thumbnail image in the 'Featured image' meta box.
  1324. *
  1325. * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
  1326. * image size is registered, which differs from the 'thumbnail' image size
  1327. * managed via the Settings > Media screen.
  1328. *
  1329. * @since 4.4.0
  1330. *
  1331. * @param string|int[] $size Requested image size. Can be any registered image size name, or
  1332. * an array of width and height values in pixels (in that order).
  1333. * @param int $thumbnail_id Post thumbnail attachment ID.
  1334. * @param WP_Post $post The post object associated with the thumbnail.
  1335. */
  1336. $size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post );
  1337. $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size );
  1338. if ( ! empty( $thumbnail_html ) ) {
  1339. $content = sprintf(
  1340. $set_thumbnail_link,
  1341. esc_url( $upload_iframe_src ),
  1342. ' aria-describedby="set-post-thumbnail-desc"',
  1343. $thumbnail_html
  1344. );
  1345. $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>';
  1346. $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
  1347. }
  1348. }
  1349. $content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />';
  1350. /**
  1351. * Filters the admin post thumbnail HTML markup to return.
  1352. *
  1353. * @since 2.9.0
  1354. * @since 3.5.0 Added the `$post_id` parameter.
  1355. * @since 4.6.0 Added the `$thumbnail_id` parameter.
  1356. *
  1357. * @param string $content Admin post thumbnail HTML markup.
  1358. * @param int $post_id Post ID.
  1359. * @param int|null $thumbnail_id Thumbnail attachment ID, or null if there isn't one.
  1360. */
  1361. return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID, $thumbnail_id );
  1362. }
  1363. /**
  1364. * Check to see if the post is currently being edited by another user.
  1365. *
  1366. * @since 2.5.0
  1367. *
  1368. * @param int|WP_Post $post_id ID or object of the post to check for editing.
  1369. * @return int|false ID of the user with lock. False if the post does not exist, post is not locked,
  1370. * the user with lock does not exist, or the post is locked by current user.
  1371. */
  1372. function wp_check_post_lock( $post_id ) {
  1373. $post = get_post( $post_id );
  1374. if ( ! $post ) {
  1375. return false;
  1376. }
  1377. $lock = get_post_meta( $post->ID, '_edit_lock', true );
  1378. if ( ! $lock ) {
  1379. return false;
  1380. }
  1381. $lock = explode( ':', $lock );
  1382. $time = $lock[0];
  1383. $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
  1384. if ( ! get_userdata( $user ) ) {
  1385. return false;
  1386. }
  1387. /** This filter is documented in wp-admin/includes/ajax-actions.php */
  1388. $time_window = apply_filters( 'wp_check_post_lock_window', 150 );
  1389. if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
  1390. return $user;
  1391. }
  1392. return false;
  1393. }
  1394. /**
  1395. * Mark the post as currently being edited by the current user
  1396. *
  1397. * @since 2.5.0
  1398. *
  1399. * @param int|WP_Post $post_id ID or object of the post being edited.
  1400. * @return array|false Array of the lock time and user ID. False if the post does not exist, or
  1401. * there is no current user.
  1402. */
  1403. function wp_set_post_lock( $post_id ) {
  1404. $post = get_post( $post_id );
  1405. if ( ! $post ) {
  1406. return false;
  1407. }
  1408. $user_id = get_current_user_id();
  1409. if ( 0 == $user_id ) {
  1410. return false;
  1411. }
  1412. $now = time();
  1413. $lock = "$now:$user_id";
  1414. update_post_meta( $post->ID, '_edit_lock', $lock );
  1415. return array( $now, $user_id );
  1416. }
  1417. /**
  1418. * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
  1419. *
  1420. * @since 2.8.5
  1421. */
  1422. function _admin_notice_post_locked() {
  1423. $post = get_post();
  1424. if ( ! $post ) {
  1425. return;
  1426. }
  1427. $user = null;
  1428. $user_id = wp_check_post_lock( $post->ID );
  1429. if ( $user_id ) {
  1430. $user = get_userdata( $user_id );
  1431. }
  1432. if ( $user ) {
  1433. /**
  1434. * Filters whether to show the post locked dialog.
  1435. *
  1436. * Returning false from the filter will prevent the dialog from being displayed.
  1437. *
  1438. * @since 3.6.0
  1439. *
  1440. * @param bool $display Whether to display the dialog. Default true.
  1441. * @param WP_Post $post Post object.
  1442. * @param WP_User $user The user with the lock for the post.
  1443. */
  1444. if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
  1445. return;
  1446. }
  1447. $locked = true;
  1448. } else {
  1449. $locked = false;
  1450. }
  1451. $sendback = wp_get_referer();
  1452. if ( $locked && $sendback && false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
  1453. $sendback_text = __( 'Go back' );
  1454. } else {
  1455. $sendback = admin_url( 'edit.php' );
  1456. if ( 'post' !== $post->post_type ) {
  1457. $sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
  1458. }
  1459. $sendback_text = get_post_type_object( $post->post_type )->labels->all_items;
  1460. }
  1461. $hidden = $locked ? '' : ' hidden';
  1462. ?>
  1463. <div id="post-lock-dialog" class="notification-dialog-wrap<?php echo $hidden; ?>">
  1464. <div class="notification-dialog-background"></div>
  1465. <div class="notification-dialog">
  1466. <?php
  1467. if ( $locked ) {
  1468. $query_args = array();
  1469. if ( get_post_type_object( $post->post_type )->public ) {
  1470. if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
  1471. // Latest content is in autosave.
  1472. $nonce = wp_create_nonce( 'post_preview_' . $post->ID );
  1473. $query_args['preview_id'] = $post->ID;
  1474. $query_args['preview_nonce'] = $nonce;
  1475. }
  1476. }
  1477. $preview_link = get_preview_post_link( $post->ID, $query_args );
  1478. /**
  1479. * Filters whether to allow the post lock to be overridden.
  1480. *
  1481. * Returning false from the filter will disable the ability
  1482. * to override the post lock.
  1483. *
  1484. * @since 3.6.0
  1485. *
  1486. * @param bool $override Whether to allow the post lock to be overridden. Default true.
  1487. * @param WP_Post $post Post object.
  1488. * @param WP_User $user The user with the lock for the post.
  1489. */
  1490. $override = apply_filters( 'override_post_lock', true, $post, $user );
  1491. $tab_last = $override ? '' : ' wp-tab-last';
  1492. ?>
  1493. <div class="post-locked-message">
  1494. <div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div>
  1495. <p class="currently-editing wp-tab-first" tabindex="0">
  1496. <?php
  1497. if ( $override ) {
  1498. /* translators: %s: User's display name. */
  1499. printf( __( '%s is currently editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
  1500. } else {
  1501. /* translators: %s: User's display name. */
  1502. printf( __( '%s is currently editing this post.' ), esc_html( $user->display_name ) );
  1503. }
  1504. ?>
  1505. </p>
  1506. <?php
  1507. /**
  1508. * Fires inside the post locked dialog before the buttons are displayed.
  1509. *
  1510. * @since 3.6.0
  1511. * @since 5.4.0 The $user parameter was added.
  1512. *
  1513. * @param WP_Post $post Post object.
  1514. * @param WP_User $user The user with the lock for the post.
  1515. */
  1516. do_action( 'post_locked_dialog', $post, $user );
  1517. ?>
  1518. <p>
  1519. <a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a>
  1520. <?php if ( $preview_link ) { ?>
  1521. <a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e( 'Preview' ); ?></a>
  1522. <?php
  1523. }
  1524. // Allow plugins to prevent some users overriding the post lock.
  1525. if ( $override ) {
  1526. ?>
  1527. <a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a>
  1528. <?php
  1529. }
  1530. ?>
  1531. </p>
  1532. </div>
  1533. <?php
  1534. } else {
  1535. ?>
  1536. <div class="post-taken-over">
  1537. <div class="post-locked-avatar"></div>
  1538. <p class="wp-tab-first" tabindex="0">
  1539. <span class="currently-editing"></span><br />
  1540. <span class="locked-saving hidden"><img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" width="16" height="16" alt="" /> <?php _e( 'Saving revision&hellip;' ); ?></span>
  1541. <span class="locked-saved hidden"><?php _e( 'Your latest changes were saved as a revision.' ); ?></span>
  1542. </p>
  1543. <?php
  1544. /**
  1545. * Fires inside the dialog displayed when a user has lost the post lock.
  1546. *
  1547. * @since 3.6.0
  1548. *
  1549. * @param WP_Post $post Post object.
  1550. */
  1551. do_action( 'post_lock_lost_dialog', $post );
  1552. ?>
  1553. <p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a></p>
  1554. </div>
  1555. <?php
  1556. }
  1557. ?>
  1558. </div>
  1559. </div>
  1560. <?php
  1561. }
  1562. /**
  1563. * Creates autosave data for the specified post from $_POST data.
  1564. *
  1565. * @since 2.6.0
  1566. *
  1567. * @param array|int $post_data Associative array containing the post data or int post ID.
  1568. * @return int|WP_Error The autosave revision ID. WP_Error or 0 on error.
  1569. */
  1570. function wp_create_post_autosave( $post_data ) {
  1571. if ( is_numeric( $post_data ) ) {
  1572. $post_id = $post_data;
  1573. $post_data = $_POST;
  1574. } else {
  1575. $post_id = (int) $post_data['post_ID'];
  1576. }
  1577. $post_data = _wp_translate_postdata( true, $post_data );
  1578. if ( is_wp_error( $post_data ) ) {
  1579. return $post_data;
  1580. }
  1581. $post_data = _wp_get_allowed_postdata( $post_data );
  1582. $post_author = get_current_user_id();
  1583. // Store one autosave per author. If there is already an autosave, overwrite it.
  1584. $old_autosave = wp_get_post_autosave( $post_id, $post_author );
  1585. if ( $old_autosave ) {
  1586. $new_autosave = _wp_post_revision_data( $post_data, true );
  1587. $new_autosave['ID'] = $old_autosave->ID;
  1588. $new_autosave['post_author'] = $post_author;
  1589. $post = get_post( $post_id );
  1590. // If the new autosave has the same content as the post, delete the autosave.
  1591. $autosave_is_different = false;
  1592. foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
  1593. if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
  1594. $autosave_is_different = true;
  1595. break;
  1596. }
  1597. }
  1598. if ( ! $autosave_is_different ) {
  1599. wp_delete_post_revision( $old_autosave->ID );
  1600. return 0;
  1601. }
  1602. /**
  1603. * Fires before an autosave is stored.
  1604. *
  1605. * @since 4.1.0
  1606. *
  1607. * @param array $new_autosave Post array - the autosave that is about to be saved.
  1608. */
  1609. do_action( 'wp_creating_autosave', $new_autosave );
  1610. return wp_update_post( $new_autosave );
  1611. }
  1612. // _wp_put_post_revision() expects unescaped.
  1613. $post_data = wp_unslash( $post_data );
  1614. // Otherwise create the new autosave as a special post revision.
  1615. return _wp_put_post_revision( $post_data, true );
  1616. }
  1617. /**
  1618. * Saves a draft or manually autosaves for the purpose of showing a post preview.
  1619. *
  1620. * @since 2.7.0
  1621. *
  1622. * @return string URL to redirect to show the preview.
  1623. */
  1624. function post_preview() {
  1625. $post_ID = (int) $_POST['post_ID'];
  1626. $_POST['ID'] = $post_ID;
  1627. $post = get_post( $post_ID );
  1628. if ( ! $post ) {
  1629. wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  1630. }
  1631. if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1632. wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  1633. }
  1634. $is_autosave = false;
  1635. if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
  1636. && ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
  1637. ) {
  1638. $saved_post_id = edit_post();
  1639. } else {
  1640. $is_autosave = true;
  1641. if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) {
  1642. $_POST['post_status'] = 'draft';
  1643. }
  1644. $saved_post_id = wp_create_post_autosave( $post->ID );
  1645. }
  1646. if ( is_wp_error( $saved_post_id ) ) {
  1647. wp_die( $saved_post_id->get_error_message() );
  1648. }
  1649. $query_args = array();
  1650. if ( $is_autosave && $saved_post_id ) {
  1651. $query_args['preview_id'] = $post->ID;
  1652. $query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID );
  1653. if ( isset( $_POST['post_format'] ) ) {
  1654. $query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] );
  1655. }
  1656. if ( isset( $_POST['_thumbnail_id'] ) ) {
  1657. $query_args['_thumbnail_id'] = ( (int) $_POST['_thumbnail_id'] <= 0 ) ? '-1' : (int) $_POST['_thumbnail_id'];
  1658. }
  1659. }
  1660. return get_preview_post_link( $post, $query_args );
  1661. }
  1662. /**
  1663. * Save a post submitted with XHR
  1664. *
  1665. * Intended for use with heartbeat and autosave.js
  1666. *
  1667. * @since 3.9.0
  1668. *
  1669. * @param array $post_data Associative array of the submitted post data.
  1670. * @return mixed The value 0 or WP_Error on failure. The saved post ID on success.
  1671. * The ID can be the draft post_id or the autosave revision post_id.
  1672. */
  1673. function wp_autosave( $post_data ) {
  1674. // Back-compat.
  1675. if ( ! defined( 'DOING_AUTOSAVE' ) ) {
  1676. define( 'DOING_AUTOSAVE', true );
  1677. }
  1678. $post_id = (int) $post_data['post_id'];
  1679. $post_data['ID'] = $post_id;
  1680. $post_data['post_ID'] = $post_id;
  1681. if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) {
  1682. return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );
  1683. }
  1684. $post = get_post( $post_id );
  1685. if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1686. return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
  1687. }
  1688. if ( 'auto-draft' === $post->post_status ) {
  1689. $post_data['post_status'] = 'draft';
  1690. }
  1691. if ( 'page' !== $post_data['post_type'] && ! empty( $post_data['catslist'] ) ) {
  1692. $post_data['post_category'] = explode( ',', $post_data['catslist'] );
  1693. }
  1694. if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
  1695. && ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
  1696. ) {
  1697. // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
  1698. return edit_post( wp_slash( $post_data ) );
  1699. } else {
  1700. // Non-drafts or other users' drafts are not overwritten.
  1701. // The autosave is stored in a special post revision for each user.
  1702. return wp_create_post_autosave( wp_slash( $post_data ) );
  1703. }
  1704. }
  1705. /**
  1706. * Redirect to previous page.
  1707. *
  1708. * @since 2.7.0
  1709. *
  1710. * @param int $post_id Optional. Post ID.
  1711. */
  1712. function redirect_post( $post_id = '' ) {
  1713. if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
  1714. $status = get_post_status( $post_id );
  1715. if ( isset( $_POST['publish'] ) ) {
  1716. switch ( $status ) {
  1717. case 'pending':
  1718. $message = 8;
  1719. break;
  1720. case 'future':
  1721. $message = 9;
  1722. break;
  1723. default:
  1724. $message = 6;
  1725. }
  1726. } else {
  1727. $message = 'draft' === $status ? 10 : 1;
  1728. }
  1729. $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
  1730. } elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) {
  1731. $location = add_query_arg( 'message', 2, wp_get_referer() );
  1732. $location = explode( '#', $location );
  1733. $location = $location[0] . '#postcustom';
  1734. } elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) {
  1735. $location = add_query_arg( 'message', 3, wp_get_referer() );
  1736. $location = explode( '#', $location );
  1737. $location = $location[0] . '#postcustom';
  1738. } else {
  1739. $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
  1740. }
  1741. /**
  1742. * Filters the post redirect destination URL.
  1743. *
  1744. * @since 2.9.0
  1745. *
  1746. * @param string $location The destination URL.
  1747. * @param int $post_id The post ID.
  1748. */
  1749. wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
  1750. exit;
  1751. }
  1752. /**
  1753. * Sanitizes POST values from a checkbox taxonomy metabox.
  1754. *
  1755. * @since 5.1.0
  1756. *
  1757. * @param string $taxonomy The taxonomy name.
  1758. * @param array $terms Raw term data from the 'tax_input' field.
  1759. * @return int[] Array of sanitized term IDs.
  1760. */
  1761. function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
  1762. return array_map( 'intval', $terms );
  1763. }
  1764. /**
  1765. * Sanitizes POST values from an input taxonomy metabox.
  1766. *
  1767. * @since 5.1.0
  1768. *
  1769. * @param string $taxonomy The taxonomy name.
  1770. * @param array|string $terms Raw term data from the 'tax_input' field.
  1771. * @return array
  1772. */
  1773. function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
  1774. /*
  1775. * Assume that a 'tax_input' string is a comma-separated list of term names.
  1776. * Some languages may use a character other than a comma as a delimiter, so we standardize on
  1777. * commas before parsing the list.
  1778. */
  1779. if ( ! is_array( $terms ) ) {
  1780. $comma = _x( ',', 'tag delimiter' );
  1781. if ( ',' !== $comma ) {
  1782. $terms = str_replace( $comma, ',', $terms );
  1783. }
  1784. $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
  1785. }
  1786. $clean_terms = array();
  1787. foreach ( $terms as $term ) {
  1788. // Empty terms are invalid input.
  1789. if ( empty( $term ) ) {
  1790. continue;
  1791. }
  1792. $_term = get_terms(
  1793. array(
  1794. 'taxonomy' => $taxonomy,
  1795. 'name' => $term,
  1796. 'fields' => 'ids',
  1797. 'hide_empty' => false,
  1798. )
  1799. );
  1800. if ( ! empty( $_term ) ) {
  1801. $clean_terms[] = (int) $_term[0];
  1802. } else {
  1803. // No existing term was found, so pass the string. A new term will be created.
  1804. $clean_terms[] = $term;
  1805. }
  1806. }
  1807. return $clean_terms;
  1808. }
  1809. /**
  1810. * Return whether the post can be edited in the block editor.
  1811. *
  1812. * @since 5.0.0
  1813. *
  1814. * @param int|WP_Post $post Post ID or WP_Post object.
  1815. * @return bool Whether the post can be edited in the block editor.
  1816. */
  1817. function use_block_editor_for_post( $post ) {
  1818. $post = get_post( $post );
  1819. if ( ! $post ) {
  1820. return false;
  1821. }
  1822. // We're in the meta box loader, so don't use the block editor.
  1823. if ( isset( $_GET['meta-box-loader'] ) ) {
  1824. check_admin_referer( 'meta-box-loader', 'meta-box-loader-nonce' );
  1825. return false;
  1826. }
  1827. $use_block_editor = use_block_editor_for_post_type( $post->post_type );
  1828. /**
  1829. * Filters whether a post is able to be edited in the block editor.
  1830. *
  1831. * @since 5.0.0
  1832. *
  1833. * @param bool $use_block_editor Whether the post can be edited or not.
  1834. * @param WP_Post $post The post being checked.
  1835. */
  1836. return apply_filters( 'use_block_editor_for_post', $use_block_editor, $post );
  1837. }
  1838. /**
  1839. * Return whether a post type is compatible with the block editor.
  1840. *
  1841. * The block editor depends on the REST API, and if the post type is not shown in the
  1842. * REST API, then it won't work with the block editor.
  1843. *
  1844. * @since 5.0.0
  1845. *
  1846. * @param string $post_type The post type.
  1847. * @return bool Whether the post type can be edited with the block editor.
  1848. */
  1849. function use_block_editor_for_post_type( $post_type ) {
  1850. if ( ! post_type_exists( $post_type ) ) {
  1851. return false;
  1852. }
  1853. if ( ! post_type_supports( $post_type, 'editor' ) ) {
  1854. return false;
  1855. }
  1856. $post_type_object = get_post_type_object( $post_type );
  1857. if ( $post_type_object && ! $post_type_object->show_in_rest ) {
  1858. return false;
  1859. }
  1860. /**
  1861. * Filters whether a post is able to be edited in the block editor.
  1862. *
  1863. * @since 5.0.0
  1864. *
  1865. * @param bool $use_block_editor Whether the post type can be edited or not. Default true.
  1866. * @param string $post_type The post type being checked.
  1867. */
  1868. return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
  1869. }
  1870. /**
  1871. * Prepares server-registered blocks for the block editor.
  1872. *
  1873. * Returns an associative array of registered block data keyed by block name. Data includes properties
  1874. * of a block relevant for client registration.
  1875. *
  1876. * @since 5.0.0
  1877. *
  1878. * @return array An associative array of registered block data.
  1879. */
  1880. function get_block_editor_server_block_settings() {
  1881. $block_registry = WP_Block_Type_Registry::get_instance();
  1882. $blocks = array();
  1883. $fields_to_pick = array(
  1884. 'api_version' => 'apiVersion',
  1885. 'title' => 'title',
  1886. 'description' => 'description',
  1887. 'icon' => 'icon',
  1888. 'attributes' => 'attributes',
  1889. 'provides_context' => 'providesContext',
  1890. 'uses_context' => 'usesContext',
  1891. 'supports' => 'supports',
  1892. 'category' => 'category',
  1893. 'styles' => 'styles',
  1894. 'textdomain' => 'textdomain',
  1895. 'parent' => 'parent',
  1896. 'keywords' => 'keywords',
  1897. 'example' => 'example',
  1898. 'variations' => 'variations',
  1899. );
  1900. foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  1901. foreach ( $fields_to_pick as $field => $key ) {
  1902. if ( ! isset( $block_type->{ $field } ) ) {
  1903. continue;
  1904. }
  1905. if ( ! isset( $blocks[ $block_name ] ) ) {
  1906. $blocks[ $block_name ] = array();
  1907. }
  1908. $blocks[ $block_name ][ $key ] = $block_type->{ $field };
  1909. }
  1910. }
  1911. return $blocks;
  1912. }
  1913. /**
  1914. * Renders the meta boxes forms.
  1915. *
  1916. * @since 5.0.0
  1917. */
  1918. function the_block_editor_meta_boxes() {
  1919. global $post, $current_screen, $wp_meta_boxes;
  1920. // Handle meta box state.
  1921. $_original_meta_boxes = $wp_meta_boxes;
  1922. /**
  1923. * Fires right before the meta boxes are rendered.
  1924. *
  1925. * This allows for the filtering of meta box data, that should already be
  1926. * present by this point. Do not use as a means of adding meta box data.
  1927. *
  1928. * @since 5.0.0
  1929. *
  1930. * @param array $wp_meta_boxes Global meta box state.
  1931. */
  1932. $wp_meta_boxes = apply_filters( 'filter_block_editor_meta_boxes', $wp_meta_boxes );
  1933. $locations = array( 'side', 'normal', 'advanced' );
  1934. $priorities = array( 'high', 'sorted', 'core', 'default', 'low' );
  1935. // Render meta boxes.
  1936. ?>
  1937. <form class="metabox-base-form">
  1938. <?php the_block_editor_meta_box_post_form_hidden_fields( $post ); ?>
  1939. </form>
  1940. <form id="toggle-custom-fields-form" method="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>">
  1941. <?php wp_nonce_field( 'toggle-custom-fields', 'toggle-custom-fields-nonce' ); ?>
  1942. <input type="hidden" name="action" value="toggle-custom-fields" />
  1943. </form>
  1944. <?php foreach ( $locations as $location ) : ?>
  1945. <form class="metabox-location-<?php echo esc_attr( $location ); ?>" onsubmit="return false;">
  1946. <div id="poststuff" class="sidebar-open">
  1947. <div id="postbox-container-2" class="postbox-container">
  1948. <?php
  1949. do_meta_boxes(
  1950. $current_screen,
  1951. $location,
  1952. $post
  1953. );
  1954. ?>
  1955. </div>
  1956. </div>
  1957. </form>
  1958. <?php endforeach; ?>
  1959. <?php
  1960. $meta_boxes_per_location = array();
  1961. foreach ( $locations as $location ) {
  1962. $meta_boxes_per_location[ $location ] = array();
  1963. if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ] ) ) {
  1964. continue;
  1965. }
  1966. foreach ( $priorities as $priority ) {
  1967. if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ] ) ) {
  1968. continue;
  1969. }
  1970. $meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ];
  1971. foreach ( $meta_boxes as $meta_box ) {
  1972. if ( false == $meta_box || ! $meta_box['title'] ) {
  1973. continue;
  1974. }
  1975. // If a meta box is just here for back compat, don't show it in the block editor.
  1976. if ( isset( $meta_box['args']['__back_compat_meta_box'] ) && $meta_box['args']['__back_compat_meta_box'] ) {
  1977. continue;
  1978. }
  1979. $meta_boxes_per_location[ $location ][] = array(
  1980. 'id' => $meta_box['id'],
  1981. 'title' => $meta_box['title'],
  1982. );
  1983. }
  1984. }
  1985. }
  1986. /**
  1987. * Sadly we probably can not add this data directly into editor settings.
  1988. *
  1989. * Some meta boxes need admin_head to fire for meta box registry.
  1990. * admin_head fires after admin_enqueue_scripts, which is where we create our
  1991. * editor instance.
  1992. */
  1993. $script = 'window._wpLoadBlockEditor.then( function() {
  1994. wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' );
  1995. } );';
  1996. wp_add_inline_script( 'wp-edit-post', $script );
  1997. /**
  1998. * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed. Otherwise,
  1999. * meta boxes will not display because inline scripts for `wp-edit-post` will not be printed again after this point.
  2000. */
  2001. if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
  2002. printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) );
  2003. }
  2004. /**
  2005. * If the 'postcustom' meta box is enabled, then we need to perform some
  2006. * extra initialization on it.
  2007. */
  2008. $enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
  2009. if ( $enable_custom_fields ) {
  2010. $script = "( function( $ ) {
  2011. if ( $('#postcustom').length ) {
  2012. $( '#the-list' ).wpList( {
  2013. addBefore: function( s ) {
  2014. s.data += '&post_id=$post->ID';
  2015. return s;
  2016. },
  2017. addAfter: function() {
  2018. $('table#list-table').show();
  2019. }
  2020. });
  2021. }
  2022. } )( jQuery );";
  2023. wp_enqueue_script( 'wp-lists' );
  2024. wp_add_inline_script( 'wp-lists', $script );
  2025. }
  2026. // Reset meta box data.
  2027. $wp_meta_boxes = $_original_meta_boxes;
  2028. }
  2029. /**
  2030. * Renders the hidden form required for the meta boxes form.
  2031. *
  2032. * @since 5.0.0
  2033. *
  2034. * @param WP_Post $post Current post object.
  2035. */
  2036. function the_block_editor_meta_box_post_form_hidden_fields( $post ) {
  2037. $form_extra = '';
  2038. if ( 'auto-draft' === $post->post_status ) {
  2039. $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
  2040. }
  2041. $form_action = 'editpost';
  2042. $nonce_action = 'update-post_' . $post->ID;
  2043. $form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";
  2044. $referer = wp_get_referer();
  2045. $current_user = wp_get_current_user();
  2046. $user_id = $current_user->ID;
  2047. wp_nonce_field( $nonce_action );
  2048. /*
  2049. * Some meta boxes hook into these actions to add hidden input fields in the classic post form. For backwards
  2050. * compatibility, we can capture the output from these actions, and extract the hidden input fields.
  2051. */
  2052. ob_start();
  2053. /** This filter is documented in wp-admin/edit-form-advanced.php */
  2054. do_action( 'edit_form_after_title', $post );
  2055. /** This filter is documented in wp-admin/edit-form-advanced.php */
  2056. do_action( 'edit_form_advanced', $post );
  2057. $classic_output = ob_get_clean();
  2058. $classic_elements = wp_html_split( $classic_output );
  2059. $hidden_inputs = '';
  2060. foreach ( $classic_elements as $element ) {
  2061. if ( 0 !== strpos( $element, '<input ' ) ) {
  2062. continue;
  2063. }
  2064. if ( preg_match( '/\stype=[\'"]hidden[\'"]\s/', $element ) ) {
  2065. echo $element;
  2066. }
  2067. }
  2068. ?>
  2069. <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" />
  2070. <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
  2071. <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
  2072. <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post->post_type ); ?>" />
  2073. <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />
  2074. <input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
  2075. <?php
  2076. if ( 'draft' !== get_post_status( $post ) ) {
  2077. wp_original_referer_field( true, 'previous' );
  2078. }
  2079. echo $form_extra;
  2080. wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
  2081. wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
  2082. // Permalink title nonce.
  2083. wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
  2084. /**
  2085. * Add hidden input fields to the meta box save form.
  2086. *
  2087. * Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to
  2088. * the server when meta boxes are saved.
  2089. *
  2090. * @since 5.0.0
  2091. *
  2092. * @param WP_Post $post The post that is being edited.
  2093. */
  2094. do_action( 'block_editor_meta_box_hidden_fields', $post );
  2095. }