There is no code right now. I wasn’t sure which function would handle it and am not that familiar with using hooks (and also not sure which class controls that). So I removed the function until I can figure it out. Here’s the function that updates the posts in options, though…
<?php
add_action('save_post', 'protect_post');
add_action('delete_post', 'protect_post');
function protect_post($post_id) {
global $wpdb;
global $post;
if ($post->post_type == "property") {
$customFields = get_fields();
$sql = "SELECT * FROM wp_protected WHERE post_id = ".$post_id;
$protected = $wpdb->get_row($sql);
if (empty($protected)) { // post doesn't exist
if ($customFields['property_mark_free'] != 1) {
$data=array('post_id' => $post_id);
$wpdb->insert('wp_protected', $data);
}
} else { // post already exists
if (($customFields['property_mark_free'] == 1) || ($post->post_status != "publish")) {
$wpdb->delete( 'wp_protected', array( 'post_id' => $post_id ) );
}
}
$sql = "SELECT * FROM wp_protected ORDER BY `post_id` ASC";
$protects = $wpdb->get_results($sql, ARRAY_A);
if (count($protects) < 1) {
$protectedPosts = '';
} elseif (count($protects) == 1) {
$protectedPosts = $protects[0]['post_id'];
} elseif (count($protects) > 1) {
$protectedPosts = $protects[0]['post_id'];
$counter=1;
while (count($protects) > $counter) {
$protectedPosts .= ','.$protects[$counter]['post_id'];
$counter++;
}
}
$s2memberOptions = "a:211:{s:16:\"options_checksum\";s:32:\"de8ee91ab82783ea74eec5369fd7b206\";s:15:\"options_version\";s:5:\"1.002\";s:18:\"gateway_debug_logs\";s:1:\"0\";s:28:\"gateway_debug_logs_extensive\";s:1:\"0\";s:16:\"lazy_load_css_js\";s:1:\"0\";s:28:\"sc_conds_allow_arbitrary_php\";s:1:\"0\";s:18:\"sec_encryption_key\";s:0:\"\";s:26:\"sec_encryption_key_history\";a:0:{}s:24:\"def_combo_encryption_key\";s:0:\"\";s:32:\"def_combo_encryption_key_history\";a:0:{}s:32:\"def_custom_combo_encryption_keys\";a:0:{}s:22:\"s_badge_status_enabled\";s:1:\"0\";s:18:\"max_ip_restriction\";s:1:\"5\";s:23:\"max_ip_restriction_time\";s:4:\"3600\";s:25:\"max_failed_login_attempts\";s:1:\"5\";s:23:\"max_simultaneous_logins\";s:1:\"0\";s:31:\"max_simultaneous_logins_timeout\";s:10:\"30 minutes\";s:22:\"run_uninstall_routines\";s:1:\"0\";s:17:\"custom_reg_fields\";s:0:\"\";s:16:\"custom_reg_names\";s:1:\"1\";s:23:\"custom_reg_display_name\";s:4:\"full\";s:19:\"custom_reg_password\";s:1:\"0\";s:30:\"custom_reg_password_min_length\";s:1:\"8\";s:32:\"custom_reg_password_min_strength\";s:4:\"good\";s:17:\"custom_reg_opt_in\";s:1:\"1\";s:23:\"custom_reg_opt_in_label\";s:41:\"Yes, I want to receive updates via email.\";s:24:\"custom_reg_auto_opt_outs\";a:0:{}s:35:\"custom_reg_auto_opt_out_transitions\";s:1:\"0\";s:21:\"custom_reg_fields_4bp\";a:0:{}s:32:\"custom_reg_force_personal_emails\";s:0:\"\";s:20:\"allow_subscribers_in\";s:1:\"0\";s:20:\"force_admin_lockouts\";s:1:\"0\";s:15:\"filter_wp_query\";a:1:{i:0;s:3:\"all\";}s:21:\"default_url_shortener\";s:8:\"tiny_url\";s:25:\"default_url_shortener_key\";s:0:\"\";s:32:\"default_custom_str_url_shortener\";s:0:\"\";s:14:\"mms_auto_patch\";s:1:\"1\";s:21:\"mms_registration_file\";s:8:\"wp-login\";s:23:\"mms_registration_grants\";s:4:\"none\";s:29:\"mms_registration_blogs_level0\";s:1:\"0\";s:29:\"mms_registration_blogs_level1\";s:1:\"5\";s:29:\"mms_registration_blogs_level2\";s:2:\"10\";s:29:\"mms_registration_blogs_level3\";s:2:\"15\";s:29:\"mms_registration_blogs_level4\";s:2:\"20\";s:18:\"login_welcome_page\";s:0:\"\";s:26:\"login_redirection_override\";s:0:\"\";s:23:\"membership_options_page\";s:3:\"922\";s:35:\"membership_options_page_vars_enable\";s:1:\"1\";s:38:\"membership_options_page_ga_vars_enable\";s:1:\"1\";s:24:\"login_reg_design_enabled\";s:1:\"1\";s:26:\"login_reg_background_color\";s:6:\"FFFFFF\";s:26:\"login_reg_background_image\";s:66:\"https://gf.tjohns.co/wp-content/plugins/s2member/src/images/bg.png\";s:33:\"login_reg_background_image_repeat\";s:6:\"repeat\";s:31:\"login_reg_background_text_color\";s:6:\"000000\";s:38:\"login_reg_background_text_shadow_color\";s:6:\"EEEEEE\";s:37:\"login_reg_background_box_shadow_color\";s:6:\"EEEEEE\";s:18:\"login_reg_logo_src\";s:68:\"https://gf.tjohns.co/wp-content/plugins/s2member/src/images/logo.png\";s:24:\"login_reg_logo_src_width\";s:3:\"550\";s:25:\"login_reg_logo_src_height\";s:3:\"100\";s:18:\"login_reg_logo_url\";s:21:\"https://gf.tjohns.co/\";s:20:\"login_reg_logo_title\";s:26:\"Great Fixer in Los Angeles\";s:19:\"login_reg_font_size\";s:4:\"12px\";s:21:\"login_reg_font_family\";s:30:\"'Verdana', 'Arial', sans-serif\";s:25:\"login_reg_font_field_size\";s:4:\"18px\";s:27:\"login_reg_footer_backtoblog\";s:1:\"0\";s:23:\"login_reg_footer_design\";s:0:\"\";s:19:\"reg_email_from_name\";s:26:\"Great Fixer in Los Angeles\";s:20:\"reg_email_from_email\";s:22:\"contact@greatfixer.com\";s:22:\"reg_email_support_link\";s:29:\"mailto:contact@greatfixer.com\";s:23:\"new_user_emails_enabled\";s:1:\"0\";s:22:\"new_user_email_subject\";s:46:\"[Great Fixer in Los Angeles] Username/Password\";s:22:\"new_user_email_message\";s:147:\"Your Username/Password for:
Great Fixer in Los Angeles
Username: %%user_login%%
To set your password, visit: %%wp_set_pass_url%%
%%wp_login_url%%\";s:31:\"new_user_admin_email_recipients\";s:22:\"contact@greatfixer.com\";s:28:\"new_user_admin_email_subject\";s:50:\"[Great Fixer in Los Angeles] New User Registration\";s:28:\"new_user_admin_email_message\";s:155:\"New User Registration on your site:
Great Fixer in Los Angeles
User ID: %%user_id%%
Username: %%user_login%%
Email: %%user_email%%
IP Address: %%user_ip%%\";s:14:\"paypal_sandbox\";s:1:\"0\";s:15:\"paypal_business\";s:0:\"\";s:18:\"paypal_merchant_id\";s:0:\"\";s:19:\"paypal_api_username\";s:0:\"\";s:19:\"paypal_api_password\";s:0:\"\";s:20:\"paypal_api_signature\";s:0:\"\";s:21:\"paypal_identity_token\";s:0:\"\";s:21:\"paypal_btn_encryption\";s:1:\"1\";s:27:\"paypal_payflow_api_username\";s:0:\"\";s:26:\"paypal_payflow_api_partner\";s:6:\"PayPal\";s:25:\"paypal_payflow_api_vendor\";s:0:\"\";s:27:\"paypal_payflow_api_password\";s:0:\"\";s:21:\"signup_tracking_codes\";s:0:\"\";s:27:\"modification_tracking_codes\";s:0:\"\";s:19:\"ccap_tracking_codes\";s:0:\"\";s:17:\"sp_tracking_codes\";s:0:\"\";s:23:\"signup_email_recipients\";s:33:\"\"%%full_name%%\" <%%payer_email%%>\";s:20:\"signup_email_subject\";s:52:\"Congratulations! (your membership has been approved)\";s:20:\"signup_email_message\";s:286:\"Thanks %%first_name%%! Your membership has been approved.
If you haven't already done so, the next step is to Register a Username.
Complete your registration here:
%%registration_url%%
If you have any trouble, please feel free to contact us.
Best Regards,
Great Fixer in Los Angeles\";s:29:\"modification_email_recipients\";s:33:\"\"%%full_name%%\" <%%payer_email%%>\";s:26:\"modification_email_subject\";s:41:\"Thank you! Your account has been updated.\";s:26:\"modification_email_message\";s:169:\"Thanks %%first_name%%! Your account now has access to: %%item_name%%.
If you have any trouble, please feel free to contact us.
Best Regards,
Great Fixer in Los Angeles\";s:21:\"ccap_email_recipients\";s:33:\"\"%%full_name%%\" <%%payer_email%%>\";s:18:\"ccap_email_subject\";s:41:\"Thank you! Your account has been updated.\";s:18:\"ccap_email_message\";s:169:\"Thanks %%first_name%%! Your account now has access to: %%item_name%%.
If you have any trouble, please feel free to contact us.
Best Regards,
Great Fixer in Los Angeles\";s:19:\"sp_email_recipients\";s:33:\"\"%%full_name%%\" <%%payer_email%%>\";s:16:\"sp_email_subject\";s:36:\"Thank You! (instructions for access)\";s:16:\"sp_email_message\";s:226:\"Thanks %%first_name%%!
%%item_name%%
Your order can be retrieved here:
%%sp_access_url%%
(link expires in %%sp_access_exp%%)
If you have any trouble, please feel free to contact us.
Best Regards,
Great Fixer in Los Angeles\";s:17:\"mailchimp_api_key\";s:0:\"\";s:19:\"getresponse_api_key\";s:0:\"\";s:14:\"aweber_api_key\";s:0:\"\";s:23:\"aweber_internal_api_key\";s:0:\"\";s:15:\"aweber_api_type\";s:5:\"email\";s:25:\"level0_mailchimp_list_ids\";s:0:\"\";s:25:\"level1_mailchimp_list_ids\";s:0:\"\";s:25:\"level2_mailchimp_list_ids\";s:0:\"\";s:25:\"level3_mailchimp_list_ids\";s:0:\"\";s:25:\"level4_mailchimp_list_ids\";s:0:\"\";s:27:\"level0_getresponse_list_ids\";s:0:\"\";s:27:\"level1_getresponse_list_ids\";s:0:\"\";s:27:\"level2_getresponse_list_ids\";s:0:\"\";s:27:\"level3_getresponse_list_ids\";s:0:\"\";s:27:\"level4_getresponse_list_ids\";s:0:\"\";s:22:\"level0_aweber_list_ids\";s:0:\"\";s:22:\"level1_aweber_list_ids\";s:0:\"\";s:22:\"level2_aweber_list_ids\";s:0:\"\";s:22:\"level3_aweber_list_ids\";s:0:\"\";s:22:\"level4_aweber_list_ids\";s:0:\"\";s:24:\"signup_notification_urls\";s:0:\"\";s:30:\"registration_notification_urls\";s:0:\"\";s:25:\"payment_notification_urls\";s:0:\"\";s:30:\"modification_notification_urls\";s:0:\"\";s:30:\"cancellation_notification_urls\";s:0:\"\";s:25:\"eot_del_notification_urls\";s:0:\"\";s:25:\"ref_rev_notification_urls\";s:0:\"\";s:25:\"sp_sale_notification_urls\";s:0:\"\";s:28:\"sp_ref_rev_notification_urls\";s:0:\"\";s:30:\"signup_notification_recipients\";s:0:\"\";s:36:\"registration_notification_recipients\";s:0:\"\";s:31:\"payment_notification_recipients\";s:0:\"\";s:36:\"modification_notification_recipients\";s:0:\"\";s:36:\"cancellation_notification_recipients\";s:0:\"\";s:31:\"eot_del_notification_recipients\";s:0:\"\";s:31:\"ref_rev_notification_recipients\";s:0:\"\";s:31:\"sp_sale_notification_recipients\";s:0:\"\";s:34:\"sp_ref_rev_notification_recipients\";s:0:\"\";s:12:\"level0_label\";s:15:\"Free Subscriber\";s:12:\"level1_label\";s:13:\"Bronze Member\";s:12:\"level2_label\";s:13:\"Silver Member\";s:12:\"level3_label\";s:11:\"Gold Member\";s:12:\"level4_label\";s:15:\"Platinum Member\";s:24:\"apply_label_translations\";s:1:\"0\";s:29:\"level0_file_downloads_allowed\";s:0:\"\";s:29:\"level1_file_downloads_allowed\";s:0:\"\";s:29:\"level2_file_downloads_allowed\";s:0:\"\";s:29:\"level3_file_downloads_allowed\";s:0:\"\";s:29:\"level4_file_downloads_allowed\";s:0:\"\";s:34:\"level0_file_downloads_allowed_days\";s:0:\"\";s:34:\"level1_file_downloads_allowed_days\";s:0:\"\";s:34:\"level2_file_downloads_allowed_days\";s:0:\"\";s:34:\"level3_file_downloads_allowed_days\";s:0:\"\";s:34:\"level4_file_downloads_allowed_days\";s:0:\"\";s:33:\"file_download_limit_exceeded_page\";s:0:\"\";s:31:\"file_download_inline_extensions\";s:0:\"\";s:31:\"file_download_stream_extensions\";s:0:\"\";s:35:\"file_download_content_encodong_none\";s:1:\"0\";s:22:\"amazon_s3_files_bucket\";s:0:\"\";s:29:\"amazon_s3_files_bucket_region\";s:0:\"\";s:26:\"amazon_s3_files_access_key\";s:0:\"\";s:26:\"amazon_s3_files_secret_key\";s:0:\"\";s:27:\"amazon_cf_files_private_key\";s:0:\"\";s:30:\"amazon_cf_files_private_key_id\";s:0:\"\";s:33:\"amazon_cf_files_distros_access_id\";s:0:\"\";s:36:\"amazon_cf_files_distros_s3_access_id\";s:0:\"\";s:35:\"amazon_cf_files_distro_downloads_id\";s:0:\"\";s:38:\"amazon_cf_files_distro_downloads_cname\";s:0:\"\";s:38:\"amazon_cf_files_distro_downloads_dname\";s:0:\"\";s:35:\"amazon_cf_files_distro_streaming_id\";s:0:\"\";s:38:\"amazon_cf_files_distro_streaming_cname\";s:0:\"\";s:38:\"amazon_cf_files_distro_streaming_dname\";s:0:\"\";s:42:\"amazon_cf_files_distros_auto_config_status\";s:0:\"\";s:38:\"amazon_cf_files_rtmp_policy_include_ip\";s:1:\"1\";s:20:\"ruris_case_sensitive\";s:1:\"0\";s:12:\"level0_ruris\";s:0:\"\";s:12:\"level1_ruris\";s:0:\"\";s:12:\"level2_ruris\";s:0:\"\";s:12:\"level3_ruris\";s:0:\"\";s:12:\"level4_ruris\";s:0:\"\";s:12:\"level0_catgs\";s:0:\"\";s:12:\"level1_catgs\";s:0:\"\";s:12:\"level2_catgs\";s:0:\"\";s:12:\"level3_catgs\";s:0:\"\";s:12:\"level4_catgs\";s:0:\"\";s:12:\"level0_ptags\";s:0:\"\";s:12:\"level1_ptags\";s:0:\"\";s:12:\"level2_ptags\";s:0:\"\";s:12:\"level3_ptags\";s:0:\"\";s:12:\"level4_ptags\";s:0:\"\";s:12:\"level0_posts\";s:0:\"\";s:12:\"level1_posts\";s:0:\"\";s:12:\"level2_posts\";s:0:\"\";s:12:\"level3_posts\";s:0:\"\";s:12:\"level4_posts\";s:0:\"\";s:12:\"level0_pages\";s:0:\"\";s:12:\"level1_pages\";s:0:\"\";s:12:\"level2_pages\";s:0:\"\";s:12:\"level3_pages\";s:0:\"\";s:12:\"level4_pages\";s:0:\"\";s:12:\"specific_ids\";s:17:\"".$protectedPosts."\";s:22:\"triggers_immediate_eot\";s:9:\"reversals\";s:23:\"membership_eot_behavior\";s:6:\"demote\";s:21:\"eot_time_ext_behavior\";s:6:\"extend\";s:23:\"auto_eot_system_enabled\";s:1:\"1\";s:17:\"eots_remove_ccaps\";s:1:\"1\";s:14:\"eot_grace_time\";s:5:\"86400\";s:14:\"wp_footer_code\";s:0:\"\";}";
$data=array('option_value' => $s2memberOptions);
$wpdb->update('wp_options', $data, array('option_name' => "ws_plugin__s2member_options"));
}
}