public function set_license($key = NULL, $product = NULL) { if ($key === NULL && $this->license_key_k === NULL) { return; } if ($key !== NULL) { $this->slug = $key; $this->need_license = TRUE; $this->license_key_k = $key . '-license-key'; $this->product = $product; } if (is_multisite()) { $options = new WPFront_User_Role_Editor_Options($this->main); switch_to_blog($options->ms_options_blog_id()); } $entity = new WPFront_User_Role_Editor_Entity_Options(); $this->license_key = $entity->get_option($this->license_key_k); if ($this->license_key !== NULL) { $invalid_count = $entity->get_option($this->license_key_k . '-invalid-count'); if (empty($invalid_count)) { $invalid_count = 0; } $last_checked = $entity->get_option($this->license_key_k . '-last-checked'); if (($invalid_count > 0 || is_admin()) && !WPFront_Static_URE::doing_ajax() && $last_checked < time() - 24 * 3600) { $entity->update_option($this->license_key_k . '-last-checked', time()); $result = $this->remote_get('check_license', $this->license_key); $api_params = $result[1]; $result = $result[0]; if (!empty($result)) { if (($result->activations_left === 'unlimited' || $result->activations_left >= 0) && ($result->license === 'valid' || $result->license === 'expired')) { $entity->update_option($this->license_key_k . '-status', $result->license); $entity->update_option($this->license_key_k . '-expires', $result->expires); $entity->update_option($this->license_key_k . '-download-id', $result->download_id); $entity->update_option($this->license_key_k . '-invalid-count', 0); } else { $invalid_count = $invalid_count + 1; $entity->update_option($this->license_key_k . '-invalid-count', $invalid_count); $entity->update_option($this->license_key_k . '-home-url', $api_params['url']); $this->license_status = 'invalid'; if ($invalid_count === 1) { $this->send_mail('invalid', $result, 'wpfront.com', $api_params); } else { if ($invalid_count > 7) { $this->deactivate_license(TRUE); $this->send_mail('deactivated', $result, 'wpfront.com'); return; } } } } } $this->has_license = TRUE; $this->license_expired = $entity->get_option($this->license_key_k . '-status') === 'expired'; $this->license_expires = date('F d, Y', strtotime($entity->get_option($this->license_key_k . '-expires'))); $this->download_id = $entity->get_option($this->license_key_k . '-download-id'); if (!empty($this->download_id)) { $this->renew_url = sprintf('https://wpfront.com/checkout/?edd_license_key=%s&download_id=%d', $this->license_key, $this->download_id); } //$invalid_count = $entity->get_option($this->license_key_k . '-invalid-count'); if ($invalid_count > 0) { $this->license_status = 'invalid'; $this->license_home_url = $entity->get_option($this->license_key_k . '-home-url'); } if ($this->license_status === NULL) { if ($this->license_expired) { $this->license_status = 'expired'; } else { $this->license_status = 'valid'; } } $this->license_key = str_repeat('X', strlen($this->license_key) - 4) . substr($this->license_key, strlen($this->license_key) - 4, 4); //Software licensing change $this->edd_plugin_update(); //add_action('admin_init', array($this, 'edd_plugin_update')); } else { $this->license_key = ''; $this->has_license = FALSE; $this->license_expires = NULL; } if (is_multisite()) { restore_current_blog(); } }
public function lock_menus($parent_file = NULL) { if (WPFront_Static_URE::doing_ajax()) { return $parent_file; } if (empty($this->wp_menu)) { return $parent_file; } $user = wp_get_current_user(); $roles = $user->roles; $primary = TRUE; while (!empty($roles)) { $obj_role = get_role(array_shift($roles)); if ($obj_role === NULL) { continue; } $this->override_type = $this->get_override_type($obj_role); $this->hide_new_menu = $this->get_hide_new_menus($obj_role); $this->disable_for_secondary_role = $this->get_disable_for_secondary_role($obj_role); if (!$primary) { if ($this->disable_for_secondary_role) { continue; } } $role = $obj_role->name; $entity = new WPFront_User_Role_Editor_Entity_Menu_Editor(); $data = $entity->get_all_by_role($role); $data_indexed = $this->index_table_data($data); if ($this->override_type === self::OVERRIDE_TYPE_HARD) { global $self, $submenu_file, $plugin_page; $page = $plugin_page; if ($page == NULL) { $page = $submenu_file; } if ($page == NULL) { $page = $self; } $row_data = NULL; $parent_data = NULL; if ($page != NULL) { foreach ($data as $value) { if ($value->get_menu_slug() == $page) { if ($value->get_parent_menu_slug() != '') { $row_data = $value; } else { $parent_data = $value; } } } if ($row_data == NULL) { $row_data = $parent_data; } if ($row_data == NULL) { if ($this->hide_new_menu) { wp_die($this->page_lock_data()); die; return; } } else { if (!$this->has_access($obj_role, $this->hide_new_menu, $data_indexed, $row_data->get_menu_slug(), $row_data->get_parent_menu_slug())) { wp_die($this->page_lock_data()); die; return; } } } } $menu = $this->wp_menu; $submenu = $this->wp_submenu; $prev_menu = NULL; foreach ($menu as $parent) { if (!empty($submenu[$parent[2]])) { foreach ($submenu[$parent[2]] as $child) { if (!$this->has_access($obj_role, $this->hide_new_menu, $data_indexed, $this->escape_customize_slug($child[2]), $this->escape_customize_slug($parent[2]))) { remove_submenu_page($parent[2], $child[2]); } } } // if ($this->is_menu_separator($parent)) { // if ($this->is_menu_separator($prev_menu)) { // printf('%s <br />', $parent[2]); // remove_menu_page($parent[2]); // } else { // $prev_menu = $parent; // } // } else if (!$this->has_access($obj_role, $this->hide_new_menu, $data_indexed, $parent[2])) { // remove_menu_page($parent[2]); // } else { // $prev_menu = $parent; // } if (!$this->has_access($obj_role, $this->hide_new_menu, $data_indexed, $parent[2])) { remove_menu_page($parent[2]); } } $primary = FALSE; } return $parent_file; }