Skip to content

Instantly share code, notes, and snippets.

View saroarhossain57's full-sized avatar
✌️
Coding

Saroar Hossain saroarhossain57

✌️
Coding
View GitHub Profile
@saroarhossain57
saroarhossain57 / PHP Magic Constant
Last active September 27, 2016 18:56
there are eight magical constant that changes depanding on where they are used. here are all magic constant is described
<?php
/*there are eight magical constant that changes depanding on where they are used
__LINE__ The current line number of the file.
__FILE__ The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.
__DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory.
__FUNCTION__ The function name.
@saroarhossain57
saroarhossain57 / Enable shortcode and php code in widget
Created September 27, 2016 19:07
Enable shortcode and php code in widget
/* Enable Shortcode In Wordpress Widget Area */
//Just Paste the code to functions.php file and use shortcode
add_filter('widget_text', 'do_shortcode');
//Enable PHP code in Wordpress widget area
//just paste the code functions.php file and see the result
add_filter('widget_text','execute_php',100);
function remove_default_widgets() {
unregister_widget('widget_class_name');
unregister_widget('another_class_name');
}
add_action( 'widgets_init', 'remove_default_widgets' );
The class names of the all widget is here
WP_Widget_Pages = Pages Widget
WP_Widget_Calendar = Calendar Widget
if( ! function_exists('function_name') ){
function function_name(){
register_widget('class_name');
}
add_action('widgets_init', 'function_name');
}
class class_name extends WP_Widget{
function __construct(){
<?php
$input = '<button name="submit">Delere</button>@copy;';
echo htmlentities($input);
echo '<br>';
?>
<?php
//encode a html code to string for all the charecter
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
<?php
/*
php method chaining is a technic which we can use for make your program more small. for this you have to return all the chained method all the class for this you have to use return $this;
*/
class Calculator{
private $num1;
private $num2;
private $result;
public function Set($num1, $num2){
//this class will output the structure of the bootstrap nav menu.. we can also customize the walker class for our personal use.
class Primary_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
if ( array_search( 'menu-item-has-children', $item->classes ) ) {
$output .= sprintf( "\n<li class='dropdown %s'><a href='%s' class=\"dropdown-toggle\" data-toggle=\"dropdown\" >%s</a>\n", ( array_search( 'current-menu-item', $item->classes ) || array_search( 'current-page-parent', $item->classes ) ) ? 'active' : '', $item->url, $item->title );
} else {
$output .= sprintf( "\n<li %s><a href='%s'>%s</a>\n", ( array_search( 'current-menu-item', $item->classes) ) ? ' class="active"' : '', $item->url, $item->title );
}
}
//Adding a custom metabox
function custom_meta_box_markup($object)
{
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
?>
<div>
<label for="meta-box-text">Text</label>
<input name="meta-box-text" type="text" value="<?php echo get_post_meta($object->ID, "meta-box-text", true); ?>">
//This is for a option panel menu
function mytheme_admin_menu(){
add_menu_page('MyTheme Options Page', 'MyTheme Options', 'manage_options', 'myoptions', 'myoption_cb', get_template_directory_uri() . '/img/search_icon.png');
add_submenu_page('myoptions', 'MyTheme Options Page', 'Generel Options', 'manage_options', 'myoptions', 'myoption_cb');
add_submenu_page('myoptions', 'MyTheme Generel Options', 'Header Options', 'manage_options', 'myoption_generel', 'myoption_generel_cb');
}
add_action('admin_menu', 'mytheme_admin_menu');