| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Extend the Contact Form 7 Table view |
| 10 |
* to add custom Columns |
| 11 |
* |
| 12 |
* @package forge12\contactform7\CF7OptIn |
| 13 |
*/ |
| 14 |
class WordPress_AdminTables_Columns_CF7 |
| 15 |
{ |
| 16 |
/** |
| 17 |
* Admin constructor. |
| 18 |
*/ |
| 19 |
public function __construct() |
| 20 |
{ |
| 21 |
add_action('admin_enqueue_scripts', [$this, 'addAssets']); |
| 22 |
|
| 23 |
add_filter( 'manage_toplevel_page_wpcf7_columns', array( $this, '_onLoadColumn' ), 999, 1 ); |
| 24 |
add_filter( 'wpcf7_custom_default', array( $this, '_onLoadColumnValue' ), 10, 3 ); |
| 25 |
} |
| 26 |
|
| 27 |
public function addAssets(){ |
| 28 |
wp_register_style('f12-cf7-doi-cf7', plugin_dir_url(__FILE__).'assets/admin-cf7.css'); |
| 29 |
wp_enqueue_style('f12-cf7-doi-cf7'); |
| 30 |
} |
| 31 |
|
| 32 |
public function _onLoadColumn( $columns ) { |
| 33 |
$columns['optins'] = __( 'Opt-Ins', 'affiliater' ); |
| 34 |
|
| 35 |
return $columns; |
| 36 |
} |
| 37 |
|
| 38 |
public function _onLoadColumnValue( $html, $item, $column_name ) { |
| 39 |
switch ( $column_name ) { |
| 40 |
case 'optins': |
| 41 |
$this->theOptInsCounter( $item ); |
| 42 |
break; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public function theOptInsCounter($item){ |
| 47 |
$counter = OptIn::get_count($item->id()); |
| 48 |
|
| 49 |
if($counter <= 0){ |
| 50 |
echo esc_attr($counter); |
| 51 |
}else { |
| 52 |
echo '<a href="' . admin_url('admin.php') . '?page=f12-cf7-doubleoptin&cf_form_id=' . esc_attr($counter) . '">' . esc_attr($counter) . '</a>'; |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
} |