Skip to content

Instantly share code, notes, and snippets.

View emre-edu-tech's full-sized avatar

Media Pons emre-edu-tech

View GitHub Profile
@emre-edu-tech
emre-edu-tech / style.css
Last active October 13, 2024 13:33
This is an example main style.css file to use while developing a classic custom WordPress theme.
/*
Theme Name: Media Pons (Required)
Theme URI: https://media-pons.de/mediapons-base-theme/ (Optional)
Author: Media Pons (Optional)
Author URI: https://media-pons.de/ (Optional)
Description: Custom theme that is a base theme for developing example WordPress themes. This base theme uses Tailwindcss. (Optional)
Version: 1.0.0 (Optional)
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html (Optional)
Text Domain: media-pons (Optional - it should match the theme folder name)
@emre-edu-tech
emre-edu-tech / functions.php
Created August 26, 2024 10:33
Elementor Custom Query Filter using New Search Widget. Search widget supports ajax hitting the Rest Endpoint
<?php
// Here we use tax query but meta_query is also possible
// Unfortunately, there is no way to merge Wordpress default search behaviour, meta_query and tax_query using OR
// that I could find.
// Default behaviour for merging these queries are AND.
// Custom Elementor Query for Search
function mpons_custom_property_search_query($query) {
// Get the search term from the WP_Query object
$search_term = $query->get('s');
@emre-edu-tech
emre-edu-tech / plugin-file.php
Last active October 13, 2024 12:06
Main plugin file description or settings for Wordpress to recognize our plugin.
<?php
/**
* @package MPonsCustomPlugin
*/
/*
Plugin Name: MPons Custom Plugin
Plugin URI: https://mediapons.de
Description: This is an example plugin to practice WordPress Plugin Development.
Version: 1.0.0
@emre-edu-tech
emre-edu-tech / my-custom-plugin.php
Last active August 23, 2024 15:22
Simple Wordpress Plugin and Theme security measures using ABSPATH constant and built-in add_action() function.
<?php
/*
* ABSPATH is a constant in WordPress that stores the absolute path to the WordPress installation directory on the server.
* It is defined in the core wp-config.php file like this:
*/
define('ABSPATH', dirname(__FILE__) . '/');
/*
* PURPOSE OF THE ABSPATH CHECK
* This check below guarantees that no one from outside of the WordPress installation should access this file directly.
@emre-edu-tech
emre-edu-tech / simple-wp-theme-screenshot-generator.php
Created August 23, 2024 10:18
Creating a theme screenshot.png file for Wordpress Theme Development.
<?php
// Check if GD is installed
if (!extension_loaded('gd')) {
die("GD library is not installed. Please enable it in your PHP configuration.");
}
// Set image dimensions and properties
$width = 1200;
$height = 900;
$backgroundColor = [240, 240, 240]; // Light gray background
@emre-edu-tech
emre-edu-tech / functions.php
Created August 22, 2024 21:36
Woocommerce - Show price suffix just on single product template but not on RELATED PRODUCTS section
<?php
// Show price suffix just on single product template but not on related products section
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 10, 2 );
function custom_price_suffix( $price, $product ) {
global $woocommerce_loop;
if(is_product() && ($woocommerce_loop['name'] != 'related')) {
$price = $price . ' <span class="leoshop-price-suffix"> Preis inkl. MwSt. & exkl. Versand</span>';
}
return $price;
}
@emre-edu-tech
emre-edu-tech / functions.php
Created August 19, 2024 14:09
This filter is used with All In One WP Migration plugin to exclude the stated folders from the export.
<?php
add_filter('ai1wm_exclude_content_from_export', function($exclude_filters) {
$exclude_filters[] = 'themes/your-theme-name';
return $exclude_filters;
});
@emre-edu-tech
emre-edu-tech / functions.php
Created August 13, 2024 08:36
Elementor Pro Form Prepopulate Select Field in two forms (One on a page and one on a popup)
<?php
// render elementor forms select item for year_built in Angebotsanfrage form
// rerender the select field using elementor form api
add_filter('elementor_pro/forms/render/item/select', function($item, $index, $form) {
if('vehicle_quote_form' === $form->get_settings_for_display('form_name') || 'vehicle_quote_form_popup' === $form->get_settings_for_display('form_name')) {
if('year_built' == $item['custom_id'] || 'year_built_popup' == $item['custom_id']) {
$item['field_options'] = "Bitte Jahr auswählen|\n";
for($year=date('Y'); $year >= 1970; $year--) {
if($year != 1970) {
$item['field_options'] .= $year . "|" . $year . "\n";
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 06:08
Checking the custom post type mapped capabilities while in development stage.
<?php
// FOR DEVELOPMENT PURPOSES, create a submenu page that displays the capabilities of
// Custom Post Type which is called Topic and this page is only available to ADMINS
add_action('admin_menu', 'mpons_forum_submenu');
function mpons_forum_submenu() {
add_submenu_page(
'tools.php',
__('Media Pons Topic CPT', 'media-pons-forum'),
__('Media Pons Topic CPT', 'media-pons-forum'),
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 06:51
Various code snippets for Crocoblock Plugins
<?php
// Crocoblock Code Snippets
// Jet Smart Filters
// -----------------
// Snippet No: 1
// This code below sorts an array of filters that are related to a Custom Post Type
// Because Custom Post Type values are not coming in alphabetical order, this code is needed
// 601 is the Id of Jet Smart Filter Type
function theme_name_jet_filter_options( $options, $filter_id, $filter ){