Skip to content

Commit

Permalink
Merge branch 'trunk' into update/autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland authored Dec 9, 2024
2 parents 39cd5cd + d0540b4 commit 8680033
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
38 changes: 38 additions & 0 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ function plugin_settings_link( $actions ) {
}
\add_filter( 'plugin_action_links_' . ACTIVITYPUB_PLUGIN_BASENAME, __NAMESPACE__ . '\plugin_settings_link' );

/**
* Class Autoloader.
*/
\spl_autoload_register(
function ( $full_class ) {
$base_dir = __DIR__ . '/includes/';
$base = 'Activitypub\\';

if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
$maybe_uppercase = str_replace( $base, '', $full_class );
$class = strtolower( $maybe_uppercase );
// All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that.
if ( $maybe_uppercase === $class ) {
return;
}

if ( false !== strpos( $class, '\\' ) ) {
$parts = explode( '\\', $class );
$class = array_pop( $parts );
$sub_dir = strtr( implode( '/', $parts ), '_', '-' );
$base_dir = $base_dir . $sub_dir . '/';
}

$filename = 'class-' . strtr( $class, '_', '-' );
$file = $base_dir . $filename . '.php';

if ( file_exists( $file ) && is_readable( $file ) ) {
require_once $file;
} else {
// translators: %s is the class name.
$message = sprintf( esc_html__( 'Required class not found or not readable: %s', 'activitypub' ), esc_html( $full_class ) );
Debug::write_log( $message );
\wp_die( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
);

\register_activation_hook(
__FILE__,
array(
Expand Down
16 changes: 16 additions & 0 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function init() {
}

\add_filter( 'dashboard_glance_items', array( self::class, 'dashboard_glance_items' ) );
\add_filter( 'plugin_action_links_' . ACTIVITYPUB_PLUGIN_BASENAME, array( self::class, 'add_plugin_settings_link' ) );
}

/**
Expand Down Expand Up @@ -837,4 +838,19 @@ public static function row_actions( $actions, $post ) {

return $actions;
}

/**
* Add plugin settings link.
*
* @param array $actions The current actions.
*/
public static function add_plugin_settings_link( $actions ) {
$actions[] = \sprintf(
'<a href="%1s">%2s</a>',
\menu_page_url( 'activitypub', false ),
\__( 'Settings', 'activitypub' )
);

return $actions;
}
}

0 comments on commit 8680033

Please sign in to comment.