I am trying to extend a wordpress core class inside my theme's functions.php, & the class I am trying to extend is WP_Customize_Image_Control from class wp-customize-control.php in wp-includes.
It already extends "WP_Customize_Upload_Control".
I would like to allow the .svg mime-type to be uploaded within the theme customizer.
in my theme's functions.php I am adding these lines:
class WP_Customize_Image_Control_SVG extends WP_Customize_Image_Control {
public $extensions = array( 'jpg', 'jpeg', 'gif', 'png', 'svg' );
};
but sadly this breaks everything.
Any help, hints or tips appreciated.
You are close.
/* Extend the Image Control */
class WP_Customize_Image_Control_SVG extends WP_Customize_Image_Control
{
public function __construct( $manager, $id, $args = array() )
{
parent::__construct( $manager, $id, $args );
$this->remove_tab('uploaded');
$this->extensions = array( 'jpg', 'jpeg', 'gif', 'png', 'svg' );
}
}
This goes inside your "customize_register" action
Just make sure you're registering this one instead of the normal image control.
Related
I am currently trying to copy Elementor's plugin Media control to do some adjustments to it in wordpress. I tried copying the control from \Elementor\Control_Media changing the name of the class and this method:
class Control_Custom_Media extends \Elementor\Control_Base_Multiple {
...
public function get_type() {
return 'custommedia';
}
}
Then registered it
function register_custom_controls($controls) {
include 'control-custom-media.php';
Plugin::instance()->controls_manager->register_control( 'custommedia', new Control_Custom_Media() );
}
add_action( 'elementor/controls/controls_registered', 'register_custom_controls');
Finally I created a widget with that control
protected function _register_controls() {
...
$this->add_control(
'image',
[
'label' => __( 'Test', 'custom-plugin' ),
'type' => 'custommedia',
'default' => [
'url' => \Elementor\Utils::get_placeholder_image_src(),
],
]
);
...
}
But I can't seem to make it work. The field appears on the elementor sidebar but once I click to open the media library, it doesn't work. Checked the events and the one that fires the 'openFrame' event is not bind for some reason?
To test if the media control was working I added it after and that one works
What I could be doing wrong?
Thanks in advance
I ended up extending the Media control for my custom control and add it as a control view.
var customMediaView = elementor.modules.controls.Media.extend({
onReady: function () {
/* do stuff */
}
});
elementor.addControlView('customMediaView', customMediaView);
On the enqueue method
wp_register_script( 'custommedia-control', plugins_url('/custommedia-control.js', __DIR__), [ 'elementor-editor' ], '1.0.0', true );
wp_enqueue_script( 'custommedia-control' );
I am trying to extend the File/Image class to recognize .mp4 files as Video class rather than as File class.
My code is:
VideoExtension.php
class VideoExtension extends DataExtension
{
private static $db = array(
'IsAnimation' => 'Boolean',
'AssociatedStaticPage' => 'Text',
'BarCode' => 'Text'
);
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab('Root.Main', TextField::create('BarCode', 'Bar Code'));
$fields->addFieldToTab('Root.Main', TextField::create('AssociatedStaticPage', 'URL'));
}
}
mysite/_config/config.yml
Name: mysite
After:
- 'framework/*'
- 'cms/*'
---
# YAML configuration for SilverStripe
# See http://doc.silverstripe.org/framework/en/topics/configuration
# Caution: Indentation through two spaces, not tabs
SSViewer:
theme: 'simple'
File:
extensions:
- VideoExtension
With this I get an error. If I change File to Image in the config.yml it works. I want this so I can add custom fields in the Admin section.
Any help is appreciated.
I believe you want to create a class that extends File instead of creating a DataExtension. Something like the following:
class Video extends File {
private static $allowed_extensions = array(
'mpeg', 'mpg', 'mp4', 'm1v', 'mp2', 'mpa', 'mpe', 'ifo',
'vob','avi', 'wmv', 'asf', 'm2v', 'qt', 'ogv', 'webm'
);
private static $db = array(
'IsAnimation' => 'Boolean',
'AssociatedStaticPage' => 'Text',
'BarCode' => 'Text'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', TextField::create('BarCode', 'Bar Code'));
$fields->addFieldToTab('Root.Main', TextField::create('AssociatedStaticPage', 'URL'));
return $fields;
}
}
We then need to set this class to be used for these file extensions by setting the File class_for_file_extension. We can do this is in our mysite/_config/config.yml file:
File:
class_for_file_extension:
'mpeg': 'Video'
'mpg': 'Video'
'mp4': 'Video'
'm1v': 'Video'
'mp2': 'Video'
'mpa': 'Video'
'mpe': 'Video'
'ifo': 'Video'
'vob': 'Video'
'avi': 'Video'
'wmv': 'Video'
'asf': 'Video'
'm2v': 'Video'
'qt': 'Video'
'ogv': 'Video'
'webm': 'Video'
I am trying to translate a Tab and a TextField but it is not translating at the moment. Current setup as per below:
Locale is set in _config.php - I have flushed.
i18n::set_locale('de_DE');
mysite/lang/de.yml
de:
Page:
FULLNAME: 'Testing this'
CONTACTDETAILS: 'Root.Trying to change to this text'
Page.php
<?php
class Page extends SiteTree {
private static $db = array(
'FullName' => 'Varchar(255)'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldsToTab(_t('Page.CONTACTDETAILS', 'Root.ContactDetails'), array(
TextField::create('FullName', _t('Page.FULLNAME', 'Full Name'))
));
return $fields;
}
}
But the text is not being translated it just shows in English. What am I doing wrong?
The CMS uses the currently logged in user's Locale field for translations afaik. You can change a user's locale to de_DE (whereupon your translations should work) by going to Security, selecting the user, and changing Interface Language to German (Germany).
It's also possible to set the locale inside your getCMSFields if you only want the fields in there to get translated:
public function getCMSFields()
{
$oldLocale = i18n::get_locale();
i18n::set_locale('de_DE');
$fields = parent::getCMSFields();
$fields->addFieldsToTab(_t('Page.CONTACTDETAILS', 'Root.ContactDetails'), array(
TextField::create('FullName', _t('Page.FULLNAME', 'Full Name'))
));
i18n::set_locale($oldLocale);
return $fields;
}
The Locale of new users created through the CMS will be set based on the Locale of the user that is creating them.
I'm having trouble figuring out how to display a template that lives inside of my custom module.
This is what I have:
<?php
function brl_footer_theme($existing, $type, $theme, $path) {
$theme = array();
$theme['brl_footer'] = array(
'render element' => 'content',
'template' => 'brl-footer',
'path' => drupal_get_path('module', 'brl_footer'),
);
return $theme;
}
/**
* Implements hook_block_info().
*/
function brl_footer_block_info() {
$blocks = array();
$blocks['brl_footer'] = array(
'info' => t('Custom Footer'),
);
return $blocks;
}
I have a template file in the module called brl-footer.tpl.php
It contains very basic HTML:
<h1>here's some content</h1>
Is it possible to display my template through the custom block 'brl_footer' that's being created?
The custom block is active and has been assigned to the proper region.
Any help on this would be hugely appreciated -
You'll need to implement hook_block_view to define what gets displayed in your block.
Also, if your template is just static content, you don't need to specify a "render element" or "variables" for your theme hook (though you could still make variables in a preprocess function).
I created this function to show dataobjects as page
// DISPLAY ITEM AS PAGE
public function produkt(SS_HTTPRequest $request) {
$urlSegment = $this->request->param('URLSegment');
$item = ShopItem::get()->filter('URLSegment', $urlSegment)->first();
if( $item ) {
$data = array(
'Item' => $item,
'Title' => $item->Title,
'Parent' => Shop::get()->First(),
'Controller' => $this,
'URLSegment' => $item->URLSegment
);
return $this->customise($data)->renderWith(array('ShopItem', 'Page'));
} else {
return $this->httpError(404);
}
}
That's my YML File
---
Name: productRoute
After: 'framework/routes#coreroutes'
---
Director:
rules:
'onlineshop//produkt/$URLSegment!': 'Shop_Controller'
The function is on my Shop_Controller. and the Dataobjects are shown under onlineshop/produkt/blablabla-1
That works fine but in the navigation the link "Onlineshop" is not highlight as section.
I think I need to put the "LinkinMode()" function in my dataobject. But I don't know what the function should contain. return section current or link doesen't work.
Can someone help me?
thank you in advance
You just want to highlight "Onlineshop" which is a Page in your SiteTree, right?
If so, just override the LinkingMode() method inside that Class (extending SiteTree) and make it return section or current for your custom route being active...
You would just need that method on the DataObject itself if you would like to show each DataObject in the Navigation and highlighted when active.
see http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/