map_vc_shortcodes(); vc_add_shortcode_param( 'depicter_slider_buttons', [ $this, 'slider_buttons_markup' ] ); add_action( 'vc_edit_form_fields_after_render', [ $this, 'add_scripts' ] ); } } /** * Add depicter shortcode to wpbakery * * @return void */ public function map_vc_shortcodes() { vc_map([ 'name' => __( 'Depicter', 'depicter' ), 'base' => 'depicter', 'category' => __( 'Content', 'depicter' ), 'description' => __( 'Make animated and interactive slider', 'depicter' ), 'icon' => \Depicter::core()->assets()->getUrl() . '/resources/images/svg/logo-without-text.svg', 'params' => $this->get_fields() ]); } /** * get fields * * @return array * @throws \Exception */ public function get_fields() { $list = [ __( 'Select Slider', 'depicter' ) => 0 ]; $documents = \Depicter::documentRepository()->select( ['id', 'name', 'status'] )->orderBy('modified_at', 'DESC')->findAll()->get(); $documents = $documents ? $documents->toArray() : []; foreach( $documents as $document ) { $list[ "[#{$document['id']}]: " . $document['name'] ] = $document['id']; } $fields = [ [ 'type' => 'dropdown', 'class' => '', 'admin_label' => true, 'heading' => __( 'Select Slider', 'depicter' ), 'param_name' => 'id', 'value' => $list, ] ]; if ( current_user_can( 'access_depicter' ) ) { foreach( $documents as $document ) { $fields[] = [ 'type' => 'depicter_slider_buttons', 'class' => '', 'param_name' => 'slider_control_buttons_' . $document['id'], 'isPublishedBefore' => \Depicter::documentRepository()->isPublishedBefore( $document['id'] ), 'documentStatus' => $document['status'], 'documentID' => $document['id'] ]; } } return $fields; } /** * Add script to the end of editor fields after render * * @return void */ public function add_scripts() { if ( empty( $_POST['tag'] ) || $_POST['tag'] != 'depicter' ) { return; } echo ''; } /** * Get slider buttons control field markup * * @param array $settings * @param string $value * @return string */ public function slider_buttons_markup( $settings, $value ) { return \Depicter::view('admin/notices/builders-draft-notice')->with('view_args', $settings)->toString(); } } new Module();