Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
427 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace ACFQuickEdit\Ajax; | ||
|
||
if ( ! defined('ABSPATH') ) { | ||
die('FU!'); | ||
} | ||
|
||
use ACFQuickEdit\Core; | ||
|
||
class AjaxHandler { | ||
|
||
private $_action = null; | ||
|
||
private $options = null; | ||
|
||
private $_nonce = null; | ||
|
||
/** | ||
* @param string $action | ||
* @param array $args | ||
*/ | ||
public function __construct( $action, $args ) { | ||
|
||
$this->_action = $action; | ||
|
||
$defaults = array( | ||
'public' => false, | ||
'use_nonce' => true, | ||
'capability' => 'manage_options', | ||
'callback' => null, | ||
); | ||
|
||
$this->options = (object) wp_parse_args( $args, $defaults ); | ||
|
||
if ( $this->public ) { | ||
$this->options->capability = false; | ||
add_action( "wp_ajax_nopriv_{$this->action}", array( $this, 'ajax_callback' ) ); | ||
} | ||
|
||
add_action( "wp_ajax_{$this->action}", array( $this, 'ajax_callback' ) ); | ||
} | ||
|
||
public function __get( $prop ) { | ||
if ( $prop === 'nonce' ) { | ||
return $this->get_nonce(); | ||
} else if ( $prop === 'action' ) { | ||
return $this->_action; | ||
} else if ( isset( $this->options->$prop ) ) { | ||
return $this->options->$prop; | ||
} | ||
} | ||
|
||
private function get_nonce() { | ||
if ( is_null( $this->_nonce ) ) { | ||
$this->_nonce = wp_create_nonce( '_nonce_' . $this->action ); | ||
} | ||
return $this->_nonce; | ||
} | ||
|
||
private function verify_nonce( $nonce ) { | ||
return wp_verify_nonce( $nonce, '_nonce_' . $this->action ); | ||
} | ||
|
||
public function ajax_callback() { | ||
$params = wp_parse_args( $_POST, array( | ||
'nonce' => false, | ||
)); | ||
|
||
// check nonce | ||
if ( $this->use_nonce && ( ! $params['nonce'] || ! $this->verify_nonce($_POST['nonce']) ) ) { | ||
return false; | ||
} | ||
// check capability | ||
if ( $this->capability !== false && ! current_user_can( $this->capability ) ) { | ||
return false; | ||
} | ||
|
||
$response = array( 'success' => false ); | ||
|
||
if ( is_callable( $this->callback ) ) { | ||
if ( $result = call_user_func( $this->callback, $params ) ) { | ||
$response = $result; | ||
}; | ||
} | ||
|
||
echo json_encode( $response ); | ||
|
||
exit(); | ||
} | ||
|
||
public function __destruct( ) { | ||
if ( $this->public ) { | ||
remove_action( "wp_ajax_nopriv_{$this->action}", array( $this, 'ajax_callback' ) ); | ||
} | ||
remove_action( "wp_ajax_{$this->action}", array( $this, 'ajax_callback' ) ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace ACFQuickEdit\Compat; | ||
|
||
if ( ! defined('ABSPATH') ) { | ||
die('FU!'); | ||
} | ||
|
||
|
||
use ACFQuickEdit\Core; | ||
|
||
|
||
class Sample extends Core\PluginComponent { | ||
|
||
protected function __construct() { | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function activate(){ | ||
|
||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function deactivate(){ | ||
|
||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function uninstall() { | ||
// remove content and settings | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function upgrade( $new_version, $old_version ) { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.