Skip to content

Commit

Permalink
v 0.8.1
Browse files Browse the repository at this point in the history
- Update dependencies.
- Fix translation loading.
  • Loading branch information
Darklg committed Nov 23, 2024
1 parent 304e666 commit 31a32d7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install modules
run: npm install -g eslint@^8
- name: Run ESLint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: PHP Lint
uses: michaelw90/[email protected]
31 changes: 25 additions & 6 deletions inc/WPUBaseUpdate/WPUBaseUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
Class Name: WPU Base Update
Description: A class to handle plugin update from github
Version: 0.4.5
Version: 0.6.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand All @@ -26,6 +26,7 @@ class WPUBaseUpdate {
private $plugin_id;
private $plugin_dir;
private $details;
private $is_tracked = false;

public function __construct($github_username = false, $github_project = false, $current_version = false, $details = array()) {
$this->init($github_username, $github_project, $current_version, $details);
Expand All @@ -47,9 +48,7 @@ public function init($github_username = false, $github_project = false, $current
$this->plugin_dir = (defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins') . '/' . $this->plugin_id;

$gitpath = dirname($this->plugin_dir) . '/.git';
if (is_dir($gitpath) || file_exists($gitpath)) {
return;
}
$this->is_tracked = (is_dir($gitpath) || file_exists($gitpath));

if (!is_array($details)) {
$details = array();
Expand Down Expand Up @@ -125,6 +124,13 @@ public function get_new_plugin_info() {
'sections' => array()
);

/* Disable download link if plugin is tracked */
if ($this->is_tracked) {
$plugin_info['trunk'] = '';
$plugin_info['download_link'] = '';
$plugin_info['package'] = '';
}

/* Fetch plugin data */
$plugin_data = array();
if (file_exists($this->plugin_dir)) {
Expand Down Expand Up @@ -170,7 +176,7 @@ public function plugins_api($res, $action, $args) {
return false;
}

if ('github-' . $this->github_project !== $args->slug) {
if ('github-' . $this->github_project !== $args->slug && $this->github_project !== $args->slug) {
return $res;
}

Expand All @@ -179,7 +185,20 @@ public function plugins_api($res, $action, $args) {
return (object) $plugin_info;
}

return false;
$plugin_details = array(
'name' => $this->github_project,
'slug' => $this->github_project
);

$parent_plugin = __DIR__ . '/../../' . $this->github_project . '.php';
if (file_exists($parent_plugin)) {
$plugin_name = get_plugin_data($parent_plugin);
if (isset($plugin_name['Name'])) {
$plugin_details['name'] = $plugin_name['Name'];
}
}

return (object) $plugin_details;

}

Expand Down
32 changes: 19 additions & 13 deletions wpu_override_gettext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/WordPressUtilities/wpu_override_gettext
Update URI: https://github.com/WordPressUtilities/wpu_override_gettext
Description: Override gettext strings
Version: 0.8.0
Version: 0.8.1
Author: darklg
Author URI: https://darklg.me/
Text Domain: wpu_override_gettext
Expand All @@ -22,7 +22,7 @@ class WPUOverrideGettext {
public $settings_update;
public $plugin_description;
public $adminpages;
private $plugin_version = '0.8.0';
private $plugin_version = '0.8.1';
private $plugin_settings = array(
'id' => 'wpu_override_gettext',
'name' => 'WPU Override gettext'
Expand All @@ -31,19 +31,25 @@ class WPUOverrideGettext {
private $text_domains = false;

public function __construct() {
add_action('init', array(&$this, 'load_translation'));
add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
add_action('gettext', array(&$this, 'translate_text'), 10, 3);
add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
}

public function plugins_loaded() {
$this->text_domains = apply_filters('wpu_override_gettext__text_domains', array(get_stylesheet()));

# TRANSLATION
if (!load_plugin_textdomain('wpu_override_gettext', false, dirname(plugin_basename(__FILE__)) . '/lang/')) {
load_muplugin_textdomain('wpu_override_gettext', dirname(plugin_basename(__FILE__)) . '/lang/');
# TRANSLATION
public function load_translation() {
$lang_dir = dirname(plugin_basename(__FILE__)) . '/lang/';
if (strpos(__DIR__, 'mu-plugins') !== false) {
load_muplugin_textdomain('wpu_override_gettext', $lang_dir);
} else {
load_plugin_textdomain('wpu_override_gettext', false, $lang_dir);
}
$this->plugin_description = __('Override gettext strings', 'wpu_override_gettext');
}

public function plugins_loaded() {
$this->text_domains = apply_filters('wpu_override_gettext__text_domains', array(get_stylesheet()));

# ADMIN PAGE
$admin_pages = array(
Expand Down Expand Up @@ -197,7 +203,7 @@ public function page_action__main() {
Assets
---------------------------------------------------------- */

function admin_enqueue_scripts() {
public function admin_enqueue_scripts() {

/* Back script */
wp_register_script('wpu_override_gettext_back_script', plugins_url('assets/back.js', __FILE__), array(), $this->plugin_version, true);
Expand All @@ -212,7 +218,7 @@ function admin_enqueue_scripts() {
Helpers
---------------------------------------------------------- */

function get_fixed_translations() {
public function get_fixed_translations() {

$translations = $this->wpubasefilecache->get_cache('translations', 24 * 60 * 60);
if (!$translations) {
Expand All @@ -232,7 +238,7 @@ function get_fixed_translations() {
return $translations_fixed;
}

function get_string_translation($string, $new_translation) {
public function get_string_translation($string, $new_translation) {
$translations = $this->get_fixed_translations();
if (!is_array($translations) || empty($translations)) {
return $new_translation;
Expand All @@ -245,7 +251,7 @@ function get_string_translation($string, $new_translation) {
return $new_translation;
}

function get_all_files($dir) {
public function get_all_files($dir) {
$excluded_dirs = array('node_modules', 'vendor');
$dir_name = basename($dir);
if (in_array($dir_name, $excluded_dirs)) {
Expand All @@ -271,7 +277,7 @@ function get_all_files($dir) {
return $results;
}

function translate_text($translated_text, $untranslated_text, $domain) {
public function translate_text($translated_text, $untranslated_text, $domain) {
if (!is_array($this->text_domains) || !in_array($domain, $this->text_domains) || (is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpu_override_gettext-main')) {
return $translated_text;
}
Expand Down

0 comments on commit 31a32d7

Please sign in to comment.