Beispiel #1
0
function memberful_wp_save_postdata($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // Verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if (!memberful_wp_valid_nonce(plugin_basename(__FILE__))) {
        return;
    }
    if (!in_array($_POST['post_type'], memberful_wp_metabox_types())) {
        return;
    }
    $permission = $_POST['post_type'] === 'page' ? 'edit_page' : 'edit_post';
    if (!current_user_can($permission, $post_id)) {
        return;
    }
    // Make sure we're using the actual post id and not a revision id
    if ($parent_id = wp_is_post_revision($post_id)) {
        $post_id = $parent_id;
    }
    $entities = array(Memberful_Post_ACL::DOWNLOAD, Memberful_Post_ACL::SUBSCRIPTION);
    foreach ($entities as $entity) {
        $field = 'memberful_' . $entity . '_acl';
        $acl_list = empty($_POST[$field]) ? array() : (array) $_POST[$field];
        $acl_manager = new Memberful_Post_ACL($entity);
        $acl_manager->set_acl($post_id, $acl_list);
    }
    $viewable_by_any_registered_users = isset($_POST['memberful_viewable_by_any_registered_users']) && $_POST['memberful_viewable_by_any_registered_users'] === '1';
    memberful_wp_set_post_available_to_any_registered_users($post_id, $viewable_by_any_registered_users);
    if (!isset($_POST['memberful_marketing_content'])) {
        return;
    }
    $marketing_content = trim($_POST['memberful_marketing_content']);
    memberful_wp_update_post_marketing_content($post_id, $marketing_content);
    if (!empty($_POST['memberful_make_default_marketing_content'])) {
        memberful_wp_update_default_marketing_content($marketing_content);
    }
}
Beispiel #2
0
/**
 * Displays the memberful options page
 */
function memberful_wp_options()
{
    if (!function_exists('curl_version') || isset($_GET['curl_message'])) {
        return memberful_wp_render('curl_required');
    }
    if (!empty($_POST)) {
        if (!memberful_wp_valid_nonce('memberful_options')) {
            return;
        }
        if (isset($_POST['manual_sync'])) {
            if (is_wp_error($error = memberful_wp_sync_downloads())) {
                Memberful_Wp_Reporting::report($error, 'error');
                return wp_redirect(admin_url('options-general.php?page=memberful_options'));
            }
            if (is_wp_error($error = memberful_wp_sync_subscription_plans())) {
                Memberful_Wp_Reporting::report($error, 'error');
                return wp_redirect(admin_url('options-general.php?page=memberful_options'));
            }
            return wp_redirect(admin_url('options-general.php?page=memberful_options'));
        }
        if (isset($_POST['reset_plugin'])) {
            return memberful_wp_reset();
        }
    }
    if (!memberful_wp_is_connected_to_site()) {
        return memberful_wp_register();
    }
    if (!empty($_GET['subpage'])) {
        switch ($_GET['subpage']) {
            case 'bulk_protect':
                return memberful_wp_bulk_protect();
            case 'debug':
                return memberful_wp_debug();
            case 'advanced_settings':
                return memberful_wp_advanced_settings();
            case 'protect_bbpress':
                return memberful_wp_protect_bbpress();
            case 'private_user_feed_settings':
                return memberful_wp_private_rss_feed_settings();
        }
    }
    $products = get_option('memberful_products', array());
    $subs = get_option('memberful_subscriptions', array());
    memberful_wp_render('options', array('products' => $products, 'subscriptions' => $subs));
}