is there a way to put an external link on MediaWiki's footer?
I've tried to add in my localsetting.php this code:
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = function( $sk, &$tpl ) {
$tpl->set( 'aboutus', $sk->footerLink( 'aboutus', 'aboutuspage' ) );
// or to add non-link text:
$tpl->set( 'footertext', 'Text to show in footer' );
$tpl->data['footerlinks']['places'][] = 'aboutus';
return true;
};
But this go to create a Mediawiki's page, and i want to add a link to a contact page. I've modified the MediaWiki:Aboutus and MediaWiki:Aboutuspage pages, but nothing, continue to remind me to a MediaWiki's page.
What do you put in "MediaWiki:Aboutus"? You've to actually create the html link.
Try this
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = function( $sk, &$tpl ) {
$aboutusLink = Html::element( 'a', [ 'href' => $sk->msg( 'aboutus-url' )->escaped() ],
$sk->msg( 'aboutus-label' )->text() ) ;
$tpl->set( 'aboutus', $aboutusLink );
$tpl->data['footerlinks']['places'][] = 'aboutus';
return true;
};
Then on your wiki create the page "MediaWiki:Aboutus-url" and directly place the external link you want you use. Also create the page "MediaWiki:Aboutus-label" and place the text to show on the surface. This allows you to change the url and label by modifying that wiki page messages any time, just as it seems you wanted to do so. If you want to hardcode everything in LocalSettings.php however, then use this:
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = function( $sk, &$tpl ) {
$aboutusLink = Html::rawelement( 'a', [ 'href' => 'https://stackoverflow.com/questions/59427663/modify-footer-in-mediawiki' ],
'Text to show as label' );
$tpl->set( 'aboutus', $aboutusLink );
$tpl->data['footerlinks']['places'][] = 'aboutus';
return true;
};
Related
Please, how can I remove this link from my MediaWiki Special Page?
You need to override SpecialPage::addHelpLink() in your special page class. You could either add a different help link, or just not add one at all.
Check out
languages/i18n/en.json
Line [ 233 ]
I found it:
public function addHelpLink( $to, $overrideBaseUrl = false ) {
global $wgContLang;
$msg = $this->msg( $wgContLang->lc( $this->getName() ) . '' );//-helppage
if ( !$msg->isDisabled() ) {
$helpUrl = Skin::makeUrl( $msg->plain() );
$this->getOutput()->addHelpLink( $helpUrl, true );
} else {
$this->getOutput()->addHelpLink( $to, $overrideBaseUrl );
}
}
I'd just removed -helppage from SpecialPage Class.
I'm using Woocommerce and have edited the Towns/Cities checkout form to include a dropdown of 500 towns and cities that I need users to choose from. How do I implement a searchbox, so that they are able to search for their town?
Basically, how do I create something like this:
for this:
I'm customising that field in Woocommerce, using the following code
add_filter( 'woocommerce_default_address_fields' , 'customize_checkout_city_field' );
function customize_checkout_city_field( $address_fields ) {
// Set HERE the cities (one line by city)
$towns_cities_arr = array(
'0' => __('Select your city', 'my_theme_slug'),
'paris' => 'Paris',
'versailles' => 'Versailles',
'cannes' => 'Cannes',
);
// Customizing 'billing_city' field
$address_fields['city']['type'] = 'select';
$address_fields['city']['class'] = array('form-row-last', 'my-custom-class'); // your class here
$address_fields['city']['label'] = __('Town / city', 'my_theme_slug');
$address_fields['city']['options'] = $towns_cities_arr;
// Returning Checkout customized fields
return $address_fields;
}
This plugin you want to use is Select2
https://select2.github.io/examples.html
You already have the custom class on your field called my-custom-class
All you need to do is import the select2 libs. You can do this in your theme functions.php.
function mytheme_enqueue_custom_scripts() {
wp_enqueue_style( 'select2-css', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css' );
wp_enqueue_script( 'select2-js', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js' );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_custom_scripts' );
And then add some jQuery to initialize it.
<script type="text/javascript">
jQuery(document).ready(function( $ ) {
$(".my-custom-class").select2();
});
</script>
I have a wordpress website and i am using a user role plugin.
I need to create a button that triggers to actions:
Fires the shortcode that assigns the user who clicked the button with a specific user role
Redirect the user to a specific URL to view their dashboard
How can I add the shortcode [groups_join group="Buyers"] and the URL www.xyz.com/buyerdashoboard behind a button?
First, you want to create an ajax function to trigger your shortcode like:
function fire_shortcode(){
do_shortcode( '[groups_join group="Buyers"]' );
die();
}
add_action( 'wp_ajax_fire_shortcode', 'fire_shortcode' );
add_action( 'wp_ajax_nopriv_fire_shortcode', 'fire_shortcode' );
Then in your javascript file add something like:
jQuery('.button-selector').click(function(){
var data = {
action: 'fire_shortcode',
arg1: 'value',
arg2: 'value'
};
var ajaxurl = 'http://yourwebsite.com/wp-admin/admin-ajax.php';
$.post(ajaxurl, data, function(response) {
console.log('Shortcode fired. Redirecting now...');
window.location = "http://redirectwebsite.com/";
});
});
Suppose i've many input type="text" all over a page.
I would like to erase the content of an input whenever i click into it. If i'll change the content, it will save it. If not, it will restore the original value.
I would like to assign this kind of function automatically (on document ready) to all of the input within the page.
Thanks!!!
Simple solution, uses event delegation where parent element (document.body) monitors childrens (all inputs of type text) for events:
focus ( it is triggered when the user focuses on an element )
blur ( event occurs when an element loses focus )
window.addEvent('domready', function() {
document.body.addEvents({
'focus:relay(input[type=text])': function(event, target) {
this.original = this.get( 'value' );
this.set( 'value', '' );
},
'blur:relay(input[type=text])': function(event, target) {
if ( !this.get( 'value' ) ) this.set( 'value', this.original );
}
});
});
Complete beginner here. I want to create a new tab on each page that has a custom action. When clicked, it takes you to a new page which has custom HTML on it along with the text or the original article.
So far I could create a new Tab and could give a custom action mycustomaction to it. I am pasting what I did so far here. Please let me know if I am using the correct hooks etc. and what is a better way to achieve this basic functionality.
So far with their docs I have done this:
#Hook for Tab
$wgHooks['SkinTemplateContentActions'][] = 'myTab';
#Callback
function myTab( $content_actions) {
global $wgTitle;
$content_actions['0'] = array(
'text' => 'my custom label',
'href' => $wgTitle->getFullURL( 'action=mycustomaction' ),
);
return true;
}
#new action hook
$wgHooks['UnknownAction'][] = 'mycustomaction';
#callback
function mycustomaction($action, $article) {
echo $action;
return true;
}
This gives me error:
No such action
The action specified by the URL is invalid. You might have mistyped the URL, or followed an incorrect link. This might also indicate a bug in the software used by yourplugin
What I was doing wrong:
$content_actions[‘0’] should simply be $content_actions[] (minor nitpick)
$content_actions is passed-by-reference, it should be function myTab( &$content_actions ) {}
mycustomaction() should do something along the lines of
if ( $action == ‘mycustomaction’ ) {
do stuff; return false;
}
else {
return true;
}
It should use $wgOut->addHTML() instead of echo
Thanks a lot everyone for your help!