__( 'Invalid nonce', 'copy-the-code' ) ] ); } if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( [ 'message' => __( 'You do not have permission to edit posts', 'copy-the-code' ) ] ); } $post_title = isset( $post['post_title'] ) ? sanitize_text_field( $post['post_title'] ) : ''; if ( $on_edit ) { $post_id = isset( $post['ID'] ) ? absint( $post['ID'] ) : 0; wp_update_post( [ 'ID' => $post_id, 'post_title' => $post_title, ] ); } else { $post = [ 'post_title' => $post_title, 'post_type' => 'copy-to-clipboard', 'post_status' => 'publish', ]; $post_id = wp_insert_post( $post ); } $meta = [ 'button-text' => $btn_text, 'button-copy-text' => $btn_after_copy_text, 'button-title' => $btn_title, 'copy-format' => $format, 'selector' => $selector, 'button-position' => $position, 'style' => $style_type, ]; foreach ( $meta as $key => $value ) { update_post_meta( $post_id, $key, $value ); } do_action( 'copy_the_code/dashboard/save' ); wp_send_json_success( [ 'message' => __( 'Saved', 'copy-the-code' ), 'edit_post_url' => get_edit_post_link( $post_id ), ] ); } /** * Filters the post edit link. * * @since 3.0.0 * * @param string $link The edit link. * @param int $post_id Post ID. * @param string $context The link context. If set to 'display' then ampersands * are encoded. */ public function edit_post_link( $link, $post_id, $context ) { global $mode; if ( 'list' !== $mode ) { return $link; } $post_type = get_post_type( $post_id ); if ( 'copy-to-clipboard' !== $post_type ) { return $link; } return esc_url( admin_url( 'options-general.php?page=copy-the-code&id=' . $post_id ) ); } /** * Post row actions * * @since 3.0.0 * @return array */ public function post_row_actions( $actions, $post ) { if ( 'copy-to-clipboard' !== $post->post_type ) { return $actions; } $actions['edit'] = sprintf( '%s', esc_url( admin_url( 'options-general.php?page=copy-the-code&id=' . $post->ID ) ), __( 'Edit', 'copy-the-code' ) ); return $actions; } /** * Add menus * * @since 3.0.0 * @return void */ public function add_menus() { if ( ! current_user_can( 'edit_posts' ) ) { return; } add_action( 'admin_menu', array( $this, 'register' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_footer', array( $this, 'hide_menus' ) ); } /** * Hide menus * * @since 3.0.0 * @return void */ function hide_menus() { ?> 'Support Forum', ); if ( ctc_fs()->is_not_paying() ) { $menus['copy-the-code-pricing'] = 'Upgrade'; } else { $menus['copy-the-code-account'] = 'Account'; } $menus = array_merge( $menus, array( 'copy-the-code-contact' => 'Contact Us', 'copy-the-code' => 'Dashboard', ) ); ?> COPY_THE_CODE_URI, 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'copy-the-code' ), 'onEdit' => $id ? true : false, 'editUrl' => $id ? get_edit_post_link( $id ) : admin_url( 'edit.php?post_type=copy-to-clipboard' ), 'post' => $id ? get_post( $id ) : [], 'meta' => $id ? [ 'button-text' => get_post_meta( $id, 'button-text', true ), 'button-copy-text' => get_post_meta( $id, 'button-copy-text', true ), 'button-title' => get_post_meta( $id, 'button-title', true ), 'copy-format' => get_post_meta( $id, 'copy-format', true ), 'button-position' => get_post_meta( $id, 'button-position', true ), 'selector' => get_post_meta( $id, 'selector', true ), 'style' => get_post_meta( $id, 'style', true ), ] : [ 'button-text' => 'Copy', 'button-copy-text' => 'Copied', 'button-title' => 'Copy', 'copy-format' => '', 'button-position' => 'outside', 'selector' => 'pre', 'style' => 'button', ], 'upgradeUrl' => admin_url( 'options-general.php?billing_cycle=annual&page=copy-the-code-pricing' ), 'style' => get_option( 'ctc_default_style', [ 'btn_color' => '#424242', 'btn_bg_color' => '#e1e3e8', 'btn_l_padding' => '20', 'btn_t_padding' => '10', 'btn_r_padding' => '20', 'btn_b_padding' => '10', 'btn_l_margin' => '0', 'btn_t_margin' => '0', 'btn_r_margin' => '0', 'btn_b_margin' => '0', 'btn_tl_radius' => '0', 'btn_tr_radius' => '0', 'btn_br_radius' => '0', 'btn_bl_radius' => '0', 'btn_font_size' => '14', 'btn_line_height' => '18', 'btn_h_color' => '#424242', 'btn_h_bg_color' => '#e1e3e8', 'svg_icon_color' => "#23282d", 'svg_icon_width' => "20", 'svg_icon_t_padding' => "5", 'svg_icon_r_padding' => "5", 'svg_icon_b_padding' => "5", 'svg_icon_l_padding' => "5", 'svg_icon_h_color' => "#23282d", 'cover_color' => '#424242', 'cover_font_size' => '14', ] ), 'nonce' => wp_create_nonce( 'copy-the-code' ), 'elementor' => [ 'blocks' => Blocks::get_blocks(), ] ] ); } /** * Register menus * * @since 3.0.0 * @return void */ public function register() { add_submenu_page( 'options-general.php', __( 'Add New', 'copy-the-code' ), __( ' → Add New', 'copy-the-code' ), 'manage_options', 'copy-the-code', array( $this, 'markup' ) ); } /** * Markup * * @since 3.0.0 * @return void */ public function markup() { ?>