Options_checksum

How can I stop it? I’m modifying the options in the database with a PHP function and the only thing I see different that keeps being the cause of my function failing [most likely] is the options_checksum(?) keeps changing values in the main s2member options record/value in the database… (query to access would be: SELECT option_value FROM wp_options WHERE option_name LIKE 'ws_plugin__s2member_options’).

Very beginning of record looks like:
a:211:{s:16:“options_checksum”;s:32:“de8ea91ab82783ea74eec5369fd7b206”;
[part that keeps changing is bold]

I need to either eliminate this or mimic it’s functionality in my function [which changes the s2member plugin options dynamically - specifically, the protected post IDs].

Do not stop it. Instead, use s2M’s function (I don’t know which it is) to save cofiguration options after you change them, it will set the sum.

Alternatively (my lovely way) - change configurations at each run of the plugin, after they was read. It’s easy to do at the s2M’s hook, that runs after initial start of the plugin (still I can’t remember the exactly hook, sorry). Programmer’s tricks… :slight_smile:

1 Like

Love your answers, Krum! Since my function only runs when you save a post in a specific category, I’m thinking I don’t need to do this every time the plugin runs. Plus time is kind of crucial on this and I think I can find the function easier than I can find the hook. But it’s nice to have more than one option. And for both of these options, I thank you!

Changed my mind. This is way to much work. Can’t find the function. Can’t find the hook. Or maybe I did find the correct ones and they just don’t work for me. Back to my original thought… GET RID OF IT. If I can find a way to remove this overkill on security, I’ll post it. Or if anyone knows how, please let me know.

What code are you using?

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"));


    }
}

Oh, so you’re working directly with the database. Have you tried it without including the checksum field and value? I don’t know how that gets generated, but I doubt it’s meant to be added manually like this.

I have actually. I tried with no checksum at all. I’m sure when the plugin sees that there’s no checksum, it’s the same as the checksum not matching the previous option settings (and previous checksum).

If that’s true, then deleting the checksum or using a filter to unset it (which was going to be my next suggestion) isn’t going to work either.

I think this is the way to do it: https://wordpress.stackexchange.com/questions/125605/save-new-data-to-wp-options-non-post-form/125608#125608

Of course, if speed really is of the essence, you could always do a very simple redirect:

<?php
function kts_redirect_cpt() {
    if ( !is_singular( 'property' ) ) {
	return;
    }
    if ( current_user_can( 'access_s2member_level1' ) ) {
	return;
    }
    wp_safe_redirect( S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL );
    exit;
}
add_action( 'template_redirect', 'kts_redirect_cpt' );

That’s how to save options in the wp_options table. Nothing to do with s2member resetting configuration because the checksum doesn’t match.

Of course it is.

How do you think the checksum is determined?

The checksum is determined by s2member. It’s the s2member configurations. It’s definitely 100% not determined by WordPress. Nothing to do with WordPress even though it’s stored in a core WordPress table.

Of course it’s determined by s2Member, but on what basis? It’s not predetermined. Checksums are determined by what the field contains: that’s what makes them a check.

Think you answered your own question. It’s pretty simple. Take the option values, convert them into a hash, and check the hash against those values every time the plugin loads. So it is predetermined. The checksum (first value of the meta_value column) has to match the rest of the values after the checksum.

Exactly. So that’s why I discussed earlier in this thread about how to insert values in the options field. You’ve already found that attempting to do without the checksum doesn’t work. So you need to ensure you insert the new data the right way in order to pass the checksum.

There is only one way to insert the data. And that way is the way I did it. BUT… the checksum either has to be changed to match the data or the function that checks the checksum needs to be removed. I can not find a solution to either one of those potential fixes. The very first post in this thread explains how I want to remove it. The second is Krum Cheshmedjiev offering alternatives to removing the function. And the 4th post is me saying that I can not find the functions/hooks needed for Krum’s recommendation. That’s when you chimed in. So we’re going in circles.

I didn’t “chime in.” You asked me to come here from a previous thread!

And if we are going round in circles, that’s only because you assume that the way you inserted the data is the way to do it. Self-evidently, it isn’t. Otherwise s2Member could not cope with different configurations. That’s why I pointed to guidance on how to insert the data.

One thing I’ve noticed on these forums is that the people who insist they are right never get things to work.

Thanks for that positive piece of information. You’ve completely solved my problem. Consider this thread closed.