Initial
This commit is contained in:
77
includes/class-lcp-paywall-rules.php
Normal file
77
includes/class-lcp-paywall-rules.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
class LCP_Paywall_Rules {
|
||||
private $option_name = 'lcp_paywall_rules';
|
||||
|
||||
public function get_rules() {
|
||||
return get_option($this->option_name, array());
|
||||
}
|
||||
|
||||
public function get_rules_for_post_type($post_type) {
|
||||
$rules = $this->get_rules();
|
||||
return isset($rules[$post_type]) ? $rules[$post_type] : array();
|
||||
}
|
||||
|
||||
public function save_rules($rules) {
|
||||
// Ensure settings exist for each post type
|
||||
foreach ($rules as $post_type => $data) {
|
||||
if (!isset($data['settings'])) {
|
||||
$rules[$post_type]['settings'] = $this->get_default_post_type_settings($post_type);
|
||||
}
|
||||
}
|
||||
return update_option($this->option_name, $rules);
|
||||
}
|
||||
|
||||
public function get_operators() {
|
||||
return array(
|
||||
'=' => 'Equals',
|
||||
'!=' => 'Not Equals',
|
||||
'in' => 'In',
|
||||
'notin' => 'Not In',
|
||||
'is' => 'Is',
|
||||
'isnot' => 'Is Not',
|
||||
'olderthan' => 'Older Than',
|
||||
'newerthan' => 'Newer Than',
|
||||
'hassub' => 'Has Subscription'
|
||||
);
|
||||
}
|
||||
|
||||
public function get_conditions() {
|
||||
return array(
|
||||
'user' => 'User',
|
||||
'post' => 'Post'
|
||||
);
|
||||
}
|
||||
|
||||
public function get_value_types() {
|
||||
return array(
|
||||
'logged_in' => 'Logged In',
|
||||
'taxonomy' => 'Taxonomy'
|
||||
);
|
||||
}
|
||||
|
||||
public function get_taxonomies_for_post_type($post_type) {
|
||||
return get_object_taxonomies($post_type, 'objects');
|
||||
}
|
||||
|
||||
public function get_terms_for_taxonomy($taxonomy) {
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'hide_empty' => false,
|
||||
));
|
||||
|
||||
return is_wp_error($terms) ? array() : $terms;
|
||||
}
|
||||
|
||||
public function get_default_post_type_settings($post_type) {
|
||||
$rules = $this->get_rules();
|
||||
return isset($rules[$post_type]['settings']) ? $rules[$post_type]['settings'] : array(
|
||||
'default_lock_status' => 'locked',
|
||||
'is_metered' => false,
|
||||
'metered_free_posts' => 0,
|
||||
'metered_interval' => 0
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user