Skip to content

Commit

Permalink
v 6.0.0
Browse files Browse the repository at this point in the history
- If a non multilingual field becomes multilingual, load its precedent value.
- Update dependencies.
- Add eslint github action.
  • Loading branch information
Darklg committed Nov 21, 2023
1 parent 274dbca commit ec9906b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 16 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"no-prototype-builtins": 0
},
"globals": {
"wp": true,
"tinymce": true,
"wpuoptions__settings": true,
"wpLink": true,
"jQuery": true
},
"ignorePatterns": ["assets/select2/**"]
}
17 changes: 17 additions & 0 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: ESLint

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm install -g eslint
- name: Run ESLint
run: eslint assets/ --ext .js
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Options
=================

[![JS workflow](https://github.com/WordPressUtilities/wpuoptions/actions/workflows/js.yml/badge.svg 'JS workflow')](https://github.com/WordPressUtilities/wpuoptions/actions) [![PHP workflow](https://github.com/WordPressUtilities/wpuoptions/actions/workflows/php.yml/badge.svg 'PHP workflow')](https://github.com/WordPressUtilities/wpuoptions/actions)

Friendly interface for website options.

How to install :
Expand Down
26 changes: 18 additions & 8 deletions assets/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jQuery(document).ready(function($) {
jQuery(document).ready(function() {
'use strict';
var form = jQuery('.wpu-options-form');
wputh_options_set_exportcheck();
wputh_options_set_media();
Expand All @@ -15,6 +16,7 @@ jQuery(document).ready(function($) {
---------------------------------------------------------- */

var wputh_options_set_exportcheck = function() {
'use strict';
jQuery('.wpu-export-section').on('change', '.wpu-export-title-checkbox', function() {
var $this = jQuery(this),
$parent = $this.closest('.wpu-export-section');
Expand All @@ -27,6 +29,7 @@ var wputh_options_set_exportcheck = function() {
---------------------------------------------------------- */

var wputh_options_set_wp_link = function() {
'use strict';
jQuery('[data-wpuoptions-wplink]').each(function() {
var $this = jQuery(this),
$parent = $this.parent(),
Expand All @@ -42,7 +45,7 @@ var wputh_options_set_wp_link = function() {
try {
src_json = JSON.parse($textarea.val());
}
catch (e) {}
catch (e) {console.log('Could not parse');}
if (typeof src_json == 'object') {
if (src_json.href) {
jQuery('#wp-link-url').val(src_json.href);
Expand Down Expand Up @@ -78,17 +81,19 @@ var wputh_options_set_wp_link = function() {
---------------------------------------------------------- */

var wputh_options_set_multiple_selects = function() {
'use strict';
if (!jQuery.fn.select2) {
return;
}
$('.wpu-options-box select[multiple]').select2();
jQuery('.wpu-options-box select[multiple]').select2();
};

/* ----------------------------------------------------------
Set polyfills
---------------------------------------------------------- */

var wputh_options_set_polyfills = function(form) {
'use strict';
form.find('input[type=date]').each(function() {
jQuery(this).attr('type', 'text').datepicker({
dateFormat: 'dd/mm/yy'
Expand All @@ -105,6 +110,7 @@ var wputh_options_set_polyfills = function(form) {
---------------------------------------------------------- */

var wputh_options_set_editor = function() {
'use strict';
jQuery('.wpuoptions-view-editor-switch').on('click', '.edit-link', function(e) {
e.preventDefault();
var $this = jQuery(this),
Expand All @@ -125,9 +131,10 @@ var wpuopt_file_frame,
wpuopt_datafor;

var wputh_options_set_media = function() {
var options_form = jQuery('.wpu-options-form');
var wpuopt_options_form = jQuery('.wpu-options-form');
// Remove media
options_form.on('click', '.wpu-options-upload-preview .x', function(event) {
wpuopt_options_form.on('click', '.wpu-options-upload-preview .x', function(event) {
'use strict';
event.preventDefault();
var $this = jQuery(this),
$td = $this.closest('td'),
Expand All @@ -150,7 +157,8 @@ var wputh_options_set_media = function() {
$td.find('.wpuoptions_add_media').text(defaultLabel);
});
// Add media
options_form.on('click', '.wpuoptions_add_media', function(event) {
wpuopt_options_form.on('click', '.wpuoptions_add_media', function(event) {
'use strict';
event.preventDefault();
var $this = jQuery(this);

Expand Down Expand Up @@ -235,6 +243,7 @@ var wputh_options_set_media = function() {
---------------------------------------------------------- */

var wputh_options_set_accordion = function() {
'use strict';
var form = jQuery('.wpu-options-form'),
boxes = form.find('.wpu-options-form__box');

Expand Down Expand Up @@ -264,6 +273,7 @@ var wputh_options_set_accordion = function() {
---------------------------------------------------------- */

var wputh_options_set_langs = function() {
'use strict';
var $form = jQuery('.wpu-options-form'),
$boxes = $form.find('.wpu-options-box[data-lang]'),
$langs = jQuery('.wpu-options-lang-switcher').find('a[data-lang]');
Expand All @@ -290,8 +300,8 @@ var wputh_options_set_langs = function() {
Heartbeat
---------------------------------------------------------- */

jQuery(document).ready(function($) {

jQuery(document).ready(function() {
'use strict';
var $body = jQuery('body'),
$document = jQuery(document),
$form = jQuery('.wpu-options-form'),
Expand Down
5 changes: 4 additions & 1 deletion 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.3
Version: 0.4.4
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand Down Expand Up @@ -126,6 +126,9 @@ public function get_new_plugin_info() {
/* Fetch plugin data */
$plugin_data = array();
if (file_exists($this->plugin_dir)) {
if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data($this->plugin_dir);
}

Expand Down
19 changes: 12 additions & 7 deletions wpuoptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
Plugin Name: WPU Options
Plugin URI: https://github.com/WordPressUtilities/wpuoptions
Update URI: https://github.com/WordPressUtilities/wpuoptions
Version: 5.5.0
Version: 6.0.0
Description: Friendly interface for website options
Author: Darklg
Author URI: http://darklg.me/
Author URI: https://darklg.me/
Text Domain: wpuoptions
Domain Path: /lang
Requires at least: 6.0
Requires PHP: 8.0
License: MIT License
License URI: http://opensource.org/licenses/MIT
License URI: https://opensource.org/licenses/MIT
*/

defined('ABSPATH') or die(':(');
Expand All @@ -28,7 +28,7 @@ class WPUOptions {
private $main_url;
private $options = array(
'plugin_name' => 'WPU Options',
'plugin_version' => '5.5.0',
'plugin_version' => '6.0.0',
'plugin_userlevel' => 'manage_categories',
'plugin_menutype' => 'admin.php',
'plugin_pageslug' => 'wpuoptions-settings'
Expand All @@ -54,7 +54,7 @@ class WPUOptions {
*/
public function __construct() {

include dirname(__FILE__) . '/inc/WPUBaseUpdate/WPUBaseUpdate.php';
require_once dirname(__FILE__) . '/inc/WPUBaseUpdate/WPUBaseUpdate.php';
$this->settings_update = new \wpuoptions\WPUBaseUpdate(
'WordPressUtilities',
'wpuoptions',
Expand Down Expand Up @@ -394,7 +394,7 @@ public function admin_export_page() {
$box['tab'] = 'default';
}
if ($box['tab'] == $tab_id && isset($boxes_with_fields[$box_id])) {
echo '<p><label><input class="wpu-export-boxes-check" type="checkbox" checked="checked" name="boxes[' . $box_id . ']" value="' . $box_id . '" /> ' . (empty($box['name'])?__('Default box', 'wpuoptions'): $box['name']) . '</label></p>';
echo '<p><label><input class="wpu-export-boxes-check" type="checkbox" checked="checked" name="boxes[' . $box_id . ']" value="' . $box_id . '" /> ' . (empty($box['name']) ? __('Default box', 'wpuoptions') : $box['name']) . '</label></p>';
}
}
echo '</div>';
Expand Down Expand Up @@ -558,7 +558,7 @@ private function admin_form() {

foreach ($this->boxes as $idbox => $box) {
$box_tab = isset($box['tab']) ? $box['tab'] : 'default';
$box_usercan = isset($box['current_user_can'])?current_user_can($box['current_user_can']): true;
$box_usercan = isset($box['current_user_can']) ? current_user_can($box['current_user_can']) : true;
if ($box_tab != $this->current_tab || !$box_usercan) {
continue;
}
Expand Down Expand Up @@ -628,12 +628,17 @@ private function admin_field($id, $field = array()) {
$upload_dir = wp_upload_dir();
$wpu_posttypes = apply_filters('wputh_get_posttypes', array());
$wpu_taxonomies = apply_filters('wputh_get_taxonomies', array());
$main_value = get_option($id);

foreach ($fields_versions as $field_version) {
$idf = $this->get_field_id($field_version['prefix_opt'] . $field_version['id']);
$field = $this->get_field_datas($field_version['id'], $field_version['field']);
$is_multiple = isset($field['multiple']) && $field['multiple'];
$idname = ' id="' . $idf . '" name="' . $idf . ($is_multiple ? '[]' : '') . '" ';
$originalvalue = get_option($field_version['prefix_opt'] . $field_version['id']);
if (!$originalvalue && $main_value) {
$originalvalue = $main_value;
}
$field_post_type = isset($field['post_type']) ? $field['post_type'] : 'post';
if ($originalvalue === false && isset($field['default_value']) && $this->test_field_value($field, $field['default_value'])) {
$originalvalue = $field['default_value'];
Expand Down

0 comments on commit ec9906b

Please sign in to comment.