*/
class Anker_Connect_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* The options of this plugin.
*
* @since 1.0.0
* @access private
* @var string $anker_connect_options The options of this plugin.
*/
private $anker_connect_options;
/**
* Initialize the class and set its properties.
*
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*
* @since 1.0.0
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in_Anker_Connect_Loader as all of the hooks are defined
* in that particular class.
*
* The Anker_Connect_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/anker-connect-admin.css', [], $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Anker_Connect_Loader as all of the hooks are defined
* in that particular class.
*
* The Anker_Connect_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_code_editor( [ 'type' => 'application/json' ] );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/anker-connect-admin.js', [ 'jquery' ], $this->version, false );
}
public function reset_import_status() {
delete_option( 'last_boat_import' );
delete_option( 'last_boat_import_page' );
delete_option( 'last_basement_import' );
delete_option( 'last_basement_import_page' );
}
public function delete_custom_posts( $post_type = 'boat' ) {
$posts = get_posts( [ 'post_type' => $post_type, 'numberposts' => - 1 ] );
foreach ( $posts as $post ) {
wp_delete_post( $post->ID, true );
}
}
public function truncate_data() {
$this->delete_custom_posts( 'boat' );
$this->delete_custom_posts( 'basement' );
$this->reset_import_status();
}
public function import_all_immediately() {
anker_connect_schedule_hook_boats( 10000 );
anker_connect_schedule_hook_basements( 10000 );
}
/** Settings Panel */
public function anker_connect_add_plugin_page() {
$this->anker_connect_options = get_option( 'connect_options' );
add_options_page(
__( '5 Anker Connect', '5-anker-connect' ), // page_title
__( '5 Anker Connect', '5-anker-connect' ), // menu_title
'manage_options', // capability
'5-anker-connect', // menu_slug
[ $this, 'anker_connect_create_admin_page' ] // function
);
}
public function anker_connect_create_admin_page() {
$default_tab = 'connection';
$tab = $_GET['tab'] ?? $default_tab;
?>