Skip to content

Commit

Permalink
Merge pull request #57 from iamsayan/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
iamsayan committed Mar 17, 2024
2 parents b4cac32 + a5ff8c4 commit 84e7c15
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 114 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.9.0
Release Date: March 17, 2024

* Optimize WP Options Auto Loading.
* Updated Composer Libraries.
* Tested with WordPress v6.5.

## 1.8.9
Release Date: February 9, 2024

* Added: Lock Modified Date Block Editor Support for Custom Post type which has `show_in_rest` set to `true`. This behavior can be changed by `wpar/post_type_args` filter.
* Added: Lock Modified Date Block Editor Support for Custom Post type which has `show_in_rest` set to `true`. This behavior can be changed by `wplmi/post_type_args` filter.
* Updated: @wordpress/scripts to the latest version.
* Updated: Background Process PHP Library.
* Tweak: Replaced deprecated `__experimentalGetSettings()` with `getSettings()`.
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

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

12 changes: 6 additions & 6 deletions inc/Base/AdminNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ public function dismiss_notice() {
$notice_action = join( '_', $notice );

if ( 'dismiss' === $notice_action ) {
update_option( 'wplmi_plugin_dismiss_' . $notice_type . '_notice', '1' );
update_option( 'wplmi_plugin_dismiss_' . $notice_type . '_notice', '1', false );
}

if ( 'no_thanks' === $notice_action ) {
update_option( 'wplmi_plugin_no_thanks_' . $notice_type . '_notice', '1' );
update_option( 'wplmi_plugin_dismiss_' . $notice_type . '_notice', '1' );
update_option( 'wplmi_plugin_no_thanks_' . $notice_type . '_notice', '1', false );
update_option( 'wplmi_plugin_dismiss_' . $notice_type . '_notice', '1', false );
if ( 'donate' === $notice_type ) {
update_option( 'wplmi_plugin_dismissed_time_donate', time() );
update_option( 'wplmi_plugin_dismissed_time_donate', time(), false );
} else {
update_option( 'wplmi_plugin_dismissed_time', time() );
update_option( 'wplmi_plugin_dismissed_time', time(), false );
}
}

Expand All @@ -157,7 +157,7 @@ private function calculate_time() {

if ( ! $installed_time ) {
$installed_time = time();
update_option( 'wplmi_plugin_installed_time', $installed_time );
update_option( 'wplmi_plugin_installed_time', $installed_time, false );
}

return $installed_time;
Expand Down
8 changes: 6 additions & 2 deletions inc/Base/PluginTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function import_settings() {

// Retrieve the settings from the file and convert the json object to an array.
$settings = (array) json_decode( file_get_contents( $import_file ) );
update_option( 'lmt_plugin_global_settings', $settings );
update_option( 'lmt_plugin_global_settings', $settings, false );

// set temporary transient for admin notice
set_transient( 'wplmi_import_db_done', true );
Expand Down Expand Up @@ -160,6 +160,10 @@ public function import_data() {
// security check
$this->verify_nonce();

if ( ! current_user_can( 'manage_options' ) ) {
$this->error();
}

if ( ! isset( $_REQUEST['settings_data'] ) ) {
$this->error();
}
Expand All @@ -168,7 +172,7 @@ public function import_data() {
$settings = (array) json_decode( $data );

if ( is_array( $settings ) && ! empty( $settings ) ) {
update_option( 'lmt_plugin_global_settings', $settings );
update_option( 'lmt_plugin_global_settings', $settings, false );

// set temporary transient for admin notice
set_transient( 'wplmi_import_db_done', true );
Expand Down
6 changes: 3 additions & 3 deletions inc/Core/Backend/BlockEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BlockEditor extends BaseController
* Register functions.
*/
public function register() {
$this->filter( 'register_post_type_args', 'post_type_args', 99, 2 );
$this->filter( 'register_post_type_args', 'post_type_args', 9999, 2 );
$this->action( 'init', 'register_meta' );
$this->action( 'enqueue_block_editor_assets', 'assets' );

Expand All @@ -44,11 +44,11 @@ public function register() {
* @return array $args Post type data
*/
public function post_type_args( $args, $post_type ) {
if ( ! $this->do_filter( 'enable_custom_fields_support', true ) ) {
if ( ! $this->do_filter( 'enable_custom_fields_support', true, $post_type ) ) {
return $args;
}

if ( ! empty( $args['show_in_rest'] ) ) {
if ( ! empty( $args['show_in_rest'] ) && ! post_type_supports( $post_type, 'custom-fields' ) ) {
$args['supports'][] = 'custom-fields';
}

Expand Down
2 changes: 1 addition & 1 deletion inc/Core/Backend/DashboardWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function widget_control_callback() {
// Update widget options
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['wplmi_widget_options'] ) ) {
check_admin_referer();
update_option( 'lmt_dashboard_widget_options', array_map( 'intval', $_POST['wplmi_widget_options'] ) );
update_option( 'lmt_dashboard_widget_options', array_map( 'intval', $_POST['wplmi_widget_options'] ), false );
}

// Get widget options
Expand Down
4 changes: 2 additions & 2 deletions inc/Core/Backend/PluginsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function save_data( $data ) {
$new_data[ $data->slug ]['active_installs'] = $data->active_installs;
}

return update_option( 'wplmi_plugin_api_data', array_filter( $new_data ) );
return update_option( 'wplmi_plugin_api_data', array_filter( $new_data ), false );
}

/**
Expand Down Expand Up @@ -283,7 +283,7 @@ public function deactivate_plugin( $plugin ) {

if ( isset( $saved_data[ $plugin ] ) ) {
unset( $saved_data[ $plugin ] );
update_option( 'wplmi_plugin_api_data', $saved_data );
update_option( 'wplmi_plugin_api_data', $saved_data, false );
}
}

Expand Down
18 changes: 10 additions & 8 deletions inc/Helpers/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
trait Fields {

private $option_name = 'lmt_plugin_global_settings';

/**
* Send AJAX response.
*
Expand Down Expand Up @@ -81,7 +83,7 @@ protected function do_field( $data ) {
$value = isset( $data['value'] ) ? $data['value'] : '';

if ( $data['type'] == 'hidden' ) {
echo '<input type="hidden" name="lmt_plugin_global_settings[' . esc_attr( $name ) . ']" id="' . esc_attr( $data['id'] ) . '" autocomplete="off" value="' . esc_attr( $value ) . '" />';
echo '<input type="hidden" name="' . $this->option_name . '[' . esc_attr( $name ) . ']" id="' . esc_attr( $data['id'] ) . '" autocomplete="off" value="' . esc_attr( $value ) . '" />';
return;
}

Expand All @@ -97,7 +99,7 @@ protected function do_field( $data ) {
if ( $data['type'] == 'checkbox' ) {
$value = ! empty( $value ) ? $value : '1';
echo '<label class="switch">';
echo '<input type="checkbox" name="lmt_plugin_global_settings[' . esc_attr( $name ) . ']" id="' . esc_attr( $data['id'] ) . '" class="wplmi-form-el" value="' . esc_attr( $value ) . '" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' />
echo '<input type="checkbox" name="' . $this->option_name . '[' . esc_attr( $name ) . ']" id="' . esc_attr( $data['id'] ) . '" class="wplmi-form-el" value="' . esc_attr( $value ) . '" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' />
<span class="slider">
<svg width="3" height="8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 6" class="toggle-on" role="img" aria-hidden="true" focusable="false"><path d="M0 0h2v6H0z"></path></svg>
<svg width="8" height="8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6 6" class="toggle-off" role="img" aria-hidden="true" focusable="false"><path d="M3 1.5c.8 0 1.5.7 1.5 1.5S3.8 4.5 3 4.5 1.5 3.8 1.5 3 2.2 1.5 3 1.5M3 0C1.3 0 0 1.3 0 3s1.3 3 3 3 3-1.3 3-3-1.3-3-3-3z"></path></svg>
Expand All @@ -108,12 +110,12 @@ protected function do_field( $data ) {

if ( isset( $data['type'] ) ) {
if ( in_array( $data['type'], [ 'text', 'email', 'password', 'date', 'number' ] ) ) {
echo '<input type="' . esc_attr( $data['type'] ) . '" name="lmt_plugin_global_settings[' . esc_attr( $name ) . ']" id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" autocomplete="off" value="' . esc_attr( $value ) . '" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' />';
echo '<input type="' . esc_attr( $data['type'] ) . '" name="' . $this->option_name . '[' . esc_attr( $name ) . ']" id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" autocomplete="off" value="' . esc_attr( $value ) . '" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' />';
} elseif ( $data['type'] == 'textarea' ) {
echo '<textarea class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" id="' . esc_attr( $data['id'] ) . '" name="lmt_plugin_global_settings[' . esc_attr( $name ) . ']" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' autocomplete="off">' . wp_kses_post( $value ) . '</textarea>';
echo '<textarea class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" id="' . esc_attr( $data['id'] ) . '" name="' . $this->option_name . '[' . esc_attr( $name ) . ']" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' autocomplete="off">' . wp_kses_post( $value ) . '</textarea>';
} elseif ( $data['type'] == 'select' ) {
if ( isset( $data['options'] ) && is_array( $data['options'] ) ) {
echo '<select id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" name="lmt_plugin_global_settings[' . esc_attr( $name ) . ']" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' autocomplete="off">';
echo '<select id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" name="' . $this->option_name . '[' . esc_attr( $name ) . ']" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' autocomplete="off">';
if ( ! empty( $data['options'] ) ) {
foreach ( $data['options'] as $key => $option ) {
$disabled = '';
Expand All @@ -127,7 +129,7 @@ protected function do_field( $data ) {
}
} elseif ( $data['type'] == 'multiple' ) {
if ( isset( $data['options'] ) && is_array( $data['options'] ) ) {
echo '<select id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" name="lmt_plugin_global_settings[' . esc_attr( $name ) . '][]" multiple="multiple" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' style="width: 90%">';
echo '<select id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" name="' . $this->option_name . '[' . esc_attr( $name ) . '][]" multiple="multiple" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' style="width: 90%">';
if ( ! empty( $data['options'] ) ) {
foreach ( $data['options'] as $key => $option ) {
echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $value ), true, false ) . '>' . esc_html( $option ) . '</option>';
Expand All @@ -137,7 +139,7 @@ protected function do_field( $data ) {
}
} elseif ( $data['type'] == 'multiple_tax' ) {
if ( isset( $data['options'] ) && is_array( $data['options'] ) ) {
echo '<select id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" name="lmt_plugin_global_settings[' . esc_attr( $name ) . '][]" multiple="multiple" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' style="width: 90%">';
echo '<select id="' . esc_attr( $data['id'] ) . '" class="' . esc_attr( implode( ' ', array_unique( $class ) ) ) . '" name="' . $this->option_name . '[' . esc_attr( $name ) . '][]" multiple="multiple" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . ' style="width: 90%">';
if ( ! empty( $data['options'] ) ) {
foreach ( $data['options'] as $key => $option ) {
echo '<optgroup label="' . esc_attr( $option['label'] ) . '">';
Expand All @@ -154,7 +156,7 @@ protected function do_field( $data ) {
} elseif ( $data['type'] == 'wp_editor' ) {
echo '<div class="wplmi-form-control wplmi-form-el wplmi-editor" ' . wp_kses_post( implode( ' ', array_unique( $attr ) ) ) . '>';
wp_editor( html_entity_decode( $value, ENT_COMPAT, "UTF-8" ), $data['id'], [
'textarea_name' => 'lmt_plugin_global_settings[' . esc_attr( $name ) . ']',
'textarea_name' => $this->option_name . '[' . esc_attr( $name ) . ']',
'textarea_rows' => '8',
'teeny' => true,
'tinymce' => false,
Expand Down
Loading

0 comments on commit 84e7c15

Please sign in to comment.