*/ if ( ! defined( 'WPINC' ) ) { die; } class Ace_Tic_Tac_Toe_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; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ 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 Ace_Tic_Tac_Toe_Loader as all of the hooks are defined * in that particular class. * * The Ace_Tic_Tac_Toe_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/ace-tic-tac-toe-admin.css', array(), $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 Ace_Tic_Tac_Toe_Loader as all of the hooks are defined * in that particular class. * * The Ace_Tic_Tac_Toe_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ace-tic-tac-toe-admin.js', array( 'jquery' ), $this->version, true ); wp_localize_script($this->plugin_name, 'ticTacToeData', ['ajax_url' => admin_url('admin-ajax.php')]); wp_localize_script($this->plugin_name,'ticTacToeData',array('ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('delete_avatar_nonce'),)); } public function tic_tac_toe_add_settings_page() { add_menu_page('Tic Tac Toe Settings', 'Ace Tic Tac Toe', 'manage_options', 'ace-tic-tac-toe-settings', array($this, 'tic_tac_toe_settings_page'), 'dashicons-grid-view', 30); } public function tic_tac_toe_settings_page() { ?>
[ace_tic_tac_toe]
Use this shortcode to embed the game in a post or page.
[ 'label' => 'Player X', 'value' => esc_attr($options['first_player'] ?? 'X'), 'avatar' => $first_player_avtar_image, 'avatar_field' => 'first_player_avtar', 'placeholder' => esc_attr('Enter Symbol (X)') ], 'second_player' => [ 'label' => 'Player O', 'value' => esc_attr($options['second_player'] ?? 'O'), 'avatar' => $second_player_avtar_image, 'avatar_field' => 'second_player_avtar', 'placeholder' => esc_attr('Enter Symbol (O)') ] ]; foreach ($players as $key => $player) : ?>Enter a single character (A-Z, 0-9) for each player.
Choose the background color for the Tic Tac Toe game (RGB or Hex).
Enter the RGB or Hex value for the button color (e.g., rgb(0, 123, 255) for blue).
sanitize_file_name($_FILES['tic_tac_toe_options']['name'][$key]), 'type' => sanitize_mime_type($_FILES['tic_tac_toe_options']['type'][$key]), 'tmp_name' => sanitize_text_field($_FILES['tic_tac_toe_options']['tmp_name'][$key]), 'error' => intval($_FILES['tic_tac_toe_options']['error'][$key]), 'size' => intval($_FILES['tic_tac_toe_options']['size'][$key]), ]; $upload = wp_handle_upload($file, ['test_form' => false]); if (!isset($upload['error'])) { $relative_path = str_replace(wp_upload_dir()['url'] . '/', '', $upload['url']); $options[$key] = $relative_path; } } } update_option('tic_tac_toe_options', $options); } } public function delete_tic_tac_toe_avatar_callback() { check_ajax_referer('delete_avatar_nonce', 'security'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => 'You do not have permission.')); } if (isset($_POST['player_key'])) { $player_key = sanitize_text_field(wp_unslash($_POST['player_key'])); } else { $player_key = ''; } $options = get_option('tic_tac_toe_options'); $upload_dir = wp_upload_dir(); if ($player_key === 'first_player' && !empty($options['first_player_avtar'])) { $file_path = $upload_dir['basedir'] . '/' . $options['first_player_avtar']; if (file_exists($file_path)) { wp_delete_file($file_path); } unset($options['first_player_avtar']); } elseif ($player_key === 'second_player' && !empty($options['second_player_avtar'])) { $file_path = $upload_dir['basedir'] . '/' . $options['second_player_avtar']; if (file_exists($file_path)) { wp_delete_file($file_path); } unset($options['second_player_avtar']); } else { wp_send_json_error(array('message' => 'Invalid player key or no avatar found.')); } update_option('tic_tac_toe_options', $options); wp_send_json_success(); } }