Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

CARLA I. BAMFORD carlaizumibamford

💭
I may be slow to respond.
View GitHub Profile
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 7
Created May 11, 2022
Creating A Custom Wordpress Widget Plugin Vol 7
View Creating A Custom Wordpress Widget Plugin Vol 7
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 6
Created May 11, 2022
Creating A Custom Wordpress Widget Plugin Vol 6
View Creating A Custom Wordpress Widget Plugin Vol 6
public function widget( $args, $instance ) {
extract( $args );
$title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
$text = isset( $instance['text'] ) ? $instance['text'] : '';
$textarea = isset( $instance['textarea'] ) ?$instance['textarea'] : '';
$select = isset( $instance['select'] ) ? $instance['select'] : '';
$checkbox = ! empty( $instance['checkbox'] ) ? $instance['checkbox'] : false;
echo $before_widget;
echo '<div class="widget-text wp_widget_plugin_box">';
if ( $title ) {
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 5
Created May 11, 2022
Creating A Custom Wordpress Widget Plugin Vol 5
View Creating A Custom Wordpress Widget Plugin Vol 5
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
$instance['text'] = isset( $new_instance['text'] ) ? wp_strip_all_tags( $new_instance['text'] ) : '';
$instance['textarea'] = isset( $new_instance['textarea'] ) ? wp_kses_post( $new_instance['textarea'] ) : '';
$instance['checkbox'] = isset( $new_instance['checkbox'] ) ? 1 : false;
$instance['select'] = isset( $new_instance['select'] ) ? wp_strip_all_tags( $new_instance['select'] ) : '';
return $instance;
}
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 4
Last active May 12, 2022
Creating A Custom Wordpress Widget Plugin Vol 4
View Creating A Custom Wordpress Widget Plugin Vol 4
public function form( $instance ) {
$defaults = array(
'title' => '',
'text' => '',
'textarea' => '',
'checkbox' => '',
'select' => '',
);
extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>
<p>
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 3
Created May 11, 2022
Creating A Custom Wordpress Widget Plugin Vol 3
View Creating A Custom Wordpress Widget Plugin Vol 3
public function __construct() {
parent::__construct(
'my_custom_widget',
__( 'My Custom Widget', 'text_domain' ),
array(
'customize_selective_refresh' => true,
)
);
}
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 2
Last active May 11, 2022
Creating A Custom Wordpress Widget Plugin Vol 2
View Creating A Custom Wordpress Widget Plugin Vol 2
class My_Custom_Widget extends WP_Widget {
public function __construct() {
}
public function form( $instance ) {
}
public function update( $new_instance, $old_instance ) {
}
public function widget( $args, $instance ) {
}
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 1
Created May 11, 2022
Creating A Custom Wordpress Widget Plugin Vol 1
View Creating A Custom Wordpress Widget Plugin Vol 1
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
View Echoing HTML In PHP
// In Between PHP
<?php if(condition){ ?>
HTML
<?php } ?>
// In An PHP
if(condition){
echo "HTML";
}
@carlaizumibamford
carlaizumibamford / Making Alternative has_post_thumbnail() In WordPress
Last active May 11, 2022
Making Alternative has_post_thumbnail() In WordPress
View Making Alternative has_post_thumbnail() In WordPress
Instead of
if ( has_post_thumbnail() ) {
}
use this code
$featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
if ( ! empty( $featured_image_url ) ) {
}
@carlaizumibamford
carlaizumibamford / Excluding Posts By Category Name In WordPress
Last active May 11, 2022
Excluding Posts By Category Name In WordPress
View Excluding Posts By Category Name In WordPress
$id = get_cat_id('Category-Sample');
$q = "cat=-" . $id;
query_posts($q);
if (have_posts()) : while (have_posts()) : the_post();