How to disable specific wordpress plugins from automatic upgrade

Sometime there is need to use some plugins in an application and you have the need to customize it UI or functionality to meet your business requirements.

You install the plugins and make the necessary changes to meet the configuration.

Few week later, you discover that your plugins has lost it custom formatting and the custom workflow due to recent upgrade of the plugins version.
Huhh, now what to do.

Option 1: You may look into your past backupfile to restore the plugins from your back up folder to restore the customized codes. This could be risky or not feasible. For example you may not be having the backup of the plugin , secondly you might get it but may be confused on which version you have to restore, because you had made many backup folder.

Option 2: The recommended way is to disable you customized plugins to get auto upgrade. What you need to do is put this below code in your theme functions.php file.

function disableSpecificPlugins( $value ) {
if( isset( $value->response[‘plugin-folder-name/plugin-name.php’] ) ) {
unset( $value->response[‘plugin-folder-name/plugin-name.php’] );
}
return $value;
}
add_filter( ‘site_transient_update_plugins’, ‘disableSpecificPlugins’ );

Here:

“plugin-folder-name” => plugin folder name

“plugin-name.php” => plugin main file. In most cases , the file name is same as plugin folder name. But it can also be index.hp

Drupal 8 how to get value of the webform submission in webform confirmation twig file

Put the below code in youractivetheme.theme file

/**
* Implements hook_preprocess_HOOK().
*/

function [theme]_preprocess_webform_confirmation(&$vars) {
if ($vars['webform']->id() == 'put your webform id') {
// Set your custom message here
$markup = t('Thank you for your feedback.');
$vars['message']['#markup'] = $markup;
}
}

/// How to customise the message based on the submitted value

/**
* Implements hook_preprocess_HOOK().
*/

function [theme]_preprocess_webform_confirmation(&$vars)
{
if ($vars['webform']->id() == 'put your webform id')
{
// Get the submitted form value using the below command
$submittedFormValues = $vars['webform_submission']->getRawData();
if($submittedFormValues['field_name'] == 'some condition or value'){
$markup = t('display message 1');
}
else
{
$markup = t('display message 2');
}
// Set your custom message here
$vars['message']['#markup'] = $markup;
}
}

Add default blank value for select option in contact form 7 wordpress

Normally when you use contact form 7 plugin , for dropdown select option, there is no option to set blank value for the first option to validate the select field.

For example, what we have in wordpress contact form 7

<select name=”your_field_name”>
<option value=””>—</option>
<option value=”yes”>Yes</option>
<option value=”no”>No</option>
</select>

But in actual scenario, i want to display the label for the first option as “–Select Value–” with empty value.
To make the same change, you can use the dropdown code as below
[select* your_field_name_ class:form-select class:required first_as_label “–Select Value–” “Yes” “No”]

In the above code “first_as_label” is important parameter. It instruct the plugin to use the first option as label with default empty value. So the generated output look as below

<select name=”your_field_name”>
<option value=””>–Select Value–</option>
<option value=”yes”>Yes</option>
<option value=”no”>No</option>
</select>

If you have any queries, you can write back to us or comment in the comment section.

Yii2 how to set custom value for checkbox in gridview widget

In Yii2, while you use gridview widget to display your table data, for performing any operation on the record by selecting the checkbox, gridview assign the value of the first column retrieved from your the result set.

But you need to set some different value to the checkbox, so to do that you can use the below code

GridView::widget([
	'dataProvider' => $dataProvider,
	'filterModel' => $searchModel,
	'columns' => [
		['class' => 'yii\grid\SerialColumn'],
		[
			'class' => '\kartik\grid\CheckboxColumn',
			'checkboxOptions' => function($model, $key, $index, $widget) {
				return ["value" => $model['id']]; // this can be substituted with any column value of your result data
			},
		],
		'name',
		['class' => 'yii\grid\ActionColumn'],
	],
]);

instead of the default one

GridView::widget([
	'dataProvider' => $dataProvider,
	'filterModel' => $searchModel,
	'columns' => [
		['class' => 'yii\grid\SerialColumn'],
		[
			'class' => '\kartik\grid\CheckboxColumn',
			'mergeHeader'=>false
		],
		'name',
		['class' => 'yii\grid\ActionColumn'],
	],
]);

How to search in specific content type in drupal 7

Suppose you have created a content type named as “testimonial”. Now the requirement is to for search for a value “hello” under field name “title” then you can do so by using the below query. Please make sure that you have the “Entity API”  module enabled.

 


$searchkeyword = $_REQUEST['keyword'];
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', '[The machine name for your content type]') // in our case it is "testimonial"
->propertyCondition('title', $searchkeyword)
->propertyCondition('status', 1)
->fieldCondition('field_active_status', 'value', 'active',"=") // here you have to define your where condition on additional fields if required
->execute();

Validate checkbox array and prefill with selected value on validation error in laravel 5

Say for example you have your checkbox field code in your twig file as below:-

@foreach ($serviceList as $servloop)
<div class=”checkbox”>
<label>
<input type=”checkbox” name=”services[]” value=”{{$servloop->service_id}}” {{ ( is_array(old(‘services’)) && in_array($servloop->service_id, old(‘services’)) ) ? ‘checked ‘ : ” }} />
{{$servloop->service_name}}
</label>
</div>
@endforeach

Controller file code

Validation Rule will be as below:-

$rules = [
‘services’ => ‘required|min:1’,  // min:1 means atleast one should be selected
];

$customMessages = [
‘services.required’ => ‘Select the service you will need from us, for and during the Expo.’,
];

 

 

 

How to wrap data column in Gridview widget in yii or yii2 framework

The column which you want to wrap should be added the property called “contentOptions” where you can apply the css property to suits your needs and requirements as below.

[
‘attribute’ => ‘column name’,
‘format’ => ‘html’,
‘noWrap’ => false,
‘mergeHeader’=>true,
‘contentOptions’ => [‘style’ => ‘width: 50%; overflow: scroll;word-wrap: break-word;white-space:pre-line;’],
‘value’=>function ($data) {
return $data[‘question’];
},
],

Set widget label from action file in symfony 1.4

In Action File

==========================================================

$this->form = new youFormclassname();

To set individual Label

$this->form->getWidget(‘widgetname’)->setLabel(‘widget Custom label’);

To set multiple field label

$this->form->getWidgetSchema()->setLabels(array(
‘field_name_1’    => ‘Field 1 Custom Lable’,

‘field_name_2’    => ‘Field 2 Custom Lable’,

}

++++++++++++++++++++++++++++++++++++++

In Template File

============================================

<?php echo $form[‘field_name_1’]->renderLabel() ?>

Create template specific to node in drupal 6

If you want to have custom templates for your node. You can create templates specific to node ID as follows.

Add the below function in your template.php if its not exists.

function yourcurrentthemename_preprocess_node(&$vars, $hook) {
$node = $vars[‘node’];
$vars[‘template_file’] = ‘node-‘. $node->nid;
}

If the function already exists then add the two lines at the beginning of the function.

Then clear the cache.

So if you want to have a custom template for node id 3 (say for example) then create a template with name node-3.tpl.php in your theme directory.

Now you can customise your template as you need.

Keep Rocking…..Enjoy 🙂