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 16, 2023
1 parent f23fd87 commit b27aacb
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 69 deletions.
108 changes: 86 additions & 22 deletions inc/distributor/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

namespace Figuren_Theater\Data\Distributor;

use Figuren_Theater;
use Distributor\Connection;

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

Expand Down Expand Up @@ -73,18 +74,19 @@ function load_plugin() :void {
add_action( 'admin_init', __NAMESPACE__ . '\\admin_init', 0 );
}

function admin_init() {
/**
* Fires as an admin screen or script is being initialized.
*
* @return void
*/
function admin_init() : void {

add_action( 'admin_init', __NAMESPACE__ . '\\remove_columns_from_lists', 9 );

// puc_check_now-$slug
// 'puc_check_now-distributor' => '__return_false',
//

// 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 @@ -94,10 +96,18 @@ function admin_init() {
// \add_filter( 'pre_site_option_external_updates-distributor', [ $this, 'pre_disable_updatecheck' ] );
}

function filter_site_option( $active_sitewide_plugins ) {
/**
* Add 'Distributor' to the site-wide active plugins on-the-fly.
*
* Prevents the default admin-notice for missing plugin files,
* which gets triggered by the FT_VENDOR_DIR path construct.
*
* @param array $active_sitewide_plugins WordPress' default 'active_sitewide_plugins' site-option.
*
* @return array
*/
function filter_site_option( array $active_sitewide_plugins ) : array {

Check failure on line 109 in inc/distributor/namespace.php

View workflow job for this annotation

GitHub Actions / call-workflow-build-test-measure / Static Analysis: PHP

Function Figuren_Theater\Data\Distributor\filter_site_option() has parameter $active_sitewide_plugins with no value type specified in iterable type array.

Check failure on line 109 in inc/distributor/namespace.php

View workflow job for this annotation

GitHub Actions / call-workflow-build-test-measure / Static Analysis: PHP

Function Figuren_Theater\Data\Distributor\filter_site_option() return type has no value type specified in iterable type array.

// 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 ) {
return $active_sitewide_plugins;
Expand All @@ -107,28 +117,37 @@ function filter_site_option( $active_sitewide_plugins ) {
return $active_sitewide_plugins;
}

function filter_options() : void {
/**
* Handle options
*
* @return void
*/
function filter_options() :void {

$_option_name = 'dt_settings';
$_options = [
'override_author_byline' => false,
'media_handling' => 'featured',
'email' => getenv( 'FT_DATA_DISTRIBUTOR_EMAIL' ),
'license_key' => getenv( 'FT_DATA_DISTRIBUTOR_KEY' ),
'valid_license' => false, // Distributor: "Enable updates if we have a valid license" --> f.t ;)
'valid_license' => false, // Distributor would like to "Enable updates if we have a valid license" --> But no, f.t ;) !
];

// gets added to the 'OptionsCollection'
// from within itself on creation
/*
* Gets added to the 'OptionsCollection'
* from within itself on creation.
*/
new Options\Option(
$_option_name,
$_options,
BASENAME,
'site_option'
);

// gets added to the 'OptionsCollection'
// from within itself on creation
/*
* Gets added to the 'OptionsCollection'
* from within itself on creation.
*/
new Options\Option(
$_option_name,
$_options,
Expand All @@ -137,13 +156,24 @@ function filter_options() : void {

}

/**
* Remove the plugins admin-menu.
*
* @return void
*/
function remove_menu() : void {
remove_menu_page( 'distributor' );
}

/**
* Unclutter the UI for "normal" users.
*
* @todo #20 Refactor hard dependency on 'deprecated_figuren_theater_v2'
*
* @return void
*/
function remove_columns_from_lists() : void {
// 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 ] ) ) {

Check failure on line 177 in inc/distributor/namespace.php

View workflow job for this annotation

GitHub Actions / call-workflow-build-test-measure / Static Analysis: PHP

Access to constant SLUG on an unknown class Figuren_Theater\FeaturesRepo\Feature__core__contenthub.

Check failure on line 177 in inc/distributor/namespace.php

View workflow job for this annotation

GitHub Actions / call-workflow-build-test-measure / Static Analysis: PHP

Call to static method site() on an unknown class Figuren_Theater\FT.
remove_action( 'admin_init', 'Distributor\\SyndicatedPostUI\\setup_columns' );
}
Expand Down Expand Up @@ -171,7 +201,7 @@ function pre_disable_updatecheck() {
*
* @see https://developer.wordpress.org/reference/hooks/register_post_type_args/
*
* @since 4.4.0
* @since WP 4.4.0
*
* @param array $args Array of arguments for registering a post type.
* See the register_post_type() function for accepted arguments.
Expand Down Expand Up @@ -210,7 +240,7 @@ function dt_syndicatable_capabilities( string $capabilities ) : string {
*
* @hook dt_push_post_media
*
* @param {bool} true If Distributor should push the post media.
* @param {bool} $value If Distributor should push the post media.
* @param {int} $new_post_id The newly created post ID.
* @param {array} $media List of media items attached to the post, formatted by {@link \Distributor\Utils\prepare_media()}.
* @param {int} $post_id The original post ID.
Expand All @@ -223,14 +253,48 @@ function dt_push_post_media( $value ) {
return false;
}

function dt_push_post_args( $new_post_args, $post, $connection_args, $connection ) : array {
/**
* Filter the arguments sent to the remote server during a push.
*
* @see https://10up.github.io/distributor/dt_push_post_args.html
*
* @param array $new_post_args
* @param WP_Post $post
* @param mixed $connection_args
* @param Connection $connection
*
* @return array
*/
function dt_push_post_args( array $new_post_args, WP_Post $post, mixed $connection_args, Connection $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 {
/**
* Filter the arguments passed into wp_insert_post during a pull.
*
* @see https://10up.github.io/distributor/dt_pull_post_args.html
*
* @param array $new_post_args The post data to be inserted.
* @param int $remote_post_id The remote post ID.
* @param WP_Post $remote_post The request that got the post.
* @param Connection $connection The Distributor connection pulling the post.
*
* @return array The post data to be inserted.
*/
function dt_pull_post_args( array $new_post_args, int $remote_post_id, WP_Post $remote_post, Connection $connection ) : array {
return push_pull_default_args( $new_post_args, $remote_post );
}

/**
*
*
* @todo #20 Refactor hard dependency on 'deprecated_figuren_theater_v2'
*
* @param array $new_post_args
* @param WP_Post $original_post
*
* @return array
*/
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();
Expand Down
89 changes: 49 additions & 40 deletions inc/feed-pull/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@

namespace Figuren_Theater\Data\Feed_Pull;

use Figuren_Theater\Network\Features;
use Figuren_Theater\Network\Users;

use Figuren_Theater;
use Figuren_Theater\Network\Features;
use Figuren_Theater\Options;
use function Figuren_Theater\get_config;


// use FT_VENDOR_DIR;
use WP_PLUGIN_DIR;


use function add_action;
use function add_filter;
use function current_user_can;
Expand All @@ -29,7 +20,6 @@
use function wp_doing_ajax;
use function wp_doing_cron;

// use FP_OPTION_NAME;
const FP_OPTION_NAME = 'fp_feed_pull';

const BASENAME = 'feed-pull/feed-pull.php';
Expand Down Expand Up @@ -58,45 +48,57 @@ function bootstrap() :void {
*/
function load_plugin() :void {
$config = Figuren_Theater\get_config()['modules']['data'];
if ( ! $config['feed-pull'] )
if ( ! $config['feed-pull'] ) {
return;
}

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

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

// create new 'fp_feed' posts, when a new 'ft_link' post is created
// which has an importable endpoint
// Create new 'fp_feed' posts, when a new 'ft_link' post is created
// which has an importable endpoint.
bootstrap_auto_setup();

// everything related to importing normal posts from feeds
// Everything related to importing normal posts from feeds.
bootstrap_import();

add_action( 'admin_menu', __NAMESPACE__ . '\\remove_menu', 11 );

add_filter( 'register_'. FEED_POSTTYPE .'_post_type_args', __NAMESPACE__ . '\\register_post_type_args' );
add_filter( 'register_' . FEED_POSTTYPE . '_post_type_args', __NAMESPACE__ . '\\register_post_type_args' );

add_action( 'admin_print_footer_scripts', __NAMESPACE__ . '\\custom_icons' );

add_action( 'add_meta_boxes_' . FEED_POSTTYPE, __NAMESPACE__ . '\\modify_metaboxes' );
}


function filter_options() {

/**
* Handle options
*
* @return void
*/
function filter_options() :void {
/**
* Defaults:
* 'pull_interval' => 3600,
* 'enable_feed_pull' => 1
*/
$_options = [
'pull_interval' => 3607, // default: 3600
'enable_feed_pull' => 1, // default: 1
'pull_interval' => 3607,
'enable_feed_pull' => 1,
];

// gets added to the 'OptionsCollection'
// from within itself on creation
/*
* Gets added to the 'OptionsCollection'
* from within itself on creation.
*/
new Options\Option(
FP_OPTION_NAME,
$_options,
Expand All @@ -105,6 +107,11 @@ function filter_options() {

}

/**
* Remove the plugins admin-menu.
*
* @return void
*/
function remove_menu() : void {
remove_submenu_page( 'options-general.php', 'feed-pull' );
}
Expand All @@ -114,19 +121,16 @@ function remove_menu() : void {
*
* @see https://github.com/tlovett1/feed-pull/blob/45d667c1275cca0256bd03ed6fa1655cdf26f064/includes/class-fp-source-feed-cpt.php#L136
*
* @package [package]
* @since 3.0
*
* @param array $args [description]
*
* @return [type] [description]
* @return array [description]
*/
function register_post_type_args( array $args ) : array {

$cuc = current_user_can( 'manage_sites' );

$args['public'] = false; // WHY is this 'true' by default?
$args['supports'] = array( 'title', 'post-formats' );
$args['supports'] = [ 'title', 'post-formats' ];

$args['show_ui'] = $cuc;
$args['show_in_menu'] = $cuc;
Expand All @@ -140,28 +144,33 @@ function register_post_type_args( array $args ) : array {
return $args;
}



/**
* Removes 'post slug' metabox for all users and
* removes 'custom fields' metabox for all, but super-admin, users .
*
* @return void
*/
function modify_metaboxes() : void {

remove_meta_box( 'slugdiv', null, 'normal' );

if( ! current_user_can( 'manage_sites' ) )
if ( ! current_user_can( 'manage_sites' ) ) {
remove_meta_box( 'postcustom', null, 'normal' );
}
}


/**
* Enqueue a script in the WordPress admin on post.php.
*
* @return void
*/
function custom_icons() : void {
global $pagenow, $typenow;
global $pagenow, $typenow;

if ( ('post.php' !== $pagenow && 'post-new.php' !== $pagenow) || 'fp_feed' !== $typenow ) {
return;
}
?>
if ( ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) || 'fp_feed' !== $typenow ) {
return;
}
?>
<style type="text/css">
.misc-pub-section.misc-pub-fp-last-pulled label {
background: 0;
Expand All @@ -178,5 +187,5 @@ function custom_icons() : void {
vertical-align: top;
}
</style>
<?php
<?php
}
Loading

0 comments on commit b27aacb

Please sign in to comment.