Skip to content

Commit

Permalink
good
Browse files Browse the repository at this point in the history
  • Loading branch information
beuzathor committed Jan 5, 2025
1 parent 559cd76 commit 72a413d
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/meta-gpt.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Meta GPT Generator

Plugin WordPress qui génère automatiquement les meta titles et descriptions avec ChatGPT.

## Description

Ce plugin permet de :
- Générer automatiquement les meta titles et descriptions
- Configuration simple de l'API ChatGPT
- Interface d'administration intuitive
- Génération automatique ou manuelle des metas

## Installation

1. Téléchargez le plugin
2. Activez-le dans WordPress
3. Configurez votre clé API ChatGPT
4. C'est prêt !

## Changelog

### 1.1
- Ajout de l'auto-updater
- Amélioration de la génération automatique

### 1.0
- Version initiale
5 changes: 4 additions & 1 deletion meta-gpt.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
/**
* Plugin Name: Meta GPT Generator
* Plugin URI: https://github.com/beuzathor/meta-gpt
* Description: Génère et met à jour les meta titles et descriptions avec ChatGPT
* Version: 1.1
* Author: Your Name
* Author: beuzathor
* Author URI: https://github.com/beuzathor/meta-gpt
* License: GPL-2.0+
*/

// Sécurité
Expand Down
137 changes: 137 additions & 0 deletions updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Plugin Update Checker - Add to your main plugin file
*/

// Prevent direct access
if (!defined('ABSPATH')) exit;

class PluginGitHubUpdater {
private $file;
private $plugin;
private $basename;
private $active;
private $username;
private $repository;
private $github_response;

public function __construct($file) {
$this->file = $file;
add_action('admin_init', array($this, 'set_plugin_properties'));

// Add filters for plugin updates
add_filter('pre_set_site_transient_update_plugins', array($this, 'modify_transient'), 10, 1);
add_filter('plugins_api', array($this, 'plugin_popup'), 10, 3);
add_filter('upgrader_post_install', array($this, 'after_install'), 10, 3);
}

public function set_plugin_properties() {
$this->plugin = get_plugin_data($this->file);
$this->basename = plugin_basename($this->file);
$this->active = is_plugin_active($this->basename);
}

public function set_username($username) {
$this->username = $username;
}

public function set_repository($repository) {
$this->repository = $repository;
}

private function get_repository_info() {
if (is_null($this->github_response)) {
$request_uri = sprintf('https://api.github.com/repos/%s/%s/releases/latest',
$this->username,
$this->repository
);

$response = wp_remote_get($request_uri);

if (is_wp_error($response)) {
return false;
}

$response = json_decode(wp_remote_retrieve_body($response));

if ($response) {
$this->github_response = $response;
}
}
}

public function modify_transient($transient) {
if (property_exists($transient, 'checked')) {
if ($checked = $transient->checked) {
$this->get_repository_info();

$out_of_date = version_compare(
$this->github_response->tag_name,
$checked[$this->basename],
'gt'
);

if ($out_of_date) {
$new_files = $this->github_response->zipball_url;
$slug = current(explode('/', $this->basename));

$plugin = array(
'url' => $this->plugin["PluginURI"],
'slug' => $slug,
'package' => $new_files,
'new_version' => $this->github_response->tag_name
);

$transient->response[$this->basename] = (object) $plugin;
}
}
}

return $transient;
}

public function plugin_popup($result, $action, $args) {
if ($action !== 'plugin_information') {
return false;
}

if (!empty($args->slug)) {
if ($args->slug == current(explode('/', $this->basename))) {
$this->get_repository_info();

$plugin = array(
'name' => $this->plugin["Name"],
'slug' => $this->basename,
'version' => $this->github_response->tag_name,
'author' => $this->plugin["AuthorName"],
'author_profile' => $this->plugin["AuthorURI"],
'last_updated' => $this->github_response->published_at,
'homepage' => $this->plugin["PluginURI"],
'short_description' => $this->plugin["Description"],
'sections' => array(
'Description' => $this->plugin["Description"],
'Updates' => $this->github_response->body
),
'download_link' => $this->github_response->zipball_url
);

return (object) $plugin;
}
}
return $result;
}

public function after_install($response, $hook_extra, $result) {
global $wp_filesystem;

$install_directory = plugin_dir_path($this->file);
$wp_filesystem->move($result['destination'], $install_directory);
$result['destination'] = $install_directory;

if ($this->active) {
activate_plugin($this->basename);
}

return $result;
}
}

0 comments on commit 72a413d

Please sign in to comment.