PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / includes / Admin / EditWithButton.php
kirki / includes / Admin Last commit date
views 2 months ago AdminMenu.php 3 weeks ago EditWithButton.php 3 weeks ago PostActions.php 2 months ago
EditWithButton.php
138 lines
1 <?php
2 /**
3 * EditWithButton show on post or custom post type edit page in wp admin page
4 *
5 * @package kirki
6 */
7
8 namespace Kirki\Admin;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 use Kirki\HelperFunctions;
15 use Kirki\Admin\AdminMenu;
16
17
18 /**
19 * EditWithButton Class
20 */
21 class EditWithButton {
22
23
24 /**
25 * Initialize the class
26 *
27 * @return void
28 */
29 public function __construct() {
30 if ( HelperFunctions::user_has_editor_access() ) {
31 add_filter( 'post_row_actions', array( $this, 'filter_post_row_actions' ), 10, 2 );
32 add_filter( 'page_row_actions', array( $this, 'filter_post_row_actions' ), 10, 2 );
33 add_action( 'admin_enqueue_scripts', array( $this, 'add_custom_button_click_functionality' ), 10, 1 );
34 add_action( 'admin_bar_menu', array( $this, 'add_edit_with_kirki_button' ), 100 );
35 }
36 }
37
38 public function add_edit_with_kirki_button( $wp_admin_bar ) {
39 global $post;
40
41 // Ensure we are on the front end and there's a valid post
42 if ( is_admin_bar_showing() && is_singular() && isset( $post->ID ) ) {
43
44 // Check if the editor mode is set to "Kirki" and if the user has edit access
45 $editor_mode = HelperFunctions::is_editor_mode_is_kirki( $post->ID );
46 if ( $editor_mode && HelperFunctions::user_has_post_edit_access( $post->ID ) ) {
47
48 // Fetch the post URLs using your existing helper functions
49 $post_url_arr = HelperFunctions::get_post_url_arr_from_post_id(
50 $post->ID,
51 array(
52 'editor_url' => true,
53 'ajax_url' => true,
54 )
55 );
56
57 // Add the custom button to the admin bar
58 $wp_admin_bar->add_node(
59 array(
60 'id' => 'edit_with_kirki', // Unique ID for the button
61 'title' => '<span class="dashicons-kirki" style="padding: 10px;"></span>&nbsp ' . esc_html__( 'Edit with Kirki', 'kirki' ), // Button content
62 'href' => $post_url_arr['editor_url'], // URL to the XYZ editor
63 'ajaxUrl' => $post_url_arr['ajax_url'],
64 'action' => KIRKI_EDITOR_ACTION,
65 'isEditorModeIsKirki' => $editor_mode,
66 'postId' => get_the_ID(),
67 'nonce' => wp_create_nonce( 'wp_rest' ),
68 )
69 );
70 }
71 }
72 AdminMenu::add_kirki_admin_styles();
73 }
74
75
76
77 /**
78 * Filter Post Row Actions.
79 *
80 * Let the Document to filter the array of row action links on the Posts list table.
81 *
82 * @param array $actions wp actions.
83 * @param \WP_Post $post wp post.
84 *
85 * @return array
86 */
87 public function filter_post_row_actions( $actions, $post ) {
88 $editor_mode = HelperFunctions::is_editor_mode_is_kirki( $post->ID );
89 if ( $editor_mode && HelperFunctions::user_has_post_edit_access( $post->ID ) ) {
90 $editor_url = HelperFunctions::get_post_url_arr_from_post_id( $post->ID, array( 'editor_url' => true ) )['editor_url'];
91 $actions[ 'edit_with_' . 'kirki' ] = sprintf(
92 '<a href="%1$s" style="color:#9353FF;">%2$s</a>',
93 $editor_url,
94 esc_html__( 'Edit with Kirki', 'kirki' )
95 );
96 }
97 return $actions;
98 }
99
100 /**
101 * Add custom link in toolbar and click functionality
102 *
103 * @param string $hook wp hook or page name.
104 *
105 * @return void
106 */
107 public function add_custom_button_click_functionality( $hook ) {
108 global $post;
109
110 if ( 'post-new.php' === $hook || 'post.php' === $hook ) {
111 $version = KIRKI_VERSION;
112 $editor_mode = HelperFunctions::is_editor_mode_is_kirki( get_the_ID() );
113 $post_url_arr = HelperFunctions::get_post_url_arr_from_post_id(
114 get_the_ID(),
115 array(
116 'editor_url' => true,
117 'ajax_url' => true,
118 'rest_url' => true,
119 )
120 );
121 wp_enqueue_script( 'custom_link', KIRKI_ASSETS_URL . 'js/admin/custom-link-in-toolbar.js', array(), $version, true );
122 wp_localize_script(
123 'custom_link',
124 'kirki_admin',
125 array(
126 'postEditURL' => $post_url_arr['editor_url'],
127 'ajaxUrl' => $post_url_arr['ajax_url'],
128 'restUrl' => $post_url_arr['rest_url'],
129 'action' => KIRKI_EDITOR_ACTION,
130 'isEditorModeIsKirki' => $editor_mode,
131 'postId' => get_the_ID(),
132 'nonce' => wp_create_nonce( 'wp_rest' ),
133 )
134 );
135 }
136 }
137 }
138