__( 'You are not allowed to do that.', '404zen-broken-link-fixer' ) ), 403 ); } check_ajax_referer( 'lgbf_admin_nonce', 'nonce' ); $id = isset( $_POST['link_id'] ) ? absint( $_POST['link_id'] ) : 0; if ( ! $id ) { wp_send_json_error( array( 'message' => __( 'Missing link ID.', '404zen-broken-link-fixer' ) ), 400 ); } return $id; } /** * Sends a uniform response for fixer results. * * @param true|array|WP_Error $result Fixer result. */ private static function respond( $result ) { if ( is_wp_error( $result ) ) { wp_send_json_error( array( 'message' => $result->get_error_message() ), 400 ); } wp_send_json_success( is_array( $result ) ? $result : array() ); } public static function edit_url() { $id = self::guard(); $new_url = isset( $_POST['new_url'] ) ? esc_url_raw( wp_unslash( $_POST['new_url'] ) ) : ''; self::respond( LGBF_Fixer::edit_url( $id, $new_url ) ); } public static function unlink() { self::respond( LGBF_Fixer::unlink( self::guard() ) ); } public static function dismiss() { self::respond( LGBF_Fixer::dismiss( self::guard() ) ); } public static function undismiss() { self::respond( LGBF_Fixer::undismiss( self::guard() ) ); } public static function recheck() { $id = self::guard(); $result = LGBF_Fixer::recheck( $id ); if ( is_wp_error( $result ) ) { self::respond( $result ); } wp_send_json_success( array( 'status' => $result['status'], 'http_status' => (int) $result['http_status'], ) ); } }