Skip to content

Instantly share code, notes, and snippets.

View gicolek's full-sized avatar

Rafał Gicgier - Certified Codeable Expert Developer gicolek

View GitHub Profile
@gicolek
gicolek / tinymce.php
Last active December 11, 2015 02:08
tinymce.
<?php
// alter tinymce body classes
function mss_tiny_mce_before_init($init_array) {
// accessing global variable post
global $post;
$title = strtolower ($post->post_title);
if($title=='home'){
$init_array['body_class'] = $post->post_title;
}
@gicolek
gicolek / TinyMCE filter - add buttons
Created January 14, 2013 08:09
TinyMCE filter adding buttons
<?php
/**
* Filter TinyMCE styleselect dropdown
*
* @link http://codex.wordpress.org/TinyMCE_Custom_Styles
* @param array $init_array
* @return type
* @hook tiny_mce_before_init
*/
function wp_light_mce_before_init_insert_formats($init_array) {
@gicolek
gicolek / gf.php
Created January 14, 2013 12:11
Gravity Form filters
<?php
static function _modify_gravity_form_lead_detail_table($cat_id) {
global $wpdb;
$lead_details_table_name = RGFormsModel::get_lead_details_table_name();
// get new category name
$new_name = $_POST['name'];
// get db category name
@gicolek
gicolek / gf-ldtable.php
Last active September 2, 2017 16:31
Gravity Forms modify lead detail table
<?php
function update() {
global $wpdb;
// get the lead detail table name
$lead_details_table_name = RGFormsModel::get_lead_details_table_name();
// as stored in the $lead_details_table_name * 10
@gicolek
gicolek / blah.php
Created February 6, 2013 16:47
Handle ajax requests (omitting admin-ajax.php)
<?php
function _foo_handle_ajax_request_for_db_data() {
$path = parse_url (site_url());
if ( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) === $path['path'] . '/sth' ) {
status_header(200);
// do sth
exit ;
@gicolek
gicolek / corg.php
Created March 18, 2013 16:46
Code organization
// sth above
<?php if ( $related_posts->have_posts() ): ?>
<h3> Related Posts</h3>
<ul>
<?php while ( $related_posts->have_posts() ): $related_posts->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
@gicolek
gicolek / ocwps.php
Created March 18, 2013 16:50
Output Control WP Shortcode
<?php
add_shortcode( 'list-posts', 'smoney_list_posts' );
function smoney_list_posts($atts, $content = null) {
extract( shortcode_atts( array(
'numb' => 5,
), $atts ) );
if ( !is_page() ) {
$out = 'This shortcode can only be used on a page';
@gicolek
gicolek / bcwpsc.php
Created March 18, 2013 17:02
How not to code WP shortcodes
<?php
$output = '';
if ( $related_posts->have_posts() ){
$out .= '<h3> Related Posts</h3>';
$out .= '<ul>';
while ( $related_posts->have_posts() ){
$related_posts->the_post();
$out .= '<li><a href="'.the_permalink().'">'.get_the_title().'</a></li>';
@gicolek
gicolek / ajax-form-wp.php
Created March 21, 2013 12:56
Sample Ajax Form WP
<?php
/**
* Validate data and send mail.
*
* @see http://codex.wordpress.org/Function_Reference/wp_mail
* @return {int} Status of message:
* -2 => Invalid data
* -1 => Failed to send
* 1 => OK
@gicolek
gicolek / paginacja.php
Created April 15, 2013 12:36
paginacj
<?php
/**
* Generate the navigation for blog listing pages
*
* @global obj $wp_query
*/
function bg_page_navi($query = null, $paged = null) {
?>
<ul class="page-navi">
<?php