Skip to content

Commit

Permalink
WIP Fix CS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Sep 15, 2023
1 parent 0f820c7 commit f23fd87
Show file tree
Hide file tree
Showing 15 changed files with 599 additions and 597 deletions.
2 changes: 2 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<!--
<exclude-pattern>*/bin/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern> -->
<exclude-pattern>*/templates/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>

<!--
is created during composer install,
when package is tested
and not running within ft-platform
-->
<exclude-pattern>*/wordpress/*</exclude-pattern>
<exclude-pattern>*/wp-content/*</exclude-pattern>

<!-- Use figuren.theater Coding Standards -->
Expand Down
26 changes: 17 additions & 9 deletions inc/distributor-remote-quickedit/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

namespace Figuren_Theater\Data\Distributor_Remote_Quickedit;

use FT_VENDOR_DIR;

use Figuren_Theater;
use function Figuren_Theater\get_config;

use FT_VENDOR_DIR;
use function add_action;

use function is_admin;
use function is_network_admin;
use function is_user_admin;
Expand All @@ -22,25 +21,34 @@

/**
* Bootstrap module, when enabled.
*
* @return void
*/
function bootstrap() {
function bootstrap() :void {

add_action( 'plugins_loaded', __NAMESPACE__ . '\\load_plugin', 9 );
}

function load_plugin() {
/**
* Conditionally load the plugin itself and its modifications.
*
* @return void
*/
function load_plugin() :void {

$config = Figuren_Theater\get_config()['modules']['data'];
if ( ! $config['distributor-remote-quickedit'] )
return; // early
if ( ! $config['distributor-remote-quickedit'] ) {
return;
}

// Do only load in "normal" admin view
// Not for:
// - and public views
// - network-admin views
// - user-admin views
if ( ! is_admin() || is_network_admin() || is_user_admin() )
// - user-admin views.
if ( ! is_admin() || is_network_admin() || is_user_admin() ) {
return;
}

require_once FT_VENDOR_DIR . PLUGINPATH; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant
}
93 changes: 46 additions & 47 deletions inc/distributor/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,62 @@

namespace Figuren_Theater\Data\Distributor;

use FT_VENDOR_DIR;

use WP_DEBUG;
use WP_ENVIRONMENT_TYPE;

use WP_Post;

use Figuren_Theater;

use Figuren_Theater\FeaturesRepo;
use Figuren_Theater\Network\Users;

use Figuren_Theater\Options;
use function Figuren_Theater\get_config;

use FT_VENDOR_DIR;
use function add_action;
use function add_filter;
use function current_user_can;
use function remove_menu_page;

use function remove_action;
use function remove_menu_page;
use WP_DEBUG;
use WP_ENVIRONMENT_TYPE;
use WP_Post;

const BASENAME = 'distributor/distributor.php';
const PLUGINPATH = '/10up/' . BASENAME;

/**
* Bootstrap module, when enabled.
*
* @return void
*/
function bootstrap() {
function bootstrap() :void {

add_action( 'Figuren_Theater\loaded', __NAMESPACE__ . '\\filter_options', 11 );

add_action( 'plugins_loaded', __NAMESPACE__ . '\\load_plugin', 0 );
}

function load_plugin() {
/**
* Conditionally load the plugin itself and its modifications.
*
* @return void
*/
function load_plugin() :void {

// because this makes things visible
// to normal 'administrator' users
if ( ! defined( 'DISTRIBUTOR_DEBUG' ) && 'local' === WP_ENVIRONMENT_TYPE )
// Because this makes things visible
// to normal 'administrator' users.
if ( ! defined( 'DISTRIBUTOR_DEBUG' ) && 'local' === WP_ENVIRONMENT_TYPE ) {
define( 'DISTRIBUTOR_DEBUG', WP_DEBUG );
}

// the plugin checks for option 'active_sitewide_plugins'
// so we need to filter 'active_sitewide_plugins'
// The plugin checks for option 'active_sitewide_plugins'
// so we need to filter 'active_sitewide_plugins'.
add_filter( 'site_option_active_sitewide_plugins', __NAMESPACE__ . '\\filter_site_option', 0 );

require_once FT_VENDOR_DIR . PLUGINPATH; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant

// Filters the arguments for registering a post type.
add_filter( 'register_post_type_args', __NAMESPACE__ . '\\register_post_type_args', 20, 2 );

// Remove plugins menu
// Remove plugins menu.
add_action( 'network_admin_menu', __NAMESPACE__ . '\\remove_menu', 11 );
add_action( 'admin_menu', __NAMESPACE__ . '\\remove_menu', 11 );

Expand All @@ -77,8 +84,7 @@ function admin_init() {
// Allow bypassing of all media processing.
add_filter( 'dt_push_post_media', __NAMESPACE__ . '\\dt_push_post_media' );

//
add_filter( 'dt_push_post_args', __NAMESPACE__ . '\\dt_push_post_args', 9, 4 );
add_filter( 'dt_push_post_args', __NAMESPACE__ . '\\dt_push_post_args', 9, 4 );
add_filter( 'dt_pull_post_args', __NAMESPACE__ . '\\dt_pull_post_args', 9, 4 );

// Filter Distributor capabilities allowed to syndicate content.
Expand All @@ -88,15 +94,14 @@ function admin_init() {
// \add_filter( 'pre_site_option_external_updates-distributor', [ $this, 'pre_disable_updatecheck' ] );
}



function filter_site_option( $active_sitewide_plugins ) {

// prevents the default admin-notice for missing plugin files,
// which gets triggered by the FT_VENDOR_DIR path construct
// Prevents the default admin-notice for missing plugin files,
// which gets triggered by the FT_VENDOR_DIR path construct.
global $pagenow;
if ( 'plugins.php' === $pagenow )
if ( 'plugins.php' === $pagenow ) {
return $active_sitewide_plugins;
}

$active_sitewide_plugins[ BASENAME ] = BASENAME;
return $active_sitewide_plugins;
Expand Down Expand Up @@ -130,23 +135,20 @@ function filter_options() : void {
BASENAME
);


}



function remove_menu() : void {
remove_menu_page( 'distributor' );
}

function remove_columns_from_lists() : void {
// unclutter the UI for "normal" users
// Unclutter the UI for "normal" users.
// if ( 'this-site-is-not-a-network-hub' && ! \is_main_site( null, 1 ) )
if ( ! Figuren_Theater\FT::site()->has_feature( [ FeaturesRepo\Feature__core__contenthub::SLUG ] ) )
if ( ! Figuren_Theater\FT::site()->has_feature( [ FeaturesRepo\Feature__core__contenthub::SLUG ] ) ) {
remove_action( 'admin_init', 'Distributor\\SyndicatedPostUI\\setup_columns' );
}
}


/**
* [pre_disable_updatecheck description]
*
Expand All @@ -164,7 +166,6 @@ function pre_disable_updatecheck() {
}
*/


/**
* Filters the arguments for registering a post type.
*
Expand All @@ -176,16 +177,15 @@ function pre_disable_updatecheck() {
* See the register_post_type() function for accepted arguments.
* @param string $post_type Post type key.
*/
function register_post_type_args( array $args, String $post_type ) : array {
if ( in_array( $post_type, ['dt_ext_connection','dt_subscription']) ) {
function register_post_type_args( array $args, string $post_type ) : array {
if ( in_array( $post_type, [ 'dt_ext_connection', 'dt_subscription' ], true ) ) {
$args['can_export'] = current_user_can( 'manage_sites' );
$args['show_ui'] = false; // disable this anoying 'dt_subscription'-menu, as it is only needed for ext. connections
$args['show_ui'] = false; // Disable this anoying 'dt_subscription'-menu, as it is only needed for ext. connections.
}

return $args;
}


/**
* Filter Distributor capabilities allowed to syndicate content.
*
Expand All @@ -195,11 +195,11 @@ function register_post_type_args( array $args, String $post_type ) : array {
*
* @see https://10up.github.io/distributor/dt_syndicatable_capabilities.html
*
* @param String $capabilities default: edit_posts The capability allowed to syndicate content.
* @return [type] [description]
* @param string $capabilities default: edit_posts The capability allowed to syndicate content.
*
* @return string [description]
*/
function dt_syndicatable_capabilities( String $capabilities ) : string
{
function dt_syndicatable_capabilities( string $capabilities ) : string {
return 'manage_sites';
}

Expand All @@ -219,25 +219,24 @@ function dt_syndicatable_capabilities( String $capabilities ) : string
*
* @return {bool} If Distributor should push the post media.
*/
function dt_push_post_media($value)
{
function dt_push_post_media( $value ) {
return false;
}

function dt_push_post_args($new_post_args, $post, $connection_args, $connection) : array {
function dt_push_post_args( $new_post_args, $post, $connection_args, $connection ) : array {
return push_pull_default_args( $new_post_args, $post );
}

function dt_pull_post_args($new_post_args, $remote_post_id, $remote_post, $connection) : array {
function dt_pull_post_args( $new_post_args, $remote_post_id, $remote_post, $connection ) : array {
return push_pull_default_args( $new_post_args, $remote_post );
}

function push_pull_default_args( array $new_post_args, WP_Post $original_post ) : array {
// set author to machine user
$new_post_args['post_author'] = Users\ft_bot::id();
// Set author to machine user.
$new_post_args['post_author'] = Users\ft_bot::id();

// by default 'Distributor' sets the current date as new published_date
$new_post_args['post_date'] = $original_post->post_date;
// By default 'Distributor' sets the current date as new published_date.
$new_post_args['post_date'] = $original_post->post_date;
// ..and all related dates ...
$new_post_args['post_date_gmt'] = $original_post->post_date_gmt;
$new_post_args['post_modified'] = $original_post->post_modified;
Expand Down
Loading

0 comments on commit f23fd87

Please sign in to comment.