wp code utils
<?php
// Debug
//Activate log files in wp-config.php
define( 'WP_DEBUG', true ); //Enabling WP_DEBUG will cause all PHP errors, notices and warnings to be displayed.
define( 'WP_DEBUG_DISPLAY', true ); //controls whether debug messages are shown inside the HTML of pages or not.
define( 'WP_DEBUG_LOG', true ); //Enable Debug logging to the /wp-content/debug.log file
Cod pentru dezactivarea formatarii automate a codului html in redactor text.
// functions.php;
// De inclus la final de cod
remove_filter('the_content' , 'wpauto');
remove_filter('the_excerpt' , 'wpauto');
remove_filter('comment_text' , 'wpauto');
Hook pentru a citi variabilele din admin
function dwwp(){
global $wp_admin_bar;
echo "<pre>";
// var_dump($wp_admin_bar);
print_r($wp_admin_bar);
echo "</pre>";
}
add_action('wp_before_admin_bar_render', 'dwwp');
//-------------- Mail --------------//
add_action('phpmailer_init','send_smtp_email');
function send_smtp_email( $mail ) {
// Define that we are sending with SMTP
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = 'mail.servername.com';
$mail->Port = '587';//'465';
$mail->SMTPAuth = true;//true;
$mail->Username = "";
$mail->Password = "";
$mail->SMTPSecure = "tls";
$mail->IsHTML(true);
}
//-------------- Translate --------------//
//qTranslate
[:en]English Text[:][:de]Deutsch[:]
// obsolete way
<!--:en-->English Text<!--:--><!--:de-->Deutsch<!--:-->
//-------------- Widget --------------//
//Widget, display post by ID
class Show_Contacts extends WP_Widget{
//setup the widget name, description, etc...
public function __construct(){
$widget_ops = array(
'classname' => 'show_contacts_widget',
'description' => 'Show Contacts Widget',
);
parent::__construct( 'show_contacts', 'Show Contacts', $widget_ops );
}
function widget( $args, $instance ) {
// Widget output
// echo "Widget plugin";
$post = get_post(372);
print_r($post);
// echo $post[post_title];
echo $post->post_title;
echo $post->post_type;
echo $post->post_content;
}
}
add_action( 'widgets_init', function(){
register_widget( 'Show_Contacts' );
});
//-------------- Add setting option in "Settings General" panel --------------//
//******* Plugins *******//
//CF7
// [contact-form-7 id="1135" title="Contact form 1" html_class="form-inline"] add class name (html_class="form-inline")
// Disable Auto <p> tag and others https://contactform7.com/controlling-behavior-by-setting-constants/
// add_filter( 'wpcf7_autop_or_not', '__return_false' ); also disable tag p
// .wpcf7 general class tu apply for custom elements
// CF 7 Settigns
define('WPCF7_AUTOP', false);
// ACF
// get field values quantity
count(get_field('field_name'));
//-------------- Localization --------------//
//qTranslate
//Detect page language
//https://qtranslatexteam.wordpress.com/interface/
qtranxf_getLanguage();
qtranxf_getLanguageName();