first commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
( function( $ ) {
|
||||
|
||||
$( document ).ready( function() {
|
||||
|
||||
var customPostView = elementor.modules.controls.BaseData.extend( {
|
||||
onReady: function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
$( self.el ).find( 'select' ).select2( {
|
||||
ajax: {
|
||||
url: cpConfig.ajaxurl,
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function( params ) {
|
||||
var query = {
|
||||
posts_per_page: 10,
|
||||
q: params.term,
|
||||
paged: params.page || 1,
|
||||
action: 'handler_custom_posts'
|
||||
};
|
||||
|
||||
return query;
|
||||
},
|
||||
processResults: function (data, params) {
|
||||
params.page = params.page || 1;
|
||||
|
||||
return {
|
||||
results: data.results,
|
||||
pagination: {
|
||||
more: data.more
|
||||
}
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
allowClear: true,
|
||||
minimumInputLength: 3,
|
||||
placeholder : 'Select post',
|
||||
templateSelection: function(state){
|
||||
var $state = state;
|
||||
|
||||
if ( !isNaN( state.text.trim() ) ) {
|
||||
$state = $.ajax({
|
||||
global: false,
|
||||
type: "POST",
|
||||
url: cpConfig.ajaxurl,
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: {
|
||||
post_id: state.text.trim(),
|
||||
action: 'handler_post_title'
|
||||
},
|
||||
async:false
|
||||
} ).responseText;
|
||||
} else {
|
||||
$state = state.text;
|
||||
}
|
||||
|
||||
return $state;
|
||||
},
|
||||
} );
|
||||
|
||||
},
|
||||
} );
|
||||
|
||||
elementor.addControlView( 'custom_post', customPostView );
|
||||
} );
|
||||
} )( jQuery );
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Control Custom Post.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
namespace Sight_Elementor\Controls;
|
||||
|
||||
use Elementor\Base_Data_Control;
|
||||
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor Control
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Sight_Control_Custom_Post extends Base_Data_Control {
|
||||
|
||||
/**
|
||||
* Retrieve the control type.
|
||||
*
|
||||
* @return string Control type.
|
||||
*/
|
||||
public function get_type() {
|
||||
return 'custom_post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default settings.
|
||||
*
|
||||
* @return string Default settings.
|
||||
*/
|
||||
protected function get_default_settings() {
|
||||
return array(
|
||||
'label' => esc_html__( 'Custom Post', 'sight' ),
|
||||
'label_block' => true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render field control output in the editor.
|
||||
*/
|
||||
public function content_template() {
|
||||
$control_uid = $this->get_control_uid();
|
||||
?>
|
||||
<div class="elementor-control-field">
|
||||
<label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-title">{{{ data.label }}}</label>
|
||||
|
||||
<div class="elementor-control-input-wrapper">
|
||||
<select name="eae-file-link" class="elementor-control-tag-area" title="{{ data.title }}" data-setting="{{ data.name }}" id="<?php echo esc_attr( $control_uid ); ?>">
|
||||
<# if ( data.controlValue ) { #>
|
||||
<option value="{{ data.controlValue }}" selected="selected">{{{ data.controlValue }}}</div>
|
||||
<# } #>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue control scripts and styles.
|
||||
*
|
||||
* Used to register and enqueue custom scripts and styles used by the control.
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_style( 'elementor-select2' );
|
||||
|
||||
wp_enqueue_script( 'jquery-elementor-select2' );
|
||||
|
||||
wp_register_script(
|
||||
'custom_post',
|
||||
SIGHT_URL . 'elementor/assets/custom-post.js',
|
||||
array( 'jquery', 'jquery-elementor-select2' ),
|
||||
filemtime( SIGHT_PATH . 'elementor/assets/custom-post.js' ),
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'custom_post',
|
||||
'cpConfig',
|
||||
array(
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
)
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'custom_post' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Elementor Integration Help.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
namespace Sight_Elementor;
|
||||
|
||||
/**
|
||||
* Elementor Control Point
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Sight_Elementor_Helper {
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_handler_custom_posts', array( $this, 'handler_custom_posts' ) );
|
||||
add_action( 'wp_ajax_nopriv_handler_custom_posts', array( $this, 'handler_custom_posts' ) );
|
||||
add_action( 'wp_ajax_handler_post_title', array( $this, 'handler_post_title' ) );
|
||||
add_action( 'wp_ajax_nopriv_handler_post_title', array( $this, 'handler_post_title' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom posts.
|
||||
*/
|
||||
public function handler_custom_posts() {
|
||||
|
||||
$posts = array();
|
||||
|
||||
$more = false;
|
||||
|
||||
$search_results = new \WP_Query(
|
||||
array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'post',
|
||||
'ignore_sticky_posts' => 1,
|
||||
's' => sanitize_text_field( $_REQUEST['q'] ),
|
||||
'paged' => sanitize_text_field( $_REQUEST['paged'] ),
|
||||
'posts_per_page' => sanitize_text_field( $_REQUEST['posts_per_page'] ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( $search_results->have_posts() ) {
|
||||
while ( $search_results->have_posts() ) {
|
||||
$search_results->the_post();
|
||||
|
||||
$posts[] = array(
|
||||
'id' => get_the_ID(),
|
||||
'text' => get_the_title(),
|
||||
);
|
||||
|
||||
$more = true;
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json( array(
|
||||
'results' => $posts,
|
||||
'more' => $more,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post title.
|
||||
*/
|
||||
public function handler_post_title() {
|
||||
$post_id = sanitize_text_field( $_REQUEST['post_id'] );
|
||||
|
||||
if ( $post_id ) {
|
||||
echo esc_html( get_the_title( $post_id ) );
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
new Sight_Elementor_Helper();
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Support Elementor.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
namespace Sight_Elementor;
|
||||
|
||||
/**
|
||||
* Class Sight_Elementor_Integraion
|
||||
*/
|
||||
class Sight_Elementor_Integraion {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @since 1.2.0
|
||||
* @access private
|
||||
* @static
|
||||
*
|
||||
* @var Sight_Elementor_Integraion The single instance of the class.
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* Ensures only one instance of the class is loaded or can be loaded.
|
||||
*
|
||||
* @return Sight_Elementor_Integraion An instance of the class.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Сontrols
|
||||
*
|
||||
* Register new Elementor controls.
|
||||
*/
|
||||
public function register_controls() {
|
||||
// Its is now safe to include Сontrols files.
|
||||
require_once SIGHT_PATH . 'elementor/control-custom-post.php';
|
||||
|
||||
// Register Сontrols.
|
||||
\Elementor\Plugin::instance()->controls_manager->register_control( 'custom_post', new Controls\Sight_Control_Custom_Post() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Widgets
|
||||
*
|
||||
* Register new Elementor widgets.
|
||||
*/
|
||||
public function register_widgets() {
|
||||
// Its is now safe to include Widgets files.
|
||||
require_once SIGHT_PATH . 'elementor/widget-portfolio.php';
|
||||
|
||||
// Register Widgets.
|
||||
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Sight_Widget_Portfolio() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin class constructor
|
||||
*
|
||||
* Register plugin action hooks and filters
|
||||
*/
|
||||
public function __construct() {
|
||||
require_once SIGHT_PATH . 'elementor/helper.php';
|
||||
|
||||
// Actions registered.
|
||||
add_action( 'elementor/controls/controls_registered', array( $this, 'register_controls' ) );
|
||||
add_action( 'elementor/widgets/widgets_registered', array( $this, 'register_widgets' ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate Sight_Elementor_Integraion Class.
|
||||
Sight_Elementor_Integraion::instance();
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user