Skip to content

Commit

Permalink
Merge pull request #266 from codepress/release/4.0.1
Browse files Browse the repository at this point in the history
Release/4.0.1
  • Loading branch information
DGStefan authored Feb 18, 2020
2 parents 98c1230 + bcb418e commit 12a0071
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 55 deletions.
2 changes: 1 addition & 1 deletion assets/js/admin-page-columns.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/admin-page-columns.js.map

Large diffs are not rendered by default.

64 changes: 41 additions & 23 deletions classes/AdminColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function __construct() {
$this->list_screen_repository = new ListScreenRepository\Aggregate();
$this->list_screen_repository->register_repository( new ListScreenRepository\DataBase( ListScreenTypes::instance() ) );

$modules = [
$services = [
new Ajax\NumberFormat( new Request() ),
new Deprecated\Hooks,
new Screen,
Expand All @@ -75,28 +75,29 @@ private function __construct() {
new ListScreenRestoreColumns( $this->list_screen_repository ),
];

foreach ( $modules as $module ) {
if ( $module instanceof Registrable ) {
$module->register();
foreach ( $services as $service ) {
if ( $service instanceof Registrable ) {
$service->register();
}
}

$this->register_admin();
$this->localize();

add_action( 'init', array( $this, 'install' ), 1000 );
add_action( 'init', array( $this, 'notice_checks' ) );
add_action( 'init', array( $this, 'register_global_scripts' ) );
add_action( 'init', [ $this, 'install' ], 1000 );
add_action( 'init', [ $this, 'notice_checks' ] );
add_action( 'init', [ $this, 'register_global_scripts' ] );

add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 1, 2 );
add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 1, 2 );
add_filter( 'plugin_action_links', [ $this, 'add_pro_link' ], 10, 2 );

add_action( 'ac/screen', array( $this, 'init_table_on_screen' ) );
add_action( 'wp_ajax_ac_get_column_value', array( $this, 'table_ajax_value' ) );
add_action( 'ac/screen', [ $this, 'init_table_on_screen' ] );
add_action( 'wp_ajax_ac_get_column_value', [ $this, 'table_ajax_value' ] );

add_filter( 'wp_redirect', array( $this, 'redirect_after_status_change' ) );
add_filter( 'wp_redirect', [ $this, 'redirect_after_status_change' ] );

// run after all post types are registered
add_action( 'init', array( $this, 'register_list_screens' ), 1000 );
add_action( 'init', [ $this, 'register_list_screens' ], 1000 );
}

/**
Expand Down Expand Up @@ -218,9 +219,9 @@ public function table_ajax_value() {
* Init checks
*/
public function notice_checks() {
$checks = array(
$checks = [
new Check\Review(),
);
];

if ( ! ac_is_pro_active() ) {
foreach ( new PromoCollection() as $promo ) {
Expand Down Expand Up @@ -276,6 +277,23 @@ public function add_settings_link( $links, $file ) {
return $links;
}

/**
* @param array $links
* @param string $file
*
* @return array
*/
public function add_pro_link( $links, $file ) {
if ( $file === $this->get_basename() && ! ac_is_pro_active() ) {
$links[] = sprintf( '<a href="%s" target="_blank">%s</a>',
esc_url( ac_get_site_utm_url( 'admin-columns-pro', 'upgrade' ) ),
sprintf( '<span style="font-weight: bold;">%s</span>', __( 'Go Pro', 'codepress-admin-columns' ) )
);
}

return $links;
}

/**
* @since 2.5
*/
Expand Down Expand Up @@ -334,10 +352,10 @@ public function register_list_screens() {
* @return void
*/
public function register_global_scripts() {
wp_register_script( 'ac-select2-core', $this->get_url() . 'assets/js/select2.js', array(), $this->get_version() );
wp_register_script( 'ac-select2', $this->get_url() . 'assets/js/select2_conflict_fix.js', array( 'jquery', 'ac-select2-core' ), $this->get_version() );
wp_register_style( 'ac-select2', $this->get_url() . 'assets/css/select2.css', array(), $this->get_version() );
wp_register_style( 'ac-jquery-ui', $this->get_url() . 'assets/css/ac-jquery-ui.css', array(), $this->get_version() );
wp_register_script( 'ac-select2-core', $this->get_url() . 'assets/js/select2.js', [], $this->get_version() );
wp_register_script( 'ac-select2', $this->get_url() . 'assets/js/select2_conflict_fix.js', [ 'jquery', 'ac-select2-core' ], $this->get_version() );
wp_register_style( 'ac-select2', $this->get_url() . 'assets/css/select2.css', [], $this->get_version() );
wp_register_style( 'ac-jquery-ui', $this->get_url() . 'assets/css/ac-jquery-ui.css', [], $this->get_version() );
}

/**
Expand All @@ -346,12 +364,12 @@ public function register_global_scripts() {
* @since 1.0
*/
public function get_post_types() {
$post_types = get_post_types( array(
$post_types = get_post_types( [
'_builtin' => false,
'show_ui' => true,
) );
] );

foreach ( array( 'post', 'page' ) as $builtin ) {
foreach ( [ 'post', 'page' ] as $builtin ) {
if ( post_type_exists( $builtin ) ) {
$post_types[ $builtin ] = $builtin;
}
Expand Down Expand Up @@ -425,11 +443,11 @@ public function redirect_after_status_change( $location ) {
return $location;
}

$location = add_query_arg( array(
$location = add_query_arg( [
'status' => $status,
'plugin' => $integration->get_slug(),
'_ac_nonce' => wp_create_nonce( 'ac-plugin-status-change' ),
), $this->admin()->get_url( 'addons' ) );
], $this->admin()->get_url( 'addons' ) );

return $location;
}
Expand Down
10 changes: 5 additions & 5 deletions classes/Column/Post/PostParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public function __construct() {
}

public function get_value( $post_id ) {
$title = false;
$parent_id = $this->get_raw_value( $post_id );

if ( $parent_id = $this->get_raw_value( $post_id ) ) {
$title = ac_helper()->html->link( get_edit_post_link( $parent_id ), ac_helper()->post->get_raw_field( 'post_title', $parent_id ) );
if ( ! $parent_id ) {
return $this->get_empty_char();
}

return $title;
return ac_helper()->html->link( get_edit_post_link( $parent_id ), ac_helper()->post->get_raw_field( 'post_title', $parent_id ) );
}

public function get_raw_value( $post_id ) {
$parent_id = ac_helper()->post->get_raw_field( 'post_parent', $post_id );

return $parent_id && is_numeric( $parent_id ) ? $parent_id : false;
return $parent_id && is_numeric( $parent_id ) ? (int) $parent_id : false;
}

public function is_valid() {
Expand Down
16 changes: 10 additions & 6 deletions classes/Helper/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Date {
* @return int|false
*/
public function strtotime( $date ) {
if ( empty( $date ) || in_array( $date, array( '0000-00-00 00:00:00', '0000-00-00', '00:00:00' ) ) || ! is_scalar( $date ) ) {
if ( empty( $date ) || in_array( $date, [ '0000-00-00 00:00:00', '0000-00-00', '00:00:00' ] ) || ! is_scalar( $date ) ) {
return false;
}

Expand Down Expand Up @@ -58,7 +58,11 @@ public function get_timestamp_from_format( $date, $format ) {
return $date;
}

return ( DateTime::createFromFormat( $format, $date ) )->format( 'U' );
$_date = DateTime::createFromFormat( $format, $date );

return $_date
? $_date->format( 'U' )
: false;
}

/**
Expand Down Expand Up @@ -153,7 +157,7 @@ public function time( $date, $format = '' ) {
* @since 1.1
*/
public function parse_jquery_dateformat( $format ) {
$replace = array(
$replace = [
'^dd^d' => 'j',
'dd' => 'd',
'DD' => 'l',
Expand All @@ -162,10 +166,10 @@ public function parse_jquery_dateformat( $format ) {
'^mm^m' => 'n',
'mm' => 'm',
'yy' => 'Y',
);
];

$replace_from = array();
$replace_to = array();
$replace_from = [];
$replace_to = [];

foreach ( $replace as $from => $to ) {
$replace_from[] = '/' . $from . '/';
Expand Down
18 changes: 9 additions & 9 deletions classes/PluginInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function get_dirname() {
* @return bool
*/
public function is_installed() {
return $this->get_plugin_info() ? true : false;
return null !== $this->get_plugin_info();
}

/**
Expand All @@ -35,7 +35,7 @@ public function is_active() {
}

/**
* @return string|false Returns the plugin version if the plugin is installed, false otherwise
* @return string|null
*/
public function get_version() {
return $this->get_plugin_var( 'Version' );
Expand All @@ -49,20 +49,20 @@ public function get_basename() {
}

/**
* @return string Name
* @return string
*/
public function get_name() {
return $this->get_plugin_var( 'Name' );
}

/**
* @return array|false
* @return array|null
*/
private function get_plugin_info() {
$plugins = (array) get_plugins();

if ( ! array_key_exists( $this->basename, $plugins ) ) {
return false;
return null;
}

return $plugins[ $this->basename ];
Expand All @@ -71,13 +71,13 @@ private function get_plugin_info() {
/**
* @param string $var
*
* @return string|false
* @return string|null
*/
public function get_plugin_var( $var ) {
private function get_plugin_var( $var ) {
$info = $this->get_plugin_info();

if ( ! isset( $info[ $var ] ) ) {
return false;
if ( ! $info || ! isset( $info[ $var ] ) ) {
return null;
}

return $info[ $var ];
Expand Down
38 changes: 32 additions & 6 deletions classes/Settings/Column/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class CustomField extends Settings\Column {
private $field;

protected function define_options() {
return array( 'field' );
return [ 'field' ];
}

/**
* @return View
*/
public function create_view() {
$view = new View( array(
$view = new View( [
'label' => __( 'Field', 'codepress-admin-columns' ),
'setting' => $this->get_setting_field(),
) );
] );

return $view;
}
Expand All @@ -33,8 +33,25 @@ protected function set_name() {
$this->name = 'custom_field';
}

protected function get_setting_field() {
$options = $this->get_field() ? array( $this->get_field() => $this->get_field() ) : array();
private function use_text_field() {
return (bool) apply_filters( 'ac/column/custom_field/use_text_input', false );
}

/**
* @return AC\Form\Element\Input
*/
private function get_settings_field_text() {
return $this->create_element( 'text', 'field' )
->set_attribute( 'placeholder', 'Custom field key' );
}

/**
* @return AC\Form\Element\Select
*/
private function get_settings_field_select() {
$options = $this->get_field()
? [ $this->get_field() => $this->get_field() ]
: [];

return $this->create_element( 'select', 'field' )
->set_attribute( 'data-selected', $this->get_field() )
Expand All @@ -44,8 +61,17 @@ protected function get_setting_field() {
->set_attribute( 'class', 'custom_field' );
}

/**
* @return AC\Form\Element
*/
protected function get_setting_field() {
return $this->use_text_field()
? $this->get_settings_field_text()
: $this->get_settings_field_select();
}

public function get_dependent_settings() {
return array( new Settings\Column\CustomFieldType( $this->column ) );
return [ new Settings\Column\CustomFieldType( $this->column ) ];
}

protected function get_meta_type() {
Expand Down
4 changes: 2 additions & 2 deletions codepress-admin-columns.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Admin Columns
Version: 4.0.0
Version: 4.0.1
Description: Customize columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.
Author: AdminColumns.com
Author URI: https://www.admincolumns.com
Expand Down Expand Up @@ -36,7 +36,7 @@
}

define( 'AC_FILE', __FILE__ );
define( 'AC_VERSION', '4.0.0' );
define( 'AC_VERSION', '4.0.1' );

require_once __DIR__ . '/classes/Dependencies.php';

Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: plugins, wordpress, admin, column, columns, custom columns, custom fields,
Requires at least: 4.5
Tested up to: 5.3.2
Requires PHP: 5.6.20
Stable tag: 4.0.0
Stable tag: 4.0.1

Customise columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.

Expand Down Expand Up @@ -213,6 +213,12 @@ You can find a list of the available actions and filters (and examples on how to

== Changelog ==

= 4.0.1 =
Release Date: February 18th, 2020

* [Fixed] Fatal error in Date helper that occurs in PHP 5.6
* [Improved] Re-added the hook `ac/column/custom_field/use_text_input` to use a text field for the custom field column setting

= 4.0.0 =
Release Date: February 3rd, 2020

Expand Down
2 changes: 1 addition & 1 deletion src/js/admin/columns/settings/custom-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CustomField {
this.column = column;
this.setting = column.$el[ 0 ].querySelector( '.ac-column-setting--custom_field' );

if ( !this.setting ) {
if ( !this.setting || !this.setting.querySelector( '.custom_field' ) ) {
return;
}

Expand Down

0 comments on commit 12a0071

Please sign in to comment.