Skip to content

Instantly share code, notes, and snippets.

View gwin's full-sized avatar

Greg Winiarski gwin

View GitHub Profile
@gwin
gwin / cowe-trigger-navigation-thumbnails.php
Created November 17, 2023 12:37
Cowe Trigger Navigation Thumbnails
<?php
add_action( "wp_footer", function() {
if( ! is_singular( 'advert' ) ) {
return;
}
?>
<script type="text/javascript">
jQuery(function($) {
$(".my-trigger-thumbnails").on("click", function(e) {
<?php
add_shortcode("current_user_id", "current_user_id");
function current_user_id() {
$user = wp_get_current_user();
if( isset( $user->ID ) ) {
return $user->ID;
} else {
return "0";
<?php
add_filter( "adverts_form_load", "my_adverts_form_load" );
function my_adverts_form_load( $form ) {
if( $form['name'] != "advert" ) {
return $form;
}
foreach( $form["field"] as $key => $field ) {
if( in_array($field["name"], array("adverts_price", "adverts_location", "adverts_phone") ) ) {
function wpadverts_mal_save_advert( $post_ID, $post, $update ) {
if( !isset( $_POST ) || empty( $_POST ) ) {
return;
}
include_once ADVERTS_PATH . '/includes/class-form.php';
$form = new Adverts_Form;
$form->load( Adverts::instance()->get( "form_mal" ) );
<?php
// Assign a filter
add_filter( 'wphd_file_upload', 'my_wphd_file_upload' );
/**
* Check if uploaded file extension is valid.
*
* This function is executed using 'wphd_file_upload' filter,
* it stops file upload using die() if incorrect file type is sent
<?php
add_filter("wpjb_form_init_alert", "my_form_init_alert");
function my_form_init_alert($form) {
$e = $form->create("frequency", "select");
$e->addOption("1", "1", "Daily");
$e->addOption("2", "2", "Weekly");
$e->addClass("wpjb-widget-alert-frequency");
$form->addElement($e, "alert");
@gwin
gwin / wpadverts-enable-comments.php
Created August 31, 2015 07:16
Enable comments in Adverts
<?php
add_action("adverts_post_type", "enable_adverts_comments");
add_action("adverts_insert_post", "enable_adverts_comments_check");
add_action("adverts_update_post", "enable_adverts_comments_check");
function enable_adverts_comments( $args ) {
$args["supports"][] = "comments";
return $args;
@gwin
gwin / wpadverts-custom-fields-api.php
Created June 7, 2015 15:57
WORK IN PROGRESS Explains Adverts Forms API
<?php
/**
* Plugin Name: [Adverts] Custom Fields API
* Version: 1.0
* Author: Greg Winiarski
* Description: This plugin explains how to create custom fields for Add Advert form.
*/
add_filter( "adverts_form_load", "my_adverts_form_load" );
@gwin
gwin / wpadverts-custom-slugs.php
Last active August 29, 2015 14:22
Customize Adverts Custom Post Type and Taxonomy
<?php
/*
* Plugin Name: Customize Adverts slugs.
* Plugin URI: http://wpadverts.com/
* Description: This code snippet/plugin explains how to customize Adverts slugs.
* Author: Greg Winiarski
*
* IMPORTANT NOTE !!!
* In order to use this code either: download this file, then upload it to your wp-content/plugins/ directory
* and activate from wp-admin / Plugins panel (recommended) or copy whole code and upload it to your theme
@gwin
gwin / wphd-action-new-message-tpl.php
Created May 28, 2015 15:39
Action my_wphd_new_message Basci Example
<?php
// Register action, notice fourth argument (3)
// it allows to pass 3 params to callback function
add_action("wphd_new_message", "my_wphd_new_message", 10, 3);
/**
* @var $thread Wphd_Model_Thread Current thread
* @var $message Wphd_Model_Message Current message
* @var $context string One of: "admin", "email-import", "submit-ticket", "tickets"