PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 120213
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v120213
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / classes / meta-box-saves.inc.php

meta-box-saves.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 120213, at includes/classes/meta-box-saves.inc.php

148 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Meta box saves.
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\Meta_Boxes
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_meta_box_saves"))
21 {
22 /**
23 * Meta box saves.
24 *
25 * @package s2Member\Meta_Boxes
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_meta_box_saves
29 {
30 /**
31 * Saves data entered into meta boxes on Post/Page editing stations.
32 *
33 * @package s2Member\Meta_Boxes
34 * @since 3.5
35 *
36 * @attaches-to ``add_action("save_post");``
37 *
38 * @param int|str $post_id Numeric Post/Page ID.
39 * @return null
40 */
41 public static function save_meta_boxes ($post_id = FALSE)
42 {
43 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
44 do_action ("ws_plugin__s2member_before_save_meta_boxes", get_defined_vars ());
45 unset ($__refs, $__v); /* Unset defined __refs, __v. */
46 /**/
47 if ($post_id && !empty ($_POST["ws_plugin__s2member_security_meta_box_save"]) && ($nonce = $_POST["ws_plugin__s2member_security_meta_box_save"]) && wp_verify_nonce ($nonce, "ws-plugin--s2member-security-meta-box-save"))
48 if (!empty ($_POST["ws_plugin__s2member_security_meta_box_save_id"]) && $post_id == $_POST["ws_plugin__s2member_security_meta_box_save_id"] && !empty ($_POST["post_type"]))
49 /* We do NOT process historical revisions here; because it causes confusion in the General Options panel for s2Member. */
50 {
51 $_p = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST)); /* Clean and create a local copy. */
52 /**/
53 if (($_p["post_type"] === "page" && current_user_can ("edit_page", $post_id)) || current_user_can ("edit_post", $post_id))
54 {
55 if ($_p["post_type"] === "page" && ($page_id = $post_id)) /* OK. So we're dealing with a Page classification. */
56 {
57 if (isset ($_p["ws_plugin__s2member_security_meta_box_level"])) /* CAN be empty. */
58 {
59 for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
60 $pages[$n] = array_unique (preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_pages"]));
61 /**/
62 for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
63 $posts[$n] = array_unique (preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_posts"]));
64 /**/
65 for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
66 if (($i = array_search ($page_id, $pages[$n])) !== false)
67 unset($pages[$n][$i]);
68 /**/
69 if (isset ($pages[$_p["ws_plugin__s2member_security_meta_box_level"]]) && is_array ($pages[$_p["ws_plugin__s2member_security_meta_box_level"]]))
70 if ($pages[$_p["ws_plugin__s2member_security_meta_box_level"]] !== array ("all")&& !in_array ("all-pages", $posts[$_p["ws_plugin__s2member_security_meta_box_level"]]))
71 array_push ($pages[$_p["ws_plugin__s2member_security_meta_box_level"]], (string)$page_id);
72 /**/
73 for ($n = 0, $new_options = array (); $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
74 $new_options = array_merge ($new_options, array ("ws_plugin__s2member_level" . $n . "_pages" => trim (implode (",", $pages[$n]))));
75 /**/
76 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
77 do_action ("ws_plugin__s2member_during_save_meta_boxes", get_defined_vars ());
78 unset ($__refs, $__v); /* Unset defined __refs, __v. */
79 /**/
80 c_ws_plugin__s2member_menu_pages::update_all_options ($new_options, true, false, array ("page-conflict-warnings"), true);
81 }
82 }
83 /**/
84 else /* Otherwise, we assume this is a Post, or possibly a Custom Post Type. It's NOT a Page. */
85 {
86 if (isset ($_p["ws_plugin__s2member_security_meta_box_level"])) /* CAN be empty. */
87 {
88 for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
89 $posts[$n] = array_unique (preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_posts"]));
90 /**/
91 for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
92 if (($i = array_search ($post_id, $posts[$n])) !== false)
93 unset($posts[$n][$i]);
94 /**/
95 if (isset ($posts[$_p["ws_plugin__s2member_security_meta_box_level"]]) && is_array ($posts[$_p["ws_plugin__s2member_security_meta_box_level"]]))
96 if ($posts[$_p["ws_plugin__s2member_security_meta_box_level"]] !== array ("all")&& !in_array ("all-" . $_p["post_type"] . "s", $posts[$_p["ws_plugin__s2member_security_meta_box_level"]]))
97 array_push ($posts[$_p["ws_plugin__s2member_security_meta_box_level"]], (string)$post_id);
98 /**/
99 for ($n = 0, $new_options = array (); $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++)
100 $new_options = array_merge ($new_options, array ("ws_plugin__s2member_level" . $n . "_posts" => trim (implode (",", $posts[$n]))));
101 /**/
102 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
103 do_action ("ws_plugin__s2member_during_save_meta_boxes", get_defined_vars ());
104 unset ($__refs, $__v); /* Unset defined __refs, __v. */
105 /**/
106 c_ws_plugin__s2member_menu_pages::update_all_options ($new_options, true, false, array ("page-conflict-warnings"), true);
107 }
108 }
109 /**/
110 if ($_p["post_type"] === "page" && ($page_id = $post_id)) /* OK. So we're dealing with a Page classification. */
111 {
112 if (isset ($_p["ws_plugin__s2member_security_meta_box_ccaps"])) /* CAN be empty. */
113 {
114 $ccaps_req = trim (strtolower ($_p["ws_plugin__s2member_security_meta_box_ccaps"]), ",");
115 $ccaps_req = trim (preg_replace ("/[^a-z_0-9,]/", "", $ccaps_req), ",");
116 /**/
117 if (strlen ($ccaps_req) && ($s2member_ccaps_req = preg_split ("/[\r\n\t\s;,]+/", $ccaps_req)))
118 update_post_meta ($page_id, "s2member_ccaps_req", $s2member_ccaps_req);
119 /**/
120 else /* Otherwise, the array is empty. Safe to delete. */
121 delete_post_meta ($page_id, "s2member_ccaps_req");
122 }
123 }
124 /**/
125 else /* Otherwise, we assume this is a Post, or possibly a Custom Post Type. It's NOT a Page. */
126 {
127 if (isset ($_p["ws_plugin__s2member_security_meta_box_ccaps"])) /* CAN be empty. */
128 {
129 $ccaps_req = trim (strtolower ($_p["ws_plugin__s2member_security_meta_box_ccaps"]), ",");
130 $ccaps_req = trim (preg_replace ("/[^a-z_0-9,]/", "", $ccaps_req), ",");
131 /**/
132 if (strlen ($ccaps_req) && ($s2member_ccaps_req = preg_split ("/[\r\n\t\s;,]+/", $ccaps_req)))
133 update_post_meta ($post_id, "s2member_ccaps_req", $s2member_ccaps_req);
134 /**/
135 else /* Otherwise, the array is empty. Safe to delete. */
136 delete_post_meta ($post_id, "s2member_ccaps_req");
137 }
138 }
139 }
140 }
141 /**/
142 do_action ("ws_plugin__s2member_after_save_meta_boxes", get_defined_vars ());
143 /**/
144 return; /* Return for uniformity. */
145 }
146 }
147 }
148 ?>