Reputation: 117
or to be completely concise with my question:
( Within a Namespace'd file ) is it possible to declare a new class ( that extends a class defined in the global namespace ) to the global space?
namespace Roots\Sage\VisualComposer;
...
...
if ( class_exists( '\\WPBakeryShortCodesContainer' ) ) {
class WPBakeryShortCode_Your_Gallery extends \WPBakeryShortCodesContainer {}
}
echo 'x: ' . WPBakeryShortCodesContainer::class . PHP_EOL;
echo 'y: ' . WPBakeryShortCode_Your_Gallery::class . PHP_EOL;
Returns:
x: WPBakeryShortCodesContainer
y: Roots\Sage\VisualComposer\WPBakeryShortCode_Your_Gallery
So my new class of WPBakeryShortCode_Your_Gallery
is in the Roots\Sage\VisualComposer
namespace, not the global...
Upvotes: 2
Views: 296
Reputation: 1595
Use alternative syntax for namespaces:
namespace Roots\Sage\VisualComposer {
//...
}
//...
namespace Roots\Sage\VisualEditor {
//...
}
//...
namespace { // global code
if ( class_exists( '\\WPBakeryShortCodesContainer' ) ) {
class WPBakeryShortCode_Your_Gallery extends \WPBakeryShortCodesContainer {}
}
}
More: Defining multiple namespaces in the same file
Upvotes: 2