Skip to content

Instantly share code, notes, and snippets.

View meloniq's full-sized avatar
👣
Don't overthink!

Andrzej Piotrowski meloniq

👣
Don't overthink!
View GitHub Profile
@meloniq
meloniq / views.php
Created December 3, 2014 13:50
CP 3.4 - Buy Featured example
class MYCP_Buy_Featured extends APP_View {
function condition() {
return is_singular( APP_POST_TYPE ) && ! empty( $_GET['buy_featured'] );
}
function template_redirect() {
appthemes_require_login( array(
'login_text' => __( 'You must first login to feature ad listing.', APP_TD ),
'login_register_text' => __( 'You must first login or <a href="%s">register</a> to feature ad listing.', APP_TD )
@meloniq
meloniq / functions.php
Created December 4, 2014 16:19
Allow PDF's upload on frontend in CP
function childtheme_allow_pdf_files( $config ) {
$config['plupload']['filters']['extensions'] = 'jpg,jpeg,gif,png,pdf';
return $config;
}
add_filter( 'appthemes_plupload_config', 'childtheme_allow_pdf_files', 10, 1 );
add_filter( 'app_plupload_config', 'childtheme_allow_pdf_files', 10, 1 ); // legacy, pre CP 3.4
<?php
/**
* Class that validate and retrieve data from PESEL number in object-oriented style
*
* Example:
* $pesel = new Pesel('85042510356');
* $pesel->getBirthday()->format("d-m-Y")
* $pesel->getSex()
* $pesel->getAge("%a")
nbachiyski = Nikolay Bachiyski <nb@nikolay.bg>
matt = Matt Mullenweg <m@mullenweg.com>
nacin = Andrew Nacin <andrewnacin@gmail.com>
tellyworth = Alex Shiels <alex@automattic.com>
markjaquith = Mark Jaquith <markjaquith@gmail.com>
westi = Peter Westwood <peter@automattic.com>
ryan = Ryan Boren <ryan@boren.me>
convissor = Daniel Convissor <danielc@analysisandsolutions.com>
duck_ = Jon Cave <jon@lionsgoroar.co.uk>
dd32 = Dion Hulse <dd32@dd32.id.au>
@meloniq
meloniq / functions.php
Last active December 19, 2015 10:19
ClassiPress - add sponsored ads to search results
function childtheme_add_ads_to_search() {
if ( ! is_search() )
return;
// display ads
cp_adbox_336x280();
}
add_action( 'appthemes_before_loop', 'childtheme_add_ads_to_search' ); // before listings
add_action( 'appthemes_after_loop', 'childtheme_add_ads_to_search' ); // after listings
@meloniq
meloniq / functions.php
Created July 11, 2013 08:18
QualityControl - disable Assignment and Milestones components
function childtheme_remove_theme_supports() {
remove_theme_support( 'ticket-milestones' );
remove_theme_support( 'ticket-assignment' );
}
add_action( 'after_setup_theme', 'childtheme_remove_theme_supports', 11 );
@meloniq
meloniq / functions.php
Last active December 20, 2015 05:19
Clipper - prevent duplicate import of coupons
<?php
function childtheme_duplicate_check_of_id_field( $post_meta ) {
global $wpdb;
foreach ( $post_meta as $meta_key => $meta_value ) {
if ( $meta_key == 'clpr_id' && ! empty( $meta_value ) ) {
$sql = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'clpr_id' AND meta_value = %s", $meta_value );
if ( $wpdb->get_var( $sql ) ) {
$post_meta[ $meta_key ] = 'delete_this_post';
@meloniq
meloniq / functions.php
Created July 29, 2013 13:58
Disable AppThemes themed login pages
function childtheme_remove_theme_supports() {
remove_theme_support( 'app-login' );
}
add_action( 'appthemes_init', 'childtheme_remove_theme_supports' );
@meloniq
meloniq / functions.php
Created August 5, 2013 14:01
Remove deprecated file on child theme activation
function childtheme_remove_deprecated_files() {
if ( file_exists( get_stylesheet_directory() . '/some-file.php' ) ) {
unlink( get_stylesheet_directory() . '/some-file.php' );
}
}
add_action( 'appthemes_first_run', 'childtheme_remove_deprecated_files' );
@meloniq
meloniq / functions.php
Created October 8, 2013 16:48
Restrict access to 'wp-admin' only to admins
function childtheme_block_wp_admin() {
if ( ! current_user_can( 'manage_options' ) && ! defined( 'DOING_AJAX' ) ) {
wp_redirect( home_url( '/' ) );
}
}
add_action( 'admin_init', 'childtheme_block_wp_admin' );