get_default_permissions($type)); /* * Case post type disabled. */ if ( ! $post_type_limit->enabled) { return false; } /* * Case unlimited posts */ if (absint($post_type_limit->number) === 0) { return true; } return absint($value_to_check) < absint($post_type_limit->number); } /** * Adds a magic getter for subtypes. * * @since 2.0.0 * * @param string $sub_type The sub type. * @return object */ public function __get($sub_type) { $type = (object) wu_get_isset($this->get_limit(), $sub_type, $this->get_default_permissions($sub_type)); return (object) wp_parse_args($type, $this->get_default_permissions($sub_type)); } /** * Returns default permissions. * * @since 2.0.0 * * @param string $type Type for sub-checking. * @return array */ public function get_default_permissions($type) { return [ 'enabled' => true, 'number' => '', // unlimited ]; } /** * Checks if a theme exists on the current module. * * @since 2.0.0 * * @param string $type The type. * @return bool */ public function exists($type) { $results = wu_get_isset($this->get_limit(), $type, []); return wu_get_isset($results, 'number', 'not-set') !== 'not-set'; } /** * Handles limits on post submission. * * @since 2.0.0 * @return mixed */ public function handle_limit() { $received = wu_get_isset($_POST['modules'][ $this->id ], 'limit', []); foreach ($received as $post_type => &$limitations) { $limitations['enabled'] = (bool) wu_get_isset($_POST['modules'][ $this->id ]['limit'][ $post_type ], 'enabled', false); } return $received; } }