Skip to content

Instantly share code, notes, and snippets.

@imjjss
imjjss / custom tax drop-down
Created February 23, 2012 09:19
taxonomy dropdown
<p><?php $syntax = get_object_taxonomies('snip');
$syntaxterms=get_terms($syntax, 'orderby=count&offset=1&hide_empty=0&fields=all');
// var_dump($syntaxterms); die; ?>
<select name='syntax' id='syntax' tabindex="4">
<option value='' <?php if (!count( $names )) echo "selected";?>>Select syntax</option>
<?php foreach ( $syntaxterms as $code ) { echo '<option value="' . $code->slug . '" selected>' . $code->name . '</option>',"\n"; } ?>
</select></p>
@imjjss
imjjss / add favorit post
Created February 24, 2012 17:31
add favorit (not working since bp1.3)
<?php
//For the functions.php file
function my_bp_activity_is_favorite($activity_id) {
global $bp, $activities_template;
return apply_filters( 'bp_get_activity_is_favorite', in_array( $activity_id, (array)$activities_template->my_favs ) );
}
function my_bp_activity_favorite_link($activity_id) {
@imjjss
imjjss / gist:1902287
Created February 24, 2012 17:37
add favorit(coped from web, not tested yet)
1. The first thing I did was find out how BuddyPress adds activities in core code when a blog posts is published. I found out that this is done in bp_blogs_record_activity method of bp-blogs.php. Inside this method I found that I can actually retrieve an activity id of a single blog post by calling the method bp_activity_get_activity_id(). If I have the id of an activity, I can easily add it as my favorite from any place on my site.
2. With the above knowledge in hand, I went to my single.php theme template file and added the following inside my the_post loop:
global $bp;
$activity_id = bp_activity_get_activity_id( array(
'user_id' => $post->author_id,
'type' => 'new_blog_post',
'component' => 'blogs',
'item_id' => 1,
@imjjss
imjjss / gist:2670212
Created May 13, 2012 01:51
filter the name of your blog to be red every time it appears in a post
<?php
add_filter('the_content', 'styleBlogName');
function styleBlogName($content) {
$blogTitle = get_bloginfo('name');
$content = str_replace($blogTitle, '<span style="color: Red;">' . $blogTitle . '</span>', $content);
return $content;
}
?>
@imjjss
imjjss / gist:2670240
Created May 13, 2012 01:58
only want the Admin to be able to post to.Authors not even be able to see it in the category checklist when composing a new post
<?php
// add_filter('get_terms', 'restrict_categories');
function restrict_categories($categories) {
// If we are in the new/edit post page and not an admin, then restrict the categories
$onPostPage = (strpos($_SERVER['PHP_SELF'], 'post.php') || strpos($_SERVER['PHP_SELF'], 'post-new.php'));
if (is_admin() && $onPostPage && !current_user_can('level_10')) {
$size = count($categories);
for ($i = 0; $i < $size; $i++) {
if ($categories[$i]->slug != 'site_news')
@imjjss
imjjss / gist:2670250
Created May 13, 2012 02:00
filter upload dir
<?php
add_filter('upload_dir', 'my_upload_dir');
$upload = wp_upload_dir();
remove_filter('upload_dir', 'my_upload_dir');
funcion my_upload_dir($upload) {
$upload['subdir'] = '/sub-dir-to-use' . $upload['subdir'];
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
@imjjss
imjjss / gist:2691241
Created May 14, 2012 01:50
activation,deactivation, uninstall
<? php
// Class example (inside ex. filename.php):
if ( ! class_exists('YourPluginNameInit' ) ) :
/**
* This class triggers functions that run during activation/deactivation & uninstallation
* NOTE: All comments are just my *suggestions*.
*/
class YourPluginNameInit
{
// Set this to true to get the state of origin, so you don't need to always uninstall during development.
@imjjss
imjjss / gist:2701294
Created May 15, 2012 12:15
insert term
<? php
function insert_term($term, $taxonomy, $args = array()) {
if (isset ( $args ['parent'] )) {
$parent = $args ['parent'];
} else {
$parent = 0;
}
$result = term_exists ( $term, $taxonomy, $parent );
if ($result == false || $result == 0) {
return wp_insert_term ( $term, $taxonomy, $args );
@imjjss
imjjss / gist:2708160
Created May 16, 2012 06:53
add a new column on media page that will allow to "re-attach"
<? php
add_filter("manage_upload_columns", 'upload_columns');
add_action("manage_media_custom_column", 'media_custom_columns', 0, 2);
function upload_columns($columns) {
unset($columns['parent']);
$columns['better_parent'] = "Parent";
return $columns;
@imjjss
imjjss / gist:2716433
Created May 17, 2012 04:44
Front-end editor in WordPress 3.3
<? php
//syntax:
wp_editor( $content, $editor_id, $settings = array() );
// default settings
$settings = array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."