254fa1fa by Jeremy Groot

plugin updates

1 parent 3305b4e1
Showing 1000 changed files with 1544 additions and 437 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

.editable-container .acf-editable-range input[type=range]{width:150px;display:inline-block;vertical-align:middle;margin-right:10px}.editable-container .acf-editable-range input[type=text]{width:50px;display:inline-block}.aceditable.-acf_range input[type=range]{width:200px;height:30px;background:none;margin-right:5px}.aceditable.-acf_range input[name=reflection]{width:60px}.ac-modal.-bulkedit .aceditable.-acf_range input[type=range]{width:100%}.ac-repeater-divider{display:block;border-bottom:1px dotted #ccc;clear:both;margin-bottom:3px}.ac-repeater-divider:before{content:"";display:block;clear:both;float:none;height:3px}
body.acf-admin-field-groups .tablenav.top{display:block}body.acf-admin-field-groups .tablenav.top .bulkactions{display:none}body.acf-admin-field-groups .tablenav.top .query-builder .ac-button-group button.ac-button__add-filter{border-top-left-radius:3px;border-bottom-left-radius:3px}body.acf-admin-field-groups .tablenav.top .query-builder .ac-button-group button.ac-button__segments{border-top-right-radius:3px;border-bottom-right-radius:3px}body.acf-admin-field-groups .tablenav.top .ac-search .button{height:25px}body.acf-admin-field-groups .tablenav.top .acp-nav-tab-wrapper{margin-top:0}body.acf-admin-field-groups .tablenav.top .query-builder .ac-button-group button.ac-button__segments:before{transform:none}body.acf-admin-field-groups .tablenav.top #post-query-submit{height:25px;border-radius:3px}body.acf-admin-field-groups .tablenav.top .alignleft.actions select{height:25px;border-radius:3px}.editable-container .acf-editable-range input[type=range]{width:150px;display:inline-block;vertical-align:middle;margin-right:10px}.editable-container .acf-editable-range input[type=text]{width:50px;display:inline-block}.aceditable.-acf_range input[type=range]{width:200px;height:30px;background:none;margin-right:5px}.aceditable.-acf_range input[name=reflection]{width:60px}.ac-modal.-bulkedit .aceditable.-acf_range input[type=range]{width:100%}.ac-repeater-divider{display:block;border-bottom:1px dotted #ccc;clear:both;margin-bottom:3px}.ac-repeater-divider:before{content:"";display:block;clear:both;float:none;height:3px}
......
......@@ -7,12 +7,10 @@ use AC\Registerable;
use AC\Request;
use ACA\ACF\ConditionalFormatting\FieldFormattableFactory;
use ACA\ACF\FieldGroup;
use ACA\ACF\ListScreenFactory\FieldGroupFactory;
use ACA\ACF\RequestHandler\MapLegacyListScreen;
use ACA\ACF\Search;
use ACA\ACF\Service\AddColumns;
use ACA\ACF\Service\ColumnSettings;
use ACA\ACF\Service\InitColumn;
use ACA\ACF\Service\Scripts;
use ACA\ACF\Service;
use ACA\ACF\Sorting;
use ACP;
use ACP\RequestHandlerFactory;
......@@ -31,6 +29,8 @@ final class AdvancedCustomFields implements Registerable {
return;
}
AC\ListScreenFactory::add( new FieldGroupFactory() );
$column_initiator = new ColumnInstantiator(
new ConfigFactory( new FieldFactory() ),
new Search\ComparisonFactory(),
......@@ -46,21 +46,22 @@ final class AdvancedCustomFields implements Registerable {
$services = [
new ACP\Service\IntegrationStatus( 'ac-addon-acf' ),
new ColumnGroup(),
new Service\ColumnSettings(),
new Service\EditingFix(),
new Service\LegacyColumnMapper(),
new Service\ListScreens(),
new Service\RemoveDeprecatedColumnFromTypeSelector(),
new AddColumns(
new Service\AddColumns(
new FieldRepository( new FieldGroup\QueryFactory() ),
new FieldsFactory(),
new ColumnFactory( $column_initiator )
),
new Scripts( $this->location ),
new InitColumn( $column_initiator ),
new ColumnSettings(),
new Service\Scripts( $this->location ),
new Service\InitColumn( $column_initiator ),
new RequestParser( $request_handler_factory ),
];
array_map( function ( Registerable $service ) {
array_map( static function ( Registerable $service ) {
$service->register();
}, $services );
}
......
<?php
namespace ACA\ACF\Column\FieldGroup;
use AC;
use ACA\ACF\Search;
use ACP\Search\Searchable;
class Location extends AC\Column implements Searchable {
public function __construct() {
$this
->set_type( 'acf-location' )
->set_original( true );
}
public function search() {
return new Search\Comparison\FieldGroup\Location();
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ class ColumnGroup implements AC\Registerable {
}
public function register_column_groups( AC\Groups $groups ) {
$groups->register_group( self::SLUG, 'Advanced Custom Fields', 11 );
$groups->add( self::SLUG, 'Advanced Custom Fields', 11 );
}
}
\ No newline at end of file
......
......@@ -20,6 +20,7 @@ class ModelFactory {
case FieldType::TYPE_RADIO:
case FieldType::TYPE_CHECKBOX:
case FieldType::TYPE_POST:
case FieldType::TYPE_GOOGLE_MAP:
case FieldType::TYPE_RELATIONSHIP:
case FieldType::TYPE_USER:
case FieldType::TYPE_TAXONOMY:
......
<?php
namespace ACA\ACF\ListScreen;
use ACA\ACF;
use ACP;
use ACP\Column;
class FieldGroup extends ACP\ListScreen\Post {
public function __construct() {
parent::__construct( 'acf-field-group' );
$this->set_group( 'acf' );
}
protected function register_column_types() {
$this->register_column_types_from_list( [
Column\CustomField::class,
Column\Actions::class,
Column\Post\Author::class,
Column\Post\Content::class,
Column\Post\DatePublished::class,
Column\Post\ID::class,
Column\Post\Modified::class,
Column\Post\Status::class,
Column\Post\Title::class,
Column\Post\TitleRaw::class,
ACF\Column\FieldGroup\Location::class,
] );
}
}
\ No newline at end of file
<?php
namespace ACA\ACF\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\ACF\ListScreen\FieldGroup;
use LogicException;
use WP_Screen;
class FieldGroupFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'acf-field-group' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new FieldGroup(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'acf-field-group';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new FieldGroup(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\ACF\Search\Comparison\FieldGroup;
use AC\Helper\Select\Options;
use ACP\Search\Comparison;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
class Location extends Comparison implements Comparison\Values {
public function __construct() {
$operators = new Operators( [
Operators::EQ,
] );
parent::__construct( $operators );
}
protected function create_query_bindings( $operator, Value $value ) {
global $wpdb;
$binding = new Bindings();
$groups = acf_get_field_groups( [ $value->get_value() => true ] );
$ids = is_array( $groups ) ? wp_list_pluck( $groups, 'ID' ) : [];
if ( empty( $ids ) ) {
$ids = [ 0 ];
}
$binding->where( sprintf( $wpdb->posts . '.ID IN (%s)', implode( ',', $ids ) ) );
return $binding;
}
public function get_values() {
return Options::create_from_array( [
'block' => _x( 'Block', 'ACF location', 'codepress-admin-columns' ),
'user_form' => _x( 'Users', 'ACF location', 'codepress-admin-columns' ),
'taxonomy' => __( 'Taxonomy' ),
'comment' => __( 'Comment' ),
'post_type' => _x( 'Post Type', 'ACF location', 'codepress-admin-columns' ),
'widget' => _x( 'Widget', 'ACF location', 'codepress-admin-columns' ),
'options_page' => _x( 'Option Page', 'ACF location', 'codepress-admin-columns' ),
'nav_menu' => _x( 'Menu', 'ACF location', 'codepress-admin-columns' ),
] );
}
}
\ No newline at end of file
<?php
namespace ACA\ACF\Service;
use AC\Column;
use AC\Groups;
use AC\Registerable;
use ACA\ACF\ListScreen;
class ListScreens implements Registerable {
public function register() {
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_groups' ] );
add_filter( 'ac/export/value', [ $this, 'strip_tags_export_value' ], 10, 2 );
}
public function strip_tags_export_value( string $value, Column $column ) {
if ( $column->get_list_screen() instanceof ListScreen\FieldGroup && $column->is_original() ) {
$value = strip_tags( $value );
}
return $value;
}
public function register_list_screen_groups( Groups $groups ): void {
$groups->add( 'acf', __( 'Advanced Custom Fields', 'codepress-admin-columns' ), 7 );
}
}
\ No newline at end of file
<?php
namespace ACA\BbPress\ListScreen;
use ACA\BbPress\Column;
use ACP;
class Forum extends ACP\ListScreen\Post {
public function __construct() {
parent::__construct( 'forum' );
$this->set_group( 'bbpress' );
}
}
\ No newline at end of file
<?php
namespace ACA\BbPress\ListScreen;
use ACA\BbPress\Column;
use ACP;
class Reply extends ACP\ListScreen\Post {
public function __construct() {
parent::__construct( 'reply' );
$this->set_group( 'bbpress' );
}
}
\ No newline at end of file
<?php
namespace ACA\BbPress\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\BbPress\ListScreen\Topic;
use LogicException;
use WP_Screen;
class TopicFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'topic' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new Topic(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'topic';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new Topic(), $settings );
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ class Columns implements Registerable {
* @param AC\Groups $groups
*/
public function register_column_group( AC\Groups $groups ) {
$groups->register_group( 'bbpress', __( 'bbPress' ), 25 );
$groups->add( 'bbpress', __( 'bbPress' ), 25 );
}
}
\ No newline at end of file
......
......@@ -2,8 +2,6 @@
namespace ACA\BbPress\Service;
use AC;
use AC\ListScreenTypes;
use AC\Registerable;
class Editing implements Registerable {
......@@ -12,12 +10,6 @@ class Editing implements Registerable {
add_filter( 'ac/editing/role_group', [ $this, 'editing_role_group' ], 10, 2 );
}
/**
* @param $group
* @param $role
*
* @return string
*/
public function editing_role_group( $group, $role ) {
if ( strpos( $role, "bbp_" ) === 0 ) {
$group = __( 'bbPress', 'codepress-admin-columns' );
......
......@@ -3,30 +3,37 @@
namespace ACA\BbPress\Service;
use AC;
use AC\ListScreenPost;
use AC\Registerable;
use ACA\BbPress\ListScreen;
use ACA\BbPress\ListScreenFactory\TopicFactory;
class ListScreens implements Registerable {
public function register() {
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_group' ] );
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ], 11 );
add_action( 'ac/admin/menu_group', [ $this, 'update_menu_list_groups' ], 10, 2 );
AC\ListScreenFactory::add( new TopicFactory() );
}
public function register_list_screen_group( AC\Groups $groups ): void {
$groups->register_group( 'bbpress', __( 'bbPress' ), 8 );
$groups->add( 'bbpress', __( 'bbPress' ), 8 );
}
public function register_list_screens(): void {
$list_screens = [
new ListScreen\Topic(),
new ListScreen\Forum(),
new ListScreen\Reply(),
private function get_post_list_keys(): array {
return [
'forum',
'reply',
'topic',
];
}
foreach ( $list_screens as $list_screen ) {
AC\ListScreenTypes::instance()->register_list_screen( $list_screen );
public function update_menu_list_groups( string $group, AC\ListScreen $list_screen ): string {
if ( $list_screen instanceof ListScreenPost && in_array( $list_screen->get_post_type(), $this->get_post_list_keys(), true ) ) {
return 'bbpress';
}
return $group;
}
}
\ No newline at end of file
......
......@@ -2,6 +2,7 @@
namespace ACA\BeaverBuilder;
use AC;
use AC\Registerable;
use ACA\BeaverBuilder\Service;
......@@ -9,9 +10,14 @@ class BeaverBuilder implements Registerable {
public function register() {
if ( ! class_exists( 'FLBuilderLoader' ) ) {
return;
return;
}
AC\ListScreenFactory::add( new ListScreenFactory\Templates() );
AC\ListScreenFactory::add( new ListScreenFactory\SavedColumns() );
AC\ListScreenFactory::add( new ListScreenFactory\SavedModules() );
AC\ListScreenFactory::add( new ListScreenFactory\SavedRows() );
$services = [
new Service\ListScreens(),
new Service\PostTypes(),
......
......@@ -6,33 +6,26 @@ use ACP;
class Template extends ACP\ListScreen\Post {
/*
* @var string
*/
public const POST_TYPE = 'fl-builder-template';
private $template_page;
/*
* @var string
*/
private $page_label;
private $custom_label;
public function __construct( $page, $label ) {
public function __construct( string $template_page, string $label ) {
parent::__construct( 'fl-builder-template' );
$this->template_page = (string) $page;
$this->page_label = (string) $label;
$this->template_page = $template_page;
$this->custom_label = $label;
$this->set_key( 'fl-builder-template' . $page )
$this->set_key( self::POST_TYPE . $template_page )
->set_group( 'beaver_builder' )
->set_label( $label )
->set_screen_id( $this->get_screen_base() . '-fl-builder-template' );
}
public function is_current_screen( $wp_screen ) {
return parent::is_current_screen( $wp_screen ) && filter_input( INPUT_GET, 'fl-builder-template-type' ) === $this->template_page;
}
public function get_label() {
return $this->page_label;
return $this->custom_label;
}
public function get_screen_link() {
......
<?php
declare( strict_types=1 );
namespace ACA\BeaverBuilder;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\BeaverBuilder\ListScreen\Template;
use LogicException;
use WP_Screen;
abstract class ListScreenFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
private function create_list_screen(): Template {
return new Template( $this->get_page(), $this->get_label() );
}
abstract protected function get_label(): string;
abstract protected function get_page(): string;
public function can_create( string $key ): bool {
return $key === Template::POST_TYPE . $this->get_page() && post_type_exists( Template::POST_TYPE );
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid key' );
}
return $this->add_settings( $this->create_list_screen(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return 'edit' === $screen->base
&& $screen->post_type
&& 'edit-' . $screen->post_type === $screen->id
&& $this->get_page() === filter_input( INPUT_GET, 'fl-builder-template-type' );
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid screen' );
}
return $this->add_settings( $this->create_list_screen(), $settings );
}
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace ACA\BeaverBuilder\ListScreenFactory;
use ACA\BeaverBuilder\ListScreenFactory;
class SavedColumns extends ListScreenFactory {
protected function get_label(): string {
return __( 'Saved Columns', 'fl-builder' );
}
protected function get_page(): string {
return 'column';
}
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace ACA\BeaverBuilder\ListScreenFactory;
use ACA\BeaverBuilder\ListScreenFactory;
class SavedModules extends ListScreenFactory {
protected function get_label(): string {
return __( 'Saved Modules', 'fl-builder' );
}
protected function get_page(): string {
return 'module';
}
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace ACA\BeaverBuilder\ListScreenFactory;
use ACA\BeaverBuilder\ListScreenFactory;
class SavedRows extends ListScreenFactory {
protected function get_label(): string {
return __( 'Saved Rows', 'fl-builder' );
}
protected function get_page(): string {
return 'row';
}
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace ACA\BeaverBuilder\ListScreenFactory;
use ACA\BeaverBuilder\ListScreenFactory;
class Templates extends ListScreenFactory {
protected function get_label(): string {
return __( 'Templates', 'fl-builder' );
}
protected function get_page(): string {
return 'layout';
}
}
\ No newline at end of file
......@@ -2,37 +2,53 @@
namespace ACA\BeaverBuilder\Service;
use AC;
use AC\Groups;
use AC\ListScreen;
use AC\Registerable;
use ACA\BeaverBuilder\ListScreen;
use AC\Table\ListKeyCollection;
use AC\Type\ListKey;
use ACA\BeaverBuilder\ListScreen\Template;
use ACP\ListScreen\Taxonomy;
class ListScreens implements Registerable {
public function register(): void {
add_action( 'ac/list_screen_groups', [ $this, 'register_beaver_builder_group' ] );
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ] );
add_filter( 'ac/admin/menu_group', [ $this, 'update_menu_list_groups' ], 10, 2 );
add_action( 'ac/list_keys', [ $this, 'add_list_keys' ] );
}
public function register_beaver_builder_group( Groups $groups ): void {
$groups->register_group( 'beaver_builder', __( 'Beaver Builder', 'codepress-admin-columns' ), 6 );
}
public function add_list_keys( ListKeyCollection $list_keys ): void {
$templates = [
'column',
'module',
'row',
'layout',
];
public function register_list_screens( AC\ListScreens $list_screens ): void {
if ( ! post_type_exists( PostTypes::POST_TYPE_TEMPLATE ) ) {
return;
foreach ( $templates as $template ) {
$list_keys->add( new ListKey( Template::POST_TYPE . $template ) );
}
}
$bb_list_screens = [
new ListScreen\Template( 'layout', __( 'Templates', 'fl-builder' ) ),
new ListScreen\Template( 'row', __( 'Saved Rows', 'fl-builder' ) ),
new ListScreen\Template( 'column', __( 'Saved Columns', 'fl-builder' ) ),
new ListScreen\Template( 'module', __( 'Saved Modules', 'fl-builder' ) ),
public function register_beaver_builder_group( Groups $groups ): void {
$groups->add( 'beaver_builder', __( 'Beaver Builder', 'codepress-admin-columns' ), 6 );
}
public function update_menu_list_groups( string $group, ListScreen $list_screen ): string {
$keys = [
Template::POST_TYPE . 'column',
Template::POST_TYPE . 'module',
Template::POST_TYPE . 'row',
Template::POST_TYPE . 'layout',
Taxonomy::KEY_PREFIX . 'fl-builder-template-category',
];
foreach ( $bb_list_screens as $list_screen ) {
$list_screens->register_list_screen( $list_screen );
if ( in_array( $list_screen->get_key(), $keys, true ) ) {
$group = 'beaver_builder';
}
return $group;
}
}
\ No newline at end of file
......
......@@ -4,6 +4,7 @@ namespace ACA\BP;
use AC;
use AC\Registerable;
use ACA\BP\ListScreenFactory;
use ACA\BP\Service;
use ACP\Service\IntegrationStatus;
......@@ -29,6 +30,9 @@ final class BuddyPress implements Registerable {
];
array_map( [ $this, 'register_service' ], $services );
AC\ListScreenFactory::add( new ListScreenFactory\Email() );
AC\ListScreenFactory::add( new ListScreenFactory\Group() );
}
private function register_service( $service ) {
......
......@@ -6,25 +6,16 @@ use ACA\BP\Editing\RequestHandler;
use ACP;
class Group implements ACP\Editing\Strategy {
/**
* @param int|object $entry_id
*
* @return bool|int
*/
public function user_can_edit_item( $entry_id ) {
if ( is_object( $entry_id ) ) {
$entry_id = $entry_id->id;
}
return current_user_can( 'bp_moderate', $entry_id );
public function user_can_edit_item( int $id ): bool {
return current_user_can( 'bp_moderate', $id );
}
public function user_can_edit() {
public function user_can_edit(): bool {
return current_user_can( 'bp_moderate' );
}
public function get_query_request_handler() {
public function get_query_request_handler(): ACP\Editing\RequestHandler {
return new RequestHandler\Query\Groups();
}
......
......@@ -49,10 +49,6 @@ class Group extends AC\ListScreenWP
add_action( 'bp_groups_admin_get_group_custom_column', [ $this, 'manage_value' ], 100, 3 );
}
public function is_current_screen( $wp_screen ) {
return $wp_screen && $wp_screen->id === $this->get_screen_id() && 'edit' !== filter_input( INPUT_GET, 'action' );
}
public function get_screen_link() {
return add_query_arg( [ 'page' => $this->get_page(), 'layout' => $this->get_layout_id() ], $this->get_admin_url() );
}
......
<?php
namespace ACA\BP\ListScreenFactory;
use AC;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\BP\ListScreen;
use LogicException;
use WP_Screen;
class Email implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'bp-email' === $key;
}
public function create( string $key, array $settings = [] ): AC\ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new ListScreen\Email(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'bp-email';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): AC\ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new ListScreen\Email(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\BP\ListScreenFactory;
use AC;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\BP\ListScreen;
use LogicException;
use WP_Screen;
class Group implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'bp-groups' === $key;
}
public function create( string $key, array $settings = [] ): AC\ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new ListScreen\Group(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->id === 'toplevel_page_bp-groups' && 'edit' !== filter_input( INPUT_GET, 'action' );
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): AC\ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new ListScreen\Group(), $settings );
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ class Columns implements Registerable {
* @param AC\Groups $groups
*/
public function register_column_groups( AC\Groups $groups ) {
$groups->register_group( 'buddypress', 'BuddyPress', 11 );
$groups->add( 'buddypress', 'BuddyPress', 11 );
}
}
\ No newline at end of file
......
......@@ -4,28 +4,37 @@ namespace ACA\BP\Service;
use AC;
use AC\Registerable;
use ACA\BP\ListScreen;
use AC\Table\ListKeyCollection;
use AC\Type\ListKey;
final class ListScreens implements Registerable {
public function register() {
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_group' ] );
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ] );
add_filter( 'ac/admin/menu_group', [ $this, 'update_menu_list_groups' ], 10, 2 );
add_action( 'ac/list_keys', [ $this, 'add_list_keys' ] );
}
/**
* @param AC\AdminColumns $admin_columns
*/
public function register_list_screens( AC\ListScreens $list_screens ) {
$list_screens->register_list_screen( new ListScreen\Email() )
->register_list_screen( new ListScreen\Group() );
public function add_list_keys( ListKeyCollection $list_keys ): void {
if ( bp_is_active( 'groups' ) ) {
$list_keys->add( new ListKey( 'bp-groups' ) );
}
}
/**
* @param AC\Groups $groups
*/
public function register_list_screen_group( AC\Groups $groups ) {
$groups->register_group( 'buddypress', __( 'BuddyPress' ), 14 );
public function register_list_screen_group( AC\Groups $groups ): void {
$groups->add( 'buddypress', __( 'BuddyPress' ), 14 );
}
public function update_menu_list_groups( string $group, AC\ListScreen $list_screen ): string {
$keys = [
'bp-email',
];
if ( in_array( $list_screen->get_key(), $keys, true ) ) {
return 'buddypress';
}
return $group;
}
}
\ No newline at end of file
......
......@@ -27,7 +27,7 @@ final class EventsCalendar implements Registerable {
new Service\Scripts( $this->location ),
new Service\TableScreen( $this->location ),
new ImportListscreens\Message( new ImportListscreens\ImportedSetting() ),
new ImportListscreens\Controller( new AC\Request(), AC()->get_storage(), new DecoderFactory( AC\ListScreenTypes::instance() ), $this->location ),
new ImportListscreens\Controller( new AC\Request(), AC()->get_storage(), new DecoderFactory( new AC\ListScreenFactory() ), $this->location ),
new IntegrationStatus( 'ac-addon-events-calendar' ),
];
......
<?php
namespace ACA\EC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\EC\ListScreen\Event;
use LogicException;
use WP_Screen;
class EventFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'tribe_events' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new Event(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'tribe_events';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new Event(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\EC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\EC\ListScreen\EventSeries;
use LogicException;
use WP_Screen;
class EventSeriesFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'tribe_event_series' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new EventSeries(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'tribe_event_series';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new EventSeries(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\EC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\EC\ListScreen\Organizer;
use LogicException;
use WP_Screen;
class OrganizerFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'tribe_organizer' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new Organizer(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'tribe_organizer';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new Organizer(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\EC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\EC\ListScreen\Venue;
use LogicException;
use WP_Screen;
class VenueFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'tribe_venue' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new Venue(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'tribe_venue';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new Venue(), $settings );
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
namespace ACA\EC\Service;
use AC;
use AC\Groups;
use AC\Registerable;
final class ColumnGroups implements Registerable {
......@@ -14,12 +15,9 @@ final class ColumnGroups implements Registerable {
add_action( 'ac/column_groups', [ $this, 'register_column_groups' ] );
}
/**
* @param AC\Groups $groups
*/
public function register_column_groups( $groups ) {
$groups->register_group( self::EVENTS_CALENDAR, 'The Events Calendar', 11 );
$groups->register_group( self::EVENTS_CALENDAR_FIELDS, 'The Events Calendar' . ' - ' . __( 'Additional Fields', 'tribe-events-calendar-pro' ), 11 );
public function register_column_groups( Groups $groups ) {
$groups->add( self::EVENTS_CALENDAR, 'The Events Calendar', 11 );
$groups->add( self::EVENTS_CALENDAR_FIELDS, 'The Events Calendar' . ' - ' . __( 'Additional Fields', 'tribe-events-calendar-pro' ), 11 );
}
}
\ No newline at end of file
......
......@@ -4,27 +4,44 @@ namespace ACA\EC\Service;
use AC;
use AC\Registerable;
use ACA\EC\ListScreen;
use ACA\EC\ListScreenFactory;
final class ListScreens implements Registerable {
public function register() {
AC\ListScreenFactory::add( new ListScreenFactory\EventFactory() );
AC\ListScreenFactory::add( new ListScreenFactory\OrganizerFactory() );
AC\ListScreenFactory::add( new ListScreenFactory\VenueFactory() );
if ( post_type_exists( 'tribe_event_series' ) ) {
AC\ListScreenFactory::add( new ListScreenFactory\EventSeriesFactory() );
}
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_groups' ] );
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ] );
add_filter( 'ac/admin/menu_group', [ $this, 'update_menu_list_groups' ], 10, 2 );
}
public function register_list_screen_groups( AC\Groups $groups ): void {
$groups->register_group( 'events-calendar', 'Events Calendar', 7 );
$groups->add( 'events-calendar', 'Events Calendar', 7 );
}
public function register_list_screens( AC\ListScreens $list_screens ): void {
$list_screens->register_list_screen( new ListScreen\Event() )
->register_list_screen( new ListScreen\Venue() )
->register_list_screen( new ListScreen\Organizer() );
private function get_post_list_keys(): array {
return [
'tribe_organizer',
'tribe_events',
'tribe_event_series',
'tribe_venue',
];
}
public function update_menu_list_groups( string $group, AC\ListScreen $list_screen ): string {
$keys = $this->get_post_list_keys();
if( post_type_exists( 'tribe_event_series' ) ){
$list_screens->register_list_screen( new ListScreen\EventSeries() );
if ( in_array( $list_screen->get_key(), $keys, true ) ) {
return 'events-calendar';
}
return $group;
}
}
\ No newline at end of file
......
......@@ -68,10 +68,7 @@ class TableScreen implements Registerable {
$prefix = 'ac_related_filter_';
$input = filter_input_array( INPUT_GET, [
$prefix . 'post_type' => FILTER_SANITIZE_STRING,
$prefix . 'value' => FILTER_SANITIZE_NUMBER_INT,
$prefix . 'date' => FILTER_SANITIZE_STRING,
$prefix . 'return_url' => FILTER_SANITIZE_STRING,
$prefix . 'value' => FILTER_SANITIZE_NUMBER_INT,
] );
foreach ( $input as $k => $v ) {
......@@ -81,7 +78,7 @@ class TableScreen implements Registerable {
$input = (object) $input;
switch ( $input->post_type ) {
switch ( $input->post_type ?? '') {
case 'tribe_venue':
$this->filter_on_venue( $input->value );
......
......@@ -25,7 +25,7 @@ final class EntryConfigurator implements AC\Registerable {
add_action( 'ac/list_screen/column_created', [ $this, 'configure_column' ] );
}
public function configure_column( AC\Column $column ) {
public function configure_column( AC\Column $column ): void {
if ( ! $column instanceof Column\Entry ) {
return;
}
......
......@@ -4,6 +4,7 @@ namespace ACA\GravityForms\Editing\Strategy;
use ACA\GravityForms;
use ACP;
use ACP\Editing\RequestHandler;
use GF_Entry_List_Table;
use GFCommon;
......@@ -18,15 +19,15 @@ class Entry implements ACP\Editing\Strategy {
$this->list_table = $list_table;
}
public function user_can_edit() {
public function user_can_edit(): bool {
return GFCommon::current_user_can_any( GravityForms\Capabilities::EDIT_ENTRIES );
}
public function user_can_edit_item( $object_id ) {
public function user_can_edit_item( int $id ): bool {
return $this->user_can_edit();
}
public function get_query_request_handler() {
public function get_query_request_handler(): RequestHandler {
return new GravityForms\Editing\RequestHandler\Query\Entry( $this->list_table );
}
......
......@@ -5,21 +5,19 @@ namespace ACA\GravityForms;
use AC;
use AC\Asset\Script;
use AC\Asset\Style;
use AC\DefaultColumnsRepository;
use AC\Registerable;
use ACA\GravityForms\Column\EntryConfigurator;
use ACA\GravityForms\Column\EntryFactory;
use ACA\GravityForms\ListScreen;
use ACA\GravityForms\Search\Query;
use ACA\GravityForms\TableScreen;
use ACP\Search\QueryFactory;
use ACP\Search\TableScreenFactory;
use ACP\Service\IntegrationStatus;
use GFAPI;
use GFCommon;
final class GravityForms implements Registerable {
const GROUP = 'gravity_forms';
public const GROUP = 'gravity_forms';
private $location;
......@@ -27,9 +25,6 @@ final class GravityForms implements Registerable {
$this->location = $location;
}
/**
* Register hooks
*/
public function register() {
if ( ! class_exists( 'GFCommon', false ) ) {
return;
......@@ -41,25 +36,22 @@ final class GravityForms implements Registerable {
return;
}
add_action( 'ac/list_screens', [ $this, 'register_list_screen' ] );
AC\ListScreenFactory::add( new ListScreenFactory\EntryFactory() );
// Group labels
add_action( 'ac/column_groups', [ $this, 'register_column_group' ] );
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_group' ] );
add_action( 'ac/admin_scripts', [ $this, 'admin_scripts' ] );
add_action( 'ac/table_scripts', [ $this, 'table_scripts' ] );
add_filter( "gform_noconflict_styles", [ $this, 'allowed_acp_styles' ] );
add_filter( "gform_noconflict_scripts", [ $this, 'allowed_acp_scripts' ] );
$services = [
new TableScreen\Entry(),
new Service\ListScreens(),
new TableScreen\Entry( new AC\ListScreenFactory(), AC()->get_storage(), new DefaultColumnsRepository() ),
new Admin(),
new IntegrationStatus( 'ac-addon-gravityforms' ),
];
array_map( function ( Registerable $service ) {
array_map( static function ( Registerable $service ) {
$service->register();
}, $services );
......@@ -68,32 +60,8 @@ final class GravityForms implements Registerable {
TableScreenFactory::register( ListScreen\Entry::class, Search\TableScreen\Entry::class );
}
public function register_list_screen() {
$list_screen_types = AC\ListScreenTypes::instance();
if ( ! $list_screen_types ) {
return;
}
$forms = array_merge( GFAPI::get_forms(), GFAPI::get_forms( [ 'active' => false ] ) );
foreach ( $forms as $form ) {
$fieldFactory = new FieldFactory();
$columnFactory = new EntryFactory( new FieldFactory() );
$configurator = new EntryConfigurator( (int) $form['id'], $columnFactory, $fieldFactory );
$configurator->register();
$list_screen_types->register_list_screen( new ListScreen\Entry( $form['id'], $configurator ) );
}
}
public function register_list_screen_group( AC\Groups $groups ) {
$groups->register_group( self::GROUP, __( 'Gravity Forms', 'codepress-admin-columns' ), 8 );
}
public function register_column_group( $groups ) {
$groups->register_group( self::GROUP, __( 'Gravity Forms', 'codepress-admin-columns' ), 11 );
public function register_column_group( AC\Groups $groups ): void {
$groups->add( 'gravity_forms', __( 'Gravity Forms', 'codepress-admin-columns' ), 14 );
}
/**
......
......@@ -10,26 +10,18 @@ use ACP\Editing;
use ACP\Export;
use GF_Entry_List_Table;
use GFAPI;
use GFForms;
use GFFormsModel;
class Entry extends AC\ListScreenWP implements Editing\ListScreen, Export\ListScreen {
/**
* @var int $form_id
*/
private $form_id;
/**
* @var EntryConfigurator
*/
private $column_configurator;
public function __construct( $form_id, EntryConfigurator $column_configurator ) {
$this->form_id = (int) $form_id;
public function __construct( int $form_id, EntryConfigurator $column_configurator ) {
$this->form_id = $form_id;
$this->column_configurator = $column_configurator;
$this->set_group( GravityForms\GravityForms::GROUP )
$this->set_group( 'gravity_forms' )
->set_page( 'gf_entries' )
->set_screen_id( '_page_gf_entries' )
->set_screen_base( '_page_gf_entries' )
......@@ -91,30 +83,6 @@ class Entry extends AC\ListScreenWP implements Editing\ListScreen, Export\ListSc
return $this->form_id;
}
public function is_current_screen( $wp_screen ): bool {
return
strpos( $wp_screen->id, '_page_gf_entries' ) !== false &&
strpos( $wp_screen->base, '_page_gf_entries' ) !== false &&
$this->get_current_form_id() === $this->form_id;
}
/**
* @return int
*/
private function get_current_form_id() {
$form_id = GFForms::get( 'id' );
if ( ! $form_id ) {
$forms = GFFormsModel::get_forms();
if ( $forms ) {
$form_id = $forms[0]->id;
}
}
return (int) $form_id;
}
protected function get_admin_url() {
return admin_url( 'admin.php' );
}
......
<?php
namespace ACA\GravityForms\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\GravityForms;
use ACA\GravityForms\Column\EntryConfigurator;
use ACA\GravityForms\FieldFactory;
use ACA\GravityForms\ListScreen\Entry;
use GFForms;
use GFFormsModel;
use LogicException;
use WP_Screen;
class EntryFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return null !== $this->get_form_id_from_list_key( $key );
}
private function get_form_id_from_list_key( string $key ): ?int {
if ( ! ac_helper()->string->starts_with( $key, 'gf_entry_' ) ) {
return null;
}
$entry_id = ac_helper()->string->remove_prefix( $key, 'gf_entry_' );
return is_numeric( $entry_id )
? (int) $entry_id
: null;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid key' );
}
$form_id = $this->get_form_id_from_list_key( $key );
if ( null === $form_id ) {
throw new LogicException( 'Invalid form id' );
}
return $this->add_settings(
new Entry( $form_id, $this->create_entry_configurator( $form_id ) ),
$settings
);
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return strpos( $screen->id, '_page_gf_entries' ) !== false &&
strpos( $screen->base, '_page_gf_entries' ) !== false &&
$this->has_form_id();
}
private function has_form_id(): bool {
return $this->get_current_form_id() > 0;
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid screen' );
}
$form_id = $this->get_current_form_id();
return $this->add_settings(
new Entry( $form_id, $this->create_entry_configurator( $form_id ) ),
$settings
);
}
private function get_current_form_id(): int {
$form_id = GFForms::get( 'id' );
if ( ! $form_id ) {
$forms = GFFormsModel::get_forms();
if ( $forms ) {
$form_id = $forms[0]->id;
}
}
return (int) $form_id;
}
private function create_entry_configurator( int $form_id ): EntryConfigurator {
$fieldFactory = new FieldFactory();
$columnFactory = new GravityForms\Column\EntryFactory( $fieldFactory );
$entry_configurator = new EntryConfigurator( $form_id, $columnFactory, $fieldFactory );
$entry_configurator->register();
return $entry_configurator;
}
}
\ No newline at end of file
<?php
namespace ACA\GravityForms\Service;
use AC;
use AC\Registerable;
use AC\Table\ListKeyCollection;
use AC\Type\ListKey;
use GFAPI;
class ListScreens implements Registerable {
public function register() {
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_group' ] );
add_action( 'ac/list_keys', [ $this, 'add_list_keys' ] );
}
public function register_list_screen_group( AC\Groups $groups ): void {
$groups->add( 'gravity_forms', __( 'Gravity Forms', 'codepress-admin-columns' ), 8 );
}
public function add_list_keys( ListKeyCollection $keys ): ListKeyCollection {
$forms = array_merge( GFAPI::get_forms(), GFAPI::get_forms( false ) );
foreach ( $forms as $form ) {
$keys->add( new ListKey( 'gf_entry_' . $form['id'] ) );
}
return $keys;
}
}
\ No newline at end of file
......@@ -3,6 +3,10 @@
namespace ACA\GravityForms\TableScreen;
use AC;
use AC\DefaultColumnsRepository;
use AC\ListScreenFactoryInterface;
use AC\ListScreenRepository\Storage;
use AC\Type\ListScreenId;
use ACA\GravityForms\Column;
use ACA\GravityForms\Editing;
use ACA\GravityForms\HideOnScreen\EntryFilters;
......@@ -14,11 +18,27 @@ use GFFormsModel;
class Entry implements AC\Registerable {
private $list_screen_factory;
private $storage;
private $default_columns_repository;
public function __construct(
ListScreenFactoryInterface $list_screen_factory,
Storage $storage,
DefaultColumnsRepository $default_columns_repository
) {
$this->list_screen_factory = $list_screen_factory;
$this->storage = $storage;
$this->default_columns_repository = $default_columns_repository;
}
public function register() {
add_filter( 'gform_entry_list_columns', [ $this, 'remove_selector_column' ], 11, 2 );
add_filter( 'acp/editing/result', [ $this, 'get_editing_ajax_value' ], 10, 3 );
add_action( 'ac/table/list_screen', [ $this, 'create_default_list_screen' ], 9 );
add_action( 'ac/table/list_screen', [ $this, 'store_active_gf_columns' ], 10 );
add_action( 'ac/table/list_screen', [ $this, 'store_active_gf_columns' ] );
add_action( 'ac/table/list_screen', [ $this, 'register_table_rows' ] );
add_action( 'ac/admin_head', [ $this, 'hide_entry_filters' ] );
add_action( 'ac/admin_head', [ $this, 'hide_wordpress_notifications' ] );
......@@ -37,14 +57,11 @@ class Entry implements AC\Registerable {
<?php
}
/**
* @return bool
*/
private function has_stored_default_columns( AC\ListScreen $list_screen ) {
return ! empty( ( new AC\DefaultColumnsRepository() )->get( $list_screen->get_key() ) );
private function has_stored_default_columns( string $list_key ): bool {
return ! empty( $this->default_columns_repository->get( $list_key ) );
}
public function hide_wordpress_notifications( AC\ListScreen $list_screen ) {
public function hide_wordpress_notifications( AC\ListScreen $list_screen ): void {
if ( ! $list_screen instanceof ListScreen\Entry || ! ( new WordPressNotifications() )->is_hidden( $list_screen ) ) {
return;
}
......@@ -77,8 +94,8 @@ class Entry implements AC\Registerable {
return $result;
}
public function create_default_list_screen( AC\ListScreen $list_screen ) {
if ( ! $list_screen instanceof ListScreen\Entry || ! $this->has_stored_default_columns( $list_screen ) ) {
public function create_default_list_screen( AC\ListScreen $list_screen ): void {
if ( ! $list_screen instanceof ListScreen\Entry ) {
return;
}
......@@ -86,52 +103,83 @@ class Entry implements AC\Registerable {
return;
}
if ( $list_screen->has_id() && AC()->get_storage()->exists( $list_screen->get_id() ) ) {
$list_key = $list_screen->get_key();
if ( ! $this->has_stored_default_columns( $list_key ) ) {
return;
}
$default_columns = GFFormsModel::get_grid_columns( $list_screen->get_form_id() );
$settings = [
if ( $list_screen->has_id() && $this->storage->exists( $list_screen->get_id() ) ) {
return;
}
if ( ! $this->list_screen_factory->can_create( $list_key ) ) {
return;
}
$columns = [
'is_starred' => [
'label' => '<span class="dashicons dashicons-star-filled"></span>',
'type' => 'is_starred',
],
];
foreach ( $default_columns as $field_id => $info ) {
foreach ( GFFormsModel::get_grid_columns( $list_screen->get_form_id() ) as $field_id => $data ) {
$key = 'field_id-' . $field_id;
$settings[ $key ] = [
'label' => $info['label'],
$columns[ $key ] = [
'label' => $data['label'],
'type' => $key,
];
}
$list_screen->set_settings( $settings );
$list_screen->set_title( 'Default' );
$list_screen->set_layout_id( AC\Type\ListScreenId::generate()->get_id() );
$settings = [
'list_id' => ListScreenId::generate()->get_id(),
'title' => __( 'Default', 'codepress-admin-columns' ),
'columns' => $columns,
];
AC()->get_storage()->save( $list_screen );
$this->storage->save( $this->list_screen_factory->create( $list_key, $settings ) );
}
public function store_active_gf_columns( AC\ListScreen $list_screen ) {
if ( ! $list_screen instanceof ListScreen\Entry || ! $this->has_stored_default_columns( $list_screen ) ) {
public function store_active_gf_columns( AC\ListScreen $list_screen ): void {
if ( ! $list_screen instanceof ListScreen\Entry ) {
return;
}
$form_id = $list_screen->get_form_id();
if ( ! $form_id ) {
return;
}
$list_key = $list_screen->get_key();
if ( ! $this->has_stored_default_columns( $list_key ) ) {
return;
}
$grid_columns = array_keys( GFFormsModel::get_grid_columns( $list_screen->get_form_id() ) );
$grid_columns = array_keys( GFFormsModel::get_grid_columns( $form_id ) );
foreach ( $grid_columns as $key => $column ) {
$field = GFAPI::get_field( $list_screen->get_form_id(), $column );
$field = GFAPI::get_field( $form_id, $column );
if ( $field && in_array( $field['type'], $this->get_unsupported_field_types(), false ) ) {
unset( $grid_columns[ $key ] );
}
}
$current_columns = array_merge( $grid_columns, $this->get_field_ids( GFAPI::get_form( $list_screen->get_form_id() ) ), $this->get_default_table_column_names() );
$forms = GFAPI::get_form( $form_id );
$form_fields = $forms['fields'] ?? [];
if ( ! $form_fields ) {
return;
}
$current_columns = array_merge( $grid_columns, $this->get_field_ids( $form_fields ), $this->get_default_table_column_names() );
$current_columns = array_unique( $current_columns );
if ( md5( serialize( GFFormsModel::get_grid_column_meta( $list_screen->get_form_id() ) ) ) !== md5( serialize( $current_columns ) ) ) {
GFFormsModel::update_grid_column_meta( $list_screen->get_form_id(), $current_columns );
if ( md5( serialize( GFFormsModel::get_grid_column_meta( $form_id ) ) ) !== md5( serialize( $current_columns ) ) ) {
GFFormsModel::update_grid_column_meta( $form_id, $current_columns );
}
}
......@@ -167,21 +215,18 @@ class Entry implements AC\Registerable {
return [ 'section', 'html', 'page' ];
}
/**
* @param array $form
*
* @return array
*/
private function get_field_ids( $form ) {
private function get_field_ids( array $form_fields ): array {
$field_ids = [];
/**
* @var GF_Field $field
*/
foreach ( $form['fields'] as $field ) {
if ( in_array( $field['type'], $this->get_unsupported_field_types(), false ) ) {
foreach ( $form_fields as $field ) {
if ( ! $field instanceof GF_Field ) {
continue;
}
if ( in_array( $field->type, $this->get_unsupported_field_types(), false ) ) {
continue;
}
$inputs = $field->get_entry_inputs();
$field_ids[] = $field->id;
......
......@@ -14,8 +14,8 @@ final class ColumnGroups implements AC\Registerable {
}
public function register_column_groups( AC\Groups $groups ) {
$groups->register_group( self::JET_ENGINE, __( 'JetEngine', 'codepress-admin-columns' ), 11 );
$groups->register_group( self::JET_ENGINE_RELATION, __( 'JetEngine Relationship', 'codepress-admin-columns' ), 11 );
$groups->add( self::JET_ENGINE, __( 'JetEngine', 'codepress-admin-columns' ), 11 );
$groups->add( self::JET_ENGINE_RELATION, __( 'JetEngine Relationship', 'codepress-admin-columns' ), 11 );
}
}
\ No newline at end of file
......
......@@ -4,10 +4,11 @@ declare( strict_types=1 );
namespace ACA\MLA\Editing;
use ACP;
use ACP\Editing\RequestHandler;
class Strategy extends ACP\Editing\Strategy\Post {
public function get_query_request_handler() {
public function get_query_request_handler(): RequestHandler {
global $wp_list_table;
// Re-execute the query because the table object can be shared with custom plugins using the MLA filters/actions
......
......@@ -17,7 +17,7 @@ class MediaLibrary extends AC\ThirdParty\MediaLibraryAssistant\ListScreen\MediaL
}
public function editing() {
return new Editing\Strategy( 'attachment' );
return new Editing\Strategy( get_post_type_object( 'attachment' ) );
}
public function register_column_types() {
......
<?php
namespace ACA\MLA\ListScreenFactory;
use AC;
use AC\ThirdParty\MediaLibraryAssistant\ListScreenFactory;
use ACA\MLA\ListScreen\MediaLibrary;
class MediaLibraryFactory extends ListScreenFactory {
protected function create_list_screen(): AC\ThirdParty\MediaLibraryAssistant\ListScreen\MediaLibrary {
return new MediaLibrary();
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ class ColumnGroup implements Registerable {
}
public function register_column_group( AC\Groups $groups ) {
$groups->register_group( self::NAME, __( 'Media Library Assistant' ), 25 );
$groups->add( self::NAME, __( 'Media Library Assistant' ), 25 );
}
}
\ No newline at end of file
......
......@@ -4,16 +4,12 @@ namespace ACA\MLA\Service;
use AC;
use AC\Registerable;
use ACA\MLA\ListScreen;
use ACA\MLA\ListScreenFactory\MediaLibraryFactory;
class ListScreens implements Registerable {
public function register() {
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ], 11 );
}
public function register_list_screens() {
AC\ListScreenTypes::instance()->register_list_screen( new ListScreen\MediaLibrary() );
AC\ListScreenFactory::add( new MediaLibraryFactory() );
}
}
\ No newline at end of file
......
......@@ -43,8 +43,8 @@ class Columns implements Registerable {
}
public function register_column_groups( AC\Groups $groups ) {
$groups->register_group( 'metabox', 'MetaBox', 11 );
$groups->register_group( 'metabox_relation', 'MetaBox Relation', 11 );
$groups->add( 'metabox', 'MetaBox', 11 );
$groups->add( 'metabox_relation', 'MetaBox Relation', 11 );
}
public function add_columns( AC\ListScreen $list_screen ) {
......
......@@ -18,7 +18,7 @@ final class Columns implements Registerable {
* @param AC\Groups $groups
*/
public function register_column_groups( $groups ) {
$groups->register_group( 'pods', 'Pods', 11 );
$groups->add( 'pods', 'Pods', 11 );
}
......
......@@ -17,7 +17,7 @@ class Columns implements Registerable {
}
public function register_column_groups( AC\Groups $groups ): void {
$groups->register_group( self::GROUP_NAME, 'Polylang', 25 );
$groups->add( self::GROUP_NAME, 'Polylang', 25 );
}
public function add_columns( AC\ListScreen $list_screen ): void {
......
......@@ -36,7 +36,7 @@ final class Columns implements AC\Registerable {
}
public function register_column_groups( AC\Groups $groups ) {
$groups->register_group( 'types', 'Toolset Types', 11 );
$groups->add( 'types', 'Toolset Types', 11 );
}
}
\ No newline at end of file
......
{"version":3,"sourceRoot":"","sources":["../../src/scss/_editables.scss","../../src/scss/table.scss"],"names":[],"mappings":"CAKG,wDACC,YAQF,qEACC,qBACA,WAIF,4BACC,cACA,yBACA,kBACA,aACA,cACA,eAGA,mCACC,mBACA,cAGD,kCACC,cACA,kBAEA,yCACC,WACA,kBACA,OACA,QACA,QACA,WACA,mBAQF,0CACC,YAGD,yDACC,WAOD,+EACC,YAIF,qDACC,YAKC,+EACC,WAKH,2CACC,cAOA,iDACC,kBAKD,0DACC,eAIF,6CACC,cAGD,+CACC,YACA,kBAGD,gDACC,iBACA,iBAEA,uDACC,kBACA,kBAGD,mHAEC,gBACA,qBACA,iBAMD,uEACC,2BACA,mBAEA,+FACC,2BACA,qBAOF,oFACC,YACA,kBAGD,wEACC,gBACA,mBACA,eAMF,uDACC,cAEA,6DACC,cACA,mBAOF,iDACC,2BACA,aAKA,+DACC,YACA,8BACA,iBACA,uBACA,kBACA,kBAKD,2DACC,YACA,mBACA,kBAGD,6CACC,YACA,iBAGD,wCACC,gBACA,kBAEA,6CACC,qBACA,eACA,eAIF,0CACC,iBACA,qBACA,gBACA,gBAGD,wCACC,mBAEA,oDACC,eAGD,mDACC,kBAGD,oEACC,mBAED,kEACC,mBAID,8CACC,YACA,gBACA,aACA,mBAGD,8CACC,eACA,eACA,aAGC,0DACC,kBACA,YAEA,+DACC,cACA,iCAIF,4DACC,iCACA,0BACA,eC5PL,+IACC,aAMD,uFACC,qBAIF,kDACC,+BAKC,iDACC,WAEA,uEACC,WAJF,+CACC,WAEA,qEACC,WAJF,iDACC,WAEA,uEACC,WAJF,8CACC,WAEA,oEACC,WASH,qIACC,0BAEA,mKACC,6BAKH,qBACC,qBAGD,gCACC,WAGC,4EACC,kBACA,oBAIF,2CACC,mBACA,6BAKC,wFACC,6BAKD,8GACC,mBAKH,6CACC,gBACA,eAEA,uDACC,eACA,iBAGD,mDACC,eAGD,mDACC,eACA,sBAIF,yCACC,iBAMA,qCACC,qBACA,sBACA,YACA,WACA,YACA,+BACA,kBACA,kBACA,YAEA,2CACC,qBAKD,uCACC,oCACA,YAYA,0SACC,oBAEA,sUACC,YACA,cACA,oCAaH,wDACC,YAGD,mEACC,WAQH,2CACC,cAMD,gCACC,kBACA,cAGD,gCACC,eACA,iBACA,cACA,iBAGD,gCACC,qBACA,eAGD,kCACC,cAGD,8BACC,gBACA,kBACA,sBACA,cACA,eAGD,qCACC,WAGD,gCACC,cAMD,8BACC,kBACA,iBAEA,qCACC,8BACA,WACA,gBACA,oBACA,oBACA,cACA,mCACA,oBACA,cACA,kBACA,qBACA,sBACA,mBAIF,6CACC,YACA,cAGD,+CACC,YACA,cAGD,6CACC,YACA,WAGD,4CACC,YACA,cAGD,+CACC,YACA,WAGD,gDACC,YACA,cAGD,8CACC,YACA,WAKD,iDACC,kBACA,iBAEA,wDACC,8BACA,WACA,gBACA,oBACA,oBACA,cACA,mCACA,oBACA,cACA,kBACA,qBACA,sBACA,mBAIF,+DACC,YACA,cAGD,gEACC,YACA,cAGD,kEACC,YACA,WAGD,iEACC,YACA,WAGD,gEACC,YACA,WAGD,gEACC,YACA,cAGD,uEACC,YACA,WAKD,yBACC,kBAEA,8BACC,sBACA,cACA,eAGD,+BACC,eAOF,iCACC,qBAGD,4CACC,qBACA,iBACA,sBAGD,uCACC,mBAEA,kDACC,gBAQF,iCACC,yBACA,oBACA,kBACA,WACA,UACA,eACA,gBACA,SAEA,uCACC,kCACA,WACA,gBACA,oBACA,oBACA,cACA,mCACA,SACA,cACA,kBACA,MACA,OACA,WACA,YACA,kBACA,WACA,cAGD,qGAEC,YACA,WAGD,iDACC,YACA,cAGD,+CACC,YACA,cAGD,gDACC,YACA,WAGD,8CACC,YACA,cAGD,kDACC,YACA,cAGD,iDACC,YACA,WAOF,oCACC,mBAGD,mCACC,WAGD,0CACC,WACA,kBAMC,mEACC,WACA,kBACA,mBAGD,gEACC,WAGD,qEACC,UAKD,uEACC,iBAGD,gEACC,iBAGD,mEACC,kBAOD,gIACC,iBAYF,qJACC,gBAEA,6KACC,YAIF,yKACC,kBAGD,qJACC,iBAIF,iHACC,iBASC,wDACC,YAWH,yXACC,oCACA,sBAGD,yOACC,eAGD,qKACC,wBAGD,iQACC,iBAGD,qYACC,iBAGD,iWACC,YAGD,iSACC,iBACA,eAMA,mEACC,gBAEA,8FACC,YAGD,sFACC,qBASF,uMAEC,aAKD,iGACC,wBAKD,yMAEC,aAKH,oEACC,gBAGD,uDACC,WACA,gBAGC,0HACC,YAEA,8JACC,WACA,mBACA,eAGD,gKACC,gBACA,WAEA,oNACC,gBACA,mBACA,gBACA,uBAUH,0EACC,mBAKH,oDACC","file":"table.css"}
\ No newline at end of file
{"version":3,"sourceRoot":"","sources":["../../src/scss/_editables.scss","../../src/scss/table.scss"],"names":[],"mappings":"CAKG,wDACC,YAQF,qEACC,qBACA,WAIF,4BACC,cACA,yBACA,kBACA,aACA,cACA,eAGA,mCACC,mBACA,cAGD,kCACC,cACA,kBAEA,yCACC,WACA,kBACA,OACA,QACA,QACA,WACA,mBAQF,0CACC,YAGD,yDACC,WAOD,+EACC,YAIF,qDACC,YAKC,+EACC,WAKH,2CACC,cAOA,iDACC,kBAKD,0DACC,eAIF,6CACC,cAGD,+CACC,YACA,kBAGD,gDACC,iBACA,iBAEA,uDACC,kBACA,kBAGD,mHAEC,gBACA,qBACA,iBAMD,uEACC,2BACA,mBAEA,+FACC,2BACA,qBAOF,oFACC,YACA,kBAGD,wEACC,gBACA,mBACA,eAMF,uDACC,cAEA,6DACC,cACA,mBAOF,iDACC,2BACA,aAKA,+DACC,YACA,8BACA,iBACA,uBACA,kBACA,kBAKD,2DACC,YACA,mBACA,kBAGD,6CACC,YACA,iBAGD,wCACC,gBACA,kBAEA,6CACC,qBACA,eACA,eAIF,0CACC,iBACA,qBACA,gBACA,gBAGD,wCACC,mBAEA,oDACC,eAGD,mDACC,kBAGD,oEACC,mBAED,kEACC,mBAID,8CACC,YACA,gBACA,aACA,mBAGD,8CACC,eACA,eACA,aAGC,0DACC,kBACA,YAEA,+DACC,cACA,iCAIF,4DACC,iCACA,0BACA,eC5PL,+IACC,aAMD,uFACC,qBAIF,kDACC,+BAKC,iDACC,WAEA,uEACC,WAJF,+CACC,WAEA,qEACC,WAJF,iDACC,WAEA,uEACC,WAJF,8CACC,WAEA,oEACC,WASH,qIACC,0BAEA,mKACC,6BAKH,qBACC,qBAGD,gCACC,WAGC,4EACC,kBACA,oBAIF,2CACC,mBACA,6BAKC,wFACC,6BAKD,8GACC,mBAKH,6CACC,gBACA,eAEA,uDACC,eACA,iBAGD,mDACC,eAGD,mDACC,eACA,sBAIF,yCACC,iBAMA,qCACC,qBACA,sBACA,YACA,WACA,YACA,+BACA,kBACA,kBACA,YAEA,2CACC,qBAKD,uCACC,oCACA,YAYA,0SACC,oBAEA,sUACC,YACA,cACA,oCAaH,wDACC,YAGD,mEACC,WAQH,2CACC,cAMD,gCACC,kBACA,cAGD,gCACC,eACA,iBACA,cACA,iBAGD,gCACC,qBACA,eAGD,kCACC,cAGD,8BACC,gBACA,kBACA,sBACA,cACA,eAGD,qCACC,WAGD,gCACC,cAMD,8BACC,kBACA,iBAEA,qCACC,8BACA,WACA,gBACA,oBACA,oBACA,cACA,mCACA,oBACA,cACA,kBACA,qBACA,sBACA,mBAIF,6CACC,YACA,cAGD,+CACC,YACA,cAGD,6CACC,YACA,WAGD,4CACC,YACA,cAGD,+CACC,YACA,WAGD,gDACC,YACA,cAGD,8CACC,YACA,WAKD,iDACC,kBACA,iBAEA,wDACC,8BACA,WACA,gBACA,oBACA,oBACA,cACA,mCACA,oBACA,cACA,kBACA,qBACA,sBACA,mBAIF,+DACC,YACA,cAGD,gEACC,YACA,cAGD,kEACC,YACA,WAGD,iEACC,YACA,WAGD,gEACC,YACA,WAGD,gEACC,YACA,cAGD,uEACC,YACA,WAKD,yBACC,kBAEA,8BACC,sBACA,cACA,eAGD,+BACC,eAOF,iCACC,qBAGD,4CACC,qBACA,iBACA,sBAGD,uCACC,mBAEA,kDACC,gBAQF,iCACC,yBACA,oBACA,kBACA,WACA,UACA,eACA,gBACA,SAEA,uCACC,kCACA,WACA,gBACA,oBACA,oBACA,cACA,mCACA,SACA,cACA,kBACA,MACA,OACA,WACA,YACA,kBACA,WACA,cAGD,qGAEC,YACA,WAGD,iDACC,YACA,cAGD,+CACC,YACA,cAGD,gDACC,YACA,WAGD,8CACC,YACA,cAGD,kDACC,YACA,cAGD,iDACC,YACA,WAOF,oCACC,mBAGD,mCACC,WAGD,0CACC,WACA,kBAMC,mEACC,WACA,kBACA,mBAGD,gEACC,WAGD,qEACC,UAKD,uEACC,iBAGD,gEACC,iBAGD,mEACC,kBAOD,gIACC,iBAYF,qJACC,gBAEA,6KACC,YAIF,yKACC,kBAGD,qJACC,iBAIF,iHACC,iBASC,wDACC,YAWH,yXACC,oCACA,sBAGD,yOACC,eAGD,qKACC,wBAGD,iQACC,iBAGD,qYACC,iBAGD,iWACC,YAGD,iSACC,iBACA,eAMA,mEACC,gBAEA,8FACC,YAGD,sFACC,qBASF,uMAEC,aAKD,iGACC,wBAKD,yMAEC,aAKH,oEACC,gBAGD,uDACC,WACA,gBAGC,0HACC,YAEA,8JACC,WACA,mBACA,eAGD,gKACC,gBACA,WAEA,oNACC,gBACA,mBACA,gBACA,uBAUH,0EACC,mBAKH,oDACC,2BAMC,wDACC,cACA,WACA,WAID,2DACC,WAED,2GACC,SAGF,kDACC,WAGD,iDACC,gBAEA,uDACC","file":"table.css"}
\ No newline at end of file
......
{"version":3,"file":"table-orders.js","mappings":";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;ACNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACS","sources":["webpack://admincolumns/webpack/bootstrap","webpack://admincolumns/webpack/runtime/make namespace object","webpack://admincolumns/./js/table-orders.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","AC_SERVICES.addListener('Table.Ready', () => {\n var _a, _b;\n const numElement = document.querySelector('.tablenav-pages .displaying-num');\n if (numElement) {\n let numberFormatted = numElement.innerHTML.split(' ')[0];\n let number = numElement.innerHTML.replace(/\\D/g, '');\n (_b = (_a = AC_SERVICES.getService('Editing')) === null || _a === void 0 ? void 0 : _a.getService('BulkSelectionRow')) === null || _b === void 0 ? void 0 : _b.setTotalItems(parseInt(number), numberFormatted);\n }\n});\nAC_SERVICES.filters.addFilter('table_row_id', (item_id, payload) => {\n var _a, _b;\n let row = payload.row;\n if (Number.isNaN(item_id)) {\n item_id = (_b = (_a = row.querySelector('.check-column input[name=\"order[]\"]')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0;\n }\n return item_id;\n});\nexport {};\n"],"names":[],"sourceRoot":""}
\ No newline at end of file
......@@ -36,6 +36,10 @@ class SalePrice extends Price {
if ( $this->scheduled ) {
$this->schedule_from = $value['schedule']['from'];
$this->schedule_to = $value['schedule']['to'];
if ( ! empty( $this->schedule_to ) ) {
$this->schedule_to = date( 'Y-m-d 23:59:59', strtotime( $this->schedule_to ) );
}
}
}
......
......@@ -36,8 +36,8 @@ class Price {
public function save() {
$price = $this->get_calculated_price();
if ( $price <= 0 ) {
return new WP_Error( 'invalid-price', __( 'Price can not be zero or lower.', 'codepress-admin-columns' ) );
if ( $price < 0 ) {
return new WP_Error( 'invalid-price', __( 'Price can not lower than zero.', 'codepress-admin-columns' ) );
}
if ( $this->value->is_rounded() || 'flat' !== $this->value->get_price_type() ) {
......
......@@ -6,7 +6,7 @@ use ACP\Editing\Strategy;
class Product extends Strategy\Post {
public function user_can_edit() {
public function user_can_edit(): bool {
return current_user_can( 'manage_woocommerce' ) && parent::user_can_edit();
}
......
......@@ -15,7 +15,7 @@ class Product extends ACP\ListScreen\Post {
}
public function editing() {
return new Editing\Strategy\Product( $this->get_post_type() );
return new Editing\Strategy\Product( get_post_type_object( $this->get_post_type() ) );
}
protected function register_column_types() {
......
<?php
namespace ACA\WC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\WC\ListScreen\ProductCategory;
use ACP\ListScreen\Taxonomy;
use LogicException;
use WP_Screen;
class ProductCategoryFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return Taxonomy::KEY_PREFIX . 'product_cat' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new ProductCategory(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return 'edit-tags' === $screen->base && 'product_cat' === $screen->taxonomy;
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new ProductCategory(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\WC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\WC\ListScreen\Product;
use LogicException;
use WP_Screen;
class ProductFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'product' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new Product(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'product';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new Product(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\WC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\WC\ListScreen\ProductVariation;
use LogicException;
use WP_Screen;
class ProductVariationFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'product_variation' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new ProductVariation(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'product_variation';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new ProductVariation(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\WC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\WC\ListScreen\ShopCoupon;
use LogicException;
use WP_Screen;
class ShopCouponFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'shop_coupon' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new ShopCoupon(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'shop_coupon';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new ShopCoupon(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\WC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\WC\ListScreen\ShopOrder;
use LogicException;
use WP_Screen;
class ShopOrderFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'shop_order' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new ShopOrder(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'shop_order';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new ShopOrder(), $settings );
}
}
\ No newline at end of file
<?php
namespace ACA\WC\ListScreenFactory;
use AC\ListScreen;
use AC\ListScreenFactory\ListSettingsTrait;
use AC\ListScreenFactoryInterface;
use ACA\WC\ListScreen\Subscriptions;
use LogicException;
use WP_Screen;
class ShopSubscriptionFactory implements ListScreenFactoryInterface {
use ListSettingsTrait;
public function can_create( string $key ): bool {
return 'shop_subscription' === $key;
}
public function create( string $key, array $settings = [] ): ListScreen {
if ( ! $this->can_create( $key ) ) {
throw new LogicException( 'Invalid Listscreen key' );
}
return $this->add_settings( new Subscriptions(), $settings );
}
public function can_create_by_wp_screen( WP_Screen $screen ): bool {
return $screen->base === 'edit' && $screen->post_type === 'shop_subscription';
}
public function create_by_wp_screen( WP_Screen $screen, array $settings = [] ): ListScreen {
if ( ! $this->can_create_by_wp_screen( $screen ) ) {
throw new LogicException( 'Invalid Screen' );
}
return $this->add_settings( new Subscriptions(), $settings );
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ class ColumnGroups implements Registerable {
}
public function register_column_groups( Groups $groups ) {
$groups->register_group( 'woocommerce', __( 'WooCommerce', 'codepress-admin-columns' ), 15 );
$groups->add( 'woocommerce', __( 'WooCommerce', 'codepress-admin-columns' ), 15 );
}
}
\ No newline at end of file
......
......@@ -3,16 +3,64 @@
namespace ACA\WC\Service;
use AC\Groups;
use AC\ListScreen;
use AC\Registerable;
use ACP\ListScreen\Taxonomy;
class ListScreenGroups implements Registerable {
public function register() {
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_groups' ] );
add_action( 'ac/admin/menu_group', [ $this, 'update_menu_list_groups' ], 10, 2 );
}
public function register_list_screen_groups( Groups $groups ) {
$groups->register_group( 'woocommerce', __( 'WooCommerce', 'codepress-admin-columns' ), 7 );
public function update_menu_list_groups( string $group, ListScreen $list_screen ): string {
if ( in_array( $list_screen->get_key(), $this->get_post_list_keys(), true ) ) {
return 'woocommerce';
}
if ( in_array( $list_screen->get_key(), $this->get_attribute_list_keys(), true ) ) {
return 'woocommerce_attributes';
}
if ( in_array( $list_screen->get_key(), $this->get_taxonomy_list_keys(), true ) ) {
return 'woocommerce_taxonomy';
}
return $group;
}
public function register_list_screen_groups( Groups $groups ): void {
$groups->add( 'woocommerce', __( 'WooCommerce', 'codepress-admin-columns' ), 11 );
$groups->add( 'woocommerce_taxonomy', sprintf( '%s - %s', __( 'WooCommerce', 'codepress-admin-columns' ), __( 'Taxonomy', 'codepress-admin-columns' ) ), 11 );
$groups->add( 'woocommerce_attributes', sprintf( '%s - %s', __( 'WooCommerce', 'codepress-admin-columns' ), __( 'Attribute', 'codepress-admin-columns' ) ), 11 );
}
private function get_attribute_list_keys(): array {
$taxonomies = [];
foreach ( wc_get_attribute_taxonomy_names() as $taxonomy_name ) {
$taxonomies[] = Taxonomy::KEY_PREFIX . $taxonomy_name;
}
return $taxonomies;
}
private function get_post_list_keys(): array {
return [
'product',
'product_variation',
'shop_order',
'shop_coupon',
'shop_subscription',
];
}
private function get_taxonomy_list_keys(): array {
return [
Taxonomy::KEY_PREFIX . 'product_cat',
Taxonomy::KEY_PREFIX . 'product_tag',
];
}
}
\ No newline at end of file
......
......@@ -2,39 +2,30 @@
namespace ACA\WC\Service;
use AC;
use AC\ListScreenFactory;
use AC\Registerable;
use ACA\WC\ListScreen;
use ACA\WC\ListScreenFactory\ProductCategoryFactory;
use ACA\WC\ListScreenFactory\ProductFactory;
use ACA\WC\ListScreenFactory\ProductVariationFactory;
use ACA\WC\ListScreenFactory\ShopCouponFactory;
use ACA\WC\ListScreenFactory\ShopOrderFactory;
class ListScreens implements Registerable {
/**
* @var bool
*/
private $use_product_variations;
public function __construct( $use_product_variations ) {
public function __construct( bool $use_product_variations ) {
$this->use_product_variations = $use_product_variations;
}
public function register() {
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ] );
}
public function register_list_screens() {
$list_screens = [
new ListScreen\ShopOrder(),
new ListScreen\ShopCoupon(),
new ListScreen\Product(),
new ListScreen\ProductCategory(),
];
ListScreenFactory::add( new ProductFactory() );
ListScreenFactory::add( new ShopCouponFactory() );
ListScreenFactory::add( new ShopOrderFactory() );
ListScreenFactory::add( new ProductCategoryFactory() );
if ( $this->use_product_variations ) {
$list_screens[] = new ListScreen\ProductVariation;
}
foreach ( $list_screens as $list_screen ) {
AC\ListScreenTypes::instance()->register_list_screen( $list_screen );
ListScreenFactory::add( new ProductVariationFactory() );
}
}
......
......@@ -5,6 +5,8 @@ namespace ACA\WC;
use AC;
use ACA\WC\Column;
use ACA\WC\ListScreen\Product;
use ACA\WC\ListScreenFactory\ShopSubscriptionFactory;
use ACA\WC\ListScreenFactory\WcSubscriptions;
use WC_Subscriptions;
/**
......@@ -29,20 +31,14 @@ final class Subscriptions implements AC\Registerable {
}
add_action( 'ac/column_groups', [ $this, 'register_column_groups' ] );
add_action( 'ac/list_screens', [ $this, 'register_list_screens' ] );
add_action( 'ac/column_types', [ $this, 'add_product_columns' ] );
add_action( 'ac/column_types', [ $this, 'add_user_columns' ] );
}
public function register_list_screens( AC\ListScreens $list_screens ) {
$list_screens->register_list_screen( new ListScreen\Subscriptions() );
AC\ListScreenFactory::add( new ShopSubscriptionFactory() );
}
/**
* @param AC\Groups $groups
*/
public function register_column_groups( $groups ) {
$groups->register_group( 'woocommerce_subscriptions', __( 'WooCommerce Subscriptions', 'codepress-admin-columns' ), 15 );
public function register_column_groups( AC\Groups $groups ): void {
$groups->add( 'woocommerce_subscriptions', __( 'WooCommerce Subscriptions', 'codepress-admin-columns' ), 15 );
}
public function add_product_columns( AC\ListScreen $list_screen ) {
......
......@@ -50,20 +50,12 @@ final class WooCommerce implements Registerable {
);
}
/**
* @return bool
*/
private function use_product_variations() {
private function use_product_variations(): bool {
return apply_filters( 'acp/wc/show_product_variations', true ) && $this->is_wc_version_gte( '3.3' );
}
/**
* @param string $version
*
* @return bool
*/
private function is_wc_version_gte( $version ) {
return version_compare( WC()->version, (string) $version, '>=' );
private function is_wc_version_gte( string $version ): bool {
return version_compare( WC()->version, $version, '>=' );
}
}
\ No newline at end of file
......
......@@ -3,10 +3,14 @@
namespace ACA\YoastSeo\Column\User;
use AC;
use AC\MetaType;
use ACA\YoastSeo\Editing;
use ACA\YoastSeo\Export;
use ACA\YoastSeo\Filtering;
use ACP;
use ACP\Editing\Service\Basic;
use ACP\Editing\Storage\Meta;
use ACP\Editing\View\TextArea;
class AuthorPageMetaDesc extends AC\Column\Meta
implements ACP\Editing\Editable, ACP\Search\Searchable, ACP\ConditionalFormat\Formattable {
......@@ -28,7 +32,7 @@ class AuthorPageMetaDesc extends AC\Column\Meta
}
public function editing() {
return new ACP\Editing\Model\Meta( $this );
return new Basic( new TextArea(), new Meta( $this->get_meta_key(), new MetaType( MetaType::USER ) ) );
}
}
\ No newline at end of file
......
......@@ -3,10 +3,14 @@
namespace ACA\YoastSeo\Column\User;
use AC;
use AC\MetaType;
use ACA\YoastSeo\Editing;
use ACA\YoastSeo\Export;
use ACA\YoastSeo\Filtering;
use ACP;
use ACP\Editing\Service\Basic;
use ACP\Editing\Storage\Meta;
use ACP\Editing\View\Text;
class AuthorPageTitle extends AC\Column\Meta
implements ACP\Editing\Editable, ACP\Search\Searchable, ACP\Sorting\Sortable, ACP\ConditionalFormat\Formattable {
......@@ -59,7 +63,7 @@ class AuthorPageTitle extends AC\Column\Meta
}
public function editing() {
return new ACP\Editing\Model\Meta( $this );
return new Basic( new Text(), new Meta( $this->get_meta_key(), new MetaType( MetaType::USER ) ) );
}
public function sorting() {
......
......@@ -12,7 +12,7 @@ final class ColumnGroups implements Registerable {
}
public function register_column_groups( AC\Groups $groups ) {
$groups->register_group( 'yoast-seo', 'Yoast SEO', 25 );
$groups->add( 'yoast-seo', 'Yoast SEO', 25 );
}
}
\ No newline at end of file
......
<?php
/*
Plugin Name: Admin Columns Pro
Version: 6.1.3
Version: 6.2.2
Description: Customize columns on the administration screens for post(types), users and other content. Filter and sort content, and edit posts directly from the posts overview. All via an intuitive, easy-to-use drag-and-drop interface.
Author: AdminColumns.com
Author URI: https://www.admincolumns.com
......@@ -37,7 +37,7 @@ if ( ! is_admin() ) {
}
define( 'ACP_FILE', __FILE__ );
define( 'ACP_VERSION', '6.1.3' );
define( 'ACP_VERSION', '6.2.2' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
......
......@@ -7,10 +7,6 @@ use AC\ListScreenCollection;
use AC\Type\ListScreenId;
use AC\Type\Url;
/**
* @since 3.0
*/
// TODO David remove the singleton, make a factory with a shared instance for AC this should be no issue
if ( ! function_exists( 'AC' ) ) {
function AC(): AC\AdminColumns {
static $ac = null;
......
.acui-dropdown{position:relative;display:inline-block}.acui-dropdown-menu{position:absolute;top:100%;background:#fff;box-shadow:0 9px 24px 0 rgba(15,15,15,.2),0 3px 6px 0 rgba(15,15,15,.1),0 0 0 1px rgba(15,15,15,.05);border-radius:2px;min-width:200px;padding:8px 0;z-index:var(--menu-z-index, 20)}.acui-dropdown-menu.-bottom-left{right:0}.acui-dropdown-item{margin:0 2px;padding:6px 10px;cursor:pointer;display:block;white-space:nowrap;text-decoration:none;color:var(--ac-text-color)}.acui-dropdown-item:hover,.acui-dropdown-item:focus{background:var(--ac-button-bg);border-radius:5px}.acui-progress{--containerWidth: 100%;--baseBackground: #ddd;--defaultBarBackground: #0073aa;--warningBarBackground: #FFB900;--errorBarBackground: var(--ac-notification-red);--finishedBarBackground: #7ED321;display:block;width:var(--containerWidth)}.acui-progress__bar{background:var(--baseBackground);width:100%;height:10px;border-radius:2px;position:relative;overflow:hidden;margin:15px 0}.acui-progress__progress{height:100%;background:var(--defaultBarBackground)}.acui-progress__progress.-finished{background-color:var(--finishedBarBackground, #7ED321)}.acui-progress__progress.-warning{background-color:var(--warningBarBackground, #FFB900)}.acui-progress__progress.-error{background-color:var(--errorBarBackground, #FFB900)}
.acui-dropdown{position:relative;display:inline-block}.acui-dropdown-menu{position:absolute;top:100%;background:#fff;box-shadow:0 9px 24px 0 rgba(15,15,15,.2),0 3px 6px 0 rgba(15,15,15,.1),0 0 0 1px rgba(15,15,15,.05);border-radius:2px;min-width:200px;padding:8px 0;z-index:var(--menu-z-index, 20)}.acui-dropdown-menu.-bottom-left{right:0}.acui-dropdown-item{margin:0 2px;padding:6px 10px;cursor:pointer;display:block;white-space:nowrap;text-decoration:none;color:var(--ac-text-color)}.acui-dropdown-item:hover,.acui-dropdown-item:focus{background:var(--ac-button-bg);border-radius:5px}.acui-progress{--containerWidth: 100%;--baseBackground: #ddd;--defaultBarBackground: #0073aa;--warningBarBackground: #FFB900;--errorBarBackground: var(--ac-notification-red);--finishedBarBackground: #7ED321;display:block;width:var(--containerWidth)}.acui-progress__bar{background:var(--baseBackground);width:100%;height:10px;border-radius:2px;position:relative;overflow:hidden;margin:15px 0}.acui-progress__progress{height:100%;background:var(--defaultBarBackground)}.acui-progress__progress.-finished{background-color:var(--finishedBarBackground, #7ED321)}.acui-progress__progress.-warning{background-color:var(--warningBarBackground, #FFB900)}.acui-progress__progress.-error{background-color:var(--errorBarBackground, #FFB900)}.acui-toggle-buttons .button{border-radius:0}.acui-toggle-buttons .button .dashicons{transform:translateY(4px)}.acui-toggle-buttons .button:active,.acui-toggle-buttons .button:focus{box-shadow:none !important}.acui-toggle-buttons .button:first-child{border-top-left-radius:3px;border-bottom-left-radius:3px}.acui-toggle-buttons .button:last-child{border-top-right-radius:3px;border-bottom-right-radius:3px}.acui-toggle-buttons .button.button-primary{padding-left:3px}.acui-button{background:#f6f7f7;border-color:var(--ac-primary-color)}.acui-tooltip{display:inline-flex;position:relative}.acui-tooltip .acui-tooltip-content.is-top{bottom:calc(100% + 4px);left:50%;transform:translateX(-50%)}.acui-tooltip .acui-tooltip-content.is-bottom{top:calc(100% + 4px);left:50%;transform:translateX(-50%)}.acui-tooltip .acui-tooltip-content.is-left{top:50%;right:calc(100% + 5px);transform:translateY(-50%)}.acui-tooltip .acui-tooltip-content.is-right{top:50%;left:calc(100% + 5px);transform:translateY(-50%)}.acui-tooltip-content{background:#000;border-radius:3px;padding:7px 14px;color:#fff;position:absolute;display:block;transition:opacity .3s;pointer-events:none;font-size:11px;line-height:16px;z-index:100000;white-space:nowrap}.acui-tooltip-content:before{content:"";display:block;width:0;height:0;border-bottom:4px solid rgba(0,0,0,.8);border-left:6px solid rgba(0,0,0,0);border-right:6px solid rgba(0,0,0,0);position:absolute}.acui-tooltip-content.is-top{margin-top:-5px}.acui-tooltip-content.is-top:before{left:50%;bottom:-4px;transform:translateX(-4px) rotate(180deg)}.acui-tooltip-content.is-bottom{margin-top:5px}.acui-tooltip-content.is-bottom:before{left:50%;top:-4px;transform:translateX(-4px)}.acui-tooltip-content.is-left{transform:translateY(-50%) translateX(-2px)}.acui-tooltip-content.is-left:before{left:100%;top:50%;transform:translateX(-4px) translateY(-50%) rotate(90deg)}.acui-tooltip-content.is-right{transform:translateY(-50%) translateX(5px)}.acui-tooltip-content.is-right:before{right:100%;top:50%;transform:translateX(4px) translateY(-50%) rotate(270deg)}.acui-tooltip-content.is-multiline{text-align:center;white-space:normal;width:var(--acui-tooltip-width, 200px)}.acui-tooltip-content.is-multiline.is-large{width:300px}.acui-tooltip-content.hover{opacity:1}
......
......@@ -22,7 +22,7 @@ class AdminScripts implements Enqueueables {
public function get_assets() {
return new Assets( [
new Script( 'ac-admin-general', $this->location->with_suffix( 'assets/js/admin-general.js' ), [ 'jquery' ] ),
new Style( 'ac-admin', $this->location->with_suffix( 'assets/css/admin-general.css' ) ),
new Style( 'ac-admin', $this->location->with_suffix( 'assets/css/admin-general.css' ), [ 'ac-ui' ] ),
] );
}
......
......@@ -5,27 +5,22 @@ namespace AC\Admin\Asset;
use AC;
use AC\Asset\Location;
use AC\Asset\Script;
use AC\DefaultColumnsRepository;
use AC\ListScreen;
use AC\ListScreenTypes;
use AC\Controller\DefaultColumns;
class Columns extends Script {
/**
* @var DefaultColumnsRepository
*/
private $default_columns;
private $list_screens;
/**
* @var ListScreen
*/
private $list_screen;
private $list_key;
private $list_id;
public function __construct(
string $handle,
Location $location,
DefaultColumnsRepository $default_columns,
ListScreen $list_screen
array $list_screens,
string $list_key,
string $list_id = null
) {
parent::__construct( $handle, $location, [
'jquery',
......@@ -34,27 +29,18 @@ class Columns extends Script {
'jquery-touch-punch',
] );
$this->default_columns = $default_columns;
$this->list_screen = $list_screen;
}
private function get_list_screens(): array {
return is_network_admin()
? ListScreenTypes::instance()->get_list_screens( [ ListScreenTypes::ARG_NETWORK => true ] )
: ListScreenTypes::instance()->get_list_screens( [ ListScreenTypes::ARG_SITE => true ] );
$this->list_screens = $list_screens;
$this->list_key = $list_key;
$this->list_id = $list_id;
}
public function register(): void {
parent::register();
if ( null === $this->list_screen ) {
return;
}
$params = [
'_ajax_nonce' => wp_create_nonce( AC\Ajax\Handler::NONCE_ACTION ),
'list_screen' => $this->list_screen->get_key(),
'layout' => $this->list_screen->has_id() ? $this->list_screen->get_id()->get_id() : null,
'list_screen' => $this->list_key,
'layout' => $this->list_id,
'original_columns' => [],
'uninitialized_list_screens' => [],
'i18n' => [
......@@ -67,16 +53,9 @@ class Columns extends Script {
],
];
foreach ( $this->get_list_screens() as $list_screen ) {
$list_key = $list_screen->get_key();
if ( $this->default_columns->exists( $list_key ) ) {
continue;
}
$params['uninitialized_list_screens'][ $list_key ] = [
'screen_link' => add_query_arg( [ 'save-default-headings' => '1', 'list_screen' => $list_key ], $list_screen->get_screen_link() ),
'label' => $list_screen->get_label(),
foreach ( $this->list_screens as $list_screen ) {
$params['uninitialized_list_screens'][ $list_screen->get_key() ] = [
'screen_link' => add_query_arg( [ DefaultColumns::QUERY_PARAM => '1' ], $list_screen->get_screen_link() ),
];
}
......
<?php
declare( strict_types=1 );
namespace AC\Admin;
use AC\DefaultColumnsRepository;
use AC\ListScreen;
use AC\ListScreenFactoryInterface;
use AC\Table\ListKeysFactoryInterface;
use AC\Type\ListKey;
class ListScreenUninitialized {
private $default_storage;
private $list_screen_factory;
private $list_keys_factory;
public function __construct(
DefaultColumnsRepository $storage,
ListScreenFactoryInterface $list_screen_factory,
ListKeysFactoryInterface $list_keys_factory
) {
$this->default_storage = $storage;
$this->list_screen_factory = $list_screen_factory;
$this->list_keys_factory = $list_keys_factory;
}
public function find( ListKey $list_key ): ?ListScreen {
if ( $this->default_storage->exists( (string) $list_key ) ) {
return null;
}
if ( ! $this->list_screen_factory->can_create( (string) $list_key ) ) {
return null;
}
return $this->list_screen_factory->create( (string) $list_key );
}
public function find_all(): array {
$list_keys = $this->list_keys_factory->create()->all();
$list_screens = array_map( [ $this, 'find' ], $list_keys );
return array_filter( $list_screens );
}
}
\ No newline at end of file
<?php
namespace AC\Admin;
interface MenuListFactory {
public function create(): MenuListItems;
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace AC\Admin\MenuListFactory;
use AC\Admin\MenuListFactory;
use AC\Admin\MenuListItems;
use AC\Admin\Type\MenuListItem;
use AC\ListScreen;
use AC\ListScreenFactory;
use AC\Table\ListKeysFactoryInterface;
class MenuFactory implements MenuListFactory {
private $list_keys_factory;
private $list_screen_factory;
public function __construct( ListKeysFactoryInterface $factory, ListScreenFactory $list_screen_factory ) {
$this->list_keys_factory = $factory;
$this->list_screen_factory = $list_screen_factory;
}
private function create_menu_item( ListScreen $list_screen ): MenuListItem {
$group = (string) apply_filters( 'ac/admin/menu_group', $list_screen->get_group(), $list_screen );
return new MenuListItem(
$list_screen->get_key(),
$list_screen->get_label(),
$group ?: 'other'
);
}
public function create(): MenuListItems {
$menu = new MenuListItems();
foreach ( $this->list_keys_factory->create()->all() as $list_key ) {
if ( $list_key->is_network() ) {
continue;
}
if ( $this->list_screen_factory->can_create( (string) $list_key ) ) {
$menu->add( $this->create_menu_item( $this->list_screen_factory->create( (string) $list_key ) ) );
}
}
do_action( 'ac/admin/menu_list', $menu );
return $menu;
}
}
\ No newline at end of file
<?php
declare( strict_types=1 );
namespace AC\Admin;
use AC\Admin\Type\MenuListItem;
class MenuListItems {
/**
* @var MenuListItem[]
*/
private $items = [];
public function __construct( array $items = [] ) {
array_map( [ $this, 'add' ], $items );
}
public function add( MenuListItem $item ): void {
$this->items[ $item->get_key() ] = $item;
}
public function get( string $key ): ?MenuListItem {
return $this->items[ $key ] ?? null;
}
public function remove( MenuListItem $item ): void {
unset( $this->items[ $item->get_key() ] );
}
/**
* @return MenuListItem[]
*/
public function all(): array {
return $this->items;
}
}
\ No newline at end of file
......@@ -10,51 +10,77 @@ use AC\Admin\PageFactoryInterface;
use AC\Admin\Preference;
use AC\Admin\Section;
use AC\Asset\Location;
use AC\Controller\Middleware;
use AC\DefaultColumnsRepository;
use AC\ListScreenFactory;
use AC\ListScreenRepository\Storage;
use AC\Request;
use AC\Table\ListKeysFactoryInterface;
use InvalidArgumentException;
class Columns implements PageFactoryInterface {
/**
* @var Storage
*/
protected $storage;
/**
* @var Location\Absolute
*/
protected $location;
/**
* @var MenuFactoryInterface
*/
protected $menu_factory;
/**
* @var bool
*/
protected $list_screen_factory;
protected $list_screen_uninitialized;
private $menu_list_factory;
private $list_keys_factory;
private $is_acp_active;
public function __construct(
Storage $storage,
Location\Absolute $location,
MenuFactoryInterface $menu_factory,
ListScreenFactory $list_screen_factory,
Admin\ListScreenUninitialized $list_screen_uninitialized,
Admin\MenuListFactory $menu_list_factory,
ListKeysFactoryInterface $list_keys_factory,
bool $is_acp_active
) {
$this->storage = $storage;
$this->location = $location;
$this->menu_factory = $menu_factory;
$this->list_screen_factory = $list_screen_factory;
$this->list_screen_uninitialized = $list_screen_uninitialized;
$this->menu_list_factory = $menu_list_factory;
$this->list_keys_factory = $list_keys_factory;
$this->is_acp_active = $is_acp_active;
}
public function create() {
$request = new Request();
$request->add_middleware(
new Middleware\ListScreenAdmin(
$this->storage,
new Preference\ListScreen(),
$this->list_screen_factory,
$this->list_keys_factory
)
);
$list_screen = $request->get( 'list_screen' );
if ( ! $list_screen ) {
throw new InvalidArgumentException( 'Invalid screen.' );
}
return new Page\Columns(
$this->location,
$list_screen,
new DefaultColumnsRepository(),
new Section\Partial\Menu(),
$this->storage,
$this->list_screen_uninitialized,
new Section\Partial\Menu( $this->menu_list_factory ),
new Admin\View\Menu( $this->menu_factory->create( 'columns' ) ),
new Preference\ListScreen(),
$this->is_acp_active
);
}
......
......@@ -12,14 +12,8 @@ class PageRequestHandler implements RequestHandlerInterface {
*/
private $factories;
/**
* @param string $slug
* @param PageFactoryInterface $factory
*
* @return $this
*/
public function add( $slug, PageFactoryInterface $factory ) {
$this->factories[ (string) $slug ] = $factory;
public function add( string $slug, PageFactoryInterface $factory ): self {
$this->factories[ $slug ] = $factory;
return $this;
}
......
......@@ -2,61 +2,43 @@
namespace AC\Admin\Section\Partial;
use AC\ListScreen;
use AC\ListScreenGroups;
use AC\ListScreenTypes;
use AC\Admin\MenuListFactory;
use AC\ListScreenGroupsFactory;
use AC\View;
class Menu {
/** @var bool */
private $is_network;
private $menu_factory;
public function __construct( $is_network = false ) {
$this->is_network = (bool) $is_network;
public function __construct( MenuListFactory $menu_factory ) {
$this->menu_factory = $menu_factory;
}
public function render( ListScreen $list_screen, $is_hidden = false ) {
public function render( string $current, string $url, bool $is_hidden = false ): string {
$menu = new View( [
'items' => $this->get_grouped_list_screens(),
'current' => $list_screen->get_key(),
'screen_link' => $list_screen->get_screen_link(),
'items' => $this->get_menu_items(),
'current' => $current,
'screen_link' => $url,
'class' => $is_hidden ? 'hidden' : '',
] );
$menu->set_template( 'admin/edit-menu' );
return $menu->render();
}
private function get_network_list_screens() {
return ListScreenTypes::instance()->get_list_screens( [ 'network_only' => true ] );
return $menu->set_template( 'admin/edit-menu' )
->render();
}
private function get_site_list_screens() {
return ListScreenTypes::instance()->get_list_screens( [ 'site_only' => true ] );
}
/**
* @return array
*/
private function get_grouped_list_screens() {
$list_screens = $this->is_network
? $this->get_network_list_screens()
: $this->get_site_list_screens();
private function get_menu_items(): array {
$items = [];
$list_screens_grouped = [];
foreach ( $list_screens as $list_screen ) {
$list_screens_grouped[ $list_screen->get_group() ][ $list_screen->get_key() ] = $list_screen->get_label();
foreach ( $this->menu_factory->create()->all() as $item ) {
$items[ $item->get_group() ][ $item->get_key() ] = $item->get_label();
}
$grouped = [];
foreach ( ListScreenGroups::get_groups()->get_groups_sorted() as $group ) {
foreach ( ListScreenGroupsFactory::create()->get_all() as $group ) {
$slug = $group['slug'];
if ( empty( $list_screens_grouped[ $slug ] ) ) {
if ( empty( $items[ $slug ] ) ) {
continue;
}
......@@ -64,11 +46,11 @@ class Menu {
$grouped[ $slug ]['title'] = $group['label'];
}
natcasesort( $list_screens_grouped[ $slug ] );
natcasesort( $items[ $slug ] );
$grouped[ $slug ]['options'] = $list_screens_grouped[ $slug ];
$grouped[ $slug ]['options'] = $items[ $slug ];
unset( $list_screens_grouped[ $slug ] );
unset( $items[ $slug ] );
}
return $grouped;
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.