Skip to content

Commit

Permalink
admin table
Browse files Browse the repository at this point in the history
  • Loading branch information
aurovrata committed Feb 13, 2017
1 parent bb00133 commit aa0e326
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 165 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "assets/cf7-admin-table"]
path = assets/cf7-admin-table
url = https://github.com/aurovrata/cf7-admin-table
111 changes: 1 addition & 110 deletions admin/class-cf7-grid-layout-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,116 +91,7 @@ public function enqueue_scripts($page) {
break;
}
}
/**
* Displays extra column in cf7 post table
* Hooked on 'manage_wpcf7_contact_form_posts_custom_column'
*
* @since 1.0.0
* @param string $column column to display.
* @param string $cf7_post_id cf7 form post id.
**/
function show_cf7_key_column( $column, $cf7_post_id ) {
switch ( $column ) {
case 'cf7_key':
$key = get_post_meta($cf7_post_id, '_smart_grid_cf7_form_key', true);
if ( empty($key) ) {
$key = 'form_'.wp_create_nonce( 'cf7_key_'.$cf7_post_id );
update_post_meta($cf7_post_id, '_smart_grid_cf7_form_key', $key);
}
echo '<span class="cf7-smart-grid cf7-form-key">'.$key.'</span>';
break;
}
}
/**
* Add an extra column to the cf7 post table
* Hooked on 'manage_edit-wpcf7_contact_form_columns'
* @since 1.0.0
* @param Array $columns an array of columsn to show .
* @return Array modified array of columns.
**/
public function add_cf7_key_column($columns){
$columns['cf7_key']=__('Form key','cf7-grid-layout');
return $columns;
}
/**
* Add a quick edit action to the cf7 post table
* Hooked on 'post_row_actions'
*
* @since 1.0.0
* @param string $p1 .
* @return string $p2 .
**/
public function add_cf7_post_action($actions, $post){
//check for your post type
if('trash'==$post->post_status) return array();

if ("wpcf7_contact_form" == $post->post_type){
$actions["inline hide-if-no-js"] = '<a href="#" class="editinline" aria-label="Quick edit &#8220;'.$post->post_title.'&#8221; inline">Quick&nbsp;Edit</a><span class="display-none cf7_post_slug">'.$post->post_name.'</span>';
}
return $actions;
}
/**
*
*
* @since 1.0.0
* @param string $p1 .
* @return string $p2 .
**/
public function quick_edit_box( $column_name, $post_type ) {
if("wpcf7_contact_form" != $post_type){
return;
}
static $printNonce = TRUE;
if ( $printNonce ) {
$printNonce = FALSE;
wp_nonce_field( plugin_basename( __DIR__ ), 'cf7_key_nonce' );
}
switch ( $column_name ) {
case 'cf7_key':
?>
<fieldset class="inline-edit-col-left inline-edit-cf7">
<legend class="inline-edit-legend">Quick Edit</legend>
<div class="inline-edit-col column-<?php echo $column_name; ?>">
<label class="inline-edit-group">
<span class="cf7-smart-grid cf7-form-key-label">Form key</span><input name="_smart_grid_cf7_form_key" type="text"/>
</label>
</div>
</fieldset>
<?php
break;
default:
echo '';
break;
}
}
/**
* Save teh cf7 key
* Hooked on 'save_post'
* @since 1.0.0
* @param string $post_id cf7 form post id.
* @param string $post cf7 form post.
**/
public function save_cf7_key($post_id, $post){
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
return ;
}
// Check permissions
if ( 'wpcf7_contact_form' != $post->post_type ) {
return;
}
if ( !current_user_can( 'edit_post', $post_id ) ){
return;
}

if (isset($_POST['_smart_grid_cf7_form_key']) && ($post->post_type != 'revision')) {
$cf7_key = trim($_POST['_smart_grid_cf7_form_key']);
$cf7_key = str_replace(' ','-',$cf7_key);
$cf7_key = strtolower($cf7_key);
if ($cf7_key){
update_post_meta( $post_id, '_smart_grid_cf7_form_key', $cf7_key);
}
}
}

/**
* Add to the wpcf7 tag generator.
* This function registers a callback function with cf7 to display
Expand Down
47 changes: 0 additions & 47 deletions admin/js/cf7-grid-layout-quick-edit.js

This file was deleted.

1 change: 1 addition & 0 deletions assets/cf7-admin-table
Submodule cf7-admin-table added at 257a6b
9 changes: 1 addition & 8 deletions includes/class-cf7-grid-layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function load_dependencies() {
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-cf7-grid-layout-admin.php';

require_once plugin_dir_path( dirname( __FILE__ ) ) . 'assets/cf7-admin-table/cf7-admin-table-loader.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
Expand Down Expand Up @@ -150,13 +150,6 @@ private function set_locale() {
private function define_admin_hooks() {

$plugin_admin = new Cf7_Grid_Layout_Admin( $this->get_plugin_name(), $this->get_version() );
//add cf7 key column
$this->loader->add_action( 'manage_wpcf7_contact_form_posts_custom_column' , $plugin_admin, 'show_cf7_key_column', 10, 2 );
$this->loader->add_filter('manage_edit-wpcf7_contact_form_columns', $plugin_admin, 'add_cf7_key_column');
//add quick edit
$this->loader->add_filter('post_row_actions', $plugin_admin, 'add_cf7_post_action',20,2);
$this->loader->add_action( 'quick_edit_custom_box', $plugin_admin, 'quick_edit_box', 100, 2 );
$this->loader->add_action('save_post',$plugin_admin, 'save_cf7_key', 10, 2);

//enqueue styles
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
Expand Down

0 comments on commit aa0e326

Please sign in to comment.