Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions globals/migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function neve_migrate_blog_columns() {
* @return void
*/
function neve_run_migration_flags() {
if ( ! class_exists( Migration_Flags::class ) ) {
return;
}
$migrator = new Migration_Flags( NEVE_VERSION );
$migrator->run();
}
Expand Down
2 changes: 1 addition & 1 deletion header-footer-grid/Core/Builder/Abstract_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ public function get_current_slot_index() {
public function render() {
$layout = $this->get_layout_data();
self::$current_builder = $this->get_id();
if ( is_customize_preview() ) {
if ( is_customize_preview() && class_exists( Css_Generator::class ) ) {
$style = $this->add_style( [] );
$generator = new Css_Generator();
$generator->set( $style );
Expand Down
77 changes: 57 additions & 20 deletions inc/admin/dashboard/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class Main {
/**
* Changelog Handler.
*
* @var Changelog_Handler
* @var Changelog_Handler|null
*/
private $cl_handler;
/**
* Plugin Helper instance.
*
* @var Plugin_Helper
* @var Plugin_Helper|null
*/
private $plugin_helper;
/**
Expand All @@ -42,8 +42,57 @@ class Main {
* Main constructor.
*/
public function __construct() {
$this->plugin_helper = new Plugin_Helper();
$this->cl_handler = new Changelog_Handler();
if ( class_exists( Plugin_Helper::class ) ) {
$this->plugin_helper = new Plugin_Helper();
}

if ( class_exists( Changelog_Handler::class ) ) {
$this->cl_handler = new Changelog_Handler();
}
}

/**
* Read a changelog through the handler, if there is one.
*
* @param string $path Absolute path to the changelog file.
*
* @return mixed[]
*/
private function get_changelog( $path ) {
if ( null === $this->cl_handler ) {
return array();
}

return $this->cl_handler->get_changelog( $path );
}

/**
* Plugin action data for a recommended plugin card.
*
* @param string $slug Plugin slug.
*
* @return array<string, mixed>
*/
private function get_plugin_actions( $slug ) {
if ( null === $this->plugin_helper ) {
return [
'cta' => 'install',
'path' => '',
'activate' => '',
'deactivate' => '',
'network' => false,
'version' => '0.0.0',
];
}

return [
'cta' => $this->plugin_helper->get_plugin_state( $slug ),
'path' => $this->plugin_helper->get_plugin_path( $slug ),
'activate' => $this->plugin_helper->get_plugin_action_link( $slug ),
'deactivate' => $this->plugin_helper->get_plugin_action_link( $slug, 'deactivate' ),
'network' => $this->plugin_helper->get_is_network_wide( $slug ),
'version' => $this->plugin_helper->get_plugin_version( $slug, '0.0.0' ),
];
}
Comment thread
girishpanchal30 marked this conversation as resolved.

/**
Expand Down Expand Up @@ -350,7 +399,7 @@ private function get_localization() {
'<a class="text-blue-600 hover:text-blue-700 hover:underline inline-flex gap-1 items-center" target="_blank" rel="external noreferrer noopener" href="' . tsdk_translate_link( 'https://store.themeisle.com/', 'query' ) . '">Themeisle<span class="sr-only">' . esc_html__( '(opens in a new tab)', 'neve' ) . '</span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-external-link shrink-0"><path d="M15 3h6v6"></path><path d="M10 14 21 3"></path><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path></svg></a>'
),
],
'changelog' => $this->cl_handler->get_changelog( get_template_directory() . '/CHANGELOG.md' ),
'changelog' => $this->get_changelog( get_template_directory() . '/CHANGELOG.md' ),
'onboarding' => [],
'hasFileSystem' => WP_Filesystem(),
'hidePluginsTab' => apply_filters( 'neve_hide_useful_plugins', ! array_key_exists( 'useful_plugins', $old_about_config ) ),
Expand All @@ -369,7 +418,7 @@ private function get_localization() {
'orbitFox' => array(
'isInstalled' => file_exists( WP_PLUGIN_DIR . '/themeisle-companion/themeisle-companion.php' ),
'isActive' => class_exists( 'Orbit_Fox' ),
'activationUrl' => $this->plugin_helper->get_plugin_action_link( 'themeisle-companion' ),
'activationUrl' => null === $this->plugin_helper ? '' : $this->plugin_helper->get_plugin_action_link( 'themeisle-companion' ),
'data' => class_exists( 'Orbit_Fox' ) ? get_option( 'obfx_data' ) : array(),
),
];
Expand All @@ -378,7 +427,7 @@ private function get_localization() {
$installed_plugins = get_plugins();
$is_otter_installed = array_key_exists( 'otter-pro/otter-pro.php', $installed_plugins );
$is_sparks_installed = array_key_exists( 'sparks-for-woocommerce/sparks-for-woocommerce.php', $installed_plugins );
$data['changelogPro'] = $this->cl_handler->get_changelog( NEVE_PRO_PATH . '/CHANGELOG.md' );
$data['changelogPro'] = $this->get_changelog( NEVE_PRO_PATH . '/CHANGELOG.md' );
$data['isOtterProInstalled'] = $is_otter_installed;
$data['otterProInstall'] = $is_otter_installed ? esc_url( wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=otter-pro%2Fotter-pro.php&plugin_status=all&paged=1&s' ), 'activate-plugin_otter-pro/otter-pro.php' ) ) : esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=install_otter_pro' ), 'install_otter_pro' ) );
$data['sparksInstallActivateEndpoint'] = $is_sparks_installed ? esc_url( wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=sparks-for-woocommerce%2Fsparks-for-woocommerce.php&plugin_status=all&paged=1&s' ), 'activate-plugin_sparks-for-woocommerce/sparks-for-woocommerce.php' ) ) : esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=install_sparks' ), 'install_sparks' ) );
Expand Down Expand Up @@ -907,19 +956,7 @@ private function get_recommended_plugins() {
continue;
}

$action = $this->plugin_helper->get_plugin_state( $slug );

$plugins[ $slug ] = array_merge(
[
'cta' => $action,
'path' => $this->plugin_helper->get_plugin_path( $slug ),
'activate' => $this->plugin_helper->get_plugin_action_link( $slug ),
'deactivate' => $this->plugin_helper->get_plugin_action_link( $slug, 'deactivate' ),
'network' => $this->plugin_helper->get_is_network_wide( $slug ),
'version' => $this->plugin_helper->get_plugin_version( $slug, '0.0.0' ),
],
$args
);
$plugins[ $slug ] = array_merge( $this->get_plugin_actions( $slug ), $args );
}

return $plugins;
Expand Down
5 changes: 5 additions & 0 deletions inc/core/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public function migrate_theme_mods_for_new_skin( $theme_mods ) {
if ( ! neve_is_new_skin() ) {
return $theme_mods;
}

if ( ! class_exists( Mods_Migrator::class ) ) {
return $theme_mods;
}

$migrator = new Mods_Migrator( $theme_mods );

return $migrator->get_migrated_mods();
Expand Down
39 changes: 35 additions & 4 deletions inc/core/core_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ private function define_modules() {
private function load_modules() {
do_action( 'neve_before_modules_load' );

if ( ! class_exists( Factory::class ) ) {
return;
}

$factory = new Factory( $this->features );
$factory->load_modules();
}
Expand All @@ -164,10 +168,9 @@ private function define_hooks() {
if ( is_customize_preview() ) {
Mods::$no_cache = true;
}
$admin = new Admin();
add_action( 'init', array( $admin, 'load_site_import' ), 20 );
add_action( 'admin_enqueue_scripts', array( $admin, 'register_react_components' ), 0 );
add_action( 'ti-about-after-sidebar-content', array( $admin, 'render_logger_toggle' ) );
if ( class_exists( Admin::class ) ) {
$this->load_admin_hooks();
}

$key_lite = str_replace( '-', '_', basename( get_template_directory() ) );
add_filter(
Expand All @@ -176,6 +179,34 @@ function () {
return [ 'mods' => array_filter( get_theme_mods() ) ];
}
);

if ( class_exists( Front_End::class ) ) {
$this->load_front_end_hooks();
}
}

/**
* Load admin hooks.
*
* @access private
*
* @return void
*/
private function load_admin_hooks() {
$admin = new Admin();
add_action( 'init', array( $admin, 'load_site_import' ), 20 );
add_action( 'admin_enqueue_scripts', array( $admin, 'register_react_components' ), 0 );
add_action( 'ti-about-after-sidebar-content', array( $admin, 'render_logger_toggle' ) );
}

/**
* Load front end hooks.
*
* @access private
*
* @return void
*/
private function load_front_end_hooks() {
$front_end = new Front_End();
add_action( 'wp_enqueue_scripts', array( $front_end, 'enqueue_scripts' ) );
add_action( 'after_setup_theme', array( $front_end, 'setup_theme' ) );
Expand Down
21 changes: 16 additions & 5 deletions inc/core/dynamic_css.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function legacy_style() {
$desktop_css = '';
$tablet_css = '';
foreach ( $classes as $class ) {
if ( ! class_exists( $class ) ) {
continue;
}

$object = new $class();
$object->init();
$mobile_css .= $object->get_style( 'mobile' );
Expand Down Expand Up @@ -68,14 +72,21 @@ public function enqueue() {
$this->legacy_style();
}

$this->generator = $is_for_gutenberg ? new Gutenberg() : new Frontend();
$_subscribers = $this->generator->get();
$generator_class = $is_for_gutenberg ? Gutenberg::class : Frontend::class;
$generated_css = '';

if ( class_exists( $generator_class ) ) {
$this->generator = new $generator_class();
$_subscribers = $this->generator->get();

$_subscribers = array_merge( $_subscribers, apply_filters( 'neve_style_subscribers', [] ) );
$_subscribers = array_merge( $_subscribers, apply_filters( 'neve_style_subscribers', [] ) );

$this->generator->set( $_subscribers );
$this->generator->set( $_subscribers );

$generated_css = $this->generator->generate();
}

$style = apply_filters( 'neve_dynamic_style_output', $this->generator->generate(), $is_for_gutenberg ? 'gutenberg' : 'frontend' );
$style = apply_filters( 'neve_dynamic_style_output', $generated_css, $is_for_gutenberg ? 'gutenberg' : 'frontend' );

$style .= self::get_root_css();

Expand Down
15 changes: 14 additions & 1 deletion inc/core/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,21 @@ public function __construct( $modules, $namespace = '\\Neve\\' ) {
public function load_modules() {
foreach ( $this->modules as $module_name ) {
$module = $this->build( $module_name );
if ( $module !== null ) {
if ( $module === null ) {
continue;
}
if ( method_exists( $module, 'init' ) ) {
$module->init();
continue;
}

$message = sprintf(
'Module "%s" was built but does not implement an init() method.',
$this->namespace . $module_name
);
if ( function_exists( '_doing_it_wrong' ) ) {
_doing_it_wrong( __METHOD__, esc_html( $message ), '4.2.12' );
continue;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions inc/core/settings/mods_migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ private function migrate_mods() {
* @return void
*/
private function attempt_builders_migration() {
if ( ! class_exists( Builder_Migrator::class ) ) {
return;
}

$hfg_migrator = new Builder_Migrator();

foreach ( $this->builder_map as $builder ) {
Expand Down
7 changes: 7 additions & 0 deletions inc/core/styles/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class Generator {
* @return string|void Css output.
*/
public function generate( $echo = false ) {
if ( ! class_exists( Dynamic_Selector::class ) ) {
if ( ! $echo ) {
return '';
}
return;
}

$desktop_css = '';
$tablet_css = '';
$all_css = '';
Expand Down
3 changes: 3 additions & 0 deletions inc/customizer/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ public function set_featured_image() {
* @return void
*/
private function load_modules() {
if ( ! class_exists( Factory::class ) ) {
return;
}
$factory = new Factory( $this->customizer_modules );
$factory->load_modules();
}
Expand Down
33 changes: 33 additions & 0 deletions tests/test-neve-autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,37 @@ public function testFailedLookupLeavesClassLoadableByNextAutoloader() {
spl_autoload_unregister( array( $autoloader, 'load_class' ) );
}
}

/**
* A miss inside a registered namespace resolves to false rather than
* requiring a file that is not there. The caller is what has to guard; the
* autoloader only reports.
*/
public function testMissingMappedClassResolvesToFalse() {
$autoloader = new \Neve\Autoloader();
$autoloader->add_namespace( 'Neve_Fixture', $this->fixture_dir );

$this->assertFalse( $autoloader->load_class( 'Neve_Fixture\\Widgets\\Absent_Widget' ) );
$this->assertFalse( class_exists( 'Neve_Fixture\\Widgets\\Absent_Widget', false ) );
}

/**
* A miss must not be remembered. The file can appear later in the same
* request, and a cached negative would keep the class unreachable.
*/
public function testMissIsNotCachedAgainstALaterFile() {
$autoloader = new \Neve\Autoloader();
$autoloader->add_namespace( 'Neve_Fixture', $this->fixture_dir );

$this->assertFalse( $autoloader->load_class( 'Neve_Fixture\\Widgets\\Deferred_Widget' ) );

mkdir( $this->fixture_dir . 'widgets/', 0777, true );
file_put_contents(
$this->fixture_dir . 'widgets/deferred_widget.php',
'<?php namespace Neve_Fixture\\Widgets; class Deferred_Widget {}'
);

$this->assertNotFalse( $autoloader->load_class( 'Neve_Fixture\\Widgets\\Deferred_Widget' ) );
$this->assertTrue( class_exists( 'Neve_Fixture\\Widgets\\Deferred_Widget', false ) );
}
Comment thread
girishpanchal30 marked this conversation as resolved.
}
Loading