Skip to content

Instantly share code, notes, and snippets.

@badabingbreda
Last active April 25, 2018 17:51
Show Gist options
  • Select an option

  • Save badabingbreda/a4c4096d58413fc71bf881d15c57e9a7 to your computer and use it in GitHub Desktop.

Select an option

Save badabingbreda/a4c4096d58413fc71bf881d15c57e9a7 to your computer and use it in GitHub Desktop.
Oxygenbuilder2.0 Add "Edit with Oxygen" button to page, post, ct_template and others
<?php
/**
* Add an 'edit with Oxygen' button on set posttypes, use filter ct_post_types to add to the array;
*/
// add a filter to add my cpt's
add_filter( 'ct_post_types', 'example_add_my_custom_post_types' , 10 ,1 );
// merge arrays
function example_add_my_custom_post_types( $post_types ) {
// add these post-types:
$new_post_types = array( 'books' );
return array_merge( $post_types, $new_post_types) ;
}
// add action to current_screen because that's where we will get info on the current post_type
add_action('current_screen' , 'ct_add_action_edit_oxygen' , 10, 1);
/**
* Add the edit with oxygen action on filtered my_post_types
* @return [type] [description]
*/
function ct_add_action_edit_oxygen () {
// set the baseline for the post_types where we want to add the 'edit with oxygen'
$my_post_types = apply_filters( 'ct_post_types', array( 'page', 'post', 'ct_template' ), $array = array() );
// get current screen info
$current_screen = get_current_screen();
// if current post_type is found in our set $my_post_types
if ( in_array($current_screen->post_type, $my_post_types) ) {
// either one is good, both is better
add_filter( "post_row_actions" , 'show_post_row_actions', 10, 2 );
add_filter( "page_row_actions" , 'show_post_row_actions', 10, 2 );
}
}
/**
* Filter that adds an action-button to the row_actions to enable direct editing
* @param [type] $actions [description]
* @param [type] $post [description]
* @return [type] [description]
*/
function show_post_row_actions ( $actions , $post ) {
$meta = get_post_meta($post->ID);
$color = array_key_exists( 'ct_builder_shortcodes', $meta)?'green':'lightgrey';
$actions['oxygen'] = '<div style="display:inline-block;border:2px solid '.$color.';border-radius:50%;width:3px;height:3px;margin:2px;margin-right:5px;background-color:'.$color.';"></div><a href="'.get_permalink($post->ID).'?ct_builder=true&ct_inner=true">'.__('Edit with Oxygen', 'textdomain').'</a>';
//var_dump( $post);
return $actions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment