post_type ) && in_array( $screen->post_type, (array) Settings::get( 'post_types' ), true ) && current_user_can( 'edit_posts' ); } /** * Enqueue the built panel (source in src/editor). * * @return void */ public static function enqueue() { if ( ! self::applies() ) { return; } $asset_file = AILSUG_DIR . 'build/index.asset.php'; if ( ! is_readable( $asset_file ) ) { return; } $asset = require $asset_file; wp_enqueue_script( 'ailsug-editor', AILSUG_URL . 'build/index.js', $asset['dependencies'], $asset['version'], true ); wp_set_script_translations( 'ailsug-editor', 'linkcortex', AILSUG_DIR . 'languages' ); wp_enqueue_style( 'ailsug-editor', AILSUG_URL . 'assets/css/editor.css', array(), AILSUG_VERSION ); wp_style_add_data( 'ailsug-editor', 'rtl', 'replace' ); } /** * Classic editor metabox (hidden in the block editor, which has the panel). * * @param string $post_type Post type. * @return void */ public static function metabox( $post_type ) { if ( ! in_array( $post_type, (array) Settings::get( 'post_types' ), true ) || ! current_user_can( 'edit_posts' ) ) { return; } add_meta_box( 'ailsug-metabox', __( 'LinkCortex', 'linkcortex' ), array( __CLASS__, 'render_metabox' ), $post_type, 'side', 'default', array( '__back_compat_meta_box' => true ) ); } /** * Render the metabox. * * @param \WP_Post $post Post. * @return void */ public static function render_metabox( $post ) { global $wpdb; if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; } $row = Indexer::get_row( $post->ID ); if ( ! $row ) { echo '

' . esc_html__( 'This page is added to the link index after it is published.', 'linkcortex' ) . '

'; return; } echo '

' . esc_html__( 'Primary keyword:', 'linkcortex' ) . ' ' . esc_html( '' !== $row['primary_keyword'] ? $row['primary_keyword'] : __( 'not set yet', 'linkcortex' ) ) . '

'; /* translators: 1: links in, 2: links out. */ echo '

' . esc_html( sprintf( __( 'Links to this page: %1$d · Links from this page: %2$d', 'linkcortex' ), (int) $row['inbound_count'], (int) $row['outbound_count'] ) ) . '

'; $t = Activator::tables(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Own table. $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM %i WHERE source_post_id = %d AND status IN ('pending','accepted') ORDER BY score DESC LIMIT 10", $t['suggestions'], $post->ID ), ARRAY_A ); if ( $rows ) { echo ''; } else { echo '

' . esc_html__( 'No link suggestions for this page yet.', 'linkcortex' ) . '

'; } echo '

' . esc_html__( 'Review and apply', 'linkcortex' ) . '

'; echo '

' . esc_html__( 'Save your changes before applying links.', 'linkcortex' ) . '

'; } }