WP init
This commit is contained in:
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
.elementskit-add-template-button{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;width:40px;height:40px;padding:0;background-color:#f2295b;border-width:0;border-radius:30px;vertical-align:-2px;cursor:pointer}.elementskit-add-template-button>img{display:block;width:16px;height:16px!important;margin:12px auto 0}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 446 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.7 KiB |
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Modules\Layout_Manager;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Init {
|
||||
private $dir;
|
||||
private $url;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
// get current directory path.
|
||||
$this->dir = dirname( __FILE__ ) . '/';
|
||||
|
||||
// get current module's url.
|
||||
$this->url = \ElementsKit_Lite::plugin_url() . 'modules/layout-manager/';
|
||||
|
||||
// print views and tab variables on footer.
|
||||
add_action( 'elementor/editor/footer', array( $this, 'script_variables' ) );
|
||||
|
||||
// enqueue editor js for elementor.
|
||||
add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'editor_scripts' ), 1 );
|
||||
|
||||
// enqueue editor css.
|
||||
add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'editor_styles' ) );
|
||||
|
||||
// enqueue modal's preview css.
|
||||
add_action( 'elementor/preview/enqueue_styles', array( $this, 'preview_styles' ) );
|
||||
|
||||
new Layout_List_Api();
|
||||
new Layout_Import_Api();
|
||||
}
|
||||
|
||||
public function editor_scripts() {
|
||||
wp_enqueue_script( 'ekit-layout-library-script', $this->url . 'assets/js/ekit-layout-library.js', array( 'jquery', 'wp-element' ), \ElementsKit_Lite::version(), true );
|
||||
}
|
||||
|
||||
public function editor_styles() {
|
||||
wp_enqueue_style( 'ekit-layout-library-style', $this->url . 'assets/css/ekit-layout-library.css', array(), \ElementsKit_Lite::version() );
|
||||
}
|
||||
|
||||
public function preview_styles() {
|
||||
wp_enqueue_style( 'ekit-layout-library-preview-style', $this->url . 'assets/css/preview.css', array(), \ElementsKit_Lite::version() );
|
||||
}
|
||||
|
||||
public function script_variables() { ?>
|
||||
<script type="text/javascript">
|
||||
|
||||
var ElementsKitLayoutManager = {
|
||||
"defaultTab": "pages",
|
||||
"nonce": "<?php echo esc_attr(wp_create_nonce( 'wp_rest' )); ?>",
|
||||
"buttonIcon": "<?php echo esc_url( \ElementsKit_Lite\Libs\Framework\Attr::get_url() . 'assets/images/ekit_icon.svg' ); ?>",
|
||||
"infoIcon": "<?php echo esc_url( $this->url . 'assets/img/info.svg' ); ?>",
|
||||
"apiUrl": "<?php echo esc_url( get_rest_url( null, 'elementskit/v1/layout-manager-api/layout_list' ) ); ?>",
|
||||
"hasPro": <?php echo ( \ElementsKit_Lite::package_type() == 'free' ? 'false' : 'true' ); ?>,
|
||||
"licenseStatus": "<?php echo esc_attr( \ElementsKit_Lite::license_status() ); ?>",
|
||||
"links": {
|
||||
"go_premium": "https://wpmet.com/elementskit-pricing",
|
||||
"active_license": "<?php echo esc_url( admin_url() ); ?>admin.php?page=elementskit-license"
|
||||
},
|
||||
"banner": {
|
||||
"enable": true,
|
||||
"img": "<?php echo esc_url( $this->url . 'assets/img/banner.jpg' ); ?>",
|
||||
"link": "https://wpmet.com/layout-manager-banner",
|
||||
"target": '_blank'
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Modules\Layout_Manager;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
|
||||
|
||||
class Layout_Import_Api {
|
||||
public function __construct() {
|
||||
add_action( 'elementor/ajax/register_actions', array( $this, 'register_ajax_actions' ) );
|
||||
}
|
||||
|
||||
public function register_ajax_actions( Ajax $ajax ) {
|
||||
$ajax->register_ajax_action(
|
||||
'get_elementskit_template_data',
|
||||
function( $data ) {
|
||||
if ( ! current_user_can( 'edit_posts' ) ) {
|
||||
throw new \Exception( 'Access Denied' );
|
||||
}
|
||||
|
||||
if ( ! empty( $data['editor_post_id'] ) ) {
|
||||
$editor_post_id = absint( $data['editor_post_id'] );
|
||||
|
||||
if ( ! get_post( $editor_post_id ) ) {
|
||||
throw new \Exception( esc_html__( 'Post not found', 'elementskit-lite' ) );
|
||||
}
|
||||
|
||||
\Elementor\Plugin::instance()->db->switch_to_post( $editor_post_id );
|
||||
}
|
||||
|
||||
if ( empty( $data['template_id'] ) ) {
|
||||
throw new \Exception( esc_html__( 'Template id missing', 'elementskit-lite' ) );
|
||||
}
|
||||
|
||||
$result = $this->get_template_data( $data );
|
||||
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function get_template_data( array $args ) {
|
||||
$source = new Library_Source();
|
||||
$data = $source->get_data( $args );
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Modules\Layout_Manager;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Layout_List_Api extends \ElementsKit_Lite\Core\Handler_Api {
|
||||
|
||||
public function config() {
|
||||
$this->prefix = 'layout-manager-api';
|
||||
}
|
||||
|
||||
public function get_layout_list() {
|
||||
$param = array_merge( \ElementsKit_Lite::license_data(), $_GET, array( 'action' => 'get_layout_list' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Passed in elementor's hook for get url which has processed the nonce already.
|
||||
|
||||
$response = wp_remote_get(
|
||||
\ElementsKit_Lite::api_url() . 'layout-manager-api/?' . http_build_query( $param ),
|
||||
array(
|
||||
'timeout' => 30,
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return json_decode( wp_remote_retrieve_body( $response ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Modules\Layout_Manager;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
use Elementor\TemplateLibrary\Source_Base;
|
||||
|
||||
class Library_Source extends Source_Base {
|
||||
|
||||
public function get_id() {
|
||||
return 'elementskit-layout-manager';
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return __( 'ElementsKit Layout Manager', 'elementskit-lite' );
|
||||
}
|
||||
|
||||
public function register_data() {}
|
||||
|
||||
public function save_item( $template_data ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot save template to a elementskit layout manager' );
|
||||
}
|
||||
|
||||
public function update_item( $new_data ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot update template to a elementskit layout manager' );
|
||||
}
|
||||
|
||||
public function delete_template( $template_id ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot delete template from a elementskit layout manager' );
|
||||
}
|
||||
|
||||
public function export_template( $template_id ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot export template from a elementskit layout manager' );
|
||||
}
|
||||
|
||||
public function get_items( $args = array() ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_item( $template_id ) {
|
||||
$templates = $this->get_items();
|
||||
|
||||
return $templates[ $template_id ];
|
||||
}
|
||||
|
||||
public function request_template_data( $template_id ) {
|
||||
if ( empty( $template_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$body = array(
|
||||
'home_url' => trailingslashit( home_url() ),
|
||||
'plugin_version' => \ElementsKit_Lite::version(),
|
||||
);
|
||||
|
||||
$query = array_merge(
|
||||
array(
|
||||
'action' => 'get_layout_data',
|
||||
'layout_id' => $template_id,
|
||||
),
|
||||
\ElementsKit_Lite::license_data()
|
||||
);
|
||||
|
||||
$request_url = \ElementsKit_Lite::api_url() . 'layout-manager-api/' . '?' . http_build_query( $query );
|
||||
$response = wp_remote_get(
|
||||
$request_url,
|
||||
array(
|
||||
'timeout' => 30,
|
||||
)
|
||||
);
|
||||
|
||||
return wp_remote_retrieve_body( $response );
|
||||
}
|
||||
|
||||
public function get_data( array $args, $context = 'display' ) {
|
||||
$data = $this->request_template_data( $args['template_id'] );
|
||||
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
if ( empty( $data ) || empty( $data['content'] ) ) {
|
||||
throw new \Exception( esc_html__( 'Template does not have any content', 'elementskit-lite' ) );
|
||||
}
|
||||
|
||||
$data['content'] = $this->replace_elements_ids( $data['content'] );
|
||||
$data['content'] = $this->process_export_import_content( $data['content'], 'on_import' );
|
||||
|
||||
$post_id = $args['editor_post_id'];
|
||||
$document = \Elementor\Plugin::instance()->documents->get( $post_id );
|
||||
|
||||
if ( $document ) {
|
||||
$data['content'] = $document->get_elements_raw_data( $data['content'], true );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user